@finatic/client 0.9.2 → 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.mjs CHANGED
@@ -1209,6 +1209,256 @@ var SessionStatus;
1209
1209
  SessionStatus["Expired"] = "expired";
1210
1210
  })(SessionStatus || (SessionStatus = {}));
1211
1211
 
1212
+ /**
1213
+ * Pagination utilities for TypeScript SDK.
1214
+ *
1215
+ * Provides PaginatedData class for wrapping paginated responses with helper methods.
1216
+ */
1217
+ /**
1218
+ * PaginatedData wraps a data array with pagination metadata and helper methods.
1219
+ *
1220
+ * This class behaves like an array, so you can use it directly:
1221
+ * - paginatedData.length returns the number of items
1222
+ * - paginatedData[0] returns the first item
1223
+ * - paginatedData.forEach(...) works directly
1224
+ * - paginatedData.map(...) works directly
1225
+ *
1226
+ * It also provides pagination methods:
1227
+ * - hasMore: Check if there are more pages
1228
+ * - nextPage(): Get the next page
1229
+ * - prevPage(): Get the previous page
1230
+ * - firstPage(): Get the first page
1231
+ * - lastPage(): Get the last page
1232
+ *
1233
+ * @template T - The element type (e.g., FDXBrokerAccount)
1234
+ *
1235
+ * Usage:
1236
+ * ```typescript
1237
+ * const response = await sdk.getAccounts();
1238
+ * const accounts = response.success.data; // Can use directly as array!
1239
+ * console.log(accounts.length); // Works directly
1240
+ * console.log(accounts[0]); // Works directly
1241
+ * accounts.forEach(account => console.log(account)); // Works directly
1242
+ *
1243
+ * if (accounts.hasMore) {
1244
+ * const nextPage = await accounts.nextPage(); // Returns PaginatedData<FDXBrokerAccount>
1245
+ * const nextAccounts = nextPage; // Can use directly as array too!
1246
+ * }
1247
+ * ```
1248
+ */
1249
+ class PaginatedData {
1250
+ constructor(items, // The actual data array
1251
+ meta,
1252
+ // Use any for method type since it's only called for paginated endpoints
1253
+ // and will return PaginatedData<T> at runtime
1254
+ originalMethod, currentParams, wrapperInstance // Reference to wrapper for method calls
1255
+ ) {
1256
+ this.items = items;
1257
+ this.meta = meta;
1258
+ this.originalMethod = originalMethod;
1259
+ this.currentParams = currentParams;
1260
+ this.wrapperInstance = wrapperInstance;
1261
+ // Create a Proxy to allow array-like indexing (paginatedData[0])
1262
+ return new Proxy(this, {
1263
+ get(target, prop) {
1264
+ // Handle numeric indices
1265
+ if (typeof prop === 'string' && /^\d+$/.test(prop)) {
1266
+ return target.items[Number(prop)];
1267
+ }
1268
+ // Handle length property
1269
+ if (prop === 'length') {
1270
+ return target.items.length;
1271
+ }
1272
+ // Handle array methods and other properties
1273
+ return target[prop];
1274
+ },
1275
+ has(target, prop) {
1276
+ // Support 'in' operator
1277
+ if (typeof prop === 'string' && /^\d+$/.test(prop)) {
1278
+ return Number(prop) < target.items.length;
1279
+ }
1280
+ return prop in target;
1281
+ },
1282
+ ownKeys(target) {
1283
+ // Include numeric indices for Object.keys()
1284
+ const keys = Object.keys(target);
1285
+ for (let i = 0; i < target.items.length; i++) {
1286
+ keys.push(String(i));
1287
+ }
1288
+ return keys;
1289
+ },
1290
+ getOwnPropertyDescriptor(target, prop) {
1291
+ if (typeof prop === 'string' && /^\d+$/.test(prop)) {
1292
+ const index = Number(prop);
1293
+ if (index < target.items.length) {
1294
+ return {
1295
+ enumerable: true,
1296
+ configurable: true,
1297
+ value: target.items[index],
1298
+ };
1299
+ }
1300
+ }
1301
+ return Object.getOwnPropertyDescriptor(target, prop);
1302
+ },
1303
+ });
1304
+ }
1305
+ /**
1306
+ * Get the number of items (allows paginatedData.length).
1307
+ */
1308
+ get length() {
1309
+ return this.items.length;
1310
+ }
1311
+ /**
1312
+ * Check if there are more pages available.
1313
+ */
1314
+ get hasMore() {
1315
+ return this.meta.has_more;
1316
+ }
1317
+ // Array-like methods - delegate to items array
1318
+ /**
1319
+ * Calls a function for each element in the array.
1320
+ */
1321
+ forEach(callbackfn, thisArg) {
1322
+ return this.items.forEach(callbackfn, thisArg);
1323
+ }
1324
+ /**
1325
+ * Creates a new array with the results of calling a function for every array element.
1326
+ */
1327
+ map(callbackfn, thisArg) {
1328
+ return this.items.map(callbackfn, thisArg);
1329
+ }
1330
+ /**
1331
+ * Returns the elements of an array that meet the condition specified in a callback function.
1332
+ */
1333
+ filter(callbackfn, thisArg) {
1334
+ return this.items.filter(callbackfn, thisArg);
1335
+ }
1336
+ /**
1337
+ * Returns the value of the first element in the array where predicate is true.
1338
+ */
1339
+ find(predicate, thisArg) {
1340
+ return this.items.find(predicate, thisArg);
1341
+ }
1342
+ /**
1343
+ * Returns the index of the first element in the array where predicate is true.
1344
+ */
1345
+ findIndex(predicate, thisArg) {
1346
+ return this.items.findIndex(predicate, thisArg);
1347
+ }
1348
+ /**
1349
+ * Returns a section of an array.
1350
+ */
1351
+ slice(start, end) {
1352
+ return this.items.slice(start, end);
1353
+ }
1354
+ /**
1355
+ * Determines whether an array includes a certain element.
1356
+ */
1357
+ includes(searchElement, fromIndex) {
1358
+ return this.items.includes(searchElement, fromIndex);
1359
+ }
1360
+ /**
1361
+ * Returns the index of the first occurrence of a value in an array.
1362
+ */
1363
+ indexOf(searchElement, fromIndex) {
1364
+ return this.items.indexOf(searchElement, fromIndex);
1365
+ }
1366
+ /**
1367
+ * Returns a string representation of an array.
1368
+ */
1369
+ toString() {
1370
+ return this.items.toString();
1371
+ }
1372
+ /**
1373
+ * Returns a string representation of an array.
1374
+ */
1375
+ toLocaleString() {
1376
+ return this.items.toLocaleString();
1377
+ }
1378
+ /**
1379
+ * Get the next page of data.
1380
+ * @returns Promise<PaginatedData<T>> - The next page (not wrapped in FinaticResponse)
1381
+ * @throws Error if no more pages are available
1382
+ */
1383
+ async nextPage() {
1384
+ if (!this.hasMore) {
1385
+ throw new Error('No more pages available');
1386
+ }
1387
+ if (this.meta.next_offset === null) {
1388
+ throw new Error('Next offset is null');
1389
+ }
1390
+ const newParams = {
1391
+ ...this.currentParams,
1392
+ offset: this.meta.next_offset,
1393
+ };
1394
+ const response = await this.originalMethod.call(this.wrapperInstance, newParams);
1395
+ if (!response.success) {
1396
+ throw new Error(response.error?.message || 'Failed to fetch next page');
1397
+ }
1398
+ return response.success.data; // Return PaginatedData directly
1399
+ }
1400
+ /**
1401
+ * Get the previous page of data.
1402
+ * @returns Promise<PaginatedData<T>> - The previous page (not wrapped in FinaticResponse)
1403
+ * @throws Error if fetch fails
1404
+ */
1405
+ async prevPage() {
1406
+ const prevOffset = Math.max(0, this.meta.current_offset - this.meta.limit);
1407
+ const newParams = {
1408
+ ...this.currentParams,
1409
+ offset: prevOffset,
1410
+ };
1411
+ const response = await this.originalMethod.call(this.wrapperInstance, newParams);
1412
+ if (!response.success) {
1413
+ throw new Error(response.error?.message || 'Failed to fetch previous page');
1414
+ }
1415
+ return response.success.data; // Return PaginatedData directly
1416
+ }
1417
+ /**
1418
+ * Get the first page of data.
1419
+ * @returns Promise<PaginatedData<T>> - The first page (not wrapped in FinaticResponse)
1420
+ * @throws Error if fetch fails
1421
+ */
1422
+ async firstPage() {
1423
+ const newParams = {
1424
+ ...this.currentParams,
1425
+ offset: 0,
1426
+ };
1427
+ const response = await this.originalMethod.call(this.wrapperInstance, newParams);
1428
+ if (!response.success) {
1429
+ throw new Error(response.error?.message || 'Failed to fetch first page');
1430
+ }
1431
+ return response.success.data; // Return PaginatedData directly
1432
+ }
1433
+ /**
1434
+ * Get the last page of data.
1435
+ * Uses iterative approach to find the last page.
1436
+ * @returns Promise<PaginatedData<T>> - The last page (not wrapped in FinaticResponse)
1437
+ * @throws Error if fetch fails
1438
+ */
1439
+ async lastPage() {
1440
+ // Iterative approach to find last page
1441
+ let currentOffset = this.meta.current_offset;
1442
+ let lastValidData = null;
1443
+ while (true) {
1444
+ const testParams = { ...this.currentParams, offset: currentOffset };
1445
+ const response = await this.originalMethod.call(this.wrapperInstance, testParams);
1446
+ if (!response.success) {
1447
+ break;
1448
+ }
1449
+ lastValidData = response.success.data;
1450
+ if (!lastValidData || !lastValidData.hasMore) {
1451
+ break;
1452
+ }
1453
+ currentOffset += this.meta.limit;
1454
+ }
1455
+ if (!lastValidData) {
1456
+ throw new Error('Failed to fetch last page');
1457
+ }
1458
+ return lastValidData; // Return PaginatedData directly
1459
+ }
1460
+ }
1461
+
1212
1462
  /**
1213
1463
  * Generated wrapper functions for brokers operations (Phase 2A).
1214
1464
  *
@@ -1258,7 +1508,7 @@ class BrokersWrapper {
1258
1508
  * -------
1259
1509
  * FinaticResponse[list[BrokerInfo]]
1260
1510
  * list of available brokers with their metadata.
1261
- * @param No parameters required for this method
1511
+ * @param params No parameters required for this method
1262
1512
  * @returns {Promise<FinaticResponse<BrokerInfo[]>>} Standard response with success/Error/Warning structure
1263
1513
  *
1264
1514
  * Generated from: GET /api/v1/brokers/
@@ -1267,7 +1517,7 @@ class BrokersWrapper {
1267
1517
  * @example
1268
1518
  * ```typescript-client
1269
1519
  * // Example with no parameters
1270
- * const result = await finatic.getBrokers();
1520
+ * const result = await finatic.getBrokers({});
1271
1521
  *
1272
1522
  * // Access the response data
1273
1523
  * if (result.success) {
@@ -1275,9 +1525,9 @@ class BrokersWrapper {
1275
1525
  * }
1276
1526
  * ```
1277
1527
  */
1278
- async getBrokers() {
1528
+ async getBrokers(params) {
1279
1529
  // No parameters - use empty params object
1280
- const params = {}; // Generate request ID
1530
+ const resolvedParams = params || {}; // Generate request ID
1281
1531
  const requestId = this._generateRequestId();
1282
1532
  // Input validation (Phase 2B: zod)
1283
1533
  if (this.sdkConfig?.validationEnabled) ;
@@ -1285,7 +1535,7 @@ class BrokersWrapper {
1285
1535
  const shouldCache = true;
1286
1536
  const cache = getCache(this.sdkConfig);
1287
1537
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1288
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', params, this.sdkConfig);
1538
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
1289
1539
  const cached = cache.get(cacheKey);
1290
1540
  if (cached) {
1291
1541
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1297,7 +1547,7 @@ class BrokersWrapper {
1297
1547
  request_id: requestId,
1298
1548
  method: 'GET',
1299
1549
  path: '/api/v1/brokers/',
1300
- params: params,
1550
+ params: resolvedParams,
1301
1551
  action: 'getBrokers'
1302
1552
  });
1303
1553
  try {
@@ -1311,9 +1561,15 @@ class BrokersWrapper {
1311
1561
  throw new Error('Unexpected response shape: missing success field');
1312
1562
  }
1313
1563
  // Convert response to plain object, removing _id fields recursively
1564
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1314
1565
  const standardResponse = convertToPlainObject(responseData);
1566
+ // Phase 2: Wrap paginated responses with PaginatedData
1567
+ const hasLimit = false;
1568
+ const hasOffset = false;
1569
+ const hasPagination = hasLimit && hasOffset;
1570
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
1315
1571
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1316
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', params, this.sdkConfig);
1572
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
1317
1573
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1318
1574
  }
1319
1575
  this.logger.debug('Get Brokers completed', {
@@ -1321,6 +1577,7 @@ class BrokersWrapper {
1321
1577
  action: 'getBrokers'
1322
1578
  });
1323
1579
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
1580
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1324
1581
  return standardResponse;
1325
1582
  }
1326
1583
  catch (error) {
@@ -1398,7 +1655,7 @@ class BrokersWrapper {
1398
1655
  * This endpoint is accessible from the portal and uses session-only authentication.
1399
1656
  * Returns connections that the user has any permissions for, including the current
1400
1657
  * company's permissions (read/write) for each connection.
1401
- * @param No parameters required for this method
1658
+ * @param params No parameters required for this method
1402
1659
  * @returns {Promise<FinaticResponse<UserBrokerConnectionWithPermissions[]>>} Standard response with success/Error/Warning structure
1403
1660
  *
1404
1661
  * Generated from: GET /api/v1/brokers/connections
@@ -1407,7 +1664,7 @@ class BrokersWrapper {
1407
1664
  * @example
1408
1665
  * ```typescript-client
1409
1666
  * // Example with no parameters
1410
- * const result = await finatic.getBrokerConnections();
1667
+ * const result = await finatic.getBrokerConnections({});
1411
1668
  *
1412
1669
  * // Access the response data
1413
1670
  * if (result.success) {
@@ -1415,10 +1672,10 @@ class BrokersWrapper {
1415
1672
  * }
1416
1673
  * ```
1417
1674
  */
1418
- async getBrokerConnections() {
1675
+ async getBrokerConnections(params) {
1419
1676
  // No parameters - use empty params object
1420
- const params = {}; // Authentication check
1421
- if (!this.sessionId) {
1677
+ const resolvedParams = params || {}; // Authentication check
1678
+ if (!this.sessionId || !this.companyId) {
1422
1679
  throw new Error('Session not initialized. Call startSession() first.');
1423
1680
  }
1424
1681
  // Generate request ID
@@ -1429,7 +1686,7 @@ class BrokersWrapper {
1429
1686
  const shouldCache = true;
1430
1687
  const cache = getCache(this.sdkConfig);
1431
1688
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1432
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', params, this.sdkConfig);
1689
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
1433
1690
  const cached = cache.get(cacheKey);
1434
1691
  if (cached) {
1435
1692
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1441,12 +1698,12 @@ class BrokersWrapper {
1441
1698
  request_id: requestId,
1442
1699
  method: 'GET',
1443
1700
  path: '/api/v1/brokers/connections',
1444
- params: params,
1701
+ params: resolvedParams,
1445
1702
  action: 'getBrokerConnections'
1446
1703
  });
1447
1704
  try {
1448
1705
  const response = await retryApiCall(async () => {
1449
- 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 } });
1706
+ 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 } : {}) } : {}) } });
1450
1707
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1451
1708
  }, {}, this.sdkConfig);
1452
1709
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1455,9 +1712,15 @@ class BrokersWrapper {
1455
1712
  throw new Error('Unexpected response shape: missing success field');
1456
1713
  }
1457
1714
  // Convert response to plain object, removing _id fields recursively
1715
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1458
1716
  const standardResponse = convertToPlainObject(responseData);
1717
+ // Phase 2: Wrap paginated responses with PaginatedData
1718
+ const hasLimit = false;
1719
+ const hasOffset = false;
1720
+ const hasPagination = hasLimit && hasOffset;
1721
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
1459
1722
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1460
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', params, this.sdkConfig);
1723
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
1461
1724
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1462
1725
  }
