@finatic/client 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var pRetry = require('p-retry');
4
- var pino = require('pino');
5
- var NodeCache = require('node-cache');
6
4
  var z = require('zod');
7
5
  var globalAxios = require('axios');
8
6
 
@@ -93,14 +91,12 @@ async function retryApiCall(fn, options = {}, config) {
93
91
  }
94
92
 
95
93
  /**
96
- * Structured logger utility with browser-safe fallback (Phase 2C).
94
+ * Structured logger utility with browser-safe console logging (Phase 2C).
97
95
  *
98
96
  * Generated - do not edit directly.
99
97
  *
100
- * This logger automatically falls back to console-based logging when pino fails
101
- * in browser environments (Vite, Next.js, etc.).
98
+ * This logger uses browser console APIs for all logging in browser environments.
102
99
  */
103
- // @ts-ignore - pino types available via @types/pino
104
100
  let _loggerInstance = null;
105
101
  /**
106
102
  * Get environment variable from various sources (browser and Node.js).
@@ -145,30 +141,6 @@ function isProduction() {
145
141
  return true;
146
142
  return false;
147
143
  }
148
- /**
149
- * Detect if we're in a browser environment.
150
- */
151
- function isBrowser() {
152
- // Check for window object (browser)
153
- if (typeof window !== 'undefined') {
154
- return true;
155
- }
156
- // Check for globalThis in browser-like environments
157
- if (typeof globalThis !== 'undefined') {
158
- // In browsers, process might be polyfilled but process.stdout won't exist
159
- try {
160
- const proc = globalThis.process;
161
- if (proc && typeof proc.stdout === 'undefined') {
162
- return true;
163
- }
164
- }
165
- catch {
166
- // If we can't check, assume browser if window exists
167
- return typeof window !== 'undefined';
168
- }
169
- }
170
- return false;
171
- }
172
144
  /**
173
145
  * Get or create a logger instance with browser-safe fallback.
174
146
  */
@@ -176,36 +148,13 @@ function getLogger(config) {
176
148
  if (_loggerInstance) {
177
149
  return _loggerInstance;
178
150
  }
179
- // In browser environments, skip pino entirely and use browser-safe logger
180
- if (isBrowser()) {
181
- return getBrowserSafeLogger(config);
182
- }
183
- // Try to use pino first (Node.js environments)
184
- try {
185
- const logLevel = (config?.logLevel || getEnvVar('FINATIC_LOG_LEVEL') || 'error');
186
- const pinoConfig = {
187
- level: logLevel === 'silent' ? 'silent' : logLevel,
188
- ...(config?.structuredLogging !== false && {
189
- formatters: {
190
- level: (label) => {
191
- return { level: label };
192
- },
193
- },
194
- timestamp: true,
195
- }),
196
- };
197
- _loggerInstance = pino(pinoConfig);
198
- return _loggerInstance;
199
- }
200
- catch (error) {
201
- // Fallback to browser-safe logger if pino fails
202
- return getBrowserSafeLogger(config, error);
203
- }
151
+ // Client SDK always uses browser-safe logger (no pino)
152
+ return getBrowserSafeLogger(config);
204
153
  }
205
154
  /**
206
- * Browser-safe logger fallback for environments where pino fails.
155
+ * Browser-safe logger for Client SDK.
207
156
  */
208
- function getBrowserSafeLogger(config, pinoError) {
157
+ function getBrowserSafeLogger(config) {
209
158
  // Log level hierarchy (matching pino's numeric levels)
210
159
  const LOG_LEVELS = {
211
160
  silent: 0,
@@ -236,7 +185,7 @@ function getBrowserSafeLogger(config, pinoError) {
236
185
  };
237
186
  const logLevel = getEffectiveLogLevel();
238
187
  const structuredLogging = config?.structuredLogging ?? false;
239
- const isProd = isProduction();
188
+ isProduction();
240
189
  /**
241
190
  * Check if we should log at this level.
242
191
  */
@@ -369,10 +318,6 @@ function getBrowserSafeLogger(config, pinoError) {
369
318
  }
370
319
  },
371
320
  };
372
- // Only warn about fallback logger if pino failed (not if we're in browser)
373
- if (pinoError && !isProd) {
374
- console.warn('[Finatic SDK] Using fallback logger due to pino initialization error:', pinoError);
375
- }
376
321
  _loggerInstance = fallbackLogger;
377
322
  return _loggerInstance;
378
323
  }
@@ -440,11 +385,96 @@ function handleError(error, requestId) {
440
385
  }
441
386
 
442
387
  /**
443
- * Response caching utility with node-cache (Phase 2B).
388
+ * Response caching utility with browser-compatible Map-based cache (Phase 2B).
444
389
  *
445
390
  * Generated - do not edit directly.
446
391
  */
447
- // @ts-ignore - node-cache types available via @types/node-cache
392
+ class MapBasedCache {
393
+ constructor(maxSize = 1000, defaultTtl = 300) {
394
+ this.cleanupInterval = null;
395
+ this.cache = new Map();
396
+ this.maxSize = maxSize;
397
+ this.defaultTtl = defaultTtl;
398
+ this.startCleanup();
399
+ }
400
+ startCleanup() {
401
+ // Clean up expired entries every minute
402
+ if (typeof window !== 'undefined') {
403
+ this.cleanupInterval = window.setInterval(() => {
404
+ this.cleanup();
405
+ }, 60000);
406
+ }
407
+ }
408
+ cleanup() {
409
+ const now = Date.now();
410
+ const keysToDelete = [];
411
+ for (const [key, entry] of this.cache.entries()) {
412
+ if (entry.expires < now) {
413
+ keysToDelete.push(key);
414
+ }
415
+ }
416
+ keysToDelete.forEach(key => this.cache.delete(key));
417
+ }
418
+ evictLRU() {
419
+ if (this.cache.size < this.maxSize) {
420
+ return;
421
+ }
422
+ // Simple LRU: remove oldest entry (first in Map)
423
+ const firstKey = this.cache.keys().next().value;
424
+ if (firstKey) {
425
+ this.cache.delete(firstKey);
426
+ }
427
+ }
428
+ get(key) {
429
+ const entry = this.cache.get(key);
430
+ if (!entry) {
431
+ return undefined;
432
+ }
433
+ // Check if expired
434
+ if (entry.expires < Date.now()) {
435
+ this.cache.delete(key);
436
+ return undefined;
437
+ }
438
+ return entry.value;
439
+ }
440
+ set(key, value, ttl) {
441
+ // Evict if at max size
442
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
443
+ this.evictLRU();
444
+ }
445
+ const expires = Date.now() + (ttl || this.defaultTtl) * 1000;
446
+ this.cache.set(key, { value, expires });
447
+ return true;
448
+ }
449
+ del(key) {
450
+ return this.cache.delete(key) ? 1 : 0;
451
+ }
452
+ clear() {
453
+ this.cache.clear();
454
+ }
455
+ keys() {
456
+ return Array.from(this.cache.keys());
457
+ }
458
+ has(key) {
459
+ const entry = this.cache.get(key);
460
+ if (!entry) {
461
+ return false;
462
+ }
463
+ // Check if expired
464
+ if (entry.expires < Date.now()) {
465
+ this.cache.delete(key);
466
+ return false;
467
+ }
468
+ return true;
469
+ }
470
+ destroy() {
471
+ if (this.cleanupInterval !== null && typeof window !== 'undefined') {
472
+ window.clearInterval(this.cleanupInterval);
473
+ this.cleanupInterval = null;
474
+ }
475
+ this.cache.clear();
476
+ }
477
+ }
448
478
  let _cacheInstance = null;
449
479
  /**
450
480
  * Get or create cache instance.
@@ -456,11 +486,7 @@ function getCache(config) {
456
486
  if (_cacheInstance) {
457
487
  return _cacheInstance;
458
488
  }
459
- _cacheInstance = new NodeCache({
460
- stdTTL: config.cacheTtl || 300,
461
- maxKeys: config.cacheMaxSize || 1000,
462
- useClones: false,
463
- });
489
+ _cacheInstance = new MapBasedCache(config.cacheMaxSize || 1000, config.cacheTtl || 300);
464
490
  return _cacheInstance;
465
491
  }
466
492
  /**
@@ -1204,6 +1230,256 @@ exports.SessionStatus = void 0;
1204
1230
  SessionStatus["Expired"] = "expired";
1205
1231
  })(exports.SessionStatus || (exports.SessionStatus = {}));
1206
1232
 
1233
+ /**
1234
+ * Pagination utilities for TypeScript SDK.
1235
+ *
1236
+ * Provides PaginatedData class for wrapping paginated responses with helper methods.
1237
+ */
1238
+ /**
1239
+ * PaginatedData wraps a data array with pagination metadata and helper methods.
1240
+ *
1241
+ * This class behaves like an array, so you can use it directly:
1242
+ * - paginatedData.length returns the number of items
1243
+ * - paginatedData[0] returns the first item
1244
+ * - paginatedData.forEach(...) works directly
1245
+ * - paginatedData.map(...) works directly
1246
+ *
1247
+ * It also provides pagination methods:
1248
+ * - hasMore: Check if there are more pages
1249
+ * - nextPage(): Get the next page
1250
+ * - prevPage(): Get the previous page
1251
+ * - firstPage(): Get the first page
1252
+ * - lastPage(): Get the last page
1253
+ *
1254
+ * @template T - The element type (e.g., FDXBrokerAccount)
1255
+ *
1256
+ * Usage:
1257
+ * ```typescript
1258
+ * const response = await sdk.getAccounts();
1259
+ * const accounts = response.success.data; // Can use directly as array!
1260
+ * console.log(accounts.length); // Works directly
1261
+ * console.log(accounts[0]); // Works directly
1262
+ * accounts.forEach(account => console.log(account)); // Works directly
1263
+ *
1264
+ * if (accounts.hasMore) {
1265
+ * const nextPage = await accounts.nextPage(); // Returns PaginatedData<FDXBrokerAccount>
1266
+ * const nextAccounts = nextPage; // Can use directly as array too!
1267
+ * }
1268
+ * ```
1269
+ */
1270
+ class PaginatedData {
1271
+ constructor(items, // The actual data array
1272
+ meta,
1273
+ // Use any for method type since it's only called for paginated endpoints
1274
+ // and will return PaginatedData<T> at runtime
1275
+ originalMethod, currentParams, wrapperInstance // Reference to wrapper for method calls
1276
+ ) {
1277
+ this.items = items;
1278
+ this.meta = meta;
1279
+ this.originalMethod = originalMethod;
1280
+ this.currentParams = currentParams;
1281
+ this.wrapperInstance = wrapperInstance;
1282
+ // Create a Proxy to allow array-like indexing (paginatedData[0])
1283
+ return new Proxy(this, {
1284
+ get(target, prop) {
1285
+ // Handle numeric indices
1286
+ if (typeof prop === 'string' && /^\d+$/.test(prop)) {
1287
+ return target.items[Number(prop)];
1288
+ }
1289
+ // Handle length property
1290
+ if (prop === 'length') {
1291
+ return target.items.length;
1292
+ }
1293
+ // Handle array methods and other properties
1294
+ return target[prop];
1295
+ },
1296
+ has(target, prop) {
1297
+ // Support 'in' operator
1298
+ if (typeof prop === 'string' && /^\d+$/.test(prop)) {
1299
+ return Number(prop) < target.items.length;
1300
+ }
1301
+ return prop in target;
1302
+ },
1303
+ ownKeys(target) {
1304
+ // Include numeric indices for Object.keys()
1305
+ const keys = Object.keys(target);
1306
+ for (let i = 0; i < target.items.length; i++) {
1307
+ keys.push(String(i));
1308
+ }
1309
+ return keys;
1310
+ },
1311
+ getOwnPropertyDescriptor(target, prop) {
1312
+ if (typeof prop === 'string' && /^\d+$/.test(prop)) {
1313
+ const index = Number(prop);
1314
+ if (index < target.items.length) {
1315
+ return {
1316
+ enumerable: true,
1317
+ configurable: true,
1318
+ value: target.items[index],
1319
+ };
1320
+ }
1321
+ }
1322
+ return Object.getOwnPropertyDescriptor(target, prop);
1323
+ },
1324
+ });
1325
+ }
1326
+ /**
1327
+ * Get the number of items (allows paginatedData.length).
1328
+ */
1329
+ get length() {
1330
+ return this.items.length;
1331
+ }
1332
+ /**
1333
+ * Check if there are more pages available.
1334
+ */
1335
+ get hasMore() {
1336
+ return this.meta.has_more;
1337
+ }
1338
+ // Array-like methods - delegate to items array
1339
+ /**
1340
+ * Calls a function for each element in the array.
1341
+ */
1342
+ forEach(callbackfn, thisArg) {
1343
+ return this.items.forEach(callbackfn, thisArg);
1344
+ }
1345
+ /**
1346
+ * Creates a new array with the results of calling a function for every array element.
1347
+ */
1348
+ map(callbackfn, thisArg) {
1349
+ return this.items.map(callbackfn, thisArg);
1350
+ }
1351
+ /**
1352
+ * Returns the elements of an array that meet the condition specified in a callback function.
1353
+ */
1354
+ filter(callbackfn, thisArg) {
1355
+ return this.items.filter(callbackfn, thisArg);
1356
+ }
1357
+ /**
1358
+ * Returns the value of the first element in the array where predicate is true.
1359
+ */
1360
+ find(predicate, thisArg) {
1361
+ return this.items.find(predicate, thisArg);
1362
+ }
1363
+ /**
1364
+ * Returns the index of the first element in the array where predicate is true.
1365
+ */
1366
+ findIndex(predicate, thisArg) {
1367
+ return this.items.findIndex(predicate, thisArg);
1368
+ }
1369
+ /**
1370
+ * Returns a section of an array.
1371
+ */
1372
+ slice(start, end) {
1373
+ return this.items.slice(start, end);
1374
+ }
1375
+ /**
1376
+ * Determines whether an array includes a certain element.
1377
+ */
1378
+ includes(searchElement, fromIndex) {
1379
+ return this.items.includes(searchElement, fromIndex);
1380
+ }
1381
+ /**
1382
+ * Returns the index of the first occurrence of a value in an array.
1383
+ */
1384
+ indexOf(searchElement, fromIndex) {
1385
+ return this.items.indexOf(searchElement, fromIndex);
1386
+ }
1387
+ /**
1388
+ * Returns a string representation of an array.
1389
+ */
1390
+ toString() {
1391
+ return this.items.toString();
1392
+ }
1393
+ /**
1394
+ * Returns a string representation of an array.
1395
+ */
1396
+ toLocaleString() {
1397
+ return this.items.toLocaleString();
1398
+ }
1399
+ /**
1400
+ * Get the next page of data.
1401
+ * @returns Promise<PaginatedData<T>> - The next page (not wrapped in FinaticResponse)
1402
+ * @throws Error if no more pages are available
1403
+ */
1404
+ async nextPage() {
1405
+ if (!this.hasMore) {
1406
+ throw new Error('No more pages available');
1407
+ }
1408
+ if (this.meta.next_offset === null) {
1409
+ throw new Error('Next offset is null');
1410
+ }
1411
+ const newParams = {
1412
+ ...this.currentParams,
1413
+ offset: this.meta.next_offset,
1414
+ };
1415
+ const response = await this.originalMethod.call(this.wrapperInstance, newParams);
1416
+ if (!response.success) {
1417
+ throw new Error(response.error?.message || 'Failed to fetch next page');
1418
+ }
1419
+ return response.success.data; // Return PaginatedData directly
1420
+ }
1421
+ /**
1422
+ * Get the previous page of data.
1423
+ * @returns Promise<PaginatedData<T>> - The previous page (not wrapped in FinaticResponse)
1424
+ * @throws Error if fetch fails
1425
+ */
1426
+ async prevPage() {
1427
+ const prevOffset = Math.max(0, this.meta.current_offset - this.meta.limit);
1428
+ const newParams = {
1429
+ ...this.currentParams,
1430
+ offset: prevOffset,
1431
+ };
1432
+ const response = await this.originalMethod.call(this.wrapperInstance, newParams);
1433
+ if (!response.success) {
1434
+ throw new Error(response.error?.message || 'Failed to fetch previous page');
1435
+ }
1436
+ return response.success.data; // Return PaginatedData directly
1437
+ }
1438
+ /**
1439
+ * Get the first page of data.
1440
+ * @returns Promise<PaginatedData<T>> - The first page (not wrapped in FinaticResponse)
1441
+ * @throws Error if fetch fails
1442
+ */
1443
+ async firstPage() {
1444
+ const newParams = {
1445
+ ...this.currentParams,
1446
+ offset: 0,
1447
+ };
1448
+ const response = await this.originalMethod.call(this.wrapperInstance, newParams);
1449
+ if (!response.success) {
1450
+ throw new Error(response.error?.message || 'Failed to fetch first page');
1451
+ }
1452
+ return response.success.data; // Return PaginatedData directly
1453
+ }
1454
+ /**
1455
+ * Get the last page of data.
1456
+ * Uses iterative approach to find the last page.
1457
+ * @returns Promise<PaginatedData<T>> - The last page (not wrapped in FinaticResponse)
1458
+ * @throws Error if fetch fails
1459
+ */
1460
+ async lastPage() {
1461
+ // Iterative approach to find last page
1462
+ let currentOffset = this.meta.current_offset;
1463
+ let lastValidData = null;
1464
+ while (true) {
1465
+ const testParams = { ...this.currentParams, offset: currentOffset };
1466
+ const response = await this.originalMethod.call(this.wrapperInstance, testParams);
1467
+ if (!response.success) {
1468
+ break;
1469
+ }
1470
+ lastValidData = response.success.data;
1471
+ if (!lastValidData || !lastValidData.hasMore) {
1472
+ break;
1473
+ }
1474
+ currentOffset += this.meta.limit;
1475
+ }
1476
+ if (!lastValidData) {
1477
+ throw new Error('Failed to fetch last page');
1478
+ }
1479
+ return lastValidData; // Return PaginatedData directly
1480
+ }
1481
+ }
1482
+
1207
1483
  /**
1208
1484
  * Generated wrapper functions for brokers operations (Phase 2A).
1209
1485
  *
@@ -1253,7 +1529,7 @@ class BrokersWrapper {
1253
1529
  * -------
1254
1530
  * FinaticResponse[list[BrokerInfo]]
1255
1531
  * list of available brokers with their metadata.
1256
- * @param No parameters required for this method
1532
+ * @param params No parameters required for this method
1257
1533
  * @returns {Promise<FinaticResponse<BrokerInfo[]>>} Standard response with success/Error/Warning structure
1258
1534
  *
1259
1535
  * Generated from: GET /api/v1/brokers/
@@ -1262,7 +1538,7 @@ class BrokersWrapper {
1262
1538
  * @example
1263
1539
  * ```typescript-client
1264
1540
  * // Example with no parameters
1265
- * const result = await finatic.getBrokers();
1541
+ * const result = await finatic.getBrokers({});
1266
1542
  *
1267
1543
  * // Access the response data
1268
1544
  * if (result.success) {
@@ -1270,9 +1546,9 @@ class BrokersWrapper {
1270
1546
  * }
1271
1547
  * ```
1272
1548
  */