1463
1726
  this.logger.debug('List Broker Connections completed', {
@@ -1465,6 +1728,7 @@ class BrokersWrapper {
1465
1728
  action: 'getBrokerConnections'
1466
1729
  });
1467
1730
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
1731
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1468
1732
  return standardResponse;
1469
1733
  }
1470
1734
  catch (error) {
@@ -1541,7 +1805,7 @@ class BrokersWrapper {
1541
1805
  *
1542
1806
  * If the company is the only one with access, the entire connection is deleted.
1543
1807
  * If other companies have access, only the company's access is removed.
1544
- * @param connectionId {string}
1808
+ * @param params.connectionId {string} Connection ID
1545
1809
  * @returns {Promise<FinaticResponse<DisconnectActionResult>>} Standard response with success/Error/Warning structure
1546
1810
  *
1547
1811
  * Generated from: DELETE /api/v1/brokers/disconnect-company/{connection_id}
@@ -1550,7 +1814,9 @@ class BrokersWrapper {
1550
1814
  * @example
1551
1815
  * ```typescript-client
1552
1816
  * // Minimal example with required parameters only
1553
- * const result = await finatic.disconnectCompanyFromBroker(connectionId: '00000000-0000-0000-0000-000000000000');
1817
+ * const result = await finatic.disconnectCompanyFromBroker({
1818
+ connectionId: '00000000-0000-0000-0000-000000000000'
1819
+ * });
1554
1820
  *
1555
1821
  * // Access the response data
1556
1822
  * if (result.success) {
@@ -1560,12 +1826,10 @@ class BrokersWrapper {
1560
1826
  * }
1561
1827
  * ```
1562
1828
  */
1563
- async disconnectCompanyFromBroker(connectionId) {
1564
- // Construct params object from individual parameters
1565
- const params = {
1566
- connectionId: connectionId
1567
- }; // Authentication check
1568
- if (!this.sessionId) {
1829
+ async disconnectCompanyFromBroker(params) {
1830
+ // Use params object (required parameters present)
1831
+ const resolvedParams = params; // Authentication check
1832
+ if (!this.sessionId || !this.companyId) {
1569
1833
  throw new Error('Session not initialized. Call startSession() first.');
1570
1834
  }
1571
1835
  // Generate request ID
@@ -1576,7 +1840,7 @@ class BrokersWrapper {
1576
1840
  const shouldCache = true;
1577
1841
  const cache = getCache(this.sdkConfig);
1578
1842
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1579
- const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', params, this.sdkConfig);
1843
+ const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
1580
1844
  const cached = cache.get(cacheKey);
1581
1845
  if (cached) {
1582
1846
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1588,12 +1852,12 @@ class BrokersWrapper {
1588
1852
  request_id: requestId,
1589
1853
  method: 'DELETE',
1590
1854
  path: '/api/v1/brokers/disconnect-company/{connection_id}',
1591
- params: params,
1855
+ params: resolvedParams,
1592
1856
  action: 'disconnectCompanyFromBroker'
1593
1857
  });
1594
1858
  try {
1595
1859
  const response = await retryApiCall(async () => {
1596
- 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 } });
1860
+ 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 } : {}) } : {}) } });
1597
1861
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1598
1862
  }, {}, this.sdkConfig);
1599
1863
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1602,9 +1866,15 @@ class BrokersWrapper {
1602
1866
  throw new Error('Unexpected response shape: missing success field');
1603
1867
  }
1604
1868
  // Convert response to plain object, removing _id fields recursively
1869
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1605
1870
  const standardResponse = convertToPlainObject(responseData);
1871
+ // Phase 2: Wrap paginated responses with PaginatedData
1872
+ const hasLimit = false;
1873
+ const hasOffset = false;
1874
+ const hasPagination = hasLimit && hasOffset;
1875
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
1606
1876
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1607
- const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', params, this.sdkConfig);
1877
+ const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
1608
1878
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1609
1879
  }
1610
1880
  this.logger.debug('Disconnect Company From Broker completed', {
@@ -1612,6 +1882,7 @@ class BrokersWrapper {
1612
1882
  action: 'disconnectCompanyFromBroker'
1613
1883
  });
1614
1884
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
1885
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1615
1886
  return standardResponse;
1616
1887
  }
1617
1888
  catch (error) {
@@ -1688,19 +1959,19 @@ class BrokersWrapper {
1688
1959
  *
1689
1960
  * This endpoint is accessible from the portal and uses session-only authentication.
1690
1961
  * Returns orders from connections the company has read access to.
1691
- * @param brokerId {string} (optional)
1692
- * @param connectionId {string} (optional)
1693
- * @param accountId {string} (optional)
1694
- * @param symbol {string} (optional)
1695
- * @param orderStatus {BrokerDataOrderStatusEnum} (optional)
1696
- * @param side {BrokerDataOrderSideEnum} (optional)
1697
- * @param assetType {BrokerDataAssetTypeEnum} (optional)
1698
- * @param limit {number} (optional)
1699
- * @param offset {number} (optional)
1700
- * @param createdAfter {string} (optional)
1701
- * @param createdBefore {string} (optional)
1702
- * @param includeMetadata {boolean} (optional)
1703
- * @returns {Promise<FinaticResponse<FDXBrokerOrder[]>>} Standard response with success/Error/Warning structure
1962
+ * @param params.brokerId {string} (optional) Filter by broker ID
1963
+ * @param params.connectionId {string} (optional) Filter by connection ID
1964
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
1965
+ * @param params.symbol {string} (optional) Filter by symbol
1966
+ * @param params.orderStatus {BrokerDataOrderStatusEnum} (optional) Filter by order status (e.g., 'filled', 'pending_new', 'cancelled')
1967
+ * @param params.side {BrokerDataOrderSideEnum} (optional) Filter by order side (e.g., 'buy', 'sell')
1968
+ * @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
1969
+ * @param params.limit {number} (optional) Maximum number of orders to return
1970
+ * @param params.offset {number} (optional) Number of orders to skip for pagination
1971
+ * @param params.createdAfter {string} (optional) Filter orders created after this timestamp
1972
+ * @param params.createdBefore {string} (optional) Filter orders created before this timestamp
1973
+ * @param params.includeMetadata {boolean} (optional) Include order metadata in response (excluded by default for FDX compliance)
1974
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrder>>>} Standard response with success/Error/Warning structure
1704
1975
  *
1705
1976
  * Generated from: GET /api/v1/brokers/data/orders
1706
1977
  * @methodId get_orders_api_v1_brokers_data_orders_get
@@ -1708,7 +1979,7 @@ class BrokersWrapper {
1708
1979
  * @example
1709
1980
  * ```typescript-client
1710
1981
  * // Example with no parameters
1711
- * const result = await finatic.getOrders();
1982
+ * const result = await finatic.getOrders({});
1712
1983
  *
1713
1984
  * // Access the response data
1714
1985
  * if (result.success) {
@@ -1718,7 +1989,11 @@ class BrokersWrapper {
1718
1989
  * @example
1719
1990
  * ```typescript-client
1720
1991
  * // Full example with optional parameters
1721
- * const result = await finatic.getOrders(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
1992
+ * const result = await finatic.getOrders({
1993
+ brokerId: 'alpaca',
1994
+ connectionId: '00000000-0000-0000-0000-000000000000',
1995
+ accountId: '123456789'
1996
+ * });
1722
1997
  *
1723
1998
  * // Handle response with warnings
1724
1999
  * if (result.success) {
@@ -1731,23 +2006,19 @@ class BrokersWrapper {
1731
2006
  * }
1732
2007
  * ```
1733
2008
  */
1734
- async getOrders(brokerId, connectionId, accountId, symbol, orderStatus, side, assetType, limit, offset, createdAfter, createdBefore, includeMetadata) {
1735
- // Construct params object from individual parameters
1736
- const params = {
1737
- brokerId: brokerId,
1738
- connectionId: connectionId,
1739
- accountId: accountId,
1740
- symbol: symbol,
1741
- orderStatus: orderStatus !== undefined ? coerceEnumValue(orderStatus, BrokerDataOrderStatusEnum, 'orderStatus') : undefined,
1742
- side: side !== undefined ? coerceEnumValue(side, BrokerDataOrderSideEnum, 'side') : undefined,
1743
- assetType: assetType !== undefined ? coerceEnumValue(assetType, BrokerDataAssetTypeEnum, 'assetType') : undefined,
1744
- limit: limit,
1745
- offset: offset,
1746
- createdAfter: createdAfter,
1747
- createdBefore: createdBefore,
1748
- includeMetadata: includeMetadata
1749
- }; // Authentication check
1750
- if (!this.sessionId) {
2009
+ async getOrders(params) {
2010
+ // Use params object (with default empty object)
2011
+ const resolvedParams = params || {};
2012
+ if (params?.orderStatus !== undefined) {
2013
+ params.orderStatus = coerceEnumValue(params.orderStatus, BrokerDataOrderStatusEnum, 'orderStatus');
2014
+ }
2015
+ if (params?.side !== undefined) {
2016
+ params.side = coerceEnumValue(params.side, BrokerDataOrderSideEnum, 'side');
2017
+ }
2018
+ if (params?.assetType !== undefined) {
2019
+ params.assetType = coerceEnumValue(params.assetType, BrokerDataAssetTypeEnum, 'assetType');
2020
+ } // Authentication check
2021
+ if (!this.sessionId || !this.companyId) {
1751
2022
  throw new Error('Session not initialized. Call startSession() first.');
1752
2023
  }
1753
2024
  // Generate request ID
@@ -1758,7 +2029,7 @@ class BrokersWrapper {
1758
2029
  const shouldCache = true;
1759
2030
  const cache = getCache(this.sdkConfig);
1760
2031
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1761
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', params, this.sdkConfig);
2032
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
1762
2033
  const cached = cache.get(cacheKey);
1763
2034
  if (cached) {
1764
2035
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1770,12 +2041,12 @@ class BrokersWrapper {
1770
2041
  request_id: requestId,
1771
2042
  method: 'GET',
1772
2043
  path: '/api/v1/brokers/data/orders',
1773
- params: params,
2044
+ params: resolvedParams,
1774
2045
  action: 'getOrders'
1775
2046
  });
1776
2047
  try {
1777
2048
  const response = await retryApiCall(async () => {
1778
- 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 } });
2049
+ 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 } : {}) } : {}) } });
1779
2050
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1780
2051
  }, {}, this.sdkConfig);
1781
2052
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1784,9 +2055,27 @@ class BrokersWrapper {
1784
2055
  throw new Error('Unexpected response shape: missing success field');
1785
2056
  }
1786
2057
  // Convert response to plain object, removing _id fields recursively
2058
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1787
2059
  const standardResponse = convertToPlainObject(responseData);
2060
+ // Phase 2: Wrap paginated responses with PaginatedData
2061
+ const hasLimit = true;
2062
+ const hasOffset = true;
2063
+ const hasPagination = hasLimit && hasOffset;
2064
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2065
+ // PaginatedData is already imported at top of file
2066
+ const paginationMeta = standardResponse.success.meta?.pagination;
2067
+ if (paginationMeta) {
2068
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2069
+ has_more: paginationMeta.has_more,
2070
+ next_offset: paginationMeta.next_offset,
2071
+ current_offset: paginationMeta.current_offset,
2072
+ limit: paginationMeta.limit,
2073
+ }, this.getOrders.bind(this), resolvedParams, this);
2074
+ standardResponse.success.data = paginatedData;
2075
+ }
2076
+ }
1788
2077
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1789
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', params, this.sdkConfig);
2078
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
1790
2079
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1791
2080
  }
1792
2081
  this.logger.debug('Get Orders completed', {
@@ -1794,6 +2083,7 @@ class BrokersWrapper {
1794
2083
  action: 'getOrders'
1795
2084
  });
1796
2085
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2086
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1797
2087
  return standardResponse;
1798
2088
  }
1799
2089
  catch (error) {
@@ -1870,19 +2160,19 @@ class BrokersWrapper {
1870
2160
  *
1871
2161
  * This endpoint is accessible from the portal and uses session-only authentication.
1872
2162
  * Returns positions from connections the company has read access to.
1873
- * @param brokerId {string} (optional)
1874
- * @param connectionId {string} (optional)
1875
- * @param accountId {string} (optional)
1876
- * @param symbol {string} (optional)
1877
- * @param side {BrokerDataOrderSideEnum} (optional)
1878
- * @param assetType {BrokerDataAssetTypeEnum} (optional)
1879
- * @param positionStatus {BrokerDataPositionStatusEnum} (optional)
1880
- * @param limit {number} (optional)
1881
- * @param offset {number} (optional)
1882
- * @param updatedAfter {string} (optional)
1883
- * @param updatedBefore {string} (optional)
1884
- * @param includeMetadata {boolean} (optional)
1885
- * @returns {Promise<FinaticResponse<FDXBrokerPosition[]>>} Standard response with success/Error/Warning structure
2163
+ * @param params.brokerId {string} (optional) Filter by broker ID
2164
+ * @param params.connectionId {string} (optional) Filter by connection ID
2165
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
2166
+ * @param params.symbol {string} (optional) Filter by symbol
2167
+ * @param params.side {BrokerDataOrderSideEnum} (optional) Filter by position side (e.g., 'long', 'short')
2168
+ * @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
2169
+ * @param params.positionStatus {BrokerDataPositionStatusEnum} (optional) Filter by position status: 'open' (quantity > 0) or 'closed' (quantity = 0)
2170
+ * @param params.limit {number} (optional) Maximum number of positions to return
2171
+ * @param params.offset {number} (optional) Number of positions to skip for pagination
2172
+ * @param params.updatedAfter {string} (optional) Filter positions updated after this timestamp
2173
+ * @param params.updatedBefore {string} (optional) Filter positions updated before this timestamp
2174
+ * @param params.includeMetadata {boolean} (optional) Include position metadata in response (excluded by default for FDX compliance)
2175
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPosition>>>} Standard response with success/Error/Warning structure
1886
2176
  *
1887
2177
  * Generated from: GET /api/v1/brokers/data/positions
1888
2178
  * @methodId get_positions_api_v1_brokers_data_positions_get
@@ -1890,7 +2180,7 @@ class BrokersWrapper {
1890
2180
  * @example
1891
2181
  * ```typescript-client
1892
2182
  * // Example with no parameters
1893
- * const result = await finatic.getPositions();
2183
+ * const result = await finatic.getPositions({});
1894
2184
  *
1895
2185
  * // Access the response data
1896
2186
  * if (result.success) {
@@ -1900,7 +2190,11 @@ class BrokersWrapper {
1900
2190
  * @example
1901
2191
  * ```typescript-client
1902
2192
  * // Full example with optional parameters
1903
- * const result = await finatic.getPositions(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
2193
+ * const result = await finatic.getPositions({
2194
+ brokerId: 'alpaca',
2195
+ connectionId: '00000000-0000-0000-0000-000000000000',
2196
+ accountId: '123456789'
2197
+ * });
1904
2198
  *
1905
2199
  * // Handle response with warnings
1906
2200
  * if (result.success) {
@@ -1913,23 +2207,19 @@ class BrokersWrapper {
1913
2207
  * }
1914
2208
  * ```
1915
2209
  */
1916
- async getPositions(brokerId, connectionId, accountId, symbol, side, assetType, positionStatus, limit, offset, updatedAfter, updatedBefore, includeMetadata) {
1917
- // Construct params object from individual parameters
1918
- const params = {
1919
- brokerId: brokerId,
1920
- connectionId: connectionId,
1921
- accountId: accountId,
1922
- symbol: symbol,
1923
- side: side !== undefined ? coerceEnumValue(side, BrokerDataOrderSideEnum, 'side') : undefined,
1924
- assetType: assetType !== undefined ? coerceEnumValue(assetType, BrokerDataAssetTypeEnum, 'assetType') : undefined,
1925
- positionStatus: positionStatus !== undefined ? coerceEnumValue(positionStatus, BrokerDataPositionStatusEnum, 'positionStatus') : undefined,
1926
- limit: limit,
1927
- offset: offset,
1928
- updatedAfter: updatedAfter,
1929
- updatedBefore: updatedBefore,
1930
- includeMetadata: includeMetadata
1931
- }; // Authentication check
1932
- if (!this.sessionId) {
2210
+ async getPositions(params) {
2211
+ // Use params object (with default empty object)
2212
+ const resolvedParams = params || {};
2213
+ if (params?.side !== undefined) {
2214
+ params.side = coerceEnumValue(params.side, BrokerDataOrderSideEnum, 'side');
2215
+ }
2216
+ if (params?.assetType !== undefined) {
2217
+ params.assetType = coerceEnumValue(params.assetType, BrokerDataAssetTypeEnum, 'assetType');
2218
+ }
2219
+ if (params?.positionStatus !== undefined) {
2220
+ params.positionStatus = coerceEnumValue(params.positionStatus, BrokerDataPositionStatusEnum, 'positionStatus');
2221
+ } // Authentication check
2222
+ if (!this.sessionId || !this.companyId) {
1933
2223
  throw new Error('Session not initialized. Call startSession() first.');
1934
2224
  }
1935
2225
  // Generate request ID
@@ -1940,7 +2230,7 @@ class BrokersWrapper {
1940
2230
  const shouldCache = true;
1941
2231
  const cache = getCache(this.sdkConfig);
1942
2232
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1943
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', params, this.sdkConfig);
2233
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
1944
2234
  const cached = cache.get(cacheKey);
1945
2235
  if (cached) {
1946
2236
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1952,12 +2242,12 @@ class BrokersWrapper {
1952
2242
  request_id: requestId,
1953
2243
  method: 'GET',
1954
2244
  path: '/api/v1/brokers/data/positions',
1955
- params: params,
2245
+ params: resolvedParams,
1956
2246
  action: 'getPositions'
1957
2247
  });
1958
2248
  try {
1959
2249
  const response = await retryApiCall(async () => {
1960
- 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 } });
2250
+ 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 } : {}) } : {}) } });
1961
2251
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1962
2252
  }, {}, this.sdkConfig);
1963
2253
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1966,9 +2256,27 @@ class BrokersWrapper {
1966
2256
  throw new Error('Unexpected response shape: missing success field');
1967
2257
  }
1968
2258
  // Convert response to plain object, removing _id fields recursively
2259
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1969
2260
  const standardResponse = convertToPlainObject(responseData);
2261
+ // Phase 2: Wrap paginated responses with PaginatedData
2262
+ const hasLimit = true;
2263
+ const hasOffset = true;
2264
+ const hasPagination = hasLimit && hasOffset;
2265
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2266
+ // PaginatedData is already imported at top of file
2267
+ const paginationMeta = standardResponse.success.meta?.pagination;
2268
+ if (paginationMeta) {
2269
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2270
+ has_more: paginationMeta.has_more,
2271
+ next_offset: paginationMeta.next_offset,
2272
+ current_offset: paginationMeta.current_offset,
2273
+ limit: paginationMeta.limit,
2274
+ }, this.getPositions.bind(this), resolvedParams, this);
2275
+ standardResponse.success.data = paginatedData;
2276
+ }
2277
+ }
1970
2278
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1971
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', params, this.sdkConfig);
2279
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
1972
2280
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1973
2281
  }
1974
2282
  this.logger.debug('Get Positions completed', {
@@ -1976,6 +2284,7 @@ class BrokersWrapper {
1976
2284
  action: 'getPositions'
1977
2285
  });
1978
2286
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2287
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
1979
2288
  return standardResponse;
1980
2289
  }
1981
2290
  catch (error) {
@@ -2052,16 +2361,16 @@ class BrokersWrapper {
2052
2361
  *
2053
2362
  * This endpoint is accessible from the portal and uses session-only authentication.
2054
2363
  * Returns balances from connections the company has read access to.
2055
- * @param brokerId {string} (optional)
2056
- * @param connectionId {string} (optional)
2057
- * @param accountId {string} (optional)
2058
- * @param isEndOfDaySnapshot {boolean} (optional)
2059
- * @param limit {number} (optional)
2060
- * @param offset {number} (optional)
2061
- * @param balanceCreatedAfter {string} (optional)
2062
- * @param balanceCreatedBefore {string} (optional)
2063
- * @param includeMetadata {boolean} (optional)
2064
- * @returns {Promise<FinaticResponse<FDXBrokerBalance[]>>} Standard response with success/Error/Warning structure
2364
+ * @param params.brokerId {string} (optional) Filter by broker ID
2365
+ * @param params.connectionId {string} (optional) Filter by connection ID
2366
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
2367
+ * @param params.isEndOfDaySnapshot {boolean} (optional) Filter by end-of-day snapshot status (true/false)
2368
+ * @param params.limit {number} (optional) Maximum number of balances to return
2369
+ * @param params.offset {number} (optional) Number of balances to skip for pagination
2370
+ * @param params.balanceCreatedAfter {string} (optional) Filter balances created after this timestamp
2371
+ * @param params.balanceCreatedBefore {string} (optional) Filter balances created before this timestamp
2372
+ * @param params.includeMetadata {boolean} (optional) Include balance metadata in response (excluded by default for FDX compliance)
2373
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerBalance>>>} Standard response with success/Error/Warning structure
2065
2374
  *
2066
2375
  * Generated from: GET /api/v1/brokers/data/balances
2067
2376
  * @methodId get_balances_api_v1_brokers_data_balances_get
@@ -2069,7 +2378,7 @@ class BrokersWrapper {
2069
2378
  * @example
2070
2379
  * ```typescript-client
2071
2380
  * // Example with no parameters
2072
- * const result = await finatic.getBalances();
2381
+ * const result = await finatic.getBalances({});
2073
2382
  *
2074
2383
  * // Access the response data
2075
2384
  * if (result.success) {
@@ -2079,7 +2388,11 @@ class BrokersWrapper {
2079
2388
  * @example
2080
2389
  * ```typescript-client
2081
2390
  * // Full example with optional parameters
2082
- * const result = await finatic.getBalances(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
2391
+ * const result = await finatic.getBalances({
2392
+ brokerId: 'alpaca',
2393
+ connectionId: '00000000-0000-0000-0000-000000000000',
2394
+ accountId: '123456789'
2395
+ * });
2083
2396
  *
2084
2397
  * // Handle response with warnings
2085
2398
  * if (result.success) {
@@ -2092,20 +2405,10 @@ class BrokersWrapper {
2092
2405
  * }
2093
2406
  * ```
2094
2407
  */
2095
- async getBalances(brokerId, connectionId, accountId, isEndOfDaySnapshot, limit, offset, balanceCreatedAfter, balanceCreatedBefore, includeMetadata) {
2096
- // Construct params object from individual parameters
2097
- const params = {
2098
- brokerId: brokerId,
2099
- connectionId: connectionId,
2100
- accountId: accountId,
2101
- isEndOfDaySnapshot: isEndOfDaySnapshot,
2102
- limit: limit,
2103
- offset: offset,
2104
- balanceCreatedAfter: balanceCreatedAfter,
2105
- balanceCreatedBefore: balanceCreatedBefore,
2106
- includeMetadata: includeMetadata
2107
- }; // Authentication check
2108
- if (!this.sessionId) {
2408
+ async getBalances(params) {
2409
+ // Use params object (with default empty object)
2410
+ const resolvedParams = params || {}; // Authentication check
2411
+ if (!this.sessionId || !this.companyId) {
2109
2412
  throw new Error('Session not initialized. Call startSession() first.');
2110
2413
  }
2111
2414
  // Generate request ID
@@ -2116,7 +2419,7 @@ class BrokersWrapper {
2116
2419
  const shouldCache = true;
2117
2420
  const cache = getCache(this.sdkConfig);
2118
2421
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2119
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', params, this.sdkConfig);
2422
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
2120
2423
  const cached = cache.get(cacheKey);
2121
2424
  if (cached) {
2122
2425
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2128,12 +2431,12 @@ class BrokersWrapper {
2128
2431
  request_id: requestId,
2129
2432
  method: 'GET',
2130
2433
  path: '/api/v1/brokers/data/balances',
2131
- params: params,
2434
+ params: resolvedParams,
2132
2435
  action: 'getBalances'
2133
2436
  });
2134
2437
  try {
2135
2438
  const response = await retryApiCall(async () => {
2136
- 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 } });
2439
+ 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 } : {}) } : {}) } });
2137
2440
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2138
2441
  }, {}, this.sdkConfig);
2139
2442
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2142,9 +2445,27 @@ class BrokersWrapper {
2142
2445
  throw new Error('Unexpected response shape: missing success field');
2143
2446
  }
2144
2447
  // Convert response to plain object, removing _id fields recursively
2448
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2145
2449
  const standardResponse = convertToPlainObject(responseData);
2450
+ // Phase 2: Wrap paginated responses with PaginatedData
2451
+ const hasLimit = true;
2452
+ const hasOffset = true;
2453
+ const hasPagination = hasLimit && hasOffset;
2454
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2455
+ // PaginatedData is already imported at top of file
2456
+ const paginationMeta = standardResponse.success.meta?.pagination;
2457
+ if (paginationMeta) {
2458
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2459
+ has_more: paginationMeta.has_more,
2460
+ next_offset: paginationMeta.next_offset,
2461
+ current_offset: paginationMeta.current_offset,
2462
+ limit: paginationMeta.limit,
2463
+ }, this.getBalances.bind(this), resolvedParams, this);
2464
+ standardResponse.success.data = paginatedData;
2465
+ }
2466
+ }
2146
2467
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2147
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', params, this.sdkConfig);
2468
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
2148
2469
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2149
2470
  }
2150
2471
  this.logger.debug('Get Balances completed', {
@@ -2152,6 +2473,7 @@ class BrokersWrapper {
2152
2473
  action: 'getBalances'
2153
2474
  });
2154
2475
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2476
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2155
2477
  return standardResponse;
2156
2478
  }
2157
2479
  catch (error) {
@@ -2228,15 +2550,15 @@ class BrokersWrapper {
2228
2550
  *
2229
2551
  * This endpoint is accessible from the portal and uses session-only authentication.
2230
2552
  * Returns accounts from connections the company has read access to.
2231
- * @param brokerId {string} (optional)
2232
- * @param connectionId {string} (optional)
2233
- * @param accountType {BrokerDataAccountTypeEnum} (optional)
2234
- * @param status {AccountStatus} (optional)
2235
- * @param currency {string} (optional)
2236
- * @param limit {number} (optional)
2237
- * @param offset {number} (optional)
2238
- * @param includeMetadata {boolean} (optional)
2239
- * @returns {Promise<FinaticResponse<FDXBrokerAccount[]>>} Standard response with success/Error/Warning structure
2553
+ * @param params.brokerId {string} (optional) Filter by broker ID
2554
+ * @param params.connectionId {string} (optional) Filter by connection ID
2555
+ * @param params.accountType {BrokerDataAccountTypeEnum} (optional) Filter by account type (e.g., 'margin', 'cash', 'crypto_wallet', 'live', 'sim')
2556
+ * @param params.status {AccountStatus} (optional) Filter by account status (e.g., 'active', 'inactive')
2557
+ * @param params.currency {string} (optional) Filter by currency (e.g., 'USD', 'EUR')
2558
+ * @param params.limit {number} (optional) Maximum number of accounts to return
2559
+ * @param params.offset {number} (optional) Number of accounts to skip for pagination
2560
+ * @param params.includeMetadata {boolean} (optional) Include connection metadata in response (excluded by default for FDX compliance)
2561
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerAccount>>>} Standard response with success/Error/Warning structure
2240
2562
  *
2241
2563
  * Generated from: GET /api/v1/brokers/data/accounts
2242
2564
  * @methodId get_accounts_api_v1_brokers_data_accounts_get
@@ -2244,7 +2566,7 @@ class BrokersWrapper {
2244
2566
  * @example
2245
2567
  * ```typescript-client
2246
2568
  * // Example with no parameters
2247
- * const result = await finatic.getAccounts();
2569
+ * const result = await finatic.getAccounts({});
2248
2570
  *
2249
2571
  * // Access the response data
2250
2572
  * if (result.success) {
@@ -2254,7 +2576,11 @@ class BrokersWrapper {
2254
2576
  * @example
2255
2577
  * ```typescript-client
2256
2578
  * // Full example with optional parameters
2257
- * const result = await finatic.getAccounts(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountType: 'margin');
2579
+ * const result = await finatic.getAccounts({
2580
+ brokerId: 'alpaca',
2581
+ connectionId: '00000000-0000-0000-0000-000000000000',
2582
+ accountType: 'margin'
2583
+ * });
2258
2584
  *
2259
2585
  * // Handle response with warnings
2260
2586
  * if (result.success) {
@@ -2267,19 +2593,13 @@ class BrokersWrapper {
2267
2593
  * }
2268
2594
  * ```
2269
2595
  */
2270
- async getAccounts(brokerId, connectionId, accountType, status, currency, limit, offset, includeMetadata) {
2271
- // Construct params object from individual parameters
2272
- const params = {
2273
- brokerId: brokerId,
2274
- connectionId: connectionId,
2275
- accountType: accountType !== undefined ? coerceEnumValue(accountType, BrokerDataAccountTypeEnum, 'accountType') : undefined,
2276
- status: status,
2277
- currency: currency,
2278
- limit: limit,
2279
- offset: offset,
2280
- includeMetadata: includeMetadata
2281
- }; // Authentication check
2282
- if (!this.sessionId) {
2596
+ async getAccounts(params) {
2597
+ // Use params object (with default empty object)
2598
+ const resolvedParams = params || {};
2599
+ if (params?.accountType !== undefined) {
2600
+ params.accountType = coerceEnumValue(params.accountType, BrokerDataAccountTypeEnum, 'accountType');
2601
+ } // Authentication check
2602
+ if (!this.sessionId || !this.companyId) {
2283
2603
  throw new Error('Session not initialized. Call startSession() first.');
2284
2604
  }
2285
2605
  // Generate request ID
@@ -2290,7 +2610,7 @@ class BrokersWrapper {
2290
2610
  const shouldCache = true;
2291
2611
  const cache = getCache(this.sdkConfig);
2292
2612
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2293
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', params, this.sdkConfig);
2613
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
2294
2614
  const cached = cache.get(cacheKey);
2295
2615
  if (cached) {
2296
2616
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2302,12 +2622,12 @@ class BrokersWrapper {
2302
2622
  request_id: requestId,
2303
2623
  method: 'GET',
2304
2624
  path: '/api/v1/brokers/data/accounts',
2305
- params: params,
2625
+ params: resolvedParams,
2306
2626
  action: 'getAccounts'
2307
2627
  });
2308
2628
  try {
2309
2629
  const response = await retryApiCall(async () => {
2310
- 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 } });
2630
+ 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 } : {}) } : {}) } });
2311
2631
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2312
2632
  }, {}, this.sdkConfig);
2313
2633
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2316,9 +2636,27 @@ class BrokersWrapper {
2316
2636
  throw new Error('Unexpected response shape: missing success field');
2317
2637
  }
2318
2638
  // Convert response to plain object, removing _id fields recursively
2639
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2319
2640
  const standardResponse = convertToPlainObject(responseData);
2641
+ // Phase 2: Wrap paginated responses with PaginatedData
2642
+ const hasLimit = true;
2643
+ const hasOffset = true;
2644
+ const hasPagination = hasLimit && hasOffset;
2645
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2646
+ // PaginatedData is already imported at top of file
2647
+ const paginationMeta = standardResponse.success.meta?.pagination;
2648
+ if (paginationMeta) {
2649
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2650
+ has_more: paginationMeta.has_more,
2651
+ next_offset: paginationMeta.next_offset,
2652
+ current_offset: paginationMeta.current_offset,
2653
+ limit: paginationMeta.limit,
2654
+ }, this.getAccounts.bind(this), resolvedParams, this);
2655
+ standardResponse.success.data = paginatedData;
2656
+ }
2657
+ }
2320
2658
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2321
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', params, this.sdkConfig);
2659
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
2322
2660
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2323
2661
  }