1273
- async getBrokers() {
1549
+ async getBrokers(params) {
1274
1550
  // No parameters - use empty params object
1275
- const params = {}; // Generate request ID
1551
+ const resolvedParams = params || {}; // Generate request ID
1276
1552
  const requestId = this._generateRequestId();
1277
1553
  // Input validation (Phase 2B: zod)
1278
1554
  if (this.sdkConfig?.validationEnabled) ;
@@ -1280,7 +1556,7 @@ class BrokersWrapper {
1280
1556
  const shouldCache = true;
1281
1557
  const cache = getCache(this.sdkConfig);
1282
1558
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1283
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', params, this.sdkConfig);
1559
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
1284
1560
  const cached = cache.get(cacheKey);
1285
1561
  if (cached) {
1286
1562
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1292,7 +1568,7 @@ class BrokersWrapper {
1292
1568
  request_id: requestId,
1293
1569
  method: 'GET',
1294
1570
  path: '/api/v1/brokers/',
1295
- params: params,
1571
+ params: resolvedParams,
1296
1572
  action: 'getBrokers'
1297
1573
  });
1298
1574
  try {
@@ -1306,9 +1582,15 @@ class BrokersWrapper {
1306
1582
  throw new Error('Unexpected response shape: missing success field');
1307
1583
  }
1308
1584
  // Convert response to plain object, removing _id fields recursively
1585
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1309
1586
  const standardResponse = convertToPlainObject(responseData);
1587
+ // Phase 2: Wrap paginated responses with PaginatedData
1588
+ const hasLimit = false;
1589
+ const hasOffset = false;
1590
+ const hasPagination = hasLimit && hasOffset;
1591
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
1310
1592
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1311
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', params, this.sdkConfig);
1593
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
1312
1594
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1313
1595
  }
1314
1596
  this.logger.debug('Get Brokers completed', {
@@ -1316,6 +1598,7 @@ class BrokersWrapper {
1316
1598
  action: 'getBrokers'
1317
1599
  });
1318
1600
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
1601
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1319
1602
  return standardResponse;
1320
1603
  }
1321
1604
  catch (error) {
@@ -1393,7 +1676,7 @@ class BrokersWrapper {
1393
1676
  * This endpoint is accessible from the portal and uses session-only authentication.
1394
1677
  * Returns connections that the user has any permissions for, including the current
1395
1678
  * company's permissions (read/write) for each connection.
1396
- * @param No parameters required for this method
1679
+ * @param params No parameters required for this method
1397
1680
  * @returns {Promise<FinaticResponse<UserBrokerConnectionWithPermissions[]>>} Standard response with success/Error/Warning structure
1398
1681
  *
1399
1682
  * Generated from: GET /api/v1/brokers/connections
@@ -1402,7 +1685,7 @@ class BrokersWrapper {
1402
1685
  * @example
1403
1686
  * ```typescript-client
1404
1687
  * // Example with no parameters
1405
- * const result = await finatic.getBrokerConnections();
1688
+ * const result = await finatic.getBrokerConnections({});
1406
1689
  *
1407
1690
  * // Access the response data
1408
1691
  * if (result.success) {
@@ -1410,10 +1693,10 @@ class BrokersWrapper {
1410
1693
  * }
1411
1694
  * ```
1412
1695
  */
1413
- async getBrokerConnections() {
1696
+ async getBrokerConnections(params) {
1414
1697
  // No parameters - use empty params object
1415
- const params = {}; // Authentication check
1416
- if (!this.sessionId) {
1698
+ const resolvedParams = params || {}; // Authentication check
1699
+ if (!this.sessionId || !this.companyId) {
1417
1700
  throw new Error('Session not initialized. Call startSession() first.');
1418
1701
  }
1419
1702
  // Generate request ID
@@ -1424,7 +1707,7 @@ class BrokersWrapper {
1424
1707
  const shouldCache = true;
1425
1708
  const cache = getCache(this.sdkConfig);
1426
1709
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1427
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', params, this.sdkConfig);
1710
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
1428
1711
  const cached = cache.get(cacheKey);
1429
1712
  if (cached) {
1430
1713
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1436,12 +1719,12 @@ class BrokersWrapper {
1436
1719
  request_id: requestId,
1437
1720
  method: 'GET',
1438
1721
  path: '/api/v1/brokers/connections',
1439
- params: params,
1722
+ params: resolvedParams,
1440
1723
  action: 'getBrokerConnections'
1441
1724
  });
1442
1725
  try {
1443
1726
  const response = await retryApiCall(async () => {
1444
- const apiResponse = await this.api.listBrokerConnectionsApiV1BrokersConnectionsGet({ headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
1727
+ const apiResponse = await this.api.listBrokerConnectionsApiV1BrokersConnectionsGet({ headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
1445
1728
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1446
1729
  }, {}, this.sdkConfig);
1447
1730
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1450,9 +1733,15 @@ class BrokersWrapper {
1450
1733
  throw new Error('Unexpected response shape: missing success field');
1451
1734
  }
1452
1735
  // Convert response to plain object, removing _id fields recursively
1736
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1453
1737
  const standardResponse = convertToPlainObject(responseData);
1738
+ // Phase 2: Wrap paginated responses with PaginatedData
1739
+ const hasLimit = false;
1740
+ const hasOffset = false;
1741
+ const hasPagination = hasLimit && hasOffset;
1742
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
1454
1743
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1455
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', params, this.sdkConfig);
1744
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
1456
1745
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1457
1746
  }
1458
1747
  this.logger.debug('List Broker Connections completed', {
@@ -1460,6 +1749,7 @@ class BrokersWrapper {
1460
1749
  action: 'getBrokerConnections'
1461
1750
  });
1462
1751
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
1752
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1463
1753
  return standardResponse;
1464
1754
  }
1465
1755
  catch (error) {
@@ -1536,7 +1826,7 @@ class BrokersWrapper {
1536
1826
  *
1537
1827
  * If the company is the only one with access, the entire connection is deleted.
1538
1828
  * If other companies have access, only the company's access is removed.
1539
- * @param connectionId {string}
1829
+ * @param params.connectionId {string} Connection ID
1540
1830
  * @returns {Promise<FinaticResponse<DisconnectActionResult>>} Standard response with success/Error/Warning structure
1541
1831
  *
1542
1832
  * Generated from: DELETE /api/v1/brokers/disconnect-company/{connection_id}
@@ -1545,7 +1835,9 @@ class BrokersWrapper {
1545
1835
  * @example
1546
1836
  * ```typescript-client
1547
1837
  * // Minimal example with required parameters only
1548
- * const result = await finatic.disconnectCompanyFromBroker(connectionId: '00000000-0000-0000-0000-000000000000');
1838
+ * const result = await finatic.disconnectCompanyFromBroker({
1839
+ connectionId: '00000000-0000-0000-0000-000000000000'
1840
+ * });
1549
1841
  *
1550
1842
  * // Access the response data
1551
1843
  * if (result.success) {
@@ -1555,12 +1847,10 @@ class BrokersWrapper {
1555
1847
  * }
1556
1848
  * ```
1557
1849
  */
1558
- async disconnectCompanyFromBroker(connectionId) {
1559
- // Construct params object from individual parameters
1560
- const params = {
1561
- connectionId: connectionId
1562
- }; // Authentication check
1563
- if (!this.sessionId) {
1850
+ async disconnectCompanyFromBroker(params) {
1851
+ // Use params object (required parameters present)
1852
+ const resolvedParams = params; // Authentication check
1853
+ if (!this.sessionId || !this.companyId) {
1564
1854
  throw new Error('Session not initialized. Call startSession() first.');
1565
1855
  }
1566
1856
  // Generate request ID
@@ -1571,7 +1861,7 @@ class BrokersWrapper {
1571
1861
  const shouldCache = true;
1572
1862
  const cache = getCache(this.sdkConfig);
1573
1863
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1574
- const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', params, this.sdkConfig);
1864
+ const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
1575
1865
  const cached = cache.get(cacheKey);
1576
1866
  if (cached) {
1577
1867
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1583,12 +1873,12 @@ class BrokersWrapper {
1583
1873
  request_id: requestId,
1584
1874
  method: 'DELETE',
1585
1875
  path: '/api/v1/brokers/disconnect-company/{connection_id}',
1586
- params: params,
1876
+ params: resolvedParams,
1587
1877
  action: 'disconnectCompanyFromBroker'
1588
1878
  });
1589
1879
  try {
1590
1880
  const response = await retryApiCall(async () => {
1591
- const apiResponse = await this.api.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete({ connectionId: connectionId }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
1881
+ const apiResponse = await this.api.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete({ connectionId: resolvedParams.connectionId }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
1592
1882
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1593
1883
  }, {}, this.sdkConfig);
1594
1884
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1597,9 +1887,15 @@ class BrokersWrapper {
1597
1887
  throw new Error('Unexpected response shape: missing success field');
1598
1888
  }
1599
1889
  // Convert response to plain object, removing _id fields recursively
1890
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1600
1891
  const standardResponse = convertToPlainObject(responseData);
1892
+ // Phase 2: Wrap paginated responses with PaginatedData
1893
+ const hasLimit = false;
1894
+ const hasOffset = false;
1895
+ const hasPagination = hasLimit && hasOffset;
1896
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
1601
1897
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1602
- const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', params, this.sdkConfig);
1898
+ const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
1603
1899
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1604
1900
  }
1605
1901
  this.logger.debug('Disconnect Company From Broker completed', {
@@ -1607,6 +1903,7 @@ class BrokersWrapper {
1607
1903
  action: 'disconnectCompanyFromBroker'
1608
1904
  });
1609
1905
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
1906
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1610
1907
  return standardResponse;
1611
1908
  }
1612
1909
  catch (error) {
@@ -1683,19 +1980,19 @@ class BrokersWrapper {
1683
1980
  *
1684
1981
  * This endpoint is accessible from the portal and uses session-only authentication.
1685
1982
  * Returns orders from connections the company has read access to.
1686
- * @param brokerId {string} (optional)
1687
- * @param connectionId {string} (optional)
1688
- * @param accountId {string} (optional)
1689
- * @param symbol {string} (optional)
1690
- * @param orderStatus {BrokerDataOrderStatusEnum} (optional)
1691
- * @param side {BrokerDataOrderSideEnum} (optional)
1692
- * @param assetType {BrokerDataAssetTypeEnum} (optional)
1693
- * @param limit {number} (optional)
1694
- * @param offset {number} (optional)
1695
- * @param createdAfter {string} (optional)
1696
- * @param createdBefore {string} (optional)
1697
- * @param includeMetadata {boolean} (optional)
1698
- * @returns {Promise<FinaticResponse<FDXBrokerOrder[]>>} Standard response with success/Error/Warning structure
1983
+ * @param params.brokerId {string} (optional) Filter by broker ID
1984
+ * @param params.connectionId {string} (optional) Filter by connection ID
1985
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
1986
+ * @param params.symbol {string} (optional) Filter by symbol
1987
+ * @param params.orderStatus {BrokerDataOrderStatusEnum} (optional) Filter by order status (e.g., 'filled', 'pending_new', 'cancelled')
1988
+ * @param params.side {BrokerDataOrderSideEnum} (optional) Filter by order side (e.g., 'buy', 'sell')
1989
+ * @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
1990
+ * @param params.limit {number} (optional) Maximum number of orders to return
1991
+ * @param params.offset {number} (optional) Number of orders to skip for pagination
1992
+ * @param params.createdAfter {string} (optional) Filter orders created after this timestamp
1993
+ * @param params.createdBefore {string} (optional) Filter orders created before this timestamp
1994
+ * @param params.includeMetadata {boolean} (optional) Include order metadata in response (excluded by default for FDX compliance)
1995
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrder>>>} Standard response with success/Error/Warning structure
1699
1996
  *
1700
1997
  * Generated from: GET /api/v1/brokers/data/orders
1701
1998
  * @methodId get_orders_api_v1_brokers_data_orders_get
@@ -1703,7 +2000,7 @@ class BrokersWrapper {
1703
2000
  * @example
1704
2001
  * ```typescript-client
1705
2002
  * // Example with no parameters
1706
- * const result = await finatic.getOrders();
2003
+ * const result = await finatic.getOrders({});
1707
2004
  *
1708
2005
  * // Access the response data
1709
2006
  * if (result.success) {
@@ -1713,7 +2010,11 @@ class BrokersWrapper {
1713
2010
  * @example
1714
2011
  * ```typescript-client
1715
2012
  * // Full example with optional parameters
1716
- * const result = await finatic.getOrders(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
2013
+ * const result = await finatic.getOrders({
2014
+ brokerId: 'alpaca',
2015
+ connectionId: '00000000-0000-0000-0000-000000000000',
2016
+ accountId: '123456789'
2017
+ * });
1717
2018
  *
1718
2019
  * // Handle response with warnings
1719
2020
  * if (result.success) {
@@ -1726,23 +2027,19 @@ class BrokersWrapper {
1726
2027
  * }
1727
2028
  * ```
1728
2029
  */
1729
- async getOrders(brokerId, connectionId, accountId, symbol, orderStatus, side, assetType, limit, offset, createdAfter, createdBefore, includeMetadata) {
1730
- // Construct params object from individual parameters
1731
- const params = {
1732
- brokerId: brokerId,
1733
- connectionId: connectionId,
1734
- accountId: accountId,
1735
- symbol: symbol,
1736
- orderStatus: orderStatus !== undefined ? coerceEnumValue(orderStatus, exports.BrokerDataOrderStatusEnum, 'orderStatus') : undefined,
1737
- side: side !== undefined ? coerceEnumValue(side, exports.BrokerDataOrderSideEnum, 'side') : undefined,
1738
- assetType: assetType !== undefined ? coerceEnumValue(assetType, exports.BrokerDataAssetTypeEnum, 'assetType') : undefined,
1739
- limit: limit,
1740
- offset: offset,
1741
- createdAfter: createdAfter,
1742
- createdBefore: createdBefore,
1743
- includeMetadata: includeMetadata
1744
- }; // Authentication check
1745
- if (!this.sessionId) {
2030
+ async getOrders(params) {
2031
+ // Use params object (with default empty object)
2032
+ const resolvedParams = params || {};
2033
+ if (params?.orderStatus !== undefined) {
2034
+ params.orderStatus = coerceEnumValue(params.orderStatus, exports.BrokerDataOrderStatusEnum, 'orderStatus');
2035
+ }
2036
+ if (params?.side !== undefined) {
2037
+ params.side = coerceEnumValue(params.side, exports.BrokerDataOrderSideEnum, 'side');
2038
+ }
2039
+ if (params?.assetType !== undefined) {
2040
+ params.assetType = coerceEnumValue(params.assetType, exports.BrokerDataAssetTypeEnum, 'assetType');
2041
+ } // Authentication check
2042
+ if (!this.sessionId || !this.companyId) {
1746
2043
  throw new Error('Session not initialized. Call startSession() first.');
1747
2044
  }
1748
2045
  // Generate request ID
@@ -1753,7 +2050,7 @@ class BrokersWrapper {
1753
2050
  const shouldCache = true;
1754
2051
  const cache = getCache(this.sdkConfig);
1755
2052
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1756
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', params, this.sdkConfig);
2053
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
1757
2054
  const cached = cache.get(cacheKey);
1758
2055
  if (cached) {
1759
2056
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1765,12 +2062,12 @@ class BrokersWrapper {
1765
2062
  request_id: requestId,
1766
2063
  method: 'GET',
1767
2064
  path: '/api/v1/brokers/data/orders',
1768
- params: params,
2065
+ params: resolvedParams,
1769
2066
  action: 'getOrders'
1770
2067
  });
1771
2068
  try {
1772
2069
  const response = await retryApiCall(async () => {
1773
- const apiResponse = await this.api.getOrdersApiV1BrokersDataOrdersGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(symbol !== undefined ? { symbol: symbol } : {}), ...(orderStatus !== undefined ? { orderStatus: orderStatus } : {}), ...(side !== undefined ? { side: side } : {}), ...(assetType !== undefined ? { assetType: assetType } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(createdAfter !== undefined ? { createdAfter: createdAfter } : {}), ...(createdBefore !== undefined ? { createdBefore: createdBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
2070
+ const apiResponse = await this.api.getOrdersApiV1BrokersDataOrdersGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, symbol: resolvedParams.symbol, orderStatus: resolvedParams.orderStatus, side: resolvedParams.side, assetType: resolvedParams.assetType, limit: resolvedParams.limit, offset: resolvedParams.offset, createdAfter: resolvedParams.createdAfter, createdBefore: resolvedParams.createdBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
1774
2071
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1775
2072
  }, {}, this.sdkConfig);
1776
2073
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1779,9 +2076,27 @@ class BrokersWrapper {
1779
2076
  throw new Error('Unexpected response shape: missing success field');
1780
2077
  }
1781
2078
  // Convert response to plain object, removing _id fields recursively
2079
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1782
2080
  const standardResponse = convertToPlainObject(responseData);
2081
+ // Phase 2: Wrap paginated responses with PaginatedData
2082
+ const hasLimit = true;
2083
+ const hasOffset = true;
2084
+ const hasPagination = hasLimit && hasOffset;
2085
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2086
+ // PaginatedData is already imported at top of file
2087
+ const paginationMeta = standardResponse.success.meta?.pagination;
2088
+ if (paginationMeta) {
2089
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2090
+ has_more: paginationMeta.has_more,
2091
+ next_offset: paginationMeta.next_offset,
2092
+ current_offset: paginationMeta.current_offset,
2093
+ limit: paginationMeta.limit,
2094
+ }, this.getOrders.bind(this), resolvedParams, this);
2095
+ standardResponse.success.data = paginatedData;
2096
+ }
2097
+ }
1783
2098
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1784
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', params, this.sdkConfig);
2099
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
1785
2100
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1786
2101
  }
1787
2102
  this.logger.debug('Get Orders completed', {
@@ -1789,6 +2104,7 @@ class BrokersWrapper {
1789
2104
  action: 'getOrders'
1790
2105
  });
1791
2106
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2107
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1792
2108
  return standardResponse;
1793
2109
  }
1794
2110
  catch (error) {
@@ -1865,19 +2181,19 @@ class BrokersWrapper {
1865
2181
  *
1866
2182
  * This endpoint is accessible from the portal and uses session-only authentication.
1867
2183
  * Returns positions from connections the company has read access to.
1868
- * @param brokerId {string} (optional)
1869
- * @param connectionId {string} (optional)
1870
- * @param accountId {string} (optional)
1871
- * @param symbol {string} (optional)
1872
- * @param side {BrokerDataOrderSideEnum} (optional)
1873
- * @param assetType {BrokerDataAssetTypeEnum} (optional)
1874
- * @param positionStatus {BrokerDataPositionStatusEnum} (optional)
1875
- * @param limit {number} (optional)
1876
- * @param offset {number} (optional)
1877
- * @param updatedAfter {string} (optional)
1878
- * @param updatedBefore {string} (optional)
1879
- * @param includeMetadata {boolean} (optional)
1880
- * @returns {Promise<FinaticResponse<FDXBrokerPosition[]>>} Standard response with success/Error/Warning structure
2184
+ * @param params.brokerId {string} (optional) Filter by broker ID
2185
+ * @param params.connectionId {string} (optional) Filter by connection ID
2186
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
2187
+ * @param params.symbol {string} (optional) Filter by symbol
2188
+ * @param params.side {BrokerDataOrderSideEnum} (optional) Filter by position side (e.g., 'long', 'short')
2189
+ * @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
2190
+ * @param params.positionStatus {BrokerDataPositionStatusEnum} (optional) Filter by position status: 'open' (quantity > 0) or 'closed' (quantity = 0)
2191
+ * @param params.limit {number} (optional) Maximum number of positions to return
2192
+ * @param params.offset {number} (optional) Number of positions to skip for pagination
2193
+ * @param params.updatedAfter {string} (optional) Filter positions updated after this timestamp
2194
+ * @param params.updatedBefore {string} (optional) Filter positions updated before this timestamp
2195
+ * @param params.includeMetadata {boolean} (optional) Include position metadata in response (excluded by default for FDX compliance)
2196
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPosition>>>} Standard response with success/Error/Warning structure
1881
2197
  *
1882
2198
  * Generated from: GET /api/v1/brokers/data/positions
1883
2199
  * @methodId get_positions_api_v1_brokers_data_positions_get
@@ -1885,7 +2201,7 @@ class BrokersWrapper {
1885
2201
  * @example
1886
2202
  * ```typescript-client
1887
2203
  * // Example with no parameters
1888
- * const result = await finatic.getPositions();
2204
+ * const result = await finatic.getPositions({});
1889
2205
  *
1890
2206
  * // Access the response data
1891
2207
  * if (result.success) {
@@ -1895,7 +2211,11 @@ class BrokersWrapper {
1895
2211
  * @example
1896
2212
  * ```typescript-client
1897
2213
  * // Full example with optional parameters
1898
- * const result = await finatic.getPositions(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
2214
+ * const result = await finatic.getPositions({
2215
+ brokerId: 'alpaca',
2216
+ connectionId: '00000000-0000-0000-0000-000000000000',
2217
+ accountId: '123456789'
2218
+ * });
1899
2219
  *
1900
2220
  * // Handle response with warnings
1901
2221
  * if (result.success) {
@@ -1908,23 +2228,19 @@ class BrokersWrapper {
1908
2228
  * }
1909
2229
  * ```
1910
2230
  */
1911
- async getPositions(brokerId, connectionId, accountId, symbol, side, assetType, positionStatus, limit, offset, updatedAfter, updatedBefore, includeMetadata) {
1912
- // Construct params object from individual parameters
1913
- const params = {
1914
- brokerId: brokerId,
1915
- connectionId: connectionId,
1916
- accountId: accountId,
1917
- symbol: symbol,
1918
- side: side !== undefined ? coerceEnumValue(side, exports.BrokerDataOrderSideEnum, 'side') : undefined,
1919
- assetType: assetType !== undefined ? coerceEnumValue(assetType, exports.BrokerDataAssetTypeEnum, 'assetType') : undefined,
1920
- positionStatus: positionStatus !== undefined ? coerceEnumValue(positionStatus, exports.BrokerDataPositionStatusEnum, 'positionStatus') : undefined,
1921
- limit: limit,
1922
- offset: offset,
1923
- updatedAfter: updatedAfter,
1924
- updatedBefore: updatedBefore,
1925
- includeMetadata: includeMetadata
1926
- }; // Authentication check
1927
- if (!this.sessionId) {
2231
+ async getPositions(params) {
2232
+ // Use params object (with default empty object)
2233
+ const resolvedParams = params || {};
2234
+ if (params?.side !== undefined) {
2235
+ params.side = coerceEnumValue(params.side, exports.BrokerDataOrderSideEnum, 'side');
2236
+ }
2237
+ if (params?.assetType !== undefined) {
2238
+ params.assetType = coerceEnumValue(params.assetType, exports.BrokerDataAssetTypeEnum, 'assetType');
2239
+ }
2240
+ if (params?.positionStatus !== undefined) {
2241
+ params.positionStatus = coerceEnumValue(params.positionStatus, exports.BrokerDataPositionStatusEnum, 'positionStatus');
2242
+ } // Authentication check
2243
+ if (!this.sessionId || !this.companyId) {
1928
2244
  throw new Error('Session not initialized. Call startSession() first.');
1929
2245
  }
1930
2246
  // Generate request ID
@@ -1935,7 +2251,7 @@ class BrokersWrapper {
1935
2251
  const shouldCache = true;
1936
2252
  const cache = getCache(this.sdkConfig);
1937
2253
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1938
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', params, this.sdkConfig);
2254
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
1939
2255
  const cached = cache.get(cacheKey);
1940
2256
  if (cached) {
1941
2257
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1947,12 +2263,12 @@ class BrokersWrapper {
1947
2263
  request_id: requestId,
1948
2264
  method: 'GET',
1949
2265
  path: '/api/v1/brokers/data/positions',
1950
- params: params,
2266
+ params: resolvedParams,
1951
2267
  action: 'getPositions'
1952
2268
  });
1953
2269
  try {
1954
2270
  const response = await retryApiCall(async () => {
1955
- const apiResponse = await this.api.getPositionsApiV1BrokersDataPositionsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(symbol !== undefined ? { symbol: symbol } : {}), ...(side !== undefined ? { side: side } : {}), ...(assetType !== undefined ? { assetType: assetType } : {}), ...(positionStatus !== undefined ? { positionStatus: positionStatus } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(updatedAfter !== undefined ? { updatedAfter: updatedAfter } : {}), ...(updatedBefore !== undefined ? { updatedBefore: updatedBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
2271
+ const apiResponse = await this.api.getPositionsApiV1BrokersDataPositionsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, symbol: resolvedParams.symbol, side: resolvedParams.side, assetType: resolvedParams.assetType, positionStatus: resolvedParams.positionStatus, limit: resolvedParams.limit, offset: resolvedParams.offset, updatedAfter: resolvedParams.updatedAfter, updatedBefore: resolvedParams.updatedBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
1956
2272
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1957
2273
  }, {}, this.sdkConfig);
1958
2274
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1961,9 +2277,27 @@ class BrokersWrapper {
1961
2277
  throw new Error('Unexpected response shape: missing success field');
1962
2278
  }
1963
2279
  // Convert response to plain object, removing _id fields recursively
2280
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1964
2281
  const standardResponse = convertToPlainObject(responseData);
2282
+ // Phase 2: Wrap paginated responses with PaginatedData
2283
+ const hasLimit = true;
2284
+ const hasOffset = true;
2285
+ const hasPagination = hasLimit && hasOffset;
2286
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2287
+ // PaginatedData is already imported at top of file
2288
+ const paginationMeta = standardResponse.success.meta?.pagination;
2289
+ if (paginationMeta) {
2290
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2291
+ has_more: paginationMeta.has_more,
2292
+ next_offset: paginationMeta.next_offset,
2293
+ current_offset: paginationMeta.current_offset,
2294
+ limit: paginationMeta.limit,
2295
+ }, this.getPositions.bind(this), resolvedParams, this);
2296
+ standardResponse.success.data = paginatedData;
2297
+ }
2298
+ }
1965
2299
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1966
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', params, this.sdkConfig);
2300
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
1967
2301
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1968
2302
  }
1969
2303
  this.logger.debug('Get Positions completed', {
@@ -1971,6 +2305,7 @@ class BrokersWrapper {
1971
2305
  action: 'getPositions'
1972
2306
  });
1973
2307
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2308
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1974
2309
  return standardResponse;
1975
2310
  }
1976
2311
  catch (error) {
@@ -2047,16 +2382,16 @@ class BrokersWrapper {
2047
2382
  *
2048
2383
  * This endpoint is accessible from the portal and uses session-only authentication.
2049
2384
  * Returns balances from connections the company has read access to.
2050
- * @param brokerId {string} (optional)
2051
- * @param connectionId {string} (optional)
2052
- * @param accountId {string} (optional)
2053
- * @param isEndOfDaySnapshot {boolean} (optional)
2054
- * @param limit {number} (optional)
2055
- * @param offset {number} (optional)
2056
- * @param balanceCreatedAfter {string} (optional)
2057
- * @param balanceCreatedBefore {string} (optional)
2058
- * @param includeMetadata {boolean} (optional)
2059
- * @returns {Promise<FinaticResponse<FDXBrokerBalance[]>>} Standard response with success/Error/Warning structure
2385
+ * @param params.brokerId {string} (optional) Filter by broker ID
2386
+ * @param params.connectionId {string} (optional) Filter by connection ID
2387
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
2388
+ * @param params.isEndOfDaySnapshot {boolean} (optional) Filter by end-of-day snapshot status (true/false)
2389
+ * @param params.limit {number} (optional) Maximum number of balances to return
2390
+ * @param params.offset {number} (optional) Number of balances to skip for pagination
2391
+ * @param params.balanceCreatedAfter {string} (optional) Filter balances created after this timestamp
2392
+ * @param params.balanceCreatedBefore {string} (optional) Filter balances created before this timestamp
2393
+ * @param params.includeMetadata {boolean} (optional) Include balance metadata in response (excluded by default for FDX compliance)
2394
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerBalance>>>} Standard response with success/Error/Warning structure
2060
2395
  *
2061
2396
  * Generated from: GET /api/v1/brokers/data/balances
2062
2397
  * @methodId get_balances_api_v1_brokers_data_balances_get
@@ -2064,7 +2399,7 @@ class BrokersWrapper {
2064
2399
  * @example
2065
2400
  * ```typescript-client
2066
2401
  * // Example with no parameters
2067
- * const result = await finatic.getBalances();
2402
+ * const result = await finatic.getBalances({});
2068
2403
  *
2069
2404
  * // Access the response data
2070
2405
  * if (result.success) {
@@ -2074,7 +2409,11 @@ class BrokersWrapper {
2074
2409
  * @example
2075
2410
  * ```typescript-client
2076
2411
  * // Full example with optional parameters
2077
- * const result = await finatic.getBalances(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
2412
+ * const result = await finatic.getBalances({
2413
+ brokerId: 'alpaca',
2414
+ connectionId: '00000000-0000-0000-0000-000000000000',
2415
+ accountId: '123456789'
2416
+ * });
2078
2417
  *
2079
2418
  * // Handle response with warnings
2080
2419
  * if (result.success) {
@@ -2087,20 +2426,10 @@ class BrokersWrapper {
2087
2426
  * }
2088
2427
  * ```
2089
2428
  */
2090
- async getBalances(brokerId, connectionId, accountId, isEndOfDaySnapshot, limit, offset, balanceCreatedAfter, balanceCreatedBefore, includeMetadata) {
2091
- // Construct params object from individual parameters
2092
- const params = {
2093
- brokerId: brokerId,
2094
- connectionId: connectionId,
2095
- accountId: accountId,
2096
- isEndOfDaySnapshot: isEndOfDaySnapshot,
2097
- limit: limit,
2098
- offset: offset,
2099
- balanceCreatedAfter: balanceCreatedAfter,
2100
- balanceCreatedBefore: balanceCreatedBefore,
2101
- includeMetadata: includeMetadata
2102
- }; // Authentication check
2103
- if (!this.sessionId) {
2429
+ async getBalances(params) {
2430
+ // Use params object (with default empty object)
2431
+ const resolvedParams = params || {}; // Authentication check
2432
+ if (!this.sessionId || !this.companyId) {
2104
2433
  throw new Error('Session not initialized. Call startSession() first.');
2105
2434
  }
2106
2435
  // Generate request ID
@@ -2111,7 +2440,7 @@ class BrokersWrapper {
2111
2440
  const shouldCache = true;
2112
2441
  const cache = getCache(this.sdkConfig);
2113
2442
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2114
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', params, this.sdkConfig);
2443
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
2115
2444
  const cached = cache.get(cacheKey);
2116
2445
  if (cached) {
2117
2446
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2123,12 +2452,12 @@ class BrokersWrapper {
2123
2452
  request_id: requestId,
2124
2453
  method: 'GET',
2125
2454
  path: '/api/v1/brokers/data/balances',
2126
- params: params,
2455
+ params: resolvedParams,
2127
2456
  action: 'getBalances'
2128
2457
  });
2129
2458
  try {
2130
2459
  const response = await retryApiCall(async () => {
2131
- const apiResponse = await this.api.getBalancesApiV1BrokersDataBalancesGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(isEndOfDaySnapshot !== undefined ? { isEndOfDaySnapshot: isEndOfDaySnapshot } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(balanceCreatedAfter !== undefined ? { balanceCreatedAfter: balanceCreatedAfter } : {}), ...(balanceCreatedBefore !== undefined ? { balanceCreatedBefore: balanceCreatedBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
2460
+ const apiResponse = await this.api.getBalancesApiV1BrokersDataBalancesGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, isEndOfDaySnapshot: resolvedParams.isEndOfDaySnapshot, limit: resolvedParams.limit, offset: resolvedParams.offset, balanceCreatedAfter: resolvedParams.balanceCreatedAfter, balanceCreatedBefore: resolvedParams.balanceCreatedBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
2132
2461
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2133
2462
  }, {}, this.sdkConfig);
2134
2463
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2137,9 +2466,27 @@ class BrokersWrapper {
2137
2466
  throw new Error('Unexpected response shape: missing success field');
2138
2467
  }
2139
2468
  // Convert response to plain object, removing _id fields recursively
2469
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2140
2470
  const standardResponse = convertToPlainObject(responseData);
2471
+ // Phase 2: Wrap paginated responses with PaginatedData
2472
+ const hasLimit = true;
2473
+ const hasOffset = true;
2474
+ const hasPagination = hasLimit && hasOffset;
2475
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2476
+ // PaginatedData is already imported at top of file
2477
+ const paginationMeta = standardResponse.success.meta?.pagination;
2478
+ if (paginationMeta) {
2479
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2480
+ has_more: paginationMeta.has_more,
2481
+ next_offset: paginationMeta.next_offset,
2482
+ current_offset: paginationMeta.current_offset,
2483
+ limit: paginationMeta.limit,
2484
+ }, this.getBalances.bind(this), resolvedParams, this);
2485
+ standardResponse.success.data = paginatedData;
2486
+ }
2487
+ }
2141
2488
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2142
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', params, this.sdkConfig);
2489
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
2143
2490
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2144
2491
  }
2145
2492
  this.logger.debug('Get Balances completed', {
@@ -2147,6 +2494,7 @@ class BrokersWrapper {
2147
2494
  action: 'getBalances'
2148
2495
  });
2149
2496
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2497
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2150
2498
  return standardResponse;
2151
2499
  }
2152
2500
  catch (error) {
@@ -2223,15 +2571,15 @@ class BrokersWrapper {
2223
2571
  *
2224
2572
  * This endpoint is accessible from the portal and uses session-only authentication.
2225
2573
  * Returns accounts from connections the company has read access to.
2226
- * @param brokerId {string} (optional)
2227
- * @param connectionId {string} (optional)
2228
- * @param accountType {BrokerDataAccountTypeEnum} (optional)
2229
- * @param status {AccountStatus} (optional)
2230
- * @param currency {string} (optional)
2231
- * @param limit {number} (optional)
2232
- * @param offset {number} (optional)
2233
- * @param includeMetadata {boolean} (optional)
2234
- * @returns {Promise<FinaticResponse<FDXBrokerAccount[]>>} Standard response with success/Error/Warning structure
2574
+ * @param params.brokerId {string} (optional) Filter by broker ID
2575
+ * @param params.connectionId {string} (optional) Filter by connection ID
2576
+ * @param params.accountType {BrokerDataAccountTypeEnum} (optional) Filter by account type (e.g., 'margin', 'cash', 'crypto_wallet', 'live', 'sim')
2577
+ * @param params.status {AccountStatus} (optional) Filter by account status (e.g., 'active', 'inactive')
2578
+ * @param params.currency {string} (optional) Filter by currency (e.g., 'USD', 'EUR')
2579
+ * @param params.limit {number} (optional) Maximum number of accounts to return
2580
+ * @param params.offset {number} (optional) Number of accounts to skip for pagination
2581
+ * @param params.includeMetadata {boolean} (optional) Include connection metadata in response (excluded by default for FDX compliance)
2582
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerAccount>>>} Standard response with success/Error/Warning structure
2235
2583
  *
2236
2584
  * Generated from: GET /api/v1/brokers/data/accounts
2237
2585
  * @methodId get_accounts_api_v1_brokers_data_accounts_get
@@ -2239,7 +2587,7 @@ class BrokersWrapper {
2239
2587
  * @example
2240
2588
  * ```typescript-client
2241
2589
  * // Example with no parameters
2242
- * const result = await finatic.getAccounts();
2590
+ * const result = await finatic.getAccounts({});
2243
2591
  *
2244
2592
  * // Access the response data
2245
2593
  * if (result.success) {
@@ -2249,7 +2597,11 @@ class BrokersWrapper {
2249
2597
  * @example
2250
2598
  * ```typescript-client
2251
2599
  * // Full example with optional parameters
2252
- * const result = await finatic.getAccounts(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountType: 'margin');
2600
+ * const result = await finatic.getAccounts({
2601
+ brokerId: 'alpaca',
2602
+ connectionId: '00000000-0000-0000-0000-000000000000',
2603
+ accountType: 'margin'
2604
+ * });
2253
2605
  *
2254
2606
  * // Handle response with warnings
2255
2607
  * if (result.success) {
@@ -2262,19 +2614,13 @@ class BrokersWrapper {
2262
2614
  * }
2263
2615
  * ```
2264
2616
  */
2265
- async getAccounts(brokerId, connectionId, accountType, status, currency, limit, offset, includeMetadata) {
2266
- // Construct params object from individual parameters
2267
- const params = {
2268
- brokerId: brokerId,
2269
- connectionId: connectionId,
2270
- accountType: accountType !== undefined ? coerceEnumValue(accountType, exports.BrokerDataAccountTypeEnum, 'accountType') : undefined,
2271
- status: status,
2272
- currency: currency,
2273
- limit: limit,
2274
- offset: offset,
2275
- includeMetadata: includeMetadata
2276
- }; // Authentication check
2277
- if (!this.sessionId) {
2617
+ async getAccounts(params) {
2618
+ // Use params object (with default empty object)
2619
+ const resolvedParams = params || {};
2620
+ if (params?.accountType !== undefined) {
2621
+ params.accountType = coerceEnumValue(params.accountType, exports.BrokerDataAccountTypeEnum, 'accountType');
2622
+ } // Authentication check
2623
+ if (!this.sessionId || !this.companyId) {
2278
2624
  throw new Error('Session not initialized. Call startSession() first.');
2279
2625
  }
2280
2626
  // Generate request ID
@@ -2285,7 +2631,7 @@ class BrokersWrapper {
2285
2631
  const shouldCache = true;
2286
2632
  const cache = getCache(this.sdkConfig);
2287
2633
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2288
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', params, this.sdkConfig);
2634
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
2289
2635
  const cached = cache.get(cacheKey);
2290
2636
  if (cached) {
2291
2637
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2297,12 +2643,12 @@ class BrokersWrapper {
2297
2643
  request_id: requestId,
2298
2644
  method: 'GET',
2299
2645
  path: '/api/v1/brokers/data/accounts',
2300
- params: params,
2646
+ params: resolvedParams,
2301
2647
  action: 'getAccounts'
2302
2648
  });
2303
2649
  try {
2304
2650
  const response = await retryApiCall(async () => {
2305
- const apiResponse = await this.api.getAccountsApiV1BrokersDataAccountsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountType !== undefined ? { accountType: accountType } : {}), ...(status !== undefined ? { status: status } : {}), ...(currency !== undefined ? { currency: currency } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
2651
+ const apiResponse = await this.api.getAccountsApiV1BrokersDataAccountsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountType: resolvedParams.accountType, status: resolvedParams.status, currency: resolvedParams.currency, limit: resolvedParams.limit, offset: resolvedParams.offset, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
2306
2652
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2307
2653
  }, {}, this.sdkConfig);
2308
2654
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2311,9 +2657,27 @@ class BrokersWrapper {
2311
2657
  throw new Error('Unexpected response shape: missing success field');
2312
2658
  }
2313
2659
  // Convert response to plain object, removing _id fields recursively
2660
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2314
2661
  const standardResponse = convertToPlainObject(responseData);
2662
+ // Phase 2: Wrap paginated responses with PaginatedData
2663
+ const hasLimit = true;
2664
+ const hasOffset = true;
2665
+ const hasPagination = hasLimit && hasOffset;
2666
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2667
+ // PaginatedData is already imported at top of file
2668
+ const paginationMeta = standardResponse.success.meta?.pagination;
2669
+ if (paginationMeta) {
2670
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2671
+ has_more: paginationMeta.has_more,
2672
+ next_offset: paginationMeta.next_offset,
2673
+ current_offset: paginationMeta.current_offset,
2674
+ limit: paginationMeta.limit,
2675
+ }, this.getAccounts.bind(this), resolvedParams, this);
2676
+ standardResponse.success.data = paginatedData;
2677
+ }
2678
+ }
2315
2679
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2316
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', params, this.sdkConfig);
2680
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
2317
2681
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2318
2682
  }
2319
2683
  this.logger.debug('Get Accounts completed', {
@@ -2321,6 +2685,7 @@ class BrokersWrapper {
2321
2685
  action: 'getAccounts'
2322
2686
  });
2323
2687
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2688
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2324
2689
  return standardResponse;
2325
2690
  }
2326
2691
  catch (error) {
@@ -2396,12 +2761,12 @@ class BrokersWrapper {
2396
2761
  * Get order fills for a specific order.
2397
2762
  *
2398
2763
  * This endpoint returns all execution fills for the specified order.
2399
- * @param orderId {string}
2400
- * @param connectionId {string} (optional)
2401
- * @param limit {number} (optional)
2402
- * @param offset {number} (optional)
2403
- * @param includeMetadata {boolean} (optional)
2404
- * @returns {Promise<FinaticResponse<FDXBrokerOrderFill[]>>} Standard response with success/Error/Warning structure
2764
+ * @param params.orderId {string} Order ID
2765
+ * @param params.connectionId {string} (optional) Filter by connection ID
2766
+ * @param params.limit {number} (optional) Maximum number of fills to return
2767
+ * @param params.offset {number} (optional) Number of fills to skip for pagination
2768
+ * @param params.includeMetadata {boolean} (optional) Include fill metadata in response (excluded by default for FDX compliance)
2769
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderFill>>>} Standard response with success/Error/Warning structure
2405
2770
  *
2406
2771
  * Generated from: GET /api/v1/brokers/data/orders/{order_id}/fills
2407
2772
  * @methodId get_order_fills_api_v1_brokers_data_orders__order_id__fills_get
@@ -2409,7 +2774,9 @@ class BrokersWrapper {
2409
2774
  * @example
2410
2775
  * ```typescript-client
2411
2776
  * // Minimal example with required parameters only
2412
- * const result = await finatic.getOrderFills(orderId: '00000000-0000-0000-0000-000000000000');
2777
+ * const result = await finatic.getOrderFills({
2778
+ orderId: '00000000-0000-0000-0000-000000000000'
2779
+ * });
2413
2780
  *
2414
2781
  * // Access the response data
2415
2782
  * if (result.success) {
@@ -2421,7 +2788,12 @@ class BrokersWrapper {
2421
2788
  * @example
2422
2789
  * ```typescript-client
2423
2790
  * // Full example with optional parameters
2424
- * const result = await finatic.getOrderFills(orderId: '00000000-0000-0000-0000-000000000000', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100, offset: 0);
2791
+ * const result = await finatic.getOrderFills({
2792
+ orderId: '00000000-0000-0000-0000-000000000000',
2793
+ connectionId: '00000000-0000-0000-0000-000000000000',
2794
+ limit: 100,
2795
+ offset: 0
2796
+ * });
2425
2797
  *
2426
2798
  * // Handle response with warnings
2427
2799
  * if (result.success) {
@@ -2434,16 +2806,10 @@ class BrokersWrapper {
2434
2806
  * }
2435
2807
  * ```
2436
2808
  */
2437
- async getOrderFills(orderId, connectionId, limit, offset, includeMetadata) {
2438
- // Construct params object from individual parameters
2439
- const params = {
2440
- orderId: orderId,
2441
- connectionId: connectionId,
2442
- limit: limit,
2443
- offset: offset,
2444
- includeMetadata: includeMetadata
2445
- }; // Authentication check
2446
- if (!this.sessionId) {
2809
+ async getOrderFills(params) {
2810
+ // Use params object (required parameters present)
2811
+ const resolvedParams = params; // Authentication check
2812
+ if (!this.sessionId || !this.companyId) {
2447
2813
  throw new Error('Session not initialized. Call startSession() first.');
2448
2814
  }
2449
2815
  // Generate request ID
@@ -2454,7 +2820,7 @@ class BrokersWrapper {
2454
2820
  const shouldCache = true;
2455
2821
  const cache = getCache(this.sdkConfig);
2456
2822
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2457
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', params, this.sdkConfig);
2823
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
2458
2824
  const cached = cache.get(cacheKey);
2459
2825
  if (cached) {
2460
2826
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2466,12 +2832,12 @@ class BrokersWrapper {
2466
2832
  request_id: requestId,
2467
2833
  method: 'GET',
2468
2834
  path: '/api/v1/brokers/data/orders/{order_id}/fills',
2469
- params: params,
2835
+ params: resolvedParams,
2470
2836
  action: 'getOrderFills'
2471
2837
  });
2472
2838
  try {
2473
2839
  const response = await retryApiCall(async () => {
2474
- const apiResponse = await this.api.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet({ orderId: orderId, ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
2840
+ const apiResponse = await this.api.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet({ orderId: resolvedParams.orderId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
2475
2841
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2476
2842
  }, {}, this.sdkConfig);
2477
2843
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2480,9 +2846,27 @@ class BrokersWrapper {
2480
2846
  throw new Error('Unexpected response shape: missing success field');
2481
2847
  }
2482
2848
  // Convert response to plain object, removing _id fields recursively
2849
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2483
2850
  const standardResponse = convertToPlainObject(responseData);
2851
+ // Phase 2: Wrap paginated responses with PaginatedData
2852
+ const hasLimit = true;
2853
+ const hasOffset = true;
2854
+ const hasPagination = hasLimit && hasOffset;
2855
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2856
+ // PaginatedData is already imported at top of file
2857
+ const paginationMeta = standardResponse.success.meta?.pagination;
2858
+ if (paginationMeta) {
2859
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2860
+ has_more: paginationMeta.has_more,
2861
+ next_offset: paginationMeta.next_offset,
2862
+ current_offset: paginationMeta.current_offset,
2863
+ limit: paginationMeta.limit,
2864
+ }, this.getOrderFills.bind(this), resolvedParams, this);
2865
+ standardResponse.success.data = paginatedData;
2866
+ }
2867
+ }
2484
2868
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2485
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', params, this.sdkConfig);
2869
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
2486
2870
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2487
2871
  }
2488
2872
  this.logger.debug('Get Order Fills completed', {
@@ -2490,6 +2874,7 @@ class BrokersWrapper {
2490
2874
  action: 'getOrderFills'
2491
2875
  });
2492
2876
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2877
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2493
2878
  return standardResponse;
2494
2879
  }
2495
2880
  catch (error) {
@@ -2565,12 +2950,12 @@ class BrokersWrapper {
2565
2950
  * Get order events for a specific order.
2566
2951
  *
2567
2952
  * This endpoint returns all lifecycle events for the specified order.
2568
- * @param orderId {string}
2569
- * @param connectionId {string} (optional)
2570
- * @param limit {number} (optional)
2571
- * @param offset {number} (optional)
2572
- * @param includeMetadata {boolean} (optional)
2573
- * @returns {Promise<FinaticResponse<FDXBrokerOrderEvent[]>>} Standard response with success/Error/Warning structure
2953
+ * @param params.orderId {string} Order ID
2954
+ * @param params.connectionId {string} (optional) Filter by connection ID
2955
+ * @param params.limit {number} (optional) Maximum number of events to return
2956
+ * @param params.offset {number} (optional) Number of events to skip for pagination
2957
+ * @param params.includeMetadata {boolean} (optional) Include event metadata in response (excluded by default for FDX compliance)
2958
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderEvent>>>} Standard response with success/Error/Warning structure
2574
2959
  *
2575
2960
  * Generated from: GET /api/v1/brokers/data/orders/{order_id}/events
2576
2961
  * @methodId get_order_events_api_v1_brokers_data_orders__order_id__events_get
@@ -2578,7 +2963,9 @@ class BrokersWrapper {
2578
2963
  * @example
2579
2964
  * ```typescript-client
2580
2965
  * // Minimal example with required parameters only
2581
- * const result = await finatic.getOrderEvents(orderId: '00000000-0000-0000-0000-000000000000');
2966
+ * const result = await finatic.getOrderEvents({
2967
+ orderId: '00000000-0000-0000-0000-000000000000'
2968
+ * });
2582
2969
  *
2583
2970
  * // Access the response data
2584
2971
  * if (result.success) {
@@ -2590,7 +2977,12 @@ class BrokersWrapper {
2590
2977
  * @example
2591
2978
  * ```typescript-client
2592
2979
  * // Full example with optional parameters
2593
- * const result = await finatic.getOrderEvents(orderId: '00000000-0000-0000-0000-000000000000', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100, offset: 0);
2980
+ * const result = await finatic.getOrderEvents({
2981
+ orderId: '00000000-0000-0000-0000-000000000000',
2982
+ connectionId: '00000000-0000-0000-0000-000000000000',
2983
+ limit: 100,
2984
+ offset: 0
2985
+ * });
2594
2986
  *
2595
2987
  * // Handle response with warnings
2596
2988
  * if (result.success) {
@@ -2603,16 +2995,10 @@ class BrokersWrapper {
2603
2995
  * }
2604
2996
  * ```
2605
2997
  */
2606
- async getOrderEvents(orderId, connectionId, limit, offset, includeMetadata) {
2607
- // Construct params object from individual parameters
2608
- const params = {
2609
- orderId: orderId,
2610
- connectionId: connectionId,
2611
- limit: limit,
2612
- offset: offset,
2613
- includeMetadata: includeMetadata
2614
- }; // Authentication check
2615
- if (!this.sessionId) {
2998
+ async getOrderEvents(params) {
2999
+ // Use params object (required parameters present)
3000
+ const resolvedParams = params; // Authentication check
3001
+ if (!this.sessionId || !this.companyId) {
2616
3002
  throw new Error('Session not initialized. Call startSession() first.');
2617
3003
  }
2618
3004
  // Generate request ID
@@ -2623,7 +3009,7 @@ class BrokersWrapper {
2623
3009
  const shouldCache = true;
2624
3010
  const cache = getCache(this.sdkConfig);
2625
3011
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2626
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', params, this.sdkConfig);
3012
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
2627
3013
  const cached = cache.get(cacheKey);
2628
3014
  if (cached) {
2629
3015
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2635,12 +3021,12 @@ class BrokersWrapper {
2635
3021
  request_id: requestId,
2636
3022
  method: 'GET',
2637
3023
  path: '/api/v1/brokers/data/orders/{order_id}/events',
2638
- params: params,
3024
+ params: resolvedParams,
2639
3025
  action: 'getOrderEvents'
2640
3026
  });
2641
3027
  try {
2642
3028
  const response = await retryApiCall(async () => {
2643
- const apiResponse = await this.api.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet({ orderId: orderId, ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
3029
+ const apiResponse = await this.api.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet({ orderId: resolvedParams.orderId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
2644
3030
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2645
3031
  }, {}, this.sdkConfig);
2646
3032
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2649,9 +3035,27 @@ class BrokersWrapper {
2649
3035
  throw new Error('Unexpected response shape: missing success field');
2650
3036
  }
2651
3037
  // Convert response to plain object, removing _id fields recursively
3038
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2652
3039
  const standardResponse = convertToPlainObject(responseData);
3040
+ // Phase 2: Wrap paginated responses with PaginatedData
3041
+ const hasLimit = true;
3042
+ const hasOffset = true;
3043
+ const hasPagination = hasLimit && hasOffset;
3044
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3045
+ // PaginatedData is already imported at top of file
3046
+ const paginationMeta = standardResponse.success.meta?.pagination;
3047
+ if (paginationMeta) {
3048
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3049
+ has_more: paginationMeta.has_more,
3050
+ next_offset: paginationMeta.next_offset,
3051
+ current_offset: paginationMeta.current_offset,
3052
+ limit: paginationMeta.limit,
3053
+ }, this.getOrderEvents.bind(this), resolvedParams, this);
3054
+ standardResponse.success.data = paginatedData;
3055
+ }
3056
+ }
2653
3057
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2654
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', params, this.sdkConfig);
3058
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
2655
3059
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2656
3060
  }
2657
3061
  this.logger.debug('Get Order Events completed', {
@@ -2659,6 +3063,7 @@ class BrokersWrapper {
2659
3063
  action: 'getOrderEvents'
2660
3064
  });
2661
3065
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3066
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2662
3067
  return standardResponse;
2663
3068
  }
2664
3069
  catch (error) {
@@ -2734,14 +3139,14 @@ class BrokersWrapper {
2734
3139
  * Get order groups.
2735
3140
  *
2736
3141
  * This endpoint returns order groups that contain multiple orders.
2737
- * @param brokerId {string} (optional)
2738
- * @param connectionId {string} (optional)
2739
- * @param limit {number} (optional)
2740
- * @param offset {number} (optional)
2741
- * @param createdAfter {string} (optional)
2742
- * @param createdBefore {string} (optional)
2743
- * @param includeMetadata {boolean} (optional)
2744
- * @returns {Promise<FinaticResponse<FDXBrokerOrderGroup[]>>} Standard response with success/Error/Warning structure
3142
+ * @param params.brokerId {string} (optional) Filter by broker ID
3143
+ * @param params.connectionId {string} (optional) Filter by connection ID
3144
+ * @param params.limit {number} (optional) Maximum number of order groups to return
3145
+ * @param params.offset {number} (optional) Number of order groups to skip for pagination
3146
+ * @param params.createdAfter {string} (optional) Filter order groups created after this timestamp
3147
+ * @param params.createdBefore {string} (optional) Filter order groups created before this timestamp
3148
+ * @param params.includeMetadata {boolean} (optional) Include group metadata in response (excluded by default for FDX compliance)
3149
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderGroup>>>} Standard response with success/Error/Warning structure
2745
3150
  *
2746
3151
  * Generated from: GET /api/v1/brokers/data/orders/groups
2747
3152
  * @methodId get_order_groups_api_v1_brokers_data_orders_groups_get
@@ -2749,7 +3154,7 @@ class BrokersWrapper {
2749
3154
  * @example
2750
3155
  * ```typescript-client
2751
3156
  * // Example with no parameters
2752
- * const result = await finatic.getOrderGroups();
3157
+ * const result = await finatic.getOrderGroups({});
2753
3158
  *
2754
3159
  * // Access the response data
2755
3160
  * if (result.success) {
@@ -2759,7 +3164,11 @@ class BrokersWrapper {
2759
3164
  * @example
2760
3165
  * ```typescript-client
2761
3166
  * // Full example with optional parameters
2762
- * const result = await finatic.getOrderGroups(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100);
3167
+ * const result = await finatic.getOrderGroups({
3168
+ brokerId: 'alpaca',
3169
+ connectionId: '00000000-0000-0000-0000-000000000000',
3170
+ limit: 100
3171
+ * });
2763
3172
  *
2764
3173
  * // Handle response with warnings
2765
3174
  * if (result.success) {
@@ -2772,18 +3181,10 @@ class BrokersWrapper {
2772
3181
  * }
2773
3182
  * ```
2774
3183
  */
2775
- async getOrderGroups(brokerId, connectionId, limit, offset, createdAfter, createdBefore, includeMetadata) {
2776
- // Construct params object from individual parameters
2777
- const params = {
2778
- brokerId: brokerId,
2779
- connectionId: connectionId,
2780
- limit: limit,
2781
- offset: offset,
2782
- createdAfter: createdAfter,
2783
- createdBefore: createdBefore,
2784
- includeMetadata: includeMetadata
2785
- }; // Authentication check
2786
- if (!this.sessionId) {
3184
+ async getOrderGroups(params) {
3185
+ // Use params object (with default empty object)
3186
+ const resolvedParams = params || {}; // Authentication check
3187
+ if (!this.sessionId || !this.companyId) {
2787
3188
  throw new Error('Session not initialized. Call startSession() first.');
2788
3189
  }
2789
3190
  // Generate request ID
@@ -2794,7 +3195,7 @@ class BrokersWrapper {
2794
3195
  const shouldCache = true;
2795
3196
  const cache = getCache(this.sdkConfig);
2796
3197
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2797
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', params, this.sdkConfig);
3198
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
2798
3199
  const cached = cache.get(cacheKey);
2799
3200
  if (cached) {
2800
3201
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2806,12 +3207,12 @@ class BrokersWrapper {
2806
3207
  request_id: requestId,
2807
3208
  method: 'GET',
2808
3209
  path: '/api/v1/brokers/data/orders/groups',
2809
- params: params,
3210
+ params: resolvedParams,
2810
3211
  action: 'getOrderGroups'
2811
3212
  });
2812
3213
  try {
2813
3214
  const response = await retryApiCall(async () => {
2814
- const apiResponse = await this.api.getOrderGroupsApiV1BrokersDataOrdersGroupsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(createdAfter !== undefined ? { createdAfter: createdAfter } : {}), ...(createdBefore !== undefined ? { createdBefore: createdBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
3215
+ const apiResponse = await this.api.getOrderGroupsApiV1BrokersDataOrdersGroupsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset, createdAfter: resolvedParams.createdAfter, createdBefore: resolvedParams.createdBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
2815
3216
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2816
3217
  }, {}, this.sdkConfig);
2817
3218
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2820,9 +3221,27 @@ class BrokersWrapper {
2820
3221
  throw new Error('Unexpected response shape: missing success field');
2821
3222
  }
2822
3223
  // Convert response to plain object, removing _id fields recursively
3224
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2823
3225
  const standardResponse = convertToPlainObject(responseData);
3226
+ // Phase 2: Wrap paginated responses with PaginatedData
3227
+ const hasLimit = true;
3228
+ const hasOffset = true;
3229
+ const hasPagination = hasLimit && hasOffset;
3230
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3231
+ // PaginatedData is already imported at top of file
3232
+ const paginationMeta = standardResponse.success.meta?.pagination;
3233
+ if (paginationMeta) {
3234
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3235
+ has_more: paginationMeta.has_more,
3236
+ next_offset: paginationMeta.next_offset,
3237
+ current_offset: paginationMeta.current_offset,
3238
+ limit: paginationMeta.limit,
3239
+ }, this.getOrderGroups.bind(this), resolvedParams, this);
3240
+ standardResponse.success.data = paginatedData;
3241
+ }
3242
+ }
2824
3243
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2825
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', params, this.sdkConfig);
3244
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
2826
3245
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2827
3246
  }
2828
3247
  this.logger.debug('Get Order Groups completed', {
@@ -2830,6 +3249,7 @@ class BrokersWrapper {
2830
3249
  action: 'getOrderGroups'
2831
3250
  });
2832
3251
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3252
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2833
3253
  return standardResponse;
2834
3254
  }
2835
3255
  catch (error) {
@@ -2906,14 +3326,14 @@ class BrokersWrapper {
2906
3326
  *
2907
3327
  * This endpoint returns tax lots for positions, which are used for tax reporting.
2908
3328
  * Each lot tracks when a position was opened/closed and at what prices.
2909
- * @param brokerId {string} (optional)
2910
- * @param connectionId {string} (optional)
2911
- * @param accountId {string} (optional)
2912
- * @param symbol {string} (optional)
2913
- * @param positionId {string} (optional)
2914
- * @param limit {number} (optional)
2915
- * @param offset {number} (optional)
2916
- * @returns {Promise<FinaticResponse<FDXBrokerPositionLot[]>>} Standard response with success/Error/Warning structure
3329
+ * @param params.brokerId {string} (optional) Filter by broker ID
3330
+ * @param params.connectionId {string} (optional) Filter by connection ID
3331
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
3332
+ * @param params.symbol {string} (optional) Filter by symbol
3333
+ * @param params.positionId {string} (optional) Filter by position ID
3334
+ * @param params.limit {number} (optional) Maximum number of position lots to return
3335
+ * @param params.offset {number} (optional) Number of position lots to skip for pagination
3336
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLot>>>} Standard response with success/Error/Warning structure
2917
3337
  *
2918
3338
  * Generated from: GET /api/v1/brokers/data/positions/lots
2919
3339
  * @methodId get_position_lots_api_v1_brokers_data_positions_lots_get
@@ -2921,7 +3341,7 @@ class BrokersWrapper {
2921
3341
  * @example
2922
3342
  * ```typescript-client
2923
3343
  * // Example with no parameters
2924
- * const result = await finatic.getPositionLots();
3344
+ * const result = await finatic.getPositionLots({});
2925
3345
  *
2926
3346
  * // Access the response data
2927
3347
  * if (result.success) {
@@ -2931,7 +3351,11 @@ class BrokersWrapper {
2931
3351
  * @example
2932
3352
  * ```typescript-client
2933
3353
  * // Full example with optional parameters
2934
- * const result = await finatic.getPositionLots(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
3354
+ * const result = await finatic.getPositionLots({
3355
+ brokerId: 'alpaca',
3356
+ connectionId: '00000000-0000-0000-0000-000000000000',
3357
+ accountId: '123456789'
3358
+ * });
2935
3359
  *
2936
3360
  * // Handle response with warnings
2937
3361
  * if (result.success) {
@@ -2944,18 +3368,10 @@ class BrokersWrapper {
2944
3368
  * }
2945
3369
  * ```
2946
3370
  */
2947
- async getPositionLots(brokerId, connectionId, accountId, symbol, positionId, limit, offset) {
2948
- // Construct params object from individual parameters
2949
- const params = {
2950
- brokerId: brokerId,
2951
- connectionId: connectionId,
2952
- accountId: accountId,
2953
- symbol: symbol,
2954
- positionId: positionId,
2955
- limit: limit,
2956
- offset: offset
2957
- }; // Authentication check
2958
- if (!this.sessionId) {
3371
+ async getPositionLots(params) {
3372
+ // Use params object (with default empty object)
3373
+ const resolvedParams = params || {}; // Authentication check
3374
+ if (!this.sessionId || !this.companyId) {
2959
3375
  throw new Error('Session not initialized. Call startSession() first.');
2960
3376
  }
2961
3377
  // Generate request ID
@@ -2966,7 +3382,7 @@ class BrokersWrapper {
2966
3382
  const shouldCache = true;
2967
3383
  const cache = getCache(this.sdkConfig);
2968
3384
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2969
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', params, this.sdkConfig);
3385
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
2970
3386
  const cached = cache.get(cacheKey);
2971
3387
  if (cached) {
2972
3388
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2978,12 +3394,12 @@ class BrokersWrapper {
2978
3394
  request_id: requestId,
2979
3395
  method: 'GET',
2980
3396
  path: '/api/v1/brokers/data/positions/lots',
2981
- params: params,
3397
+ params: resolvedParams,
2982
3398
  action: 'getPositionLots'
2983
3399
  });
2984
3400
  try {
2985
3401
  const response = await retryApiCall(async () => {
2986
- const apiResponse = await this.api.getPositionLotsApiV1BrokersDataPositionsLotsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(symbol !== undefined ? { symbol: symbol } : {}), ...(positionId !== undefined ? { positionId: positionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
3402
+ const apiResponse = await this.api.getPositionLotsApiV1BrokersDataPositionsLotsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, symbol: resolvedParams.symbol, positionId: resolvedParams.positionId, limit: resolvedParams.limit, offset: resolvedParams.offset }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
2987
3403
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2988
3404
  }, {}, this.sdkConfig);
2989
3405
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2992,9 +3408,27 @@ class BrokersWrapper {
2992
3408
  throw new Error('Unexpected response shape: missing success field');
2993
3409
  }
2994
3410
  // Convert response to plain object, removing _id fields recursively
3411
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2995
3412
  const standardResponse = convertToPlainObject(responseData);
3413
+ // Phase 2: Wrap paginated responses with PaginatedData
3414
+ const hasLimit = true;
3415
+ const hasOffset = true;
3416
+ const hasPagination = hasLimit && hasOffset;
3417
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3418
+ // PaginatedData is already imported at top of file
3419
+ const paginationMeta = standardResponse.success.meta?.pagination;
3420
+ if (paginationMeta) {
3421
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3422
+ has_more: paginationMeta.has_more,
3423
+ next_offset: paginationMeta.next_offset,
3424
+ current_offset: paginationMeta.current_offset,
3425
+ limit: paginationMeta.limit,
3426
+ }, this.getPositionLots.bind(this), resolvedParams, this);
3427
+ standardResponse.success.data = paginatedData;
3428
+ }
3429
+ }
2996
3430
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2997
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', params, this.sdkConfig);
3431
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
2998
3432
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2999
3433
  }
3000
3434
  this.logger.debug('Get Position Lots completed', {
@@ -3002,6 +3436,7 @@ class BrokersWrapper {
3002
3436
  action: 'getPositionLots'
3003
3437
  });
3004
3438
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3439
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3005
3440
  return standardResponse;
3006
3441
  }
3007
3442
  catch (error) {
@@ -3077,11 +3512,11 @@ class BrokersWrapper {
3077
3512
  * Get position lot fills for a specific lot.
3078
3513
  *
3079
3514
  * This endpoint returns all fills associated with a specific position lot.
3080
- * @param lotId {string}
3081
- * @param connectionId {string} (optional)
3082
- * @param limit {number} (optional)
3083
- * @param offset {number} (optional)
3084
- * @returns {Promise<FinaticResponse<FDXBrokerPositionLotFill[]>>} Standard response with success/Error/Warning structure
3515
+ * @param params.lotId {string} Position lot ID
3516
+ * @param params.connectionId {string} (optional) Filter by connection ID
3517
+ * @param params.limit {number} (optional) Maximum number of fills to return
3518
+ * @param params.offset {number} (optional) Number of fills to skip for pagination
3519
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLotFill>>>} Standard response with success/Error/Warning structure
3085
3520
  *
3086
3521
  * Generated from: GET /api/v1/brokers/data/positions/lots/{lot_id}/fills
3087
3522
  * @methodId get_position_lot_fills_api_v1_brokers_data_positions_lots__lot_id__fills_get
@@ -3089,7 +3524,9 @@ class BrokersWrapper {
3089
3524
  * @example
3090
3525
  * ```typescript-client
3091
3526
  * // Minimal example with required parameters only
3092
- * const result = await finatic.getPositionLotFills(lotId: '00000000-0000-0000-0000-000000000000');
3527
+ * const result = await finatic.getPositionLotFills({
3528
+ lotId: '00000000-0000-0000-0000-000000000000'
3529
+ * });
3093
3530
  *
3094
3531
  * // Access the response data
3095
3532
  * if (result.success) {
@@ -3101,7 +3538,12 @@ class BrokersWrapper {
3101
3538
  * @example
3102
3539
  * ```typescript-client
3103
3540
  * // Full example with optional parameters
3104
- * const result = await finatic.getPositionLotFills(lotId: '00000000-0000-0000-0000-000000000000', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100, offset: 0);
3541
+ * const result = await finatic.getPositionLotFills({
3542
+ lotId: '00000000-0000-0000-0000-000000000000',
3543
+ connectionId: '00000000-0000-0000-0000-000000000000',
3544
+ limit: 100,
3545
+ offset: 0
3546
+ * });
3105
3547
  *
3106
3548
  * // Handle response with warnings
3107
3549
  * if (result.success) {
@@ -3114,15 +3556,10 @@ class BrokersWrapper {
3114
3556
  * }
3115
3557
  * ```
3116
3558
  */
3117
- async getPositionLotFills(lotId, connectionId, limit, offset) {
3118
- // Construct params object from individual parameters
3119
- const params = {
3120
- lotId: lotId,
3121
- connectionId: connectionId,
3122
- limit: limit,
3123
- offset: offset
3124
- }; // Authentication check
3125
- if (!this.sessionId) {
3559
+ async getPositionLotFills(params) {
3560
+ // Use params object (required parameters present)
3561
+ const resolvedParams = params; // Authentication check
3562
+ if (!this.sessionId || !this.companyId) {
3126
3563
  throw new Error('Session not initialized. Call startSession() first.');
3127
3564
  }
3128
3565
  // Generate request ID
@@ -3133,7 +3570,7 @@ class BrokersWrapper {
3133
3570
  const shouldCache = true;
3134
3571
  const cache = getCache(this.sdkConfig);
3135
3572
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3136
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', params, this.sdkConfig);
3573
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
3137
3574
  const cached = cache.get(cacheKey);
3138
3575
  if (cached) {
3139
3576
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3145,12 +3582,12 @@ class BrokersWrapper {
3145
3582
  request_id: requestId,
3146
3583
  method: 'GET',
3147
3584
  path: '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
3148
- params: params,
3585
+ params: resolvedParams,
3149
3586
  action: 'getPositionLotFills'
3150
3587
  });
3151
3588
  try {
3152
3589
  const response = await retryApiCall(async () => {
3153
- const apiResponse = await this.api.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet({ lotId: lotId, ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
3590
+ const apiResponse = await this.api.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet({ lotId: resolvedParams.lotId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
3154
3591
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3155
3592
  }, {}, this.sdkConfig);
3156
3593
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3159,9 +3596,27 @@ class BrokersWrapper {
3159
3596
  throw new Error('Unexpected response shape: missing success field');
3160
3597
  }
3161
3598
  // Convert response to plain object, removing _id fields recursively
3599
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3162
3600
  const standardResponse = convertToPlainObject(responseData);
3601
+ // Phase 2: Wrap paginated responses with PaginatedData
3602
+ const hasLimit = true;
3603
+ const hasOffset = true;
3604
+ const hasPagination = hasLimit && hasOffset;
3605
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3606
+ // PaginatedData is already imported at top of file
3607
+ const paginationMeta = standardResponse.success.meta?.pagination;
3608
+ if (paginationMeta) {
3609
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3610
+ has_more: paginationMeta.has_more,
3611
+ next_offset: paginationMeta.next_offset,
3612
+ current_offset: paginationMeta.current_offset,
3613
+ limit: paginationMeta.limit,
3614
+ }, this.getPositionLotFills.bind(this), resolvedParams, this);
3615
+ standardResponse.success.data = paginatedData;
3616
+ }
3617
+ }
3163
3618
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3164
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', params, this.sdkConfig);
3619
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
3165
3620
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3166
3621
  }
3167
3622
  this.logger.debug('Get Position Lot Fills completed', {
@@ -3169,6 +3624,7 @@ class BrokersWrapper {
3169
3624
  action: 'getPositionLotFills'
3170
3625
  });
3171
3626
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3627
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3172
3628
  return standardResponse;
3173
3629
  }
3174
3630
  catch (error) {
@@ -3281,7 +3737,7 @@ class CompanyWrapper {
3281
3737
  * Get Company
3282
3738
  *
3283
3739
  * Get public company details by ID (no user check, no sensitive data).
3284
- * @param companyId {string}
3740
+ * @param params.companyId {string} Company ID
3285
3741
  * @returns {Promise<FinaticResponse<CompanyResponse>>} Standard response with success/Error/Warning structure
3286
3742
  *
3287
3743
  * Generated from: GET /api/v1/company/{company_id}
@@ -3290,7 +3746,9 @@ class CompanyWrapper {
3290
3746
  * @example
3291
3747
  * ```typescript-client
3292
3748
  * // Minimal example with required parameters only
3293
- * const result = await finatic.getCompany(companyId: '00000000-0000-0000-0000-000000000000');
3749
+ * const result = await finatic.getCompany({
3750
+ companyId: '00000000-0000-0000-0000-000000000000'
3751
+ * });
3294
3752
  *
3295
3753
  * // Access the response data
3296
3754
  * if (result.success) {
@@ -3300,11 +3758,9 @@ class CompanyWrapper {
3300
3758
  * }
3301
3759
  * ```
3302
3760
  */
3303
- async getCompany(companyId) {
3304
- // Construct params object from individual parameters
3305
- const params = {
3306
- companyId: companyId
3307
- }; // Generate request ID
3761
+ async getCompany(params) {
3762
+ // Use params object (required parameters present)
3763
+ const resolvedParams = params; // Generate request ID
3308
3764
  const requestId = this._generateRequestId();
3309
3765
  // Input validation (Phase 2B: zod)
3310
3766
  if (this.sdkConfig?.validationEnabled) ;
@@ -3312,7 +3768,7 @@ class CompanyWrapper {
3312
3768
  const shouldCache = true;
3313
3769
  const cache = getCache(this.sdkConfig);
3314
3770
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3315
- const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', params, this.sdkConfig);
3771
+ const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
3316
3772
  const cached = cache.get(cacheKey);
3317
3773
  if (cached) {
3318
3774
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3324,12 +3780,12 @@ class CompanyWrapper {
3324
3780
  request_id: requestId,
3325
3781
  method: 'GET',
3326
3782
  path: '/api/v1/company/{company_id}',
3327
- params: params,
3783
+ params: resolvedParams,
3328
3784
  action: 'getCompany'
3329
3785
  });
3330
3786
  try {
3331
3787
  const response = await retryApiCall(async () => {
3332
- const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: companyId }, { headers: { 'x-request-id': requestId } });
3788
+ const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: resolvedParams.companyId }, { headers: { 'x-request-id': requestId } });
3333
3789
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3334
3790
  }, {}, this.sdkConfig);
3335
3791
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3338,9 +3794,15 @@ class CompanyWrapper {
3338
3794
  throw new Error('Unexpected response shape: missing success field');
3339
3795
  }
3340
3796
  // Convert response to plain object, removing _id fields recursively
3797
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3341
3798
  const standardResponse = convertToPlainObject(responseData);
3799
+ // Phase 2: Wrap paginated responses with PaginatedData
3800
+ const hasLimit = false;
3801
+ const hasOffset = false;
3802
+ const hasPagination = hasLimit && hasOffset;
3803
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3342
3804
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3343
- const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', params, this.sdkConfig);
3805
+ const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
3344
3806
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3345
3807
  }
3346
3808
  this.logger.debug('Get Company completed', {
@@ -3348,6 +3810,7 @@ class CompanyWrapper {
3348
3810
  action: 'getCompany'
3349
3811
  });
3350
3812
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3813
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3351
3814
  return standardResponse;
3352
3815
  }
3353
3816
  catch (error) {
@@ -3460,7 +3923,7 @@ class SessionWrapper {
3460
3923
  * Init Session
3461
3924
  *
3462
3925
  * Initialize a new session with company API key.
3463
- * @param xApiKey {string}
3926
+ * @param params.xApiKey {string} Company API key
3464
3927
  * @returns {Promise<FinaticResponse<TokenResponseData>>} Standard response with success/Error/Warning structure
3465
3928
  *
3466
3929
  * Generated from: POST /api/v1/session/init
@@ -3469,7 +3932,7 @@ class SessionWrapper {
3469
3932
  * @example
3470
3933
  * ```typescript-client
3471
3934
  * // Example with no parameters
3472
- * const result = await finatic.initSession();
3935
+ * const result = await finatic.initSession({});
3473
3936
  *
3474
3937
  * // Access the response data
3475
3938
  * if (result.success) {
@@ -3477,11 +3940,9 @@ class SessionWrapper {
3477
3940
  * }
3478
3941
  * ```
3479
3942
  */
3480
- async initSession(xApiKey) {
3481
- // Construct params object from individual parameters
3482
- const params = {
3483
- xApiKey: xApiKey
3484
- }; // Generate request ID
3943
+ async initSession(params) {
3944
+ // Use params object (required parameters present)
3945
+ const resolvedParams = params; // Generate request ID
3485
3946
  const requestId = this._generateRequestId();
3486
3947
  // Input validation (Phase 2B: zod)
3487
3948
  if (this.sdkConfig?.validationEnabled) ;
@@ -3489,7 +3950,7 @@ class SessionWrapper {
3489
3950
  const shouldCache = true;
3490
3951
  const cache = getCache(this.sdkConfig);
3491
3952
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3492
- const cacheKey = generateCacheKey('POST', '/api/v1/session/init', params, this.sdkConfig);
3953
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
3493
3954
  const cached = cache.get(cacheKey);
3494
3955
  if (cached) {
3495
3956
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3501,12 +3962,12 @@ class SessionWrapper {
3501
3962
  request_id: requestId,
3502
3963
  method: 'POST',
3503
3964
  path: '/api/v1/session/init',
3504
- params: params,
3965
+ params: resolvedParams,
3505
3966
  action: 'initSession'
3506
3967
  });
3507
3968
  try {
3508
3969
  const response = await retryApiCall(async () => {
3509
- const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: xApiKey }, { headers: { 'x-request-id': requestId } });
3970
+ const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: resolvedParams.xApiKey }, { headers: { 'x-request-id': requestId } });
3510
3971
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3511
3972
  }, {}, this.sdkConfig);
3512
3973
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3515,9 +3976,15 @@ class SessionWrapper {
3515
3976
  throw new Error('Unexpected response shape: missing success field');
3516
3977
  }
3517
3978
  // Convert response to plain object, removing _id fields recursively
3979
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3518
3980
  const standardResponse = convertToPlainObject(responseData);
3981
+ // Phase 2: Wrap paginated responses with PaginatedData
3982
+ const hasLimit = false;
3983
+ const hasOffset = false;
3984
+ const hasPagination = hasLimit && hasOffset;
3985
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3519
3986
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3520
- const cacheKey = generateCacheKey('POST', '/api/v1/session/init', params, this.sdkConfig);
3987
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
3521
3988
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3522
3989
  }
3523
3990
  this.logger.debug('Init Session completed', {
@@ -3525,6 +3992,7 @@ class SessionWrapper {
3525
3992
  action: 'initSession'
3526
3993
  });
3527
3994
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3995
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3528
3996
  return standardResponse;
3529
3997
  }
3530
3998
  catch (error) {
@@ -3598,8 +4066,8 @@ class SessionWrapper {
3598
4066
  * Start Session
3599
4067
  *
3600
4068
  * Start a session with a one-time token.
3601
- * @param OneTimeToken {string}
3602
- * @param body {SessionStartRequest}
4069
+ * @param params.OneTimeToken {string} One-time use token obtained from init_session endpoint to authenticate and start the session
4070
+ * @param params.body {SessionStartRequest} Session start request containing optional user ID to associate with the session
3603
4071
  * @returns {Promise<FinaticResponse<SessionResponseData>>} Standard response with success/Error/Warning structure
3604
4072
  *
3605
4073
  * Generated from: POST /api/v1/session/start
@@ -3608,7 +4076,7 @@ class SessionWrapper {
3608
4076
  * @example
3609
4077
  * ```typescript-client
3610
4078
  * // Example with no parameters
3611
- * const result = await finatic.startSession();
4079
+ * const result = await finatic.startSession({});
3612
4080
  *
3613
4081
  * // Access the response data
3614
4082
  * if (result.success) {
@@ -3616,12 +4084,9 @@ class SessionWrapper {
3616
4084
  * }
3617
4085
  * ```
3618
4086
  */
3619
- async startSession(OneTimeToken, body) {
3620
- // Construct params object from individual parameters
3621
- const params = {
3622
- OneTimeToken: OneTimeToken,
3623
- body: body
3624
- }; // Generate request ID
4087
+ async startSession(params) {
4088
+ // Use params object (required parameters present)
4089
+ const resolvedParams = params; // Generate request ID
3625
4090
  const requestId = this._generateRequestId();
3626
4091
  // Input validation (Phase 2B: zod)
3627
4092
  if (this.sdkConfig?.validationEnabled) ;
@@ -3629,7 +4094,7 @@ class SessionWrapper {
3629
4094
  const shouldCache = true;
3630
4095
  const cache = getCache(this.sdkConfig);
3631
4096
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3632
- const cacheKey = generateCacheKey('POST', '/api/v1/session/start', params, this.sdkConfig);
4097
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
3633
4098
  const cached = cache.get(cacheKey);
3634
4099
  if (cached) {
3635
4100
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3641,12 +4106,12 @@ class SessionWrapper {
3641
4106
  request_id: requestId,
3642
4107
  method: 'POST',
3643
4108
  path: '/api/v1/session/start',
3644
- params: params,
4109
+ params: resolvedParams,
3645
4110
  action: 'startSession'
3646
4111
  });
3647
4112
  try {
3648
4113
  const response = await retryApiCall(async () => {
3649
- const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: OneTimeToken, sessionStartRequest: body }, { headers: { 'x-request-id': requestId } });
4114
+ const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: resolvedParams.OneTimeToken, sessionStartRequest: resolvedParams.body }, { headers: { 'x-request-id': requestId } });
3650
4115
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3651
4116
  }, {}, this.sdkConfig);
3652
4117
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3655,9 +4120,15 @@ class SessionWrapper {
3655
4120
  throw new Error('Unexpected response shape: missing success field');
3656
4121
  }
3657
4122
  // Convert response to plain object, removing _id fields recursively
4123
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3658
4124
  const standardResponse = convertToPlainObject(responseData);
4125
+ // Phase 2: Wrap paginated responses with PaginatedData
4126
+ const hasLimit = false;
4127
+ const hasOffset = false;
4128
+ const hasPagination = hasLimit && hasOffset;
4129
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3659
4130
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3660
- const cacheKey = generateCacheKey('POST', '/api/v1/session/start', params, this.sdkConfig);
4131
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
3661
4132
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3662
4133
  }
3663
4134
  this.logger.debug('Start Session completed', {
@@ -3665,6 +4136,7 @@ class SessionWrapper {
3665
4136
  action: 'startSession'
3666
4137
  });
3667
4138
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
4139
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3668
4140
  return standardResponse;
3669
4141
  }
3670
4142
  catch (error) {
@@ -3741,7 +4213,7 @@ class SessionWrapper {
3741
4213
  *
3742
4214
  * The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device
3743
4215
  * that initiated the session. Device info is automatically validated from the request.
3744
- * @param No parameters required for this method
4216
+ * @param params No parameters required for this method
3745
4217
  * @returns {Promise<FinaticResponse<PortalUrlResponse>>} Standard response with success/Error/Warning structure
3746
4218
  *
3747
4219
  * Generated from: GET /api/v1/session/portal
@@ -3750,7 +4222,7 @@ class SessionWrapper {
3750
4222
  * @example
3751
4223
  * ```typescript-client
3752
4224
  * // Example with no parameters
3753
- * const result = await finatic.getPortalUrl();
4225
+ * const result = await finatic.getPortalUrl({});
3754
4226
  *
3755
4227
  * // Access the response data
3756
4228
  * if (result.success) {
@@ -3758,10 +4230,10 @@ class SessionWrapper {
3758
4230
  * }
3759
4231
  * ```
3760
4232
  */
3761
- async getPortalUrl() {
4233
+ async getPortalUrl(params) {
3762
4234
  // No parameters - use empty params object
3763
- const params = {}; // Authentication check
3764
- if (!this.sessionId) {
4235
+ const resolvedParams = params || {}; // Authentication check
4236
+ if (!this.sessionId || !this.companyId) {
3765
4237
  throw new Error('Session not initialized. Call startSession() first.');
3766
4238
  }
3767
4239
  // Generate request ID
@@ -3772,7 +4244,7 @@ class SessionWrapper {
3772
4244
  const shouldCache = true;
3773
4245
  const cache = getCache(this.sdkConfig);
3774
4246
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3775
- const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', params, this.sdkConfig);
4247
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
3776
4248
  const cached = cache.get(cacheKey);
3777
4249
  if (cached) {
3778
4250
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3784,12 +4256,12 @@ class SessionWrapper {
3784
4256
  request_id: requestId,
3785
4257
  method: 'GET',
3786
4258
  path: '/api/v1/session/portal',
3787
- params: params,
4259
+ params: resolvedParams,
3788
4260
  action: 'getPortalUrl'
3789
4261
  });
3790
4262
  try {
3791
4263
  const response = await retryApiCall(async () => {
3792
- const apiResponse = await this.api.getPortalUrlApiV1SessionPortalGet({ sessionId: this.sessionId }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken, 'x-request-id': requestId } });
4264
+ const apiResponse = await this.api.getPortalUrlApiV1SessionPortalGet({ sessionId: this.sessionId }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
3793
4265
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3794
4266
  }, {}, this.sdkConfig);
3795
4267
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3798,9 +4270,15 @@ class SessionWrapper {
3798
4270
  throw new Error('Unexpected response shape: missing success field');
3799
4271
  }
3800
4272
  // Convert response to plain object, removing _id fields recursively
4273
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3801
4274
  const standardResponse = convertToPlainObject(responseData);
4275
+ // Phase 2: Wrap paginated responses with PaginatedData
4276
+ const hasLimit = false;
4277
+ const hasOffset = false;
4278
+ const hasPagination = hasLimit && hasOffset;
4279
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3802
4280
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3803
- const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', params, this.sdkConfig);
4281
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
3804
4282
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3805
4283
  }
3806
4284
  this.logger.debug('Get Portal Url completed', {
@@ -3808,6 +4286,7 @@ class SessionWrapper {
3808
4286
  action: 'getPortalUrl'
3809
4287
  });
3810
4288
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
4289
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3811
4290
  return standardResponse;
3812
4291
  }
3813
4292
  catch (error) {
@@ -3892,7 +4371,7 @@ class SessionWrapper {
3892
4371
  * - Generates fresh tokens (not returning stored ones)
3893
4372
  * - Only accessible to authenticated sessions with user_id
3894
4373
  * - Validates that header session_id matches path session_id
3895
- * @param sessionId {string}
4374
+ * @param params.sessionId {string} Session ID
3896
4375
  * @returns {Promise<FinaticResponse<SessionUserResponse>>} Standard response with success/Error/Warning structure
3897
4376
  *
3898
4377
  * Generated from: GET /api/v1/session/{session_id}/user
@@ -3901,7 +4380,9 @@ class SessionWrapper {
3901
4380
  * @example
3902
4381
  * ```typescript-client
3903
4382
  * // Minimal example with required parameters only
3904
- * const result = await finatic.getSessionUser(sessionId: 'sess_1234567890abcdef');
4383
+ * const result = await finatic.getSessionUser({
4384
+ sessionId: 'sess_1234567890abcdef'
4385
+ * });
3905
4386
  *
3906
4387
  * // Access the response data
3907
4388
  * if (result.success) {
@@ -3911,12 +4392,10 @@ class SessionWrapper {
3911
4392
  * }
3912
4393
  * ```
3913
4394
  */
3914
- async getSessionUser(sessionId) {
3915
- // Construct params object from individual parameters
3916
- const params = {
3917
- sessionId: sessionId
3918
- }; // Authentication check
3919
- if (!this.sessionId) {
4395
+ async getSessionUser(params) {
4396
+ // Use params object (required parameters present)
4397
+ const resolvedParams = params; // Authentication check
4398
+ if (!this.sessionId || !this.companyId) {
3920
4399
  throw new Error('Session not initialized. Call startSession() first.');
3921
4400
  }
3922
4401
  // Generate request ID
@@ -3927,7 +4406,7 @@ class SessionWrapper {
3927
4406
  const shouldCache = true;
3928
4407
  const cache = getCache(this.sdkConfig);
3929
4408
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3930
- const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', params, this.sdkConfig);
4409
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
3931
4410
  const cached = cache.get(cacheKey);
3932
4411
  if (cached) {
3933
4412
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3939,12 +4418,12 @@ class SessionWrapper {
3939
4418
  request_id: requestId,
3940
4419
  method: 'GET',
3941
4420
  path: '/api/v1/session/{session_id}/user',
3942
- params: params,
4421
+ params: resolvedParams,
3943
4422
  action: 'getSessionUser'
3944
4423
  });
3945
4424
  try {
3946
4425
  const response = await retryApiCall(async () => {
3947
- const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: sessionId, xSessionId: sessionId }, { headers: { 'x-request-id': requestId } });
4426
+ const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: resolvedParams.sessionId, xSessionId: resolvedParams.sessionId }, { headers: { 'x-request-id': requestId } });
3948
4427
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3949
4428
  }, {}, this.sdkConfig);
3950
4429
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3953,9 +4432,15 @@ class SessionWrapper {
3953
4432
  throw new Error('Unexpected response shape: missing success field');
3954
4433
  }
3955
4434
  // Convert response to plain object, removing _id fields recursively
4435
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3956
4436
  const standardResponse = convertToPlainObject(responseData);
4437
+ // Phase 2: Wrap paginated responses with PaginatedData
4438
+ const hasLimit = false;
4439
+ const hasOffset = false;
4440
+ const hasPagination = hasLimit && hasOffset;
4441
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3957
4442
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3958
- const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', params, this.sdkConfig);
4443
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
3959
4444
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3960
4445
  }
3961
4446
  this.logger.debug('Get Session User completed', {
@@ -3963,6 +4448,7 @@ class SessionWrapper {
3963
4448
  action: 'getSessionUser'
3964
4449
  });
3965
4450
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
4451
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3966
4452
  return standardResponse;
3967
4453
  }
3968
4454
  catch (error) {
@@ -4711,8 +5197,8 @@ const SessionApiAxiosParamCreator = function (configuration) {
4711
5197
  /**
4712
5198
  * Start a session with a one-time token.
4713
5199
  * @summary Start Session
4714
- * @param {string} oneTimeToken
4715
- * @param {SessionStartRequest} sessionStartRequest
5200
+ * @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
5201
+ * @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
4716
5202
  * @param {*} [options] Override http request option.
4717
5203
  * @throws {RequiredError}
4718
5204
  */
@@ -4795,8 +5281,8 @@ const SessionApiFp = function (configuration) {
4795
5281
  /**
4796
5282
  * Start a session with a one-time token.
4797
5283
  * @summary Start Session
4798
- * @param {string} oneTimeToken
4799
- * @param {SessionStartRequest} sessionStartRequest
5284
+ * @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
5285
+ * @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
4800
5286
  * @param {*} [options] Override http request option.
4801
5287
  * @throws {RequiredError}
4802
5288
  */
@@ -6331,11 +6817,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6331
6817
  }
6332
6818
  const sessionId = data?.session_id || '';
6333
6819
  const companyId = data?.company_id || '';
6820
+ const responseUserId = data?.user_id || '';
6334
6821
  // csrf_token is not in SessionResponseData, get from response headers if available
6335
6822
  const csrfToken = data?.csrf_token || '';
6336
6823
  this.logger.debug?.('_startSession extracted data', {
6337
6824
  sessionId,
6338
6825
  companyId,
6826
+ responseUserId,
6339
6827
  csrfToken,
6340
6828
  fullData: data,
6341
6829
  dataKeys: data ? Object.keys(data) : []
@@ -6357,6 +6845,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6357
6845
  responseKeys: response ? Object.keys(response) : []
6358
6846
  });
6359
6847
  }
6848
+ // Store userId if present in response (for getUserId() and isAuthed())
6849
+ // Use userId from response if parameter wasn't provided, or if response has a different userId
6850
+ const finalUserId = responseUserId || userId;
6851
+ if (finalUserId) {
6852
+ this.userId = finalUserId;
6853
+ this.logger.debug?.('_startSession set userId', { userId: finalUserId, source: responseUserId ? 'response' : 'parameter' });
6854
+ }
6360
6855
  return { session_id: sessionId, company_id: companyId };
6361
6856
  }
6362
6857
  /**
@@ -6368,28 +6863,30 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6368
6863
  *
6369
6864
  * @methodId get_portal_url_api_v1_session_portal_get
6370
6865
  * @category session
6371
- * @param theme - Optional theme preset or custom theme object
6372
- * @param brokers - Optional array of broker IDs to filter
6373
- * @param email - Optional email address
6374
- * @param mode - Optional mode ('light' or 'dark')
6866
+ * @param params - Optional parameters object
6867
+ * @param params.theme - Optional theme preset or custom theme object
6868
+ * @param params.brokers - Optional array of broker IDs to filter
6869
+ * @param params.email - Optional email address
6870
+ * @param params.mode - Optional mode ('light' or 'dark')
6375
6871
  * @returns Portal URL string
6376
6872
  * @example
6377
6873
  * ```typescript-client
6378
- * const url = await finatic.getPortalUrl('dark', ['broker-1'], 'user@example.com', 'dark');
6874
+ * const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
6379
6875
  * ```
6380
6876
  * @example
6381
6877
  * ```typescript-server
6382
- * const url = await finatic.getPortalUrl('dark', ['broker-1'], 'user@example.com', 'dark');
6878
+ * const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
6383
6879
  * ```
6384
6880
  * @example
6385
6881
  * ```python
6386
- * url = await finatic.get_portal_url('dark', ['broker-1'], 'user@example.com', 'dark')
6882
+ * url = await finatic.get_portal_url(theme='default', brokers=['broker-1'], email='user@example.com', mode='dark')
6387
6883
  * ```
6388
6884
  */
6389
- async getPortalUrl(theme, brokers, email, mode) {
6885
+ async getPortalUrl(params) {
6390
6886
  if (!this.sessionId) {
6391
6887
  throw new Error('Session not initialized. Call startSession() first.');
6392
6888
  }
6889
+ const { theme, brokers, email, mode } = params || {};
6393
6890
  // Get raw portal URL from SessionApi directly (not a wrapper)
6394
6891
  const axiosResponse = await this.sessionApi.getPortalUrlApiV1SessionPortalGet({
6395
6892
  sessionId: this.sessionId,
@@ -6463,29 +6960,35 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6463
6960
  *
6464
6961
  * @methodId open_portal_client_sdk
6465
6962
  * @category session
6466
- * @param theme - Optional theme preset or custom theme object
6467
- * @param brokers - Optional array of broker IDs to filter
6468
- * @param email - Optional email address
6469
- * @param mode - Optional mode ('light' or 'dark')
6963
+ * @param params - Optional parameters object
6964
+ * @param params.theme - Optional theme preset or custom theme object
6965
+ * @param params.brokers - Optional array of broker IDs to filter
6966
+ * @param params.email - Optional email address
6967
+ * @param params.mode - Optional mode ('light' or 'dark')
6470
6968
  * @param onSuccess - Optional callback when portal authentication succeeds
6471
6969
  * @param onError - Optional callback when portal authentication fails
6472
6970
  * @param onClose - Optional callback when portal is closed
6473
6971
  * @returns Promise that resolves when portal is opened
6474
6972
  * @example
6475
6973
  * ```typescript-client
6476
- * await finatic.openPortal('dark', ['broker-1'], 'user@example.com', 'dark',
6974
+ * await finatic.openPortal({
6975
+ * theme: 'default',
6976
+ * brokers: ['broker-1'],
6977
+ * email: 'user@example.com',
6978
+ * mode: 'dark'
6979
+ * },
6477
6980
  * (userId) => console.log('User authenticated:', userId),
6478
6981
  * (error) => console.error('Portal error:', error),
6479
6982
  * () => console.log('Portal closed')
6480
6983
  * );
6481
6984
  * ```
6482
6985
  */
6483
- async openPortal(theme, brokers, email, mode, onSuccess, onError, onClose) {
6986
+ async openPortal(params, onSuccess, onError, onClose) {
6484
6987
  if (!this.sessionId) {
6485
6988
  throw new Error('Session not initialized. Call startSession() first.');
6486
6989
  }
6487
6990
  // Get portal URL with all parameters
6488
- const portalUrl = await this.getPortalUrl(theme, brokers, email, mode);
6991
+ const portalUrl = await this.getPortalUrl(params);
6489
6992
  // Create portal UI if not exists
6490
6993
  if (!this.portalUI) {
6491
6994
  this.portalUI = new PortalUI(this.sdkConfig.baseUrl || 'https://api.finatic.dev');
@@ -6672,7 +7175,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6672
7175
  * ```
6673
7176
  */
6674
7177
  async getCompany(params) {
6675
- return await this.company.getCompany(params?.companyId);
7178
+ return await this.company.getCompany(params);
6676
7179
  }
6677
7180
  /**
6678
7181
  * Get Brokers
@@ -6830,7 +7333,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6830
7333
  * ```
6831
7334
  */
6832
7335
  async disconnectCompanyFromBroker(params) {
6833
- return await this.brokers.disconnectCompanyFromBroker(params?.connectionId);
7336
+ return await this.brokers.disconnectCompanyFromBroker(params);
6834
7337
  }
6835
7338
  /**
6836
7339
  * Get Orders
@@ -6910,7 +7413,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6910
7413
  * ```
6911
7414
  */
6912
7415
  async getOrders(params) {
6913
- return await this.brokers.getOrders(params?.brokerId, params?.connectionId, params?.accountId, params?.symbol, params?.orderStatus, params?.side, params?.assetType, params?.limit, params?.offset, params?.createdAfter, params?.createdBefore, params?.includeMetadata);
7416
+ return await this.brokers.getOrders(params);
6914
7417
  }
6915
7418
  /**
6916
7419
  * Get Positions
@@ -6990,7 +7493,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6990
7493
  * ```
6991
7494
  */
6992
7495
  async getPositions(params) {
6993
- return await this.brokers.getPositions(params?.brokerId, params?.connectionId, params?.accountId, params?.symbol, params?.side, params?.assetType, params?.positionStatus, params?.limit, params?.offset, params?.updatedAfter, params?.updatedBefore, params?.includeMetadata);
7496
+ return await this.brokers.getPositions(params);
6994
7497
  }
6995
7498
  /**
6996
7499
  * Get Balances
@@ -7070,7 +7573,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7070
7573
  * ```
7071
7574
  */
7072
7575
  async getBalances(params) {
7073
- return await this.brokers.getBalances(params?.brokerId, params?.connectionId, params?.accountId, params?.isEndOfDaySnapshot, params?.limit, params?.offset, params?.balanceCreatedAfter, params?.balanceCreatedBefore, params?.includeMetadata);
7576
+ return await this.brokers.getBalances(params);
7074
7577
  }
7075
7578
  /**
7076
7579
  * Get Accounts
@@ -7150,7 +7653,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7150
7653
  * ```
7151
7654
  */
7152
7655
  async getAccounts(params) {
7153
- return await this.brokers.getAccounts(params?.brokerId, params?.connectionId, params?.accountType, params?.status, params?.currency, params?.limit, params?.offset, params?.includeMetadata);
7656
+ return await this.brokers.getAccounts(params);
7154
7657
  }
7155
7658
  /**
7156
7659
  * Get Order Fills
@@ -7238,7 +7741,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7238
7741
  * ```
7239
7742
  */
7240
7743
  async getOrderFills(params) {
7241
- return await this.brokers.getOrderFills(params?.orderId, params?.connectionId, params?.limit, params?.offset, params?.includeMetadata);
7744
+ return await this.brokers.getOrderFills(params);
7242
7745
  }
7243
7746
  /**
7244
7747
  * Get Order Events
@@ -7326,7 +7829,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7326
7829
  * ```
7327
7830
  */
7328
7831
  async getOrderEvents(params) {
7329
- return await this.brokers.getOrderEvents(params?.orderId, params?.connectionId, params?.limit, params?.offset, params?.includeMetadata);
7832
+ return await this.brokers.getOrderEvents(params);
7330
7833
  }
7331
7834
  /**
7332
7835
  * Get Order Groups
@@ -7405,7 +7908,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7405
7908
  * ```
7406
7909
  */
7407
7910
  async getOrderGroups(params) {
7408
- return await this.brokers.getOrderGroups(params?.brokerId, params?.connectionId, params?.limit, params?.offset, params?.createdAfter, params?.createdBefore, params?.includeMetadata);
7911
+ return await this.brokers.getOrderGroups(params);
7409
7912
  }
7410
7913
  /**
7411
7914
  * Get Position Lots
@@ -7485,7 +7988,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7485
7988
  * ```
7486
7989
  */
7487
7990
  async getPositionLots(params) {
7488
- return await this.brokers.getPositionLots(params?.brokerId, params?.connectionId, params?.accountId, params?.symbol, params?.positionId, params?.limit, params?.offset);
7991
+ return await this.brokers.getPositionLots(params);
7489
7992
  }
7490
7993
  /**
7491
7994
  * Get Position Lot Fills
@@ -7573,7 +8076,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7573
8076
  * ```
7574
8077
  */
7575
8078
  async getPositionLotFills(params) {
7576
- return await this.brokers.getPositionLotFills(params?.lotId, params?.connectionId, params?.limit, params?.offset);
8079
+ return await this.brokers.getPositionLotFills(params);
7577
8080
  }
7578
8081
  /**
7579
8082
  * Get all Orders across all pages.
@@ -7644,7 +8147,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7644
8147
  let lastError = null;
7645
8148
  let warnings = [];
7646
8149
  while (true) {
7647
- const response = await this.brokers.getOrders(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountId, filterParams?.symbol, filterParams?.orderStatus, filterParams?.side, filterParams?.assetType, limit, offset, filterParams?.createdAfter, filterParams?.createdBefore, filterParams?.includeMetadata);
8150
+ const response = await this.brokers.getOrders({ ...filterParams, limit, offset });
7648
8151
  // Collect warnings from each page
7649
8152
  if (response.warning && Array.isArray(response.warning)) {
7650
8153
  warnings.push(...response.warning);
@@ -7654,10 +8157,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7654
8157
  break;
7655
8158
  }
7656
8159
  const result = response.success?.data || [];
7657
- if (!result || result.length === 0)
8160
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8161
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8162
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8163
+ ? result.items
8164
+ : (Array.isArray(result) ? result : [result]);
8165
+ if (!items || items.length === 0)
7658
8166
  break;
7659
- allData.push(...(Array.isArray(result) ? result : [result]));
7660
- if (result.length < limit)
8167
+ allData.push(...items);
8168
+ // If we got fewer items than the limit, there are no more pages
8169
+ if (items.length < limit)
7661
8170
  break;
7662
8171
  offset += limit;
7663
8172
  }
@@ -7749,7 +8258,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7749
8258
  let lastError = null;
7750
8259
  let warnings = [];
7751
8260
  while (true) {
7752
- const response = await this.brokers.getPositions(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountId, filterParams?.symbol, filterParams?.side, filterParams?.assetType, filterParams?.positionStatus, limit, offset, filterParams?.updatedAfter, filterParams?.updatedBefore, filterParams?.includeMetadata);
8261
+ const response = await this.brokers.getPositions({ ...filterParams, limit, offset });
7753
8262
  // Collect warnings from each page
7754
8263
  if (response.warning && Array.isArray(response.warning)) {
7755
8264
  warnings.push(...response.warning);
@@ -7759,10 +8268,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7759
8268
  break;
7760
8269
  }
7761
8270
  const result = response.success?.data || [];
7762
- if (!result || result.length === 0)
8271
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8272
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8273
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8274
+ ? result.items
8275
+ : (Array.isArray(result) ? result : [result]);
8276
+ if (!items || items.length === 0)
7763
8277
  break;
7764
- allData.push(...(Array.isArray(result) ? result : [result]));
7765
- if (result.length < limit)
8278
+ allData.push(...items);
8279
+ // If we got fewer items than the limit, there are no more pages
8280
+ if (items.length < limit)
7766
8281
  break;
7767
8282
  offset += limit;
7768
8283
  }
@@ -7854,7 +8369,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7854
8369
  let lastError = null;
7855
8370
  let warnings = [];
7856
8371
  while (true) {
7857
- const response = await this.brokers.getBalances(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountId, filterParams?.isEndOfDaySnapshot, limit, offset, filterParams?.balanceCreatedAfter, filterParams?.balanceCreatedBefore, filterParams?.includeMetadata);
8372
+ const response = await this.brokers.getBalances({ ...filterParams, limit, offset });
7858
8373
  // Collect warnings from each page
7859
8374
  if (response.warning && Array.isArray(response.warning)) {
7860
8375
  warnings.push(...response.warning);
@@ -7864,10 +8379,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7864
8379
  break;
7865
8380
  }
7866
8381
  const result = response.success?.data || [];
7867
- if (!result || result.length === 0)
8382
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8383
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8384
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8385
+ ? result.items
8386
+ : (Array.isArray(result) ? result : [result]);
8387
+ if (!items || items.length === 0)
7868
8388
  break;
7869
- allData.push(...(Array.isArray(result) ? result : [result]));
7870
- if (result.length < limit)
8389
+ allData.push(...items);
8390
+ // If we got fewer items than the limit, there are no more pages
8391
+ if (items.length < limit)
7871
8392
  break;
7872
8393
  offset += limit;
7873
8394
  }
@@ -7959,7 +8480,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7959
8480
  let lastError = null;
7960
8481
  let warnings = [];
7961
8482
  while (true) {
7962
- const response = await this.brokers.getAccounts(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountType, filterParams?.status, filterParams?.currency, limit, offset, filterParams?.includeMetadata);
8483
+ const response = await this.brokers.getAccounts({ ...filterParams, limit, offset });
7963
8484
  // Collect warnings from each page
7964
8485
  if (response.warning && Array.isArray(response.warning)) {
7965
8486
  warnings.push(...response.warning);
@@ -7969,10 +8490,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7969
8490
  break;
7970
8491
  }
7971
8492
  const result = response.success?.data || [];
7972
- if (!result || result.length === 0)
8493
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8494
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8495
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8496
+ ? result.items
8497
+ : (Array.isArray(result) ? result : [result]);
8498
+ if (!items || items.length === 0)
7973
8499
  break;
7974
- allData.push(...(Array.isArray(result) ? result : [result]));
7975
- if (result.length < limit)
8500
+ allData.push(...items);
8501
+ // If we got fewer items than the limit, there are no more pages
8502
+ if (items.length < limit)
7976
8503
  break;
7977
8504
  offset += limit;
7978
8505
  }
@@ -8063,7 +8590,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8063
8590
  let lastError = null;
8064
8591
  let warnings = [];
8065
8592
  while (true) {
8066
- const response = await this.brokers.getOrderFills(filterParams?.orderId, filterParams?.connectionId, limit, offset, filterParams?.includeMetadata);
8593
+ const response = await this.brokers.getOrderFills({ ...filterParams, limit, offset });
8067
8594
  // Collect warnings from each page
8068
8595
  if (response.warning && Array.isArray(response.warning)) {
8069
8596
  warnings.push(...response.warning);
@@ -8073,10 +8600,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8073
8600
  break;
8074
8601
  }
8075
8602
  const result = response.success?.data || [];
8076
- if (!result || result.length === 0)
8603
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8604
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8605
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8606
+ ? result.items
8607
+ : (Array.isArray(result) ? result : [result]);
8608
+ if (!items || items.length === 0)
8077
8609
  break;
8078
- allData.push(...(Array.isArray(result) ? result : [result]));
8079
- if (result.length < limit)
8610
+ allData.push(...items);
8611
+ // If we got fewer items than the limit, there are no more pages
8612
+ if (items.length < limit)
8080
8613
  break;
8081
8614
  offset += limit;
8082
8615
  }
@@ -8167,7 +8700,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8167
8700
  let lastError = null;
8168
8701
  let warnings = [];
8169
8702
  while (true) {
8170
- const response = await this.brokers.getOrderEvents(filterParams?.orderId, filterParams?.connectionId, limit, offset, filterParams?.includeMetadata);
8703
+ const response = await this.brokers.getOrderEvents({ ...filterParams, limit, offset });
8171
8704
  // Collect warnings from each page
8172
8705
  if (response.warning && Array.isArray(response.warning)) {
8173
8706
  warnings.push(...response.warning);
@@ -8177,10 +8710,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8177
8710
  break;
8178
8711
  }
8179
8712
  const result = response.success?.data || [];
8180
- if (!result || result.length === 0)
8713
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8714
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8715
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8716
+ ? result.items
8717
+ : (Array.isArray(result) ? result : [result]);
8718
+ if (!items || items.length === 0)
8181
8719
  break;
8182
- allData.push(...(Array.isArray(result) ? result : [result]));
8183
- if (result.length < limit)
8720
+ allData.push(...items);
8721
+ // If we got fewer items than the limit, there are no more pages
8722
+ if (items.length < limit)
8184
8723
  break;
8185
8724
  offset += limit;
8186
8725
  }
@@ -8272,7 +8811,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8272
8811
  let lastError = null;
8273
8812
  let warnings = [];
8274
8813
  while (true) {
8275
- const response = await this.brokers.getOrderGroups(filterParams?.brokerId, filterParams?.connectionId, limit, offset, filterParams?.createdAfter, filterParams?.createdBefore, filterParams?.includeMetadata);
8814
+ const response = await this.brokers.getOrderGroups({ ...filterParams, limit, offset });
8276
8815
  // Collect warnings from each page
8277
8816
  if (response.warning && Array.isArray(response.warning)) {
8278
8817
  warnings.push(...response.warning);
@@ -8282,10 +8821,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8282
8821
  break;
8283
8822
  }
8284
8823
  const result = response.success?.data || [];
8285
- if (!result || result.length === 0)
8824
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8825
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8826
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8827
+ ? result.items
8828
+ : (Array.isArray(result) ? result : [result]);
8829
+ if (!items || items.length === 0)
8286
8830
  break;
8287
- allData.push(...(Array.isArray(result) ? result : [result]));
8288
- if (result.length < limit)
8831
+ allData.push(...items);
8832
+ // If we got fewer items than the limit, there are no more pages
8833
+ if (items.length < limit)
8289
8834
  break;
8290
8835
  offset += limit;
8291
8836
  }
@@ -8377,7 +8922,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8377
8922
  let lastError = null;
8378
8923
  let warnings = [];
8379
8924
  while (true) {
8380
- const response = await this.brokers.getPositionLots(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountId, filterParams?.symbol, filterParams?.positionId, limit, offset);
8925
+ const response = await this.brokers.getPositionLots({ ...filterParams, limit, offset });
8381
8926
  // Collect warnings from each page
8382
8927
  if (response.warning && Array.isArray(response.warning)) {
8383
8928
  warnings.push(...response.warning);
@@ -8387,10 +8932,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8387
8932
  break;
8388
8933
  }
8389
8934
  const result = response.success?.data || [];
8390
- if (!result || result.length === 0)
8935
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8936
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8937
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8938
+ ? result.items
8939
+ : (Array.isArray(result) ? result : [result]);
8940
+ if (!items || items.length === 0)
8391
8941
  break;
8392
- allData.push(...(Array.isArray(result) ? result : [result]));
8393
- if (result.length < limit)
8942
+ allData.push(...items);
8943
+ // If we got fewer items than the limit, there are no more pages
8944
+ if (items.length < limit)
8394
8945
  break;
8395
8946
  offset += limit;
8396
8947
  }
@@ -8480,7 +9031,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8480
9031
  let lastError = null;
8481
9032
  let warnings = [];
8482
9033
  while (true) {
8483
- const response = await this.brokers.getPositionLotFills(filterParams?.lotId, filterParams?.connectionId, limit, offset);
9034
+ const response = await this.brokers.getPositionLotFills({ ...filterParams, limit, offset });
8484
9035
  // Collect warnings from each page
8485
9036
  if (response.warning && Array.isArray(response.warning)) {
8486
9037
  warnings.push(...response.warning);
@@ -8490,10 +9041,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8490
9041
  break;
8491
9042
  }
8492
9043
  const result = response.success?.data || [];
8493
- if (!result || result.length === 0)
9044
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
9045
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
9046
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
9047
+ ? result.items
9048
+ : (Array.isArray(result) ? result : [result]);
9049
+ if (!items || items.length === 0)
8494
9050
  break;
8495
- allData.push(...(Array.isArray(result) ? result : [result]));
8496
- if (result.length < limit)
9051
+ allData.push(...items);
9052
+ // If we got fewer items than the limit, there are no more pages
9053
+ if (items.length < limit)
8497
9054
  break;
8498
9055
  offset += limit;
8499
9056
  }
@@ -8553,6 +9110,7 @@ exports.Configuration = Configuration;
8553
9110
  exports.EventEmitter = EventEmitter;
8554
9111
  exports.FinaticConnect = FinaticConnect;
8555
9112
  exports.FinaticError = FinaticError;
9113
+ exports.PaginatedData = PaginatedData;
8556
9114
  exports.SessionApi = SessionApi;
8557
9115
  exports.SessionApiAxiosParamCreator = SessionApiAxiosParamCreator;
8558
9116
  exports.SessionApiFactory = SessionApiFactory;