2324
2662
  this.logger.debug('Get Accounts completed', {
@@ -2326,6 +2664,7 @@ class BrokersWrapper {
2326
2664
  action: 'getAccounts'
2327
2665
  });
2328
2666
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2667
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2329
2668
  return standardResponse;
2330
2669
  }
2331
2670
  catch (error) {
@@ -2401,12 +2740,12 @@ class BrokersWrapper {
2401
2740
  * Get order fills for a specific order.
2402
2741
  *
2403
2742
  * This endpoint returns all execution fills for the specified order.
2404
- * @param orderId {string}
2405
- * @param connectionId {string} (optional)
2406
- * @param limit {number} (optional)
2407
- * @param offset {number} (optional)
2408
- * @param includeMetadata {boolean} (optional)
2409
- * @returns {Promise<FinaticResponse<FDXBrokerOrderFill[]>>} Standard response with success/Error/Warning structure
2743
+ * @param params.orderId {string} Order ID
2744
+ * @param params.connectionId {string} (optional) Filter by connection ID
2745
+ * @param params.limit {number} (optional) Maximum number of fills to return
2746
+ * @param params.offset {number} (optional) Number of fills to skip for pagination
2747
+ * @param params.includeMetadata {boolean} (optional) Include fill metadata in response (excluded by default for FDX compliance)
2748
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderFill>>>} Standard response with success/Error/Warning structure
2410
2749
  *
2411
2750
  * Generated from: GET /api/v1/brokers/data/orders/{order_id}/fills
2412
2751
  * @methodId get_order_fills_api_v1_brokers_data_orders__order_id__fills_get
@@ -2414,7 +2753,9 @@ class BrokersWrapper {
2414
2753
  * @example
2415
2754
  * ```typescript-client
2416
2755
  * // Minimal example with required parameters only
2417
- * const result = await finatic.getOrderFills(orderId: '00000000-0000-0000-0000-000000000000');
2756
+ * const result = await finatic.getOrderFills({
2757
+ orderId: '00000000-0000-0000-0000-000000000000'
2758
+ * });
2418
2759
  *
2419
2760
  * // Access the response data
2420
2761
  * if (result.success) {
@@ -2426,7 +2767,12 @@ class BrokersWrapper {
2426
2767
  * @example
2427
2768
  * ```typescript-client
2428
2769
  * // Full example with optional parameters
2429
- * const result = await finatic.getOrderFills(orderId: '00000000-0000-0000-0000-000000000000', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100, offset: 0);
2770
+ * const result = await finatic.getOrderFills({
2771
+ orderId: '00000000-0000-0000-0000-000000000000',
2772
+ connectionId: '00000000-0000-0000-0000-000000000000',
2773
+ limit: 100,
2774
+ offset: 0
2775
+ * });
2430
2776
  *
2431
2777
  * // Handle response with warnings
2432
2778
  * if (result.success) {
@@ -2439,16 +2785,10 @@ class BrokersWrapper {
2439
2785
  * }
2440
2786
  * ```
2441
2787
  */
2442
- async getOrderFills(orderId, connectionId, limit, offset, includeMetadata) {
2443
- // Construct params object from individual parameters
2444
- const params = {
2445
- orderId: orderId,
2446
- connectionId: connectionId,
2447
- limit: limit,
2448
- offset: offset,
2449
- includeMetadata: includeMetadata
2450
- }; // Authentication check
2451
- if (!this.sessionId) {
2788
+ async getOrderFills(params) {
2789
+ // Use params object (required parameters present)
2790
+ const resolvedParams = params; // Authentication check
2791
+ if (!this.sessionId || !this.companyId) {
2452
2792
  throw new Error('Session not initialized. Call startSession() first.');
2453
2793
  }
2454
2794
  // Generate request ID
@@ -2459,7 +2799,7 @@ class BrokersWrapper {
2459
2799
  const shouldCache = true;
2460
2800
  const cache = getCache(this.sdkConfig);
2461
2801
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2462
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', params, this.sdkConfig);
2802
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
2463
2803
  const cached = cache.get(cacheKey);
2464
2804
  if (cached) {
2465
2805
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2471,12 +2811,12 @@ class BrokersWrapper {
2471
2811
  request_id: requestId,
2472
2812
  method: 'GET',
2473
2813
  path: '/api/v1/brokers/data/orders/{order_id}/fills',
2474
- params: params,
2814
+ params: resolvedParams,
2475
2815
  action: 'getOrderFills'
2476
2816
  });
2477
2817
  try {
2478
2818
  const response = await retryApiCall(async () => {
2479
- 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 } });
2819
+ 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 } : {}) } : {}) } });
2480
2820
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2481
2821
  }, {}, this.sdkConfig);
2482
2822
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2485,9 +2825,27 @@ class BrokersWrapper {
2485
2825
  throw new Error('Unexpected response shape: missing success field');
2486
2826
  }
2487
2827
  // Convert response to plain object, removing _id fields recursively
2828
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2488
2829
  const standardResponse = convertToPlainObject(responseData);
2830
+ // Phase 2: Wrap paginated responses with PaginatedData
2831
+ const hasLimit = true;
2832
+ const hasOffset = true;
2833
+ const hasPagination = hasLimit && hasOffset;
2834
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
2835
+ // PaginatedData is already imported at top of file
2836
+ const paginationMeta = standardResponse.success.meta?.pagination;
2837
+ if (paginationMeta) {
2838
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
2839
+ has_more: paginationMeta.has_more,
2840
+ next_offset: paginationMeta.next_offset,
2841
+ current_offset: paginationMeta.current_offset,
2842
+ limit: paginationMeta.limit,
2843
+ }, this.getOrderFills.bind(this), resolvedParams, this);
2844
+ standardResponse.success.data = paginatedData;
2845
+ }
2846
+ }
2489
2847
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2490
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', params, this.sdkConfig);
2848
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
2491
2849
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2492
2850
  }
2493
2851
  this.logger.debug('Get Order Fills completed', {
@@ -2495,6 +2853,7 @@ class BrokersWrapper {
2495
2853
  action: 'getOrderFills'
2496
2854
  });
2497
2855
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
2856
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2498
2857
  return standardResponse;
2499
2858
  }
2500
2859
  catch (error) {
@@ -2570,12 +2929,12 @@ class BrokersWrapper {
2570
2929
  * Get order events for a specific order.
2571
2930
  *
2572
2931
  * This endpoint returns all lifecycle events for the specified order.
2573
- * @param orderId {string}
2574
- * @param connectionId {string} (optional)
2575
- * @param limit {number} (optional)
2576
- * @param offset {number} (optional)
2577
- * @param includeMetadata {boolean} (optional)
2578
- * @returns {Promise<FinaticResponse<FDXBrokerOrderEvent[]>>} Standard response with success/Error/Warning structure
2932
+ * @param params.orderId {string} Order ID
2933
+ * @param params.connectionId {string} (optional) Filter by connection ID
2934
+ * @param params.limit {number} (optional) Maximum number of events to return
2935
+ * @param params.offset {number} (optional) Number of events to skip for pagination
2936
+ * @param params.includeMetadata {boolean} (optional) Include event metadata in response (excluded by default for FDX compliance)
2937
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderEvent>>>} Standard response with success/Error/Warning structure
2579
2938
  *
2580
2939
  * Generated from: GET /api/v1/brokers/data/orders/{order_id}/events
2581
2940
  * @methodId get_order_events_api_v1_brokers_data_orders__order_id__events_get
@@ -2583,7 +2942,9 @@ class BrokersWrapper {
2583
2942
  * @example
2584
2943
  * ```typescript-client
2585
2944
  * // Minimal example with required parameters only
2586
- * const result = await finatic.getOrderEvents(orderId: '00000000-0000-0000-0000-000000000000');
2945
+ * const result = await finatic.getOrderEvents({
2946
+ orderId: '00000000-0000-0000-0000-000000000000'
2947
+ * });
2587
2948
  *
2588
2949
  * // Access the response data
2589
2950
  * if (result.success) {
@@ -2595,7 +2956,12 @@ class BrokersWrapper {
2595
2956
  * @example
2596
2957
  * ```typescript-client
2597
2958
  * // Full example with optional parameters
2598
- * const result = await finatic.getOrderEvents(orderId: '00000000-0000-0000-0000-000000000000', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100, offset: 0);
2959
+ * const result = await finatic.getOrderEvents({
2960
+ orderId: '00000000-0000-0000-0000-000000000000',
2961
+ connectionId: '00000000-0000-0000-0000-000000000000',
2962
+ limit: 100,
2963
+ offset: 0
2964
+ * });
2599
2965
  *
2600
2966
  * // Handle response with warnings
2601
2967
  * if (result.success) {
@@ -2608,16 +2974,10 @@ class BrokersWrapper {
2608
2974
  * }
2609
2975
  * ```
2610
2976
  */
2611
- async getOrderEvents(orderId, connectionId, limit, offset, includeMetadata) {
2612
- // Construct params object from individual parameters
2613
- const params = {
2614
- orderId: orderId,
2615
- connectionId: connectionId,
2616
- limit: limit,
2617
- offset: offset,
2618
- includeMetadata: includeMetadata
2619
- }; // Authentication check
2620
- if (!this.sessionId) {
2977
+ async getOrderEvents(params) {
2978
+ // Use params object (required parameters present)
2979
+ const resolvedParams = params; // Authentication check
2980
+ if (!this.sessionId || !this.companyId) {
2621
2981
  throw new Error('Session not initialized. Call startSession() first.');
2622
2982
  }
2623
2983
  // Generate request ID
@@ -2628,7 +2988,7 @@ class BrokersWrapper {
2628
2988
  const shouldCache = true;
2629
2989
  const cache = getCache(this.sdkConfig);
2630
2990
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2631
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', params, this.sdkConfig);
2991
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
2632
2992
  const cached = cache.get(cacheKey);
2633
2993
  if (cached) {
2634
2994
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2640,12 +3000,12 @@ class BrokersWrapper {
2640
3000
  request_id: requestId,
2641
3001
  method: 'GET',
2642
3002
  path: '/api/v1/brokers/data/orders/{order_id}/events',
2643
- params: params,
3003
+ params: resolvedParams,
2644
3004
  action: 'getOrderEvents'
2645
3005
  });
2646
3006
  try {
2647
3007
  const response = await retryApiCall(async () => {
2648
- 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 } });
3008
+ 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 } : {}) } : {}) } });
2649
3009
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2650
3010
  }, {}, this.sdkConfig);
2651
3011
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2654,9 +3014,27 @@ class BrokersWrapper {
2654
3014
  throw new Error('Unexpected response shape: missing success field');
2655
3015
  }
2656
3016
  // Convert response to plain object, removing _id fields recursively
3017
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2657
3018
  const standardResponse = convertToPlainObject(responseData);
3019
+ // Phase 2: Wrap paginated responses with PaginatedData
3020
+ const hasLimit = true;
3021
+ const hasOffset = true;
3022
+ const hasPagination = hasLimit && hasOffset;
3023
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3024
+ // PaginatedData is already imported at top of file
3025
+ const paginationMeta = standardResponse.success.meta?.pagination;
3026
+ if (paginationMeta) {
3027
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3028
+ has_more: paginationMeta.has_more,
3029
+ next_offset: paginationMeta.next_offset,
3030
+ current_offset: paginationMeta.current_offset,
3031
+ limit: paginationMeta.limit,
3032
+ }, this.getOrderEvents.bind(this), resolvedParams, this);
3033
+ standardResponse.success.data = paginatedData;
3034
+ }
3035
+ }
2658
3036
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2659
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', params, this.sdkConfig);
3037
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
2660
3038
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2661
3039
  }
2662
3040
  this.logger.debug('Get Order Events completed', {
@@ -2664,6 +3042,7 @@ class BrokersWrapper {
2664
3042
  action: 'getOrderEvents'
2665
3043
  });
2666
3044
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3045
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2667
3046
  return standardResponse;
2668
3047
  }
2669
3048
  catch (error) {
@@ -2739,14 +3118,14 @@ class BrokersWrapper {
2739
3118
  * Get order groups.
2740
3119
  *
2741
3120
  * This endpoint returns order groups that contain multiple orders.
2742
- * @param brokerId {string} (optional)
2743
- * @param connectionId {string} (optional)
2744
- * @param limit {number} (optional)
2745
- * @param offset {number} (optional)
2746
- * @param createdAfter {string} (optional)
2747
- * @param createdBefore {string} (optional)
2748
- * @param includeMetadata {boolean} (optional)
2749
- * @returns {Promise<FinaticResponse<FDXBrokerOrderGroup[]>>} Standard response with success/Error/Warning structure
3121
+ * @param params.brokerId {string} (optional) Filter by broker ID
3122
+ * @param params.connectionId {string} (optional) Filter by connection ID
3123
+ * @param params.limit {number} (optional) Maximum number of order groups to return
3124
+ * @param params.offset {number} (optional) Number of order groups to skip for pagination
3125
+ * @param params.createdAfter {string} (optional) Filter order groups created after this timestamp
3126
+ * @param params.createdBefore {string} (optional) Filter order groups created before this timestamp
3127
+ * @param params.includeMetadata {boolean} (optional) Include group metadata in response (excluded by default for FDX compliance)
3128
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderGroup>>>} Standard response with success/Error/Warning structure
2750
3129
  *
2751
3130
  * Generated from: GET /api/v1/brokers/data/orders/groups
2752
3131
  * @methodId get_order_groups_api_v1_brokers_data_orders_groups_get
@@ -2754,7 +3133,7 @@ class BrokersWrapper {
2754
3133
  * @example
2755
3134
  * ```typescript-client
2756
3135
  * // Example with no parameters
2757
- * const result = await finatic.getOrderGroups();
3136
+ * const result = await finatic.getOrderGroups({});
2758
3137
  *
2759
3138
  * // Access the response data
2760
3139
  * if (result.success) {
@@ -2764,7 +3143,11 @@ class BrokersWrapper {
2764
3143
  * @example
2765
3144
  * ```typescript-client
2766
3145
  * // Full example with optional parameters
2767
- * const result = await finatic.getOrderGroups(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100);
3146
+ * const result = await finatic.getOrderGroups({
3147
+ brokerId: 'alpaca',
3148
+ connectionId: '00000000-0000-0000-0000-000000000000',
3149
+ limit: 100
3150
+ * });
2768
3151
  *
2769
3152
  * // Handle response with warnings
2770
3153
  * if (result.success) {
@@ -2777,18 +3160,10 @@ class BrokersWrapper {
2777
3160
  * }
2778
3161
  * ```
2779
3162
  */
2780
- async getOrderGroups(brokerId, connectionId, limit, offset, createdAfter, createdBefore, includeMetadata) {
2781
- // Construct params object from individual parameters
2782
- const params = {
2783
- brokerId: brokerId,
2784
- connectionId: connectionId,
2785
- limit: limit,
2786
- offset: offset,
2787
- createdAfter: createdAfter,
2788
- createdBefore: createdBefore,
2789
- includeMetadata: includeMetadata
2790
- }; // Authentication check
2791
- if (!this.sessionId) {
3163
+ async getOrderGroups(params) {
3164
+ // Use params object (with default empty object)
3165
+ const resolvedParams = params || {}; // Authentication check
3166
+ if (!this.sessionId || !this.companyId) {
2792
3167
  throw new Error('Session not initialized. Call startSession() first.');
2793
3168
  }
2794
3169
  // Generate request ID
@@ -2799,7 +3174,7 @@ class BrokersWrapper {
2799
3174
  const shouldCache = true;
2800
3175
  const cache = getCache(this.sdkConfig);
2801
3176
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2802
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', params, this.sdkConfig);
3177
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
2803
3178
  const cached = cache.get(cacheKey);
2804
3179
  if (cached) {
2805
3180
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2811,12 +3186,12 @@ class BrokersWrapper {
2811
3186
  request_id: requestId,
2812
3187
  method: 'GET',
2813
3188
  path: '/api/v1/brokers/data/orders/groups',
2814
- params: params,
3189
+ params: resolvedParams,
2815
3190
  action: 'getOrderGroups'
2816
3191
  });
2817
3192
  try {
2818
3193
  const response = await retryApiCall(async () => {
2819
- 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 } });
3194
+ 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 } : {}) } : {}) } });
2820
3195
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2821
3196
  }, {}, this.sdkConfig);
2822
3197
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2825,9 +3200,27 @@ class BrokersWrapper {
2825
3200
  throw new Error('Unexpected response shape: missing success field');
2826
3201
  }
2827
3202
  // Convert response to plain object, removing _id fields recursively
3203
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2828
3204
  const standardResponse = convertToPlainObject(responseData);
3205
+ // Phase 2: Wrap paginated responses with PaginatedData
3206
+ const hasLimit = true;
3207
+ const hasOffset = true;
3208
+ const hasPagination = hasLimit && hasOffset;
3209
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3210
+ // PaginatedData is already imported at top of file
3211
+ const paginationMeta = standardResponse.success.meta?.pagination;
3212
+ if (paginationMeta) {
3213
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3214
+ has_more: paginationMeta.has_more,
3215
+ next_offset: paginationMeta.next_offset,
3216
+ current_offset: paginationMeta.current_offset,
3217
+ limit: paginationMeta.limit,
3218
+ }, this.getOrderGroups.bind(this), resolvedParams, this);
3219
+ standardResponse.success.data = paginatedData;
3220
+ }
3221
+ }
2829
3222
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2830
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', params, this.sdkConfig);
3223
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
2831
3224
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2832
3225
  }
2833
3226
  this.logger.debug('Get Order Groups completed', {
@@ -2835,6 +3228,7 @@ class BrokersWrapper {
2835
3228
  action: 'getOrderGroups'
2836
3229
  });
2837
3230
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3231
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
2838
3232
  return standardResponse;
2839
3233
  }
2840
3234
  catch (error) {
@@ -2911,14 +3305,14 @@ class BrokersWrapper {
2911
3305
  *
2912
3306
  * This endpoint returns tax lots for positions, which are used for tax reporting.
2913
3307
  * Each lot tracks when a position was opened/closed and at what prices.
2914
- * @param brokerId {string} (optional)
2915
- * @param connectionId {string} (optional)
2916
- * @param accountId {string} (optional)
2917
- * @param symbol {string} (optional)
2918
- * @param positionId {string} (optional)
2919
- * @param limit {number} (optional)
2920
- * @param offset {number} (optional)
2921
- * @returns {Promise<FinaticResponse<FDXBrokerPositionLot[]>>} Standard response with success/Error/Warning structure
3308
+ * @param params.brokerId {string} (optional) Filter by broker ID
3309
+ * @param params.connectionId {string} (optional) Filter by connection ID
3310
+ * @param params.accountId {string} (optional) Filter by broker provided account ID
3311
+ * @param params.symbol {string} (optional) Filter by symbol
3312
+ * @param params.positionId {string} (optional) Filter by position ID
3313
+ * @param params.limit {number} (optional) Maximum number of position lots to return
3314
+ * @param params.offset {number} (optional) Number of position lots to skip for pagination
3315
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLot>>>} Standard response with success/Error/Warning structure
2922
3316
  *
2923
3317
  * Generated from: GET /api/v1/brokers/data/positions/lots
2924
3318
  * @methodId get_position_lots_api_v1_brokers_data_positions_lots_get
@@ -2926,7 +3320,7 @@ class BrokersWrapper {
2926
3320
  * @example
2927
3321
  * ```typescript-client
2928
3322
  * // Example with no parameters
2929
- * const result = await finatic.getPositionLots();
3323
+ * const result = await finatic.getPositionLots({});
2930
3324
  *
2931
3325
  * // Access the response data
2932
3326
  * if (result.success) {
@@ -2936,7 +3330,11 @@ class BrokersWrapper {
2936
3330
  * @example
2937
3331
  * ```typescript-client
2938
3332
  * // Full example with optional parameters
2939
- * const result = await finatic.getPositionLots(brokerId: 'alpaca', connectionId: '00000000-0000-0000-0000-000000000000', accountId: '123456789');
3333
+ * const result = await finatic.getPositionLots({
3334
+ brokerId: 'alpaca',
3335
+ connectionId: '00000000-0000-0000-0000-000000000000',
3336
+ accountId: '123456789'
3337
+ * });
2940
3338
  *
2941
3339
  * // Handle response with warnings
2942
3340
  * if (result.success) {
@@ -2949,18 +3347,10 @@ class BrokersWrapper {
2949
3347
  * }
2950
3348
  * ```
2951
3349
  */
2952
- async getPositionLots(brokerId, connectionId, accountId, symbol, positionId, limit, offset) {
2953
- // Construct params object from individual parameters
2954
- const params = {
2955
- brokerId: brokerId,
2956
- connectionId: connectionId,
2957
- accountId: accountId,
2958
- symbol: symbol,
2959
- positionId: positionId,
2960
- limit: limit,
2961
- offset: offset
2962
- }; // Authentication check
2963
- if (!this.sessionId) {
3350
+ async getPositionLots(params) {
3351
+ // Use params object (with default empty object)
3352
+ const resolvedParams = params || {}; // Authentication check
3353
+ if (!this.sessionId || !this.companyId) {
2964
3354
  throw new Error('Session not initialized. Call startSession() first.');
2965
3355
  }
2966
3356
  // Generate request ID
@@ -2971,7 +3361,7 @@ class BrokersWrapper {
2971
3361
  const shouldCache = true;
2972
3362
  const cache = getCache(this.sdkConfig);
2973
3363
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2974
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', params, this.sdkConfig);
3364
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
2975
3365
  const cached = cache.get(cacheKey);
2976
3366
  if (cached) {
2977
3367
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2983,12 +3373,12 @@ class BrokersWrapper {
2983
3373
  request_id: requestId,
2984
3374
  method: 'GET',
2985
3375
  path: '/api/v1/brokers/data/positions/lots',
2986
- params: params,
3376
+ params: resolvedParams,
2987
3377
  action: 'getPositionLots'
2988
3378
  });
2989
3379
  try {
2990
3380
  const response = await retryApiCall(async () => {
2991
- 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 } });
3381
+ 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 } : {}) } : {}) } });
2992
3382
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2993
3383
  }, {}, this.sdkConfig);
2994
3384
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2997,9 +3387,27 @@ class BrokersWrapper {
2997
3387
  throw new Error('Unexpected response shape: missing success field');
2998
3388
  }
2999
3389
  // Convert response to plain object, removing _id fields recursively
3390
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3000
3391
  const standardResponse = convertToPlainObject(responseData);
3392
+ // Phase 2: Wrap paginated responses with PaginatedData
3393
+ const hasLimit = true;
3394
+ const hasOffset = true;
3395
+ const hasPagination = hasLimit && hasOffset;
3396
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3397
+ // PaginatedData is already imported at top of file
3398
+ const paginationMeta = standardResponse.success.meta?.pagination;
3399
+ if (paginationMeta) {
3400
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3401
+ has_more: paginationMeta.has_more,
3402
+ next_offset: paginationMeta.next_offset,
3403
+ current_offset: paginationMeta.current_offset,
3404
+ limit: paginationMeta.limit,
3405
+ }, this.getPositionLots.bind(this), resolvedParams, this);
3406
+ standardResponse.success.data = paginatedData;
3407
+ }
3408
+ }
3001
3409
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3002
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', params, this.sdkConfig);
3410
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
3003
3411
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3004
3412
  }
3005
3413
  this.logger.debug('Get Position Lots completed', {
@@ -3007,6 +3415,7 @@ class BrokersWrapper {
3007
3415
  action: 'getPositionLots'
3008
3416
  });
3009
3417
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3418
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3010
3419
  return standardResponse;
3011
3420
  }
3012
3421
  catch (error) {
@@ -3082,11 +3491,11 @@ class BrokersWrapper {
3082
3491
  * Get position lot fills for a specific lot.
3083
3492
  *
3084
3493
  * This endpoint returns all fills associated with a specific position lot.
3085
- * @param lotId {string}
3086
- * @param connectionId {string} (optional)
3087
- * @param limit {number} (optional)
3088
- * @param offset {number} (optional)
3089
- * @returns {Promise<FinaticResponse<FDXBrokerPositionLotFill[]>>} Standard response with success/Error/Warning structure
3494
+ * @param params.lotId {string} Position lot ID
3495
+ * @param params.connectionId {string} (optional) Filter by connection ID
3496
+ * @param params.limit {number} (optional) Maximum number of fills to return
3497
+ * @param params.offset {number} (optional) Number of fills to skip for pagination
3498
+ * @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLotFill>>>} Standard response with success/Error/Warning structure
3090
3499
  *
3091
3500
  * Generated from: GET /api/v1/brokers/data/positions/lots/{lot_id}/fills
3092
3501
  * @methodId get_position_lot_fills_api_v1_brokers_data_positions_lots__lot_id__fills_get
@@ -3094,7 +3503,9 @@ class BrokersWrapper {
3094
3503
  * @example
3095
3504
  * ```typescript-client
3096
3505
  * // Minimal example with required parameters only
3097
- * const result = await finatic.getPositionLotFills(lotId: '00000000-0000-0000-0000-000000000000');
3506
+ * const result = await finatic.getPositionLotFills({
3507
+ lotId: '00000000-0000-0000-0000-000000000000'
3508
+ * });
3098
3509
  *
3099
3510
  * // Access the response data
3100
3511
  * if (result.success) {
@@ -3106,7 +3517,12 @@ class BrokersWrapper {
3106
3517
  * @example
3107
3518
  * ```typescript-client
3108
3519
  * // Full example with optional parameters
3109
- * const result = await finatic.getPositionLotFills(lotId: '00000000-0000-0000-0000-000000000000', connectionId: '00000000-0000-0000-0000-000000000000', limit: 100, offset: 0);
3520
+ * const result = await finatic.getPositionLotFills({
3521
+ lotId: '00000000-0000-0000-0000-000000000000',
3522
+ connectionId: '00000000-0000-0000-0000-000000000000',
3523
+ limit: 100,
3524
+ offset: 0
3525
+ * });
3110
3526
  *
3111
3527
  * // Handle response with warnings
3112
3528
  * if (result.success) {
@@ -3119,15 +3535,10 @@ class BrokersWrapper {
3119
3535
  * }
3120
3536
  * ```
3121
3537
  */
3122
- async getPositionLotFills(lotId, connectionId, limit, offset) {
3123
- // Construct params object from individual parameters
3124
- const params = {
3125
- lotId: lotId,
3126
- connectionId: connectionId,
3127
- limit: limit,
3128
- offset: offset
3129
- }; // Authentication check
3130
- if (!this.sessionId) {
3538
+ async getPositionLotFills(params) {
3539
+ // Use params object (required parameters present)
3540
+ const resolvedParams = params; // Authentication check
3541
+ if (!this.sessionId || !this.companyId) {
3131
3542
  throw new Error('Session not initialized. Call startSession() first.');
3132
3543
  }
3133
3544
  // Generate request ID
@@ -3138,7 +3549,7 @@ class BrokersWrapper {
3138
3549
  const shouldCache = true;
3139
3550
  const cache = getCache(this.sdkConfig);
3140
3551
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3141
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', params, this.sdkConfig);
3552
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
3142
3553
  const cached = cache.get(cacheKey);
3143
3554
  if (cached) {
3144
3555
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3150,12 +3561,12 @@ class BrokersWrapper {
3150
3561
  request_id: requestId,
3151
3562
  method: 'GET',
3152
3563
  path: '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
3153
- params: params,
3564
+ params: resolvedParams,
3154
3565
  action: 'getPositionLotFills'
3155
3566
  });
3156
3567
  try {
3157
3568
  const response = await retryApiCall(async () => {
3158
- 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 } });
3569
+ 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 } : {}) } : {}) } });
3159
3570
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3160
3571
  }, {}, this.sdkConfig);
3161
3572
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3164,9 +3575,27 @@ class BrokersWrapper {
3164
3575
  throw new Error('Unexpected response shape: missing success field');
3165
3576
  }
3166
3577
  // Convert response to plain object, removing _id fields recursively
3578
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3167
3579
  const standardResponse = convertToPlainObject(responseData);
3580
+ // Phase 2: Wrap paginated responses with PaginatedData
3581
+ const hasLimit = true;
3582
+ const hasOffset = true;
3583
+ const hasPagination = hasLimit && hasOffset;
3584
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
3585
+ // PaginatedData is already imported at top of file
3586
+ const paginationMeta = standardResponse.success.meta?.pagination;
3587
+ if (paginationMeta) {
3588
+ const paginatedData = new PaginatedData(standardResponse.success.data, {
3589
+ has_more: paginationMeta.has_more,
3590
+ next_offset: paginationMeta.next_offset,
3591
+ current_offset: paginationMeta.current_offset,
3592
+ limit: paginationMeta.limit,
3593
+ }, this.getPositionLotFills.bind(this), resolvedParams, this);
3594
+ standardResponse.success.data = paginatedData;
3595
+ }
3596
+ }
3168
3597
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3169
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', params, this.sdkConfig);
3598
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
3170
3599
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3171
3600
  }
3172
3601
  this.logger.debug('Get Position Lot Fills completed', {
@@ -3174,6 +3603,7 @@ class BrokersWrapper {
3174
3603
  action: 'getPositionLotFills'
3175
3604
  });
3176
3605
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3606
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3177
3607
  return standardResponse;
3178
3608
  }
3179
3609
  catch (error) {
@@ -3286,7 +3716,7 @@ class CompanyWrapper {
3286
3716
  * Get Company
3287
3717
  *
3288
3718
  * Get public company details by ID (no user check, no sensitive data).
3289
- * @param companyId {string}
3719
+ * @param params.companyId {string} Company ID
3290
3720
  * @returns {Promise<FinaticResponse<CompanyResponse>>} Standard response with success/Error/Warning structure
3291
3721
  *
3292
3722
  * Generated from: GET /api/v1/company/{company_id}
@@ -3295,7 +3725,9 @@ class CompanyWrapper {
3295
3725
  * @example
3296
3726
  * ```typescript-client
3297
3727
  * // Minimal example with required parameters only
3298
- * const result = await finatic.getCompany(companyId: '00000000-0000-0000-0000-000000000000');
3728
+ * const result = await finatic.getCompany({
3729
+ companyId: '00000000-0000-0000-0000-000000000000'
3730
+ * });
3299
3731
  *
3300
3732
  * // Access the response data
3301
3733
  * if (result.success) {
@@ -3305,11 +3737,9 @@ class CompanyWrapper {
3305
3737
  * }
3306
3738
  * ```
3307
3739
  */
3308
- async getCompany(companyId) {
3309
- // Construct params object from individual parameters
3310
- const params = {
3311
- companyId: companyId
3312
- }; // Generate request ID
3740
+ async getCompany(params) {
3741
+ // Use params object (required parameters present)
3742
+ const resolvedParams = params; // Generate request ID
3313
3743
  const requestId = this._generateRequestId();
3314
3744
  // Input validation (Phase 2B: zod)
3315
3745
  if (this.sdkConfig?.validationEnabled) ;
@@ -3317,7 +3747,7 @@ class CompanyWrapper {
3317
3747
  const shouldCache = true;
3318
3748
  const cache = getCache(this.sdkConfig);
3319
3749
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3320
- const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', params, this.sdkConfig);
3750
+ const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
3321
3751
  const cached = cache.get(cacheKey);
3322
3752
  if (cached) {
3323
3753
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3329,12 +3759,12 @@ class CompanyWrapper {
3329
3759
  request_id: requestId,
3330
3760
  method: 'GET',
3331
3761
  path: '/api/v1/company/{company_id}',
3332
- params: params,
3762
+ params: resolvedParams,
3333
3763
  action: 'getCompany'
3334
3764
  });
3335
3765
  try {
3336
3766
  const response = await retryApiCall(async () => {
3337
- const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: companyId }, { headers: { 'x-request-id': requestId } });
3767
+ const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: resolvedParams.companyId }, { headers: { 'x-request-id': requestId } });
3338
3768
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3339
3769
  }, {}, this.sdkConfig);
3340
3770
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3343,9 +3773,15 @@ class CompanyWrapper {
3343
3773
  throw new Error('Unexpected response shape: missing success field');
3344
3774
  }
3345
3775
  // Convert response to plain object, removing _id fields recursively
3776
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3346
3777
  const standardResponse = convertToPlainObject(responseData);
3778
+ // Phase 2: Wrap paginated responses with PaginatedData
3779
+ const hasLimit = false;
3780
+ const hasOffset = false;
3781
+ const hasPagination = hasLimit && hasOffset;
3782
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3347
3783
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3348
- const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', params, this.sdkConfig);
3784
+ const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
3349
3785
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3350
3786
  }
3351
3787
  this.logger.debug('Get Company completed', {
@@ -3353,6 +3789,7 @@ class CompanyWrapper {
3353
3789
  action: 'getCompany'
3354
3790
  });
3355
3791
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3792
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3356
3793
  return standardResponse;
3357
3794
  }
3358
3795
  catch (error) {
@@ -3465,7 +3902,7 @@ class SessionWrapper {
3465
3902
  * Init Session
3466
3903
  *
3467
3904
  * Initialize a new session with company API key.
3468
- * @param xApiKey {string}
3905
+ * @param params.xApiKey {string} Company API key
3469
3906
  * @returns {Promise<FinaticResponse<TokenResponseData>>} Standard response with success/Error/Warning structure
3470
3907
  *
3471
3908
  * Generated from: POST /api/v1/session/init
@@ -3474,7 +3911,7 @@ class SessionWrapper {
3474
3911
  * @example
3475
3912
  * ```typescript-client
3476
3913
  * // Example with no parameters
3477
- * const result = await finatic.initSession();
3914
+ * const result = await finatic.initSession({});
3478
3915
  *
3479
3916
  * // Access the response data
3480
3917
  * if (result.success) {
@@ -3482,11 +3919,9 @@ class SessionWrapper {
3482
3919
  * }
3483
3920
  * ```
3484
3921
  */
3485
- async initSession(xApiKey) {
3486
- // Construct params object from individual parameters
3487
- const params = {
3488
- xApiKey: xApiKey
3489
- }; // Generate request ID
3922
+ async initSession(params) {
3923
+ // Use params object (required parameters present)
3924
+ const resolvedParams = params; // Generate request ID
3490
3925
  const requestId = this._generateRequestId();
3491
3926
  // Input validation (Phase 2B: zod)
3492
3927
  if (this.sdkConfig?.validationEnabled) ;
@@ -3494,7 +3929,7 @@ class SessionWrapper {
3494
3929
  const shouldCache = true;
3495
3930
  const cache = getCache(this.sdkConfig);
3496
3931
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3497
- const cacheKey = generateCacheKey('POST', '/api/v1/session/init', params, this.sdkConfig);
3932
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
3498
3933
  const cached = cache.get(cacheKey);
3499
3934
  if (cached) {
3500
3935
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3506,12 +3941,12 @@ class SessionWrapper {
3506
3941
  request_id: requestId,
3507
3942
  method: 'POST',
3508
3943
  path: '/api/v1/session/init',
3509
- params: params,
3944
+ params: resolvedParams,
3510
3945
  action: 'initSession'
3511
3946
  });
3512
3947
  try {
3513
3948
  const response = await retryApiCall(async () => {
3514
- const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: xApiKey }, { headers: { 'x-request-id': requestId } });
3949
+ const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: resolvedParams.xApiKey }, { headers: { 'x-request-id': requestId } });
3515
3950
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3516
3951
  }, {}, this.sdkConfig);
3517
3952
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3520,9 +3955,15 @@ class SessionWrapper {
3520
3955
  throw new Error('Unexpected response shape: missing success field');
3521
3956
  }
3522
3957
  // Convert response to plain object, removing _id fields recursively
3958
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3523
3959
  const standardResponse = convertToPlainObject(responseData);
3960
+ // Phase 2: Wrap paginated responses with PaginatedData
3961
+ const hasLimit = false;
3962
+ const hasOffset = false;
3963
+ const hasPagination = hasLimit && hasOffset;
3964
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3524
3965
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3525
- const cacheKey = generateCacheKey('POST', '/api/v1/session/init', params, this.sdkConfig);
3966
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
3526
3967
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3527
3968
  }
3528
3969
  this.logger.debug('Init Session completed', {
@@ -3530,6 +3971,7 @@ class SessionWrapper {
3530
3971
  action: 'initSession'
3531
3972
  });
3532
3973
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
3974
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3533
3975
  return standardResponse;
3534
3976
  }
3535
3977
  catch (error) {
@@ -3603,8 +4045,8 @@ class SessionWrapper {
3603
4045
  * Start Session
3604
4046
  *
3605
4047
  * Start a session with a one-time token.
3606
- * @param OneTimeToken {string}
3607
- * @param body {SessionStartRequest}
4048
+ * @param params.OneTimeToken {string} One-time use token obtained from init_session endpoint to authenticate and start the session
4049
+ * @param params.body {SessionStartRequest} Session start request containing optional user ID to associate with the session
3608
4050
  * @returns {Promise<FinaticResponse<SessionResponseData>>} Standard response with success/Error/Warning structure
3609
4051
  *
3610
4052
  * Generated from: POST /api/v1/session/start
@@ -3613,7 +4055,7 @@ class SessionWrapper {
3613
4055
  * @example
3614
4056
  * ```typescript-client
3615
4057
  * // Example with no parameters
3616
- * const result = await finatic.startSession();
4058
+ * const result = await finatic.startSession({});
3617
4059
  *
3618
4060
  * // Access the response data
3619
4061
  * if (result.success) {
@@ -3621,12 +4063,9 @@ class SessionWrapper {
3621
4063
  * }
3622
4064
  * ```
3623
4065
  */
3624
- async startSession(OneTimeToken, body) {
3625
- // Construct params object from individual parameters
3626
- const params = {
3627
- OneTimeToken: OneTimeToken,
3628
- body: body
3629
- }; // Generate request ID
4066
+ async startSession(params) {
4067
+ // Use params object (required parameters present)
4068
+ const resolvedParams = params; // Generate request ID
3630
4069
  const requestId = this._generateRequestId();
3631
4070
  // Input validation (Phase 2B: zod)
3632
4071
  if (this.sdkConfig?.validationEnabled) ;
@@ -3634,7 +4073,7 @@ class SessionWrapper {
3634
4073
  const shouldCache = true;
3635
4074
  const cache = getCache(this.sdkConfig);
3636
4075
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3637
- const cacheKey = generateCacheKey('POST', '/api/v1/session/start', params, this.sdkConfig);
4076
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
3638
4077
  const cached = cache.get(cacheKey);
3639
4078
  if (cached) {
3640
4079
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3646,12 +4085,12 @@ class SessionWrapper {
3646
4085
  request_id: requestId,
3647
4086
  method: 'POST',
3648
4087
  path: '/api/v1/session/start',
3649
- params: params,
4088
+ params: resolvedParams,
3650
4089
  action: 'startSession'
3651
4090
  });
3652
4091
  try {
3653
4092
  const response = await retryApiCall(async () => {
3654
- const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: OneTimeToken, sessionStartRequest: body }, { headers: { 'x-request-id': requestId } });
4093
+ const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: resolvedParams.OneTimeToken, sessionStartRequest: resolvedParams.body }, { headers: { 'x-request-id': requestId } });
3655
4094
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3656
4095
  }, {}, this.sdkConfig);
3657
4096
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3660,9 +4099,15 @@ class SessionWrapper {
3660
4099
  throw new Error('Unexpected response shape: missing success field');
3661
4100
  }
3662
4101
  // Convert response to plain object, removing _id fields recursively
4102
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3663
4103
  const standardResponse = convertToPlainObject(responseData);
4104
+ // Phase 2: Wrap paginated responses with PaginatedData
4105
+ const hasLimit = false;
4106
+ const hasOffset = false;
4107
+ const hasPagination = hasLimit && hasOffset;
4108
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3664
4109
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3665
- const cacheKey = generateCacheKey('POST', '/api/v1/session/start', params, this.sdkConfig);
4110
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
3666
4111
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3667
4112
  }
3668
4113
  this.logger.debug('Start Session completed', {
@@ -3670,6 +4115,7 @@ class SessionWrapper {
3670
4115
  action: 'startSession'
3671
4116
  });
3672
4117
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
4118
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3673
4119
  return standardResponse;
3674
4120
  }
3675
4121
  catch (error) {
@@ -3746,7 +4192,7 @@ class SessionWrapper {
3746
4192
  *
3747
4193
  * The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device
3748
4194
  * that initiated the session. Device info is automatically validated from the request.
3749
- * @param No parameters required for this method
4195
+ * @param params No parameters required for this method
3750
4196
  * @returns {Promise<FinaticResponse<PortalUrlResponse>>} Standard response with success/Error/Warning structure
3751
4197
  *
3752
4198
  * Generated from: GET /api/v1/session/portal
@@ -3755,7 +4201,7 @@ class SessionWrapper {
3755
4201
  * @example
3756
4202
  * ```typescript-client
3757
4203
  * // Example with no parameters
3758
- * const result = await finatic.getPortalUrl();
4204
+ * const result = await finatic.getPortalUrl({});
3759
4205
  *
3760
4206
  * // Access the response data
3761
4207
  * if (result.success) {
@@ -3763,10 +4209,10 @@ class SessionWrapper {
3763
4209
  * }
3764
4210
  * ```
3765
4211
  */
3766
- async getPortalUrl() {
4212
+ async getPortalUrl(params) {
3767
4213
  // No parameters - use empty params object
3768
- const params = {}; // Authentication check
3769
- if (!this.sessionId) {
4214
+ const resolvedParams = params || {}; // Authentication check
4215
+ if (!this.sessionId || !this.companyId) {
3770
4216
  throw new Error('Session not initialized. Call startSession() first.');
3771
4217
  }
3772
4218
  // Generate request ID
@@ -3777,7 +4223,7 @@ class SessionWrapper {
3777
4223
  const shouldCache = true;
3778
4224
  const cache = getCache(this.sdkConfig);
3779
4225
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3780
- const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', params, this.sdkConfig);
4226
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
3781
4227
  const cached = cache.get(cacheKey);
3782
4228
  if (cached) {
3783
4229
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3789,12 +4235,12 @@ class SessionWrapper {
3789
4235
  request_id: requestId,
3790
4236
  method: 'GET',
3791
4237
  path: '/api/v1/session/portal',
3792
- params: params,
4238
+ params: resolvedParams,
3793
4239
  action: 'getPortalUrl'
3794
4240
  });
3795
4241
  try {
3796
4242
  const response = await retryApiCall(async () => {
3797
- 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 } });
4243
+ 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 } : {}) } : {}) } });
3798
4244
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3799
4245
  }, {}, this.sdkConfig);
3800
4246
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3803,9 +4249,15 @@ class SessionWrapper {
3803
4249
  throw new Error('Unexpected response shape: missing success field');
3804
4250
  }
3805
4251
  // Convert response to plain object, removing _id fields recursively
4252
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3806
4253
  const standardResponse = convertToPlainObject(responseData);
4254
+ // Phase 2: Wrap paginated responses with PaginatedData
4255
+ const hasLimit = false;
4256
+ const hasOffset = false;
4257
+ const hasPagination = hasLimit && hasOffset;
4258
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3807
4259
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3808
- const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', params, this.sdkConfig);
4260
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
3809
4261
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3810
4262
  }
3811
4263
  this.logger.debug('Get Portal Url completed', {
@@ -3813,6 +4265,7 @@ class SessionWrapper {
3813
4265
  action: 'getPortalUrl'
3814
4266
  });
3815
4267
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
4268
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3816
4269
  return standardResponse;
3817
4270
  }
3818
4271
  catch (error) {
@@ -3897,7 +4350,7 @@ class SessionWrapper {
3897
4350
  * - Generates fresh tokens (not returning stored ones)
3898
4351
  * - Only accessible to authenticated sessions with user_id
3899
4352
  * - Validates that header session_id matches path session_id
3900
- * @param sessionId {string}
4353
+ * @param params.sessionId {string} Session ID
3901
4354
  * @returns {Promise<FinaticResponse<SessionUserResponse>>} Standard response with success/Error/Warning structure
3902
4355
  *
3903
4356
  * Generated from: GET /api/v1/session/{session_id}/user
@@ -3906,7 +4359,9 @@ class SessionWrapper {
3906
4359
  * @example
3907
4360
  * ```typescript-client
3908
4361
  * // Minimal example with required parameters only
3909
- * const result = await finatic.getSessionUser(sessionId: 'sess_1234567890abcdef');
4362
+ * const result = await finatic.getSessionUser({
4363
+ sessionId: 'sess_1234567890abcdef'
4364
+ * });
3910
4365
  *
3911
4366
  * // Access the response data
3912
4367
  * if (result.success) {
@@ -3916,12 +4371,10 @@ class SessionWrapper {
3916
4371
  * }
3917
4372
  * ```
3918
4373
  */
3919
- async getSessionUser(sessionId) {
3920
- // Construct params object from individual parameters
3921
- const params = {
3922
- sessionId: sessionId
3923
- }; // Authentication check
3924
- if (!this.sessionId) {
4374
+ async getSessionUser(params) {
4375
+ // Use params object (required parameters present)
4376
+ const resolvedParams = params; // Authentication check
4377
+ if (!this.sessionId || !this.companyId) {
3925
4378
  throw new Error('Session not initialized. Call startSession() first.');
3926
4379
  }
3927
4380
  // Generate request ID
@@ -3932,7 +4385,7 @@ class SessionWrapper {
3932
4385
  const shouldCache = true;
3933
4386
  const cache = getCache(this.sdkConfig);
3934
4387
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3935
- const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', params, this.sdkConfig);
4388
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
3936
4389
  const cached = cache.get(cacheKey);
3937
4390
  if (cached) {
3938
4391
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3944,12 +4397,12 @@ class SessionWrapper {
3944
4397
  request_id: requestId,
3945
4398
  method: 'GET',
3946
4399
  path: '/api/v1/session/{session_id}/user',
3947
- params: params,
4400
+ params: resolvedParams,
3948
4401
  action: 'getSessionUser'
3949
4402
  });
3950
4403
  try {
3951
4404
  const response = await retryApiCall(async () => {
3952
- const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: sessionId, xSessionId: sessionId }, { headers: { 'x-request-id': requestId } });
4405
+ const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: resolvedParams.sessionId, xSessionId: resolvedParams.sessionId }, { headers: { 'x-request-id': requestId } });
3953
4406
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3954
4407
  }, {}, this.sdkConfig);
3955
4408
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3958,9 +4411,15 @@ class SessionWrapper {
3958
4411
  throw new Error('Unexpected response shape: missing success field');
3959
4412
  }
3960
4413
  // Convert response to plain object, removing _id fields recursively
4414
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3961
4415
  const standardResponse = convertToPlainObject(responseData);
4416
+ // Phase 2: Wrap paginated responses with PaginatedData
4417
+ const hasLimit = false;
4418
+ const hasOffset = false;
4419
+ const hasPagination = hasLimit && hasOffset;
4420
+ if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
3962
4421
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3963
- const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', params, this.sdkConfig);
4422
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
3964
4423
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3965
4424
  }
3966
4425
  this.logger.debug('Get Session User completed', {
@@ -3968,6 +4427,7 @@ class SessionWrapper {
3968
4427
  action: 'getSessionUser'
3969
4428
  });
3970
4429
  // Phase 2C: Return standard response structure (plain objects with _id fields removed)
4430
+ // Type assertion to final return type (handles both paginated and non-paginated responses)
3971
4431
  return standardResponse;
3972
4432
  }
3973
4433
  catch (error) {
@@ -4716,8 +5176,8 @@ const SessionApiAxiosParamCreator = function (configuration) {
4716
5176
  /**
4717
5177
  * Start a session with a one-time token.
4718
5178
  * @summary Start Session
4719
- * @param {string} oneTimeToken
4720
- * @param {SessionStartRequest} sessionStartRequest
5179
+ * @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
5180
+ * @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
4721
5181
  * @param {*} [options] Override http request option.
4722
5182
  * @throws {RequiredError}
4723
5183
  */
@@ -4800,8 +5260,8 @@ const SessionApiFp = function (configuration) {
4800
5260
  /**
4801
5261
  * Start a session with a one-time token.
4802
5262
  * @summary Start Session
4803
- * @param {string} oneTimeToken
4804
- * @param {SessionStartRequest} sessionStartRequest
5263
+ * @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
5264
+ * @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
4805
5265
  * @param {*} [options] Override http request option.
4806
5266
  * @throws {RequiredError}
4807
5267
  */
@@ -6336,11 +6796,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6336
6796
  }
6337
6797
  const sessionId = data?.session_id || '';
6338
6798
  const companyId = data?.company_id || '';
6799
+ const responseUserId = data?.user_id || '';
6339
6800
  // csrf_token is not in SessionResponseData, get from response headers if available
6340
6801
  const csrfToken = data?.csrf_token || '';
6341
6802
  this.logger.debug?.('_startSession extracted data', {
6342
6803
  sessionId,
6343
6804
  companyId,
6805
+ responseUserId,
6344
6806
  csrfToken,
6345
6807
  fullData: data,
6346
6808
  dataKeys: data ? Object.keys(data) : []
@@ -6362,6 +6824,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6362
6824
  responseKeys: response ? Object.keys(response) : []
6363
6825
  });
6364
6826
  }
6827
+ // Store userId if present in response (for getUserId() and isAuthed())
6828
+ // Use userId from response if parameter wasn't provided, or if response has a different userId
6829
+ const finalUserId = responseUserId || userId;
6830
+ if (finalUserId) {
6831
+ this.userId = finalUserId;
6832
+ this.logger.debug?.('_startSession set userId', { userId: finalUserId, source: responseUserId ? 'response' : 'parameter' });
6833
+ }
6365
6834
  return { session_id: sessionId, company_id: companyId };
6366
6835
  }
6367
6836
  /**
@@ -6373,28 +6842,30 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6373
6842
  *
6374
6843
  * @methodId get_portal_url_api_v1_session_portal_get
6375
6844
  * @category session
6376
- * @param theme - Optional theme preset or custom theme object
6377
- * @param brokers - Optional array of broker IDs to filter
6378
- * @param email - Optional email address
6379
- * @param mode - Optional mode ('light' or 'dark')
6845
+ * @param params - Optional parameters object
6846
+ * @param params.theme - Optional theme preset or custom theme object
6847
+ * @param params.brokers - Optional array of broker IDs to filter
6848
+ * @param params.email - Optional email address
6849
+ * @param params.mode - Optional mode ('light' or 'dark')
6380
6850
  * @returns Portal URL string
6381
6851
  * @example
6382
6852
  * ```typescript-client
6383
- * const url = await finatic.getPortalUrl('dark', ['broker-1'], 'user@example.com', 'dark');
6853
+ * const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
6384
6854
  * ```
6385
6855
  * @example
6386
6856
  * ```typescript-server
6387
- * const url = await finatic.getPortalUrl('dark', ['broker-1'], 'user@example.com', 'dark');
6857
+ * const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
6388
6858
  * ```
6389
6859
  * @example
6390
6860
  * ```python
6391
- * url = await finatic.get_portal_url('dark', ['broker-1'], 'user@example.com', 'dark')
6861
+ * url = await finatic.get_portal_url(theme='default', brokers=['broker-1'], email='user@example.com', mode='dark')
6392
6862
  * ```
6393
6863
  */
6394
- async getPortalUrl(theme, brokers, email, mode) {
6864
+ async getPortalUrl(params) {
6395
6865
  if (!this.sessionId) {
6396
6866
  throw new Error('Session not initialized. Call startSession() first.');
6397
6867
  }
6868
+ const { theme, brokers, email, mode } = params || {};
6398
6869
  // Get raw portal URL from SessionApi directly (not a wrapper)
6399
6870
  const axiosResponse = await this.sessionApi.getPortalUrlApiV1SessionPortalGet({
6400
6871
  sessionId: this.sessionId,
@@ -6468,29 +6939,35 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6468
6939
  *
6469
6940
  * @methodId open_portal_client_sdk
6470
6941
  * @category session
6471
- * @param theme - Optional theme preset or custom theme object
6472
- * @param brokers - Optional array of broker IDs to filter
6473
- * @param email - Optional email address
6474
- * @param mode - Optional mode ('light' or 'dark')
6942
+ * @param params - Optional parameters object
6943
+ * @param params.theme - Optional theme preset or custom theme object
6944
+ * @param params.brokers - Optional array of broker IDs to filter
6945
+ * @param params.email - Optional email address
6946
+ * @param params.mode - Optional mode ('light' or 'dark')
6475
6947
  * @param onSuccess - Optional callback when portal authentication succeeds
6476
6948
  * @param onError - Optional callback when portal authentication fails
6477
6949
  * @param onClose - Optional callback when portal is closed
6478
6950
  * @returns Promise that resolves when portal is opened
6479
6951
  * @example
6480
6952
  * ```typescript-client
6481
- * await finatic.openPortal('dark', ['broker-1'], 'user@example.com', 'dark',
6953
+ * await finatic.openPortal({
6954
+ * theme: 'default',
6955
+ * brokers: ['broker-1'],
6956
+ * email: 'user@example.com',
6957
+ * mode: 'dark'
6958
+ * },
6482
6959
  * (userId) => console.log('User authenticated:', userId),
6483
6960
  * (error) => console.error('Portal error:', error),
6484
6961
  * () => console.log('Portal closed')
6485
6962
  * );
6486
6963
  * ```
6487
6964
  */
6488
- async openPortal(theme, brokers, email, mode, onSuccess, onError, onClose) {
6965
+ async openPortal(params, onSuccess, onError, onClose) {
6489
6966
  if (!this.sessionId) {
6490
6967
  throw new Error('Session not initialized. Call startSession() first.');
6491
6968
  }
6492
6969
  // Get portal URL with all parameters
6493
- const portalUrl = await this.getPortalUrl(theme, brokers, email, mode);
6970
+ const portalUrl = await this.getPortalUrl(params);
6494
6971
  // Create portal UI if not exists
6495
6972
  if (!this.portalUI) {
6496
6973
  this.portalUI = new PortalUI(this.sdkConfig.baseUrl || 'https://api.finatic.dev');
@@ -6677,7 +7154,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6677
7154
  * ```
6678
7155
  */
6679
7156
  async getCompany(params) {
6680
- return await this.company.getCompany(params?.companyId);
7157
+ return await this.company.getCompany(params);
6681
7158
  }
6682
7159
  /**
6683
7160
  * Get Brokers
@@ -6835,7 +7312,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6835
7312
  * ```
6836
7313
  */
6837
7314
  async disconnectCompanyFromBroker(params) {
6838
- return await this.brokers.disconnectCompanyFromBroker(params?.connectionId);
7315
+ return await this.brokers.disconnectCompanyFromBroker(params);
6839
7316
  }
6840
7317
  /**
6841
7318
  * Get Orders
@@ -6915,7 +7392,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6915
7392
  * ```
6916
7393
  */
6917
7394
  async getOrders(params) {
6918
- 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);
7395
+ return await this.brokers.getOrders(params);
6919
7396
  }
6920
7397
  /**
6921
7398
  * Get Positions
@@ -6995,7 +7472,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6995
7472
  * ```
6996
7473
  */
6997
7474
  async getPositions(params) {
6998
- 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);
7475
+ return await this.brokers.getPositions(params);
6999
7476
  }
7000
7477
  /**
7001
7478
  * Get Balances
@@ -7075,7 +7552,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7075
7552
  * ```
7076
7553
  */
7077
7554
  async getBalances(params) {
7078
- return await this.brokers.getBalances(params?.brokerId, params?.connectionId, params?.accountId, params?.isEndOfDaySnapshot, params?.limit, params?.offset, params?.balanceCreatedAfter, params?.balanceCreatedBefore, params?.includeMetadata);
7555
+ return await this.brokers.getBalances(params);
7079
7556
  }
7080
7557
  /**
7081
7558
  * Get Accounts
@@ -7155,7 +7632,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7155
7632
  * ```
7156
7633
  */
7157
7634
  async getAccounts(params) {
7158
- return await this.brokers.getAccounts(params?.brokerId, params?.connectionId, params?.accountType, params?.status, params?.currency, params?.limit, params?.offset, params?.includeMetadata);
7635
+ return await this.brokers.getAccounts(params);
7159
7636
  }
7160
7637
  /**
7161
7638
  * Get Order Fills
@@ -7243,7 +7720,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7243
7720
  * ```
7244
7721
  */
7245
7722
  async getOrderFills(params) {
7246
- return await this.brokers.getOrderFills(params?.orderId, params?.connectionId, params?.limit, params?.offset, params?.includeMetadata);
7723
+ return await this.brokers.getOrderFills(params);
7247
7724
  }
7248
7725
  /**
7249
7726
  * Get Order Events
@@ -7331,7 +7808,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7331
7808
  * ```
7332
7809
  */
7333
7810
  async getOrderEvents(params) {
7334
- return await this.brokers.getOrderEvents(params?.orderId, params?.connectionId, params?.limit, params?.offset, params?.includeMetadata);
7811
+ return await this.brokers.getOrderEvents(params);
7335
7812
  }
7336
7813
  /**
7337
7814
  * Get Order Groups
@@ -7410,7 +7887,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7410
7887
  * ```
7411
7888
  */
7412
7889
  async getOrderGroups(params) {
7413
- return await this.brokers.getOrderGroups(params?.brokerId, params?.connectionId, params?.limit, params?.offset, params?.createdAfter, params?.createdBefore, params?.includeMetadata);
7890
+ return await this.brokers.getOrderGroups(params);
7414
7891
  }
7415
7892
  /**
7416
7893
  * Get Position Lots
@@ -7490,7 +7967,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7490
7967
  * ```
7491
7968
  */
7492
7969
  async getPositionLots(params) {
7493
- return await this.brokers.getPositionLots(params?.brokerId, params?.connectionId, params?.accountId, params?.symbol, params?.positionId, params?.limit, params?.offset);
7970
+ return await this.brokers.getPositionLots(params);
7494
7971
  }
7495
7972
  /**
7496
7973
  * Get Position Lot Fills
@@ -7578,7 +8055,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7578
8055
  * ```
7579
8056
  */
7580
8057
  async getPositionLotFills(params) {
7581
- return await this.brokers.getPositionLotFills(params?.lotId, params?.connectionId, params?.limit, params?.offset);
8058
+ return await this.brokers.getPositionLotFills(params);
7582
8059
  }
7583
8060
  /**
7584
8061
  * Get all Orders across all pages.
@@ -7649,7 +8126,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7649
8126
  let lastError = null;
7650
8127
  let warnings = [];
7651
8128
  while (true) {
7652
- 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);
8129
+ const response = await this.brokers.getOrders({ ...filterParams, limit, offset });
7653
8130
  // Collect warnings from each page
7654
8131
  if (response.warning && Array.isArray(response.warning)) {
7655
8132
  warnings.push(...response.warning);
@@ -7659,10 +8136,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7659
8136
  break;
7660
8137
  }
7661
8138
  const result = response.success?.data || [];
7662
- if (!result || result.length === 0)
8139
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8140
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8141
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8142
+ ? result.items
8143
+ : (Array.isArray(result) ? result : [result]);
8144
+ if (!items || items.length === 0)
7663
8145
  break;
7664
- allData.push(...(Array.isArray(result) ? result : [result]));
7665
- if (result.length < limit)
8146
+ allData.push(...items);
8147
+ // If we got fewer items than the limit, there are no more pages
8148
+ if (items.length < limit)
7666
8149
  break;
7667
8150
  offset += limit;
7668
8151
  }
@@ -7754,7 +8237,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7754
8237
  let lastError = null;
7755
8238
  let warnings = [];
7756
8239
  while (true) {
7757
- 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);
8240
+ const response = await this.brokers.getPositions({ ...filterParams, limit, offset });
7758
8241
  // Collect warnings from each page
7759
8242
  if (response.warning && Array.isArray(response.warning)) {
7760
8243
  warnings.push(...response.warning);
@@ -7764,10 +8247,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7764
8247
  break;
7765
8248
  }
7766
8249
  const result = response.success?.data || [];
7767
- if (!result || result.length === 0)
8250
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8251
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8252
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8253
+ ? result.items
8254
+ : (Array.isArray(result) ? result : [result]);
8255
+ if (!items || items.length === 0)
7768
8256
  break;
7769
- allData.push(...(Array.isArray(result) ? result : [result]));
7770
- if (result.length < limit)
8257
+ allData.push(...items);
8258
+ // If we got fewer items than the limit, there are no more pages
8259
+ if (items.length < limit)
7771
8260
  break;
7772
8261
  offset += limit;
7773
8262
  }
@@ -7859,7 +8348,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7859
8348
  let lastError = null;
7860
8349
  let warnings = [];
7861
8350
  while (true) {
7862
- const response = await this.brokers.getBalances(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountId, filterParams?.isEndOfDaySnapshot, limit, offset, filterParams?.balanceCreatedAfter, filterParams?.balanceCreatedBefore, filterParams?.includeMetadata);
8351
+ const response = await this.brokers.getBalances({ ...filterParams, limit, offset });
7863
8352
  // Collect warnings from each page
7864
8353
  if (response.warning && Array.isArray(response.warning)) {
7865
8354
  warnings.push(...response.warning);
@@ -7869,10 +8358,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7869
8358
  break;
7870
8359
  }
7871
8360
  const result = response.success?.data || [];
7872
- if (!result || result.length === 0)
8361
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8362
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8363
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8364
+ ? result.items
8365
+ : (Array.isArray(result) ? result : [result]);
8366
+ if (!items || items.length === 0)
7873
8367
  break;
7874
- allData.push(...(Array.isArray(result) ? result : [result]));
7875
- if (result.length < limit)
8368
+ allData.push(...items);
8369
+ // If we got fewer items than the limit, there are no more pages
8370
+ if (items.length < limit)
7876
8371
  break;
7877
8372
  offset += limit;
7878
8373
  }
@@ -7964,7 +8459,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7964
8459
  let lastError = null;
7965
8460
  let warnings = [];
7966
8461
  while (true) {
7967
- const response = await this.brokers.getAccounts(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountType, filterParams?.status, filterParams?.currency, limit, offset, filterParams?.includeMetadata);
8462
+ const response = await this.brokers.getAccounts({ ...filterParams, limit, offset });
7968
8463
  // Collect warnings from each page
7969
8464
  if (response.warning && Array.isArray(response.warning)) {
7970
8465
  warnings.push(...response.warning);
@@ -7974,10 +8469,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7974
8469
  break;
7975
8470
  }
7976
8471
  const result = response.success?.data || [];
7977
- if (!result || result.length === 0)
8472
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8473
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8474
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8475
+ ? result.items
8476
+ : (Array.isArray(result) ? result : [result]);
8477
+ if (!items || items.length === 0)
7978
8478
  break;
7979
- allData.push(...(Array.isArray(result) ? result : [result]));
7980
- if (result.length < limit)
8479
+ allData.push(...items);
8480
+ // If we got fewer items than the limit, there are no more pages
8481
+ if (items.length < limit)
7981
8482
  break;
7982
8483
  offset += limit;
7983
8484
  }
@@ -8068,7 +8569,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8068
8569
  let lastError = null;
8069
8570
  let warnings = [];
8070
8571
  while (true) {
8071
- const response = await this.brokers.getOrderFills(filterParams?.orderId, filterParams?.connectionId, limit, offset, filterParams?.includeMetadata);
8572
+ const response = await this.brokers.getOrderFills({ ...filterParams, limit, offset });
8072
8573
  // Collect warnings from each page
8073
8574
  if (response.warning && Array.isArray(response.warning)) {
8074
8575
  warnings.push(...response.warning);
@@ -8078,10 +8579,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8078
8579
  break;
8079
8580
  }
8080
8581
  const result = response.success?.data || [];
8081
- if (!result || result.length === 0)
8582
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8583
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8584
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8585
+ ? result.items
8586
+ : (Array.isArray(result) ? result : [result]);
8587
+ if (!items || items.length === 0)
8082
8588
  break;
8083
- allData.push(...(Array.isArray(result) ? result : [result]));
8084
- if (result.length < limit)
8589
+ allData.push(...items);
8590
+ // If we got fewer items than the limit, there are no more pages
8591
+ if (items.length < limit)
8085
8592
  break;
8086
8593
  offset += limit;
8087
8594
  }
@@ -8172,7 +8679,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8172
8679
  let lastError = null;
8173
8680
  let warnings = [];
8174
8681
  while (true) {
8175
- const response = await this.brokers.getOrderEvents(filterParams?.orderId, filterParams?.connectionId, limit, offset, filterParams?.includeMetadata);
8682
+ const response = await this.brokers.getOrderEvents({ ...filterParams, limit, offset });
8176
8683
  // Collect warnings from each page
8177
8684
  if (response.warning && Array.isArray(response.warning)) {
8178
8685
  warnings.push(...response.warning);
@@ -8182,10 +8689,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8182
8689
  break;
8183
8690
  }
8184
8691
  const result = response.success?.data || [];
8185
- if (!result || result.length === 0)
8692
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8693
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8694
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8695
+ ? result.items
8696
+ : (Array.isArray(result) ? result : [result]);
8697
+ if (!items || items.length === 0)
8186
8698
  break;
8187
- allData.push(...(Array.isArray(result) ? result : [result]));
8188
- if (result.length < limit)
8699
+ allData.push(...items);
8700
+ // If we got fewer items than the limit, there are no more pages
8701
+ if (items.length < limit)
8189
8702
  break;
8190
8703
  offset += limit;
8191
8704
  }
@@ -8277,7 +8790,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8277
8790
  let lastError = null;
8278
8791
  let warnings = [];
8279
8792
  while (true) {
8280
- const response = await this.brokers.getOrderGroups(filterParams?.brokerId, filterParams?.connectionId, limit, offset, filterParams?.createdAfter, filterParams?.createdBefore, filterParams?.includeMetadata);
8793
+ const response = await this.brokers.getOrderGroups({ ...filterParams, limit, offset });
8281
8794
  // Collect warnings from each page
8282
8795
  if (response.warning && Array.isArray(response.warning)) {
8283
8796
  warnings.push(...response.warning);
@@ -8287,10 +8800,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8287
8800
  break;
8288
8801
  }
8289
8802
  const result = response.success?.data || [];
8290
- if (!result || result.length === 0)
8803
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8804
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8805
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8806
+ ? result.items
8807
+ : (Array.isArray(result) ? result : [result]);
8808
+ if (!items || items.length === 0)
8291
8809
  break;
8292
- allData.push(...(Array.isArray(result) ? result : [result]));
8293
- if (result.length < limit)
8810
+ allData.push(...items);
8811
+ // If we got fewer items than the limit, there are no more pages
8812
+ if (items.length < limit)
8294
8813
  break;
8295
8814
  offset += limit;
8296
8815
  }
@@ -8382,7 +8901,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8382
8901
  let lastError = null;
8383
8902
  let warnings = [];
8384
8903
  while (true) {
8385
- const response = await this.brokers.getPositionLots(filterParams?.brokerId, filterParams?.connectionId, filterParams?.accountId, filterParams?.symbol, filterParams?.positionId, limit, offset);
8904
+ const response = await this.brokers.getPositionLots({ ...filterParams, limit, offset });
8386
8905
  // Collect warnings from each page
8387
8906
  if (response.warning && Array.isArray(response.warning)) {
8388
8907
  warnings.push(...response.warning);
@@ -8392,10 +8911,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8392
8911
  break;
8393
8912
  }
8394
8913
  const result = response.success?.data || [];
8395
- if (!result || result.length === 0)
8914
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
8915
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
8916
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
8917
+ ? result.items
8918
+ : (Array.isArray(result) ? result : [result]);
8919
+ if (!items || items.length === 0)
8396
8920
  break;
8397
- allData.push(...(Array.isArray(result) ? result : [result]));
8398
- if (result.length < limit)
8921
+ allData.push(...items);
8922
+ // If we got fewer items than the limit, there are no more pages
8923
+ if (items.length < limit)
8399
8924
  break;
8400
8925
  offset += limit;
8401
8926
  }
@@ -8485,7 +9010,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8485
9010
  let lastError = null;
8486
9011
  let warnings = [];
8487
9012
  while (true) {
8488
- const response = await this.brokers.getPositionLotFills(filterParams?.lotId, filterParams?.connectionId, limit, offset);
9013
+ const response = await this.brokers.getPositionLotFills({ ...filterParams, limit, offset });
8489
9014
  // Collect warnings from each page
8490
9015
  if (response.warning && Array.isArray(response.warning)) {
8491
9016
  warnings.push(...response.warning);
@@ -8495,10 +9020,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8495
9020
  break;
8496
9021
  }
8497
9022
  const result = response.success?.data || [];
8498
- if (!result || result.length === 0)
9023
+ // Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
9024
+ // PaginatedData has array-like behavior but we extract items for getAll* methods
9025
+ const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
9026
+ ? result.items
9027
+ : (Array.isArray(result) ? result : [result]);
9028
+ if (!items || items.length === 0)
8499
9029
  break;
8500
- allData.push(...(Array.isArray(result) ? result : [result]));
8501
- if (result.length < limit)
9030
+ allData.push(...items);
9031
+ // If we got fewer items than the limit, there are no more pages
9032
+ if (items.length < limit)
8502
9033
  break;
8503
9034
  offset += limit;
8504
9035
  }
@@ -8543,5 +9074,5 @@ class FinaticConnect extends FinaticConnect$1 {
8543
9074
  // Marker to verify custom class is being used
8544
9075
  FinaticConnect.__CUSTOM_CLASS__ = true;
8545
9076
 
8546
- export { AccountStatus, ApiError, BrokerDataAccountTypeEnum, BrokerDataAssetTypeEnum, BrokerDataOrderSideEnum, BrokerDataOrderStatusEnum, BrokerDataPositionStatusEnum, BrokersApi, BrokersApiAxiosParamCreator, BrokersApiFactory, BrokersApiFp, BrokersWrapper, CompanyApi, CompanyApiAxiosParamCreator, CompanyApiFactory, CompanyApiFp, CompanyWrapper, Configuration, EventEmitter, FDXAccountStatus, FDXAccountType, FDXAssetType, FDXBalanceType, FDXOrderClass, FDXOrderEventType, FDXOrderGroupType, FDXOrderSide, FDXOrderStatus, FDXOrderType, FDXPositionSide, FDXPositionStatus, FDXSecurityIdType, FDXTimeInForce, FinaticConnect, FinaticError, SessionApi, SessionApiAxiosParamCreator, SessionApiFactory, SessionApiFp, SessionStatus, SessionWrapper, ValidationError, addErrorInterceptor, addRequestInterceptor, addResponseInterceptor, appendBrokerFilterToURL, appendThemeToURL, applyErrorInterceptors, applyRequestInterceptors, applyResponseInterceptors, coerceEnumValue, convertToPlainObject, defaultConfig, generateCacheKey, generateRequestId, getCache, getConfig, getLogger, handleError, numberSchema, retryApiCall, stringSchema, unwrapAxiosResponse, validateParams };
9077
+ export { AccountStatus, ApiError, BrokerDataAccountTypeEnum, BrokerDataAssetTypeEnum, BrokerDataOrderSideEnum, BrokerDataOrderStatusEnum, BrokerDataPositionStatusEnum, BrokersApi, BrokersApiAxiosParamCreator, BrokersApiFactory, BrokersApiFp, BrokersWrapper, CompanyApi, CompanyApiAxiosParamCreator, CompanyApiFactory, CompanyApiFp, CompanyWrapper, Configuration, EventEmitter, FDXAccountStatus, FDXAccountType, FDXAssetType, FDXBalanceType, FDXOrderClass, FDXOrderEventType, FDXOrderGroupType, FDXOrderSide, FDXOrderStatus, FDXOrderType, FDXPositionSide, FDXPositionStatus, FDXSecurityIdType, FDXTimeInForce, FinaticConnect, FinaticError, PaginatedData, SessionApi, SessionApiAxiosParamCreator, SessionApiFactory, SessionApiFp, SessionStatus, SessionWrapper, ValidationError, addErrorInterceptor, addRequestInterceptor, addResponseInterceptor, appendBrokerFilterToURL, appendThemeToURL, applyErrorInterceptors, applyRequestInterceptors, applyResponseInterceptors, coerceEnumValue, convertToPlainObject, defaultConfig, generateCacheKey, generateRequestId, getCache, getConfig, getLogger, handleError, numberSchema, retryApiCall, stringSchema, unwrapAxiosResponse, validateParams };
8547
9078
  //# sourceMappingURL=index.mjs.map