@finatic/client 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,6 +1,4 @@
1
1
  import pRetry, { AbortError } from 'p-retry';
2
- import pino from 'pino';
3
- import NodeCache from 'node-cache';
4
2
  import * as z from 'zod';
5
3
  import globalAxios from 'axios';
6
4
 
@@ -72,14 +70,12 @@ async function retryApiCall(fn, options = {}, config) {
72
70
  }
73
71
 
74
72
  /**
75
- * Structured logger utility with browser-safe fallback (Phase 2C).
73
+ * Structured logger utility with browser-safe console logging (Phase 2C).
76
74
  *
77
75
  * Generated - do not edit directly.
78
76
  *
79
- * This logger automatically falls back to console-based logging when pino fails
80
- * in browser environments (Vite, Next.js, etc.).
77
+ * This logger uses browser console APIs for all logging in browser environments.
81
78
  */
82
- // @ts-ignore - pino types available via @types/pino
83
79
  let _loggerInstance = null;
84
80
  /**
85
81
  * Get environment variable from various sources (browser and Node.js).
@@ -124,30 +120,6 @@ function isProduction() {
124
120
  return true;
125
121
  return false;
126
122
  }
127
- /**
128
- * Detect if we're in a browser environment.
129
- */
130
- function isBrowser() {
131
- // Check for window object (browser)
132
- if (typeof window !== 'undefined') {
133
- return true;
134
- }
135
- // Check for globalThis in browser-like environments
136
- if (typeof globalThis !== 'undefined') {
137
- // In browsers, process might be polyfilled but process.stdout won't exist
138
- try {
139
- const proc = globalThis.process;
140
- if (proc && typeof proc.stdout === 'undefined') {
141
- return true;
142
- }
143
- }
144
- catch {
145
- // If we can't check, assume browser if window exists
146
- return typeof window !== 'undefined';
147
- }
148
- }
149
- return false;
150
- }
151
123
  /**
152
124
  * Get or create a logger instance with browser-safe fallback.
153
125
  */
@@ -155,36 +127,13 @@ function getLogger(config) {
155
127
  if (_loggerInstance) {
156
128
  return _loggerInstance;
157
129
  }
158
- // In browser environments, skip pino entirely and use browser-safe logger
159
- if (isBrowser()) {
160
- return getBrowserSafeLogger(config);
161
- }
162
- // Try to use pino first (Node.js environments)
163
- try {
164
- const logLevel = (config?.logLevel || getEnvVar('FINATIC_LOG_LEVEL') || 'error');
165
- const pinoConfig = {
166
- level: logLevel === 'silent' ? 'silent' : logLevel,
167
- ...(config?.structuredLogging !== false && {
168
- formatters: {
169
- level: (label) => {
170
- return { level: label };
171
- },
172
- },
173
- timestamp: true,
174
- }),
175
- };
176
- _loggerInstance = pino(pinoConfig);
177
- return _loggerInstance;
178
- }
179
- catch (error) {
180
- // Fallback to browser-safe logger if pino fails
181
- return getBrowserSafeLogger(config, error);
182
- }
130
+ // Client SDK always uses browser-safe logger (no pino)
131
+ return getBrowserSafeLogger(config);
183
132
  }
184
133
  /**
185
- * Browser-safe logger fallback for environments where pino fails.
134
+ * Browser-safe logger for Client SDK.
186
135
  */
187
- function getBrowserSafeLogger(config, pinoError) {
136
+ function getBrowserSafeLogger(config) {
188
137
  // Log level hierarchy (matching pino's numeric levels)
189
138
  const LOG_LEVELS = {
190
139
  silent: 0,
@@ -215,7 +164,7 @@ function getBrowserSafeLogger(config, pinoError) {
215
164
  };
216
165
  const logLevel = getEffectiveLogLevel();
217
166
  const structuredLogging = config?.structuredLogging ?? false;
218
- const isProd = isProduction();
167
+ isProduction();
219
168
  /**
220
169
  * Check if we should log at this level.
221
170
  */
@@ -348,10 +297,6 @@ function getBrowserSafeLogger(config, pinoError) {
348
297
  }
349
298
  },
350
299
  };
351
- // Only warn about fallback logger if pino failed (not if we're in browser)
352
- if (pinoError && !isProd) {
353
- console.warn('[Finatic SDK] Using fallback logger due to pino initialization error:', pinoError);
354
- }
355
300
  _loggerInstance = fallbackLogger;
356
301
  return _loggerInstance;
357
302
  }
@@ -419,11 +364,96 @@ function handleError(error, requestId) {
419
364
  }
420
365
 
421
366
  /**
422
- * Response caching utility with node-cache (Phase 2B).
367
+ * Response caching utility with browser-compatible Map-based cache (Phase 2B).
423
368
  *
424
369
  * Generated - do not edit directly.
425
370
  */
426
- // @ts-ignore - node-cache types available via @types/node-cache
371
+ class MapBasedCache {
372
+ constructor(maxSize = 1000, defaultTtl = 300) {
373
+ this.cleanupInterval = null;
374
+ this.cache = new Map();
375
+ this.maxSize = maxSize;
376
+ this.defaultTtl = defaultTtl;
377
+ this.startCleanup();
378
+ }
379
+ startCleanup() {
380
+ // Clean up expired entries every minute
381
+ if (typeof window !== 'undefined') {
382
+ this.cleanupInterval = window.setInterval(() => {
383
+ this.cleanup();
384
+ }, 60000);
385
+ }
386
+ }
387
+ cleanup() {
388
+ const now = Date.now();
389
+ const keysToDelete = [];
390
+ for (const [key, entry] of this.cache.entries()) {
391
+ if (entry.expires < now) {
392
+ keysToDelete.push(key);
393
+ }
394
+ }
395
+ keysToDelete.forEach(key => this.cache.delete(key));
396
+ }
397
+ evictLRU() {
398
+ if (this.cache.size < this.maxSize) {
399
+ return;
400
+ }
401
+ // Simple LRU: remove oldest entry (first in Map)
402
+ const firstKey = this.cache.keys().next().value;
403
+ if (firstKey) {
404
+ this.cache.delete(firstKey);
405
+ }
406
+ }
407
+ get(key) {
408
+ const entry = this.cache.get(key);
409
+ if (!entry) {
410
+ return undefined;
411
+ }
412
+ // Check if expired
413
+ if (entry.expires < Date.now()) {
414
+ this.cache.delete(key);
415
+ return undefined;
416
+ }
417
+ return entry.value;
418
+ }
419
+ set(key, value, ttl) {
420
+ // Evict if at max size
421
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
422
+ this.evictLRU();
423
+ }
424
+ const expires = Date.now() + (ttl || this.defaultTtl) * 1000;
425
+ this.cache.set(key, { value, expires });
426
+ return true;
427
+ }
428
+ del(key) {
429
+ return this.cache.delete(key) ? 1 : 0;
430
+ }
431
+ clear() {
432
+ this.cache.clear();
433
+ }
434
+ keys() {
435
+ return Array.from(this.cache.keys());
436
+ }
437
+ has(key) {
438
+ const entry = this.cache.get(key);
439
+ if (!entry) {
440
+ return false;
441
+ }
442
+ // Check if expired
443
+ if (entry.expires < Date.now()) {
444
+ this.cache.delete(key);
445
+ return false;
446
+ }
447
+ return true;
448
+ }
449
+ destroy() {
450
+ if (this.cleanupInterval !== null && typeof window !== 'undefined') {
451
+ window.clearInterval(this.cleanupInterval);
452
+ this.cleanupInterval = null;
453
+ }
454
+ this.cache.clear();
455
+ }
456
+ }
427
457
  let _cacheInstance = null;
428
458
  /**
429
459
  * Get or create cache instance.
@@ -435,11 +465,7 @@ function getCache(config) {
435
465
  if (_cacheInstance) {
436
466
  return _cacheInstance;
437
467
  }
438
- _cacheInstance = new NodeCache({
439
- stdTTL: config.cacheTtl || 300,
440
- maxKeys: config.cacheMaxSize || 1000,
441
- useClones: false,
442
- });
468
+ _cacheInstance = new MapBasedCache(config.cacheMaxSize || 1000, config.cacheTtl || 300);
443
469
  return _cacheInstance;
444
470
  }
445
471
  /**
@@ -1183,6 +1209,256 @@ var SessionStatus;
1183
1209
  SessionStatus["Expired"] = "expired";
1184
1210
  })(SessionStatus || (SessionStatus = {}));
1185
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
+
1186
1462
  /**
1187
1463
  * Generated wrapper functions for brokers operations (Phase 2A).
1188
1464
  *
@@ -1232,7 +1508,7 @@ class BrokersWrapper {
1232
1508
  * -------
1233
1509
  * FinaticResponse[list[BrokerInfo]]
1234
1510
  * list of available brokers with their metadata.
1235
- * @param No parameters required for this method
1511
+ * @param params No parameters required for this method
1236
1512
  * @returns {Promise<FinaticResponse<BrokerInfo[]>>} Standard response with success/Error/Warning structure
1237
1513
  *
1238
1514
  * Generated from: GET /api/v1/brokers/
@@ -1241,7 +1517,7 @@ class BrokersWrapper {
1241
1517
  * @example
1242
1518
  * ```typescript-client
1243
1519
  * // Example with no parameters
1244
- * const result = await finatic.getBrokers();
1520
+ * const result = await finatic.getBrokers({});
1245
1521
  *
1246
1522
  * // Access the response data
1247
1523
  * if (result.success) {
@@ -1249,9 +1525,9 @@ class BrokersWrapper {
1249
1525
  * }
1250
1526
  * ```
1251
1527
  */
1252
- async getBrokers() {
1528
+ async getBrokers(params) {
1253
1529
  // No parameters - use empty params object
1254
- const params = {}; // Generate request ID
1530
+ const resolvedParams = params || {}; // Generate request ID
1255
1531
  const requestId = this._generateRequestId();
1256
1532
  // Input validation (Phase 2B: zod)
1257
1533
  if (this.sdkConfig?.validationEnabled) ;
@@ -1259,7 +1535,7 @@ class BrokersWrapper {
1259
1535
  const shouldCache = true;
1260
1536
  const cache = getCache(this.sdkConfig);
1261
1537
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1262
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', params, this.sdkConfig);
1538
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
1263
1539
  const cached = cache.get(cacheKey);
1264
1540
  if (cached) {
1265
1541
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1271,7 +1547,7 @@ class BrokersWrapper {
1271
1547
  request_id: requestId,
1272
1548
  method: 'GET',
1273
1549
  path: '/api/v1/brokers/',
1274
- params: params,
1550
+ params: resolvedParams,
1275
1551
  action: 'getBrokers'
1276
1552
  });
1277
1553
  try {
@@ -1285,9 +1561,15 @@ class BrokersWrapper {
1285
1561
  throw new Error('Unexpected response shape: missing success field');
1286
1562
  }
1287
1563
  // Convert response to plain object, removing _id fields recursively
1564
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1288
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) ;
1289
1571
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1290
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', params, this.sdkConfig);
1572
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
1291
1573
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1292
1574
  }
1293
1575
  this.logger.debug('Get Brokers completed', {
@@ -1295,6 +1577,7 @@ class BrokersWrapper {
1295
1577
  action: 'getBrokers'
1296
1578
  });
1297
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)
1298
1581
  return standardResponse;
1299
1582
  }
1300
1583
  catch (error) {
@@ -1372,7 +1655,7 @@ class BrokersWrapper {
1372
1655
  * This endpoint is accessible from the portal and uses session-only authentication.
1373
1656
  * Returns connections that the user has any permissions for, including the current
1374
1657
  * company's permissions (read/write) for each connection.
1375
- * @param No parameters required for this method
1658
+ * @param params No parameters required for this method
1376
1659
  * @returns {Promise<FinaticResponse<UserBrokerConnectionWithPermissions[]>>} Standard response with success/Error/Warning structure
1377
1660
  *
1378
1661
  * Generated from: GET /api/v1/brokers/connections
@@ -1381,7 +1664,7 @@ class BrokersWrapper {
1381
1664
  * @example
1382
1665
  * ```typescript-client
1383
1666
  * // Example with no parameters
1384
- * const result = await finatic.getBrokerConnections();
1667
+ * const result = await finatic.getBrokerConnections({});
1385
1668
  *
1386
1669
  * // Access the response data
1387
1670
  * if (result.success) {
@@ -1389,10 +1672,10 @@ class BrokersWrapper {
1389
1672
  * }
1390
1673
  * ```
1391
1674
  */
1392
- async getBrokerConnections() {
1675
+ async getBrokerConnections(params) {
1393
1676
  // No parameters - use empty params object
1394
- const params = {}; // Authentication check
1395
- if (!this.sessionId) {
1677
+ const resolvedParams = params || {}; // Authentication check
1678
+ if (!this.sessionId || !this.companyId) {
1396
1679
  throw new Error('Session not initialized. Call startSession() first.');
1397
1680
  }
1398
1681
  // Generate request ID
@@ -1403,7 +1686,7 @@ class BrokersWrapper {
1403
1686
  const shouldCache = true;
1404
1687
  const cache = getCache(this.sdkConfig);
1405
1688
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1406
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', params, this.sdkConfig);
1689
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
1407
1690
  const cached = cache.get(cacheKey);
1408
1691
  if (cached) {
1409
1692
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1415,12 +1698,12 @@ class BrokersWrapper {
1415
1698
  request_id: requestId,
1416
1699
  method: 'GET',
1417
1700
  path: '/api/v1/brokers/connections',
1418
- params: params,
1701
+ params: resolvedParams,
1419
1702
  action: 'getBrokerConnections'
1420
1703
  });
1421
1704
  try {
1422
1705
  const response = await retryApiCall(async () => {
1423
- 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 } : {}) } : {}) } });
1424
1707
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1425
1708
  }, {}, this.sdkConfig);
1426
1709
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1429,9 +1712,15 @@ class BrokersWrapper {
1429
1712
  throw new Error('Unexpected response shape: missing success field');
1430
1713
  }
1431
1714
  // Convert response to plain object, removing _id fields recursively
1715
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1432
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) ;
1433
1722
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1434
- const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', params, this.sdkConfig);
1723
+ const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
1435
1724
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1436
1725
  }
1437
1726
  this.logger.debug('List Broker Connections completed', {
@@ -1439,6 +1728,7 @@ class BrokersWrapper {
1439
1728
  action: 'getBrokerConnections'
1440
1729
  });
1441
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)
1442
1732
  return standardResponse;
1443
1733
  }
1444
1734
  catch (error) {
@@ -1515,7 +1805,7 @@ class BrokersWrapper {
1515
1805
  *
1516
1806
  * If the company is the only one with access, the entire connection is deleted.
1517
1807
  * If other companies have access, only the company's access is removed.
1518
- * @param connectionId {string}
1808
+ * @param params.connectionId {string} Connection ID
1519
1809
  * @returns {Promise<FinaticResponse<DisconnectActionResult>>} Standard response with success/Error/Warning structure
1520
1810
  *
1521
1811
  * Generated from: DELETE /api/v1/brokers/disconnect-company/{connection_id}
@@ -1524,7 +1814,9 @@ class BrokersWrapper {
1524
1814
  * @example
1525
1815
  * ```typescript-client
1526
1816
  * // Minimal example with required parameters only
1527
- * 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
+ * });
1528
1820
  *
1529
1821
  * // Access the response data
1530
1822
  * if (result.success) {
@@ -1534,12 +1826,10 @@ class BrokersWrapper {
1534
1826
  * }
1535
1827
  * ```
1536
1828
  */
1537
- async disconnectCompanyFromBroker(connectionId) {
1538
- // Construct params object from individual parameters
1539
- const params = {
1540
- connectionId: connectionId
1541
- }; // Authentication check
1542
- 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) {
1543
1833
  throw new Error('Session not initialized. Call startSession() first.');
1544
1834
  }
1545
1835
  // Generate request ID
@@ -1550,7 +1840,7 @@ class BrokersWrapper {
1550
1840
  const shouldCache = true;
1551
1841
  const cache = getCache(this.sdkConfig);
1552
1842
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1553
- 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);
1554
1844
  const cached = cache.get(cacheKey);
1555
1845
  if (cached) {
1556
1846
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1562,12 +1852,12 @@ class BrokersWrapper {
1562
1852
  request_id: requestId,
1563
1853
  method: 'DELETE',
1564
1854
  path: '/api/v1/brokers/disconnect-company/{connection_id}',
1565
- params: params,
1855
+ params: resolvedParams,
1566
1856
  action: 'disconnectCompanyFromBroker'
1567
1857
  });
1568
1858
  try {
1569
1859
  const response = await retryApiCall(async () => {
1570
- 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 } : {}) } : {}) } });
1571
1861
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1572
1862
  }, {}, this.sdkConfig);
1573
1863
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1576,9 +1866,15 @@ class BrokersWrapper {
1576
1866
  throw new Error('Unexpected response shape: missing success field');
1577
1867
  }
1578
1868
  // Convert response to plain object, removing _id fields recursively
1869
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1579
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) ;
1580
1876
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1581
- 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);
1582
1878
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1583
1879
  }
1584
1880
  this.logger.debug('Disconnect Company From Broker completed', {
@@ -1586,6 +1882,7 @@ class BrokersWrapper {
1586
1882
  action: 'disconnectCompanyFromBroker'
1587
1883
  });
1588
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)
1589
1886
  return standardResponse;
1590
1887
  }
1591
1888
  catch (error) {
@@ -1662,19 +1959,19 @@ class BrokersWrapper {
1662
1959
  *
1663
1960
  * This endpoint is accessible from the portal and uses session-only authentication.
1664
1961
  * Returns orders from connections the company has read access to.
1665
- * @param brokerId {string} (optional)
1666
- * @param connectionId {string} (optional)
1667
- * @param accountId {string} (optional)
1668
- * @param symbol {string} (optional)
1669
- * @param orderStatus {BrokerDataOrderStatusEnum} (optional)
1670
- * @param side {BrokerDataOrderSideEnum} (optional)
1671
- * @param assetType {BrokerDataAssetTypeEnum} (optional)
1672
- * @param limit {number} (optional)
1673
- * @param offset {number} (optional)
1674
- * @param createdAfter {string} (optional)
1675
- * @param createdBefore {string} (optional)
1676
- * @param includeMetadata {boolean} (optional)
1677
- * @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
1678
1975
  *
1679
1976
  * Generated from: GET /api/v1/brokers/data/orders
1680
1977
  * @methodId get_orders_api_v1_brokers_data_orders_get
@@ -1682,7 +1979,7 @@ class BrokersWrapper {
1682
1979
  * @example
1683
1980
  * ```typescript-client
1684
1981
  * // Example with no parameters
1685
- * const result = await finatic.getOrders();
1982
+ * const result = await finatic.getOrders({});
1686
1983
  *
1687
1984
  * // Access the response data
1688
1985
  * if (result.success) {
@@ -1692,7 +1989,11 @@ class BrokersWrapper {
1692
1989
  * @example
1693
1990
  * ```typescript-client
1694
1991
  * // Full example with optional parameters
1695
- * 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
+ * });
1696
1997
  *
1697
1998
  * // Handle response with warnings
1698
1999
  * if (result.success) {
@@ -1705,23 +2006,19 @@ class BrokersWrapper {
1705
2006
  * }
1706
2007
  * ```
1707
2008
  */
1708
- async getOrders(brokerId, connectionId, accountId, symbol, orderStatus, side, assetType, limit, offset, createdAfter, createdBefore, includeMetadata) {
1709
- // Construct params object from individual parameters
1710
- const params = {
1711
- brokerId: brokerId,
1712
- connectionId: connectionId,
1713
- accountId: accountId,
1714
- symbol: symbol,
1715
- orderStatus: orderStatus !== undefined ? coerceEnumValue(orderStatus, BrokerDataOrderStatusEnum, 'orderStatus') : undefined,
1716
- side: side !== undefined ? coerceEnumValue(side, BrokerDataOrderSideEnum, 'side') : undefined,
1717
- assetType: assetType !== undefined ? coerceEnumValue(assetType, BrokerDataAssetTypeEnum, 'assetType') : undefined,
1718
- limit: limit,
1719
- offset: offset,
1720
- createdAfter: createdAfter,
1721
- createdBefore: createdBefore,
1722
- includeMetadata: includeMetadata
1723
- }; // Authentication check
1724
- 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) {
1725
2022
  throw new Error('Session not initialized. Call startSession() first.');
1726
2023
  }
1727
2024
  // Generate request ID
@@ -1732,7 +2029,7 @@ class BrokersWrapper {
1732
2029
  const shouldCache = true;
1733
2030
  const cache = getCache(this.sdkConfig);
1734
2031
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1735
- 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);
1736
2033
  const cached = cache.get(cacheKey);
1737
2034
  if (cached) {
1738
2035
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1744,12 +2041,12 @@ class BrokersWrapper {
1744
2041
  request_id: requestId,
1745
2042
  method: 'GET',
1746
2043
  path: '/api/v1/brokers/data/orders',
1747
- params: params,
2044
+ params: resolvedParams,
1748
2045
  action: 'getOrders'
1749
2046
  });
1750
2047
  try {
1751
2048
  const response = await retryApiCall(async () => {
1752
- 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 } : {}) } : {}) } });
1753
2050
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1754
2051
  }, {}, this.sdkConfig);
1755
2052
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1758,9 +2055,27 @@ class BrokersWrapper {
1758
2055
  throw new Error('Unexpected response shape: missing success field');
1759
2056
  }
1760
2057
  // Convert response to plain object, removing _id fields recursively
2058
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1761
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
+ }
1762
2077
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1763
- 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);
1764
2079
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1765
2080
  }
1766
2081
  this.logger.debug('Get Orders completed', {
@@ -1768,6 +2083,7 @@ class BrokersWrapper {
1768
2083
  action: 'getOrders'
1769
2084
  });
1770
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)
1771
2087
  return standardResponse;
1772
2088
  }
1773
2089
  catch (error) {
@@ -1844,19 +2160,19 @@ class BrokersWrapper {
1844
2160
  *
1845
2161
  * This endpoint is accessible from the portal and uses session-only authentication.
1846
2162
  * Returns positions from connections the company has read access to.
1847
- * @param brokerId {string} (optional)
1848
- * @param connectionId {string} (optional)
1849
- * @param accountId {string} (optional)
1850
- * @param symbol {string} (optional)
1851
- * @param side {BrokerDataOrderSideEnum} (optional)
1852
- * @param assetType {BrokerDataAssetTypeEnum} (optional)
1853
- * @param positionStatus {BrokerDataPositionStatusEnum} (optional)
1854
- * @param limit {number} (optional)
1855
- * @param offset {number} (optional)
1856
- * @param updatedAfter {string} (optional)
1857
- * @param updatedBefore {string} (optional)
1858
- * @param includeMetadata {boolean} (optional)
1859
- * @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
1860
2176
  *
1861
2177
  * Generated from: GET /api/v1/brokers/data/positions
1862
2178
  * @methodId get_positions_api_v1_brokers_data_positions_get
@@ -1864,7 +2180,7 @@ class BrokersWrapper {
1864
2180
  * @example
1865
2181
  * ```typescript-client
1866
2182
  * // Example with no parameters
1867
- * const result = await finatic.getPositions();
2183
+ * const result = await finatic.getPositions({});
1868
2184
  *
1869
2185
  * // Access the response data
1870
2186
  * if (result.success) {
@@ -1874,7 +2190,11 @@ class BrokersWrapper {
1874
2190
  * @example
1875
2191
  * ```typescript-client
1876
2192
  * // Full example with optional parameters
1877
- * 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
+ * });
1878
2198
  *
1879
2199
  * // Handle response with warnings
1880
2200
  * if (result.success) {
@@ -1887,23 +2207,19 @@ class BrokersWrapper {
1887
2207
  * }
1888
2208
  * ```
1889
2209
  */
1890
- async getPositions(brokerId, connectionId, accountId, symbol, side, assetType, positionStatus, limit, offset, updatedAfter, updatedBefore, includeMetadata) {
1891
- // Construct params object from individual parameters
1892
- const params = {
1893
- brokerId: brokerId,
1894
- connectionId: connectionId,
1895
- accountId: accountId,
1896
- symbol: symbol,
1897
- side: side !== undefined ? coerceEnumValue(side, BrokerDataOrderSideEnum, 'side') : undefined,
1898
- assetType: assetType !== undefined ? coerceEnumValue(assetType, BrokerDataAssetTypeEnum, 'assetType') : undefined,
1899
- positionStatus: positionStatus !== undefined ? coerceEnumValue(positionStatus, BrokerDataPositionStatusEnum, 'positionStatus') : undefined,
1900
- limit: limit,
1901
- offset: offset,
1902
- updatedAfter: updatedAfter,
1903
- updatedBefore: updatedBefore,
1904
- includeMetadata: includeMetadata
1905
- }; // Authentication check
1906
- 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) {
1907
2223
  throw new Error('Session not initialized. Call startSession() first.');
1908
2224
  }
1909
2225
  // Generate request ID
@@ -1914,7 +2230,7 @@ class BrokersWrapper {
1914
2230
  const shouldCache = true;
1915
2231
  const cache = getCache(this.sdkConfig);
1916
2232
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1917
- 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);
1918
2234
  const cached = cache.get(cacheKey);
1919
2235
  if (cached) {
1920
2236
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -1926,12 +2242,12 @@ class BrokersWrapper {
1926
2242
  request_id: requestId,
1927
2243
  method: 'GET',
1928
2244
  path: '/api/v1/brokers/data/positions',
1929
- params: params,
2245
+ params: resolvedParams,
1930
2246
  action: 'getPositions'
1931
2247
  });
1932
2248
  try {
1933
2249
  const response = await retryApiCall(async () => {
1934
- 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 } : {}) } : {}) } });
1935
2251
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
1936
2252
  }, {}, this.sdkConfig);
1937
2253
  // Unwrap axios response immediately - get FinaticResponse object
@@ -1940,9 +2256,27 @@ class BrokersWrapper {
1940
2256
  throw new Error('Unexpected response shape: missing success field');
1941
2257
  }
1942
2258
  // Convert response to plain object, removing _id fields recursively
2259
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
1943
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
+ }
1944
2278
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
1945
- 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);
1946
2280
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
1947
2281
  }
1948
2282
  this.logger.debug('Get Positions completed', {
@@ -1950,6 +2284,7 @@ class BrokersWrapper {
1950
2284
  action: 'getPositions'
1951
2285
  });
1952
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)
1953
2288
  return standardResponse;
1954
2289
  }
1955
2290
  catch (error) {
@@ -2026,16 +2361,16 @@ class BrokersWrapper {
2026
2361
  *
2027
2362
  * This endpoint is accessible from the portal and uses session-only authentication.
2028
2363
  * Returns balances from connections the company has read access to.
2029
- * @param brokerId {string} (optional)
2030
- * @param connectionId {string} (optional)
2031
- * @param accountId {string} (optional)
2032
- * @param isEndOfDaySnapshot {boolean} (optional)
2033
- * @param limit {number} (optional)
2034
- * @param offset {number} (optional)
2035
- * @param balanceCreatedAfter {string} (optional)
2036
- * @param balanceCreatedBefore {string} (optional)
2037
- * @param includeMetadata {boolean} (optional)
2038
- * @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
2039
2374
  *
2040
2375
  * Generated from: GET /api/v1/brokers/data/balances
2041
2376
  * @methodId get_balances_api_v1_brokers_data_balances_get
@@ -2043,7 +2378,7 @@ class BrokersWrapper {
2043
2378
  * @example
2044
2379
  * ```typescript-client
2045
2380
  * // Example with no parameters
2046
- * const result = await finatic.getBalances();
2381
+ * const result = await finatic.getBalances({});
2047
2382
  *
2048
2383
  * // Access the response data
2049
2384
  * if (result.success) {
@@ -2053,7 +2388,11 @@ class BrokersWrapper {
2053
2388
  * @example
2054
2389
  * ```typescript-client
2055
2390
  * // Full example with optional parameters
2056
- * 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
+ * });
2057
2396
  *
2058
2397
  * // Handle response with warnings
2059
2398
  * if (result.success) {
@@ -2066,20 +2405,10 @@ class BrokersWrapper {
2066
2405
  * }
2067
2406
  * ```
2068
2407
  */
2069
- async getBalances(brokerId, connectionId, accountId, isEndOfDaySnapshot, limit, offset, balanceCreatedAfter, balanceCreatedBefore, includeMetadata) {
2070
- // Construct params object from individual parameters
2071
- const params = {
2072
- brokerId: brokerId,
2073
- connectionId: connectionId,
2074
- accountId: accountId,
2075
- isEndOfDaySnapshot: isEndOfDaySnapshot,
2076
- limit: limit,
2077
- offset: offset,
2078
- balanceCreatedAfter: balanceCreatedAfter,
2079
- balanceCreatedBefore: balanceCreatedBefore,
2080
- includeMetadata: includeMetadata
2081
- }; // Authentication check
2082
- 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) {
2083
2412
  throw new Error('Session not initialized. Call startSession() first.');
2084
2413
  }
2085
2414
  // Generate request ID
@@ -2090,7 +2419,7 @@ class BrokersWrapper {
2090
2419
  const shouldCache = true;
2091
2420
  const cache = getCache(this.sdkConfig);
2092
2421
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2093
- 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);
2094
2423
  const cached = cache.get(cacheKey);
2095
2424
  if (cached) {
2096
2425
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2102,12 +2431,12 @@ class BrokersWrapper {
2102
2431
  request_id: requestId,
2103
2432
  method: 'GET',
2104
2433
  path: '/api/v1/brokers/data/balances',
2105
- params: params,
2434
+ params: resolvedParams,
2106
2435
  action: 'getBalances'
2107
2436
  });
2108
2437
  try {
2109
2438
  const response = await retryApiCall(async () => {
2110
- 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 } : {}) } : {}) } });
2111
2440
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2112
2441
  }, {}, this.sdkConfig);
2113
2442
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2116,9 +2445,27 @@ class BrokersWrapper {
2116
2445
  throw new Error('Unexpected response shape: missing success field');
2117
2446
  }
2118
2447
  // Convert response to plain object, removing _id fields recursively
2448
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2119
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
+ }
2120
2467
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2121
- 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);
2122
2469
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2123
2470
  }
2124
2471
  this.logger.debug('Get Balances completed', {
@@ -2126,6 +2473,7 @@ class BrokersWrapper {
2126
2473
  action: 'getBalances'
2127
2474
  });
2128
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)
2129
2477
  return standardResponse;
2130
2478
  }
2131
2479
  catch (error) {
@@ -2202,15 +2550,15 @@ class BrokersWrapper {
2202
2550
  *
2203
2551
  * This endpoint is accessible from the portal and uses session-only authentication.
2204
2552
  * Returns accounts from connections the company has read access to.
2205
- * @param brokerId {string} (optional)
2206
- * @param connectionId {string} (optional)
2207
- * @param accountType {BrokerDataAccountTypeEnum} (optional)
2208
- * @param status {AccountStatus} (optional)
2209
- * @param currency {string} (optional)
2210
- * @param limit {number} (optional)
2211
- * @param offset {number} (optional)
2212
- * @param includeMetadata {boolean} (optional)
2213
- * @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
2214
2562
  *
2215
2563
  * Generated from: GET /api/v1/brokers/data/accounts
2216
2564
  * @methodId get_accounts_api_v1_brokers_data_accounts_get
@@ -2218,7 +2566,7 @@ class BrokersWrapper {
2218
2566
  * @example
2219
2567
  * ```typescript-client
2220
2568
  * // Example with no parameters
2221
- * const result = await finatic.getAccounts();
2569
+ * const result = await finatic.getAccounts({});
2222
2570
  *
2223
2571
  * // Access the response data
2224
2572
  * if (result.success) {
@@ -2228,7 +2576,11 @@ class BrokersWrapper {
2228
2576
  * @example
2229
2577
  * ```typescript-client
2230
2578
  * // Full example with optional parameters
2231
- * 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
+ * });
2232
2584
  *
2233
2585
  * // Handle response with warnings
2234
2586
  * if (result.success) {
@@ -2241,19 +2593,13 @@ class BrokersWrapper {
2241
2593
  * }
2242
2594
  * ```
2243
2595
  */
2244
- async getAccounts(brokerId, connectionId, accountType, status, currency, limit, offset, includeMetadata) {
2245
- // Construct params object from individual parameters
2246
- const params = {
2247
- brokerId: brokerId,
2248
- connectionId: connectionId,
2249
- accountType: accountType !== undefined ? coerceEnumValue(accountType, BrokerDataAccountTypeEnum, 'accountType') : undefined,
2250
- status: status,
2251
- currency: currency,
2252
- limit: limit,
2253
- offset: offset,
2254
- includeMetadata: includeMetadata
2255
- }; // Authentication check
2256
- 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) {
2257
2603
  throw new Error('Session not initialized. Call startSession() first.');
2258
2604
  }
2259
2605
  // Generate request ID
@@ -2264,7 +2610,7 @@ class BrokersWrapper {
2264
2610
  const shouldCache = true;
2265
2611
  const cache = getCache(this.sdkConfig);
2266
2612
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2267
- 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);
2268
2614
  const cached = cache.get(cacheKey);
2269
2615
  if (cached) {
2270
2616
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2276,12 +2622,12 @@ class BrokersWrapper {
2276
2622
  request_id: requestId,
2277
2623
  method: 'GET',
2278
2624
  path: '/api/v1/brokers/data/accounts',
2279
- params: params,
2625
+ params: resolvedParams,
2280
2626
  action: 'getAccounts'
2281
2627
  });
2282
2628
  try {
2283
2629
  const response = await retryApiCall(async () => {
2284
- 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 } : {}) } : {}) } });
2285
2631
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2286
2632
  }, {}, this.sdkConfig);
2287
2633
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2290,9 +2636,27 @@ class BrokersWrapper {
2290
2636
  throw new Error('Unexpected response shape: missing success field');
2291
2637
  }
2292
2638
  // Convert response to plain object, removing _id fields recursively
2639
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2293
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
+ }
2294
2658
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2295
- 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);
2296
2660
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2297
2661
  }
2298
2662
  this.logger.debug('Get Accounts completed', {
@@ -2300,6 +2664,7 @@ class BrokersWrapper {
2300
2664
  action: 'getAccounts'
2301
2665
  });
2302
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)
2303
2668
  return standardResponse;
2304
2669
  }
2305
2670
  catch (error) {
@@ -2375,12 +2740,12 @@ class BrokersWrapper {
2375
2740
  * Get order fills for a specific order.
2376
2741
  *
2377
2742
  * This endpoint returns all execution fills for the specified order.
2378
- * @param orderId {string}
2379
- * @param connectionId {string} (optional)
2380
- * @param limit {number} (optional)
2381
- * @param offset {number} (optional)
2382
- * @param includeMetadata {boolean} (optional)
2383
- * @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
2384
2749
  *
2385
2750
  * Generated from: GET /api/v1/brokers/data/orders/{order_id}/fills
2386
2751
  * @methodId get_order_fills_api_v1_brokers_data_orders__order_id__fills_get
@@ -2388,7 +2753,9 @@ class BrokersWrapper {
2388
2753
  * @example
2389
2754
  * ```typescript-client
2390
2755
  * // Minimal example with required parameters only
2391
- * 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
+ * });
2392
2759
  *
2393
2760
  * // Access the response data
2394
2761
  * if (result.success) {
@@ -2400,7 +2767,12 @@ class BrokersWrapper {
2400
2767
  * @example
2401
2768
  * ```typescript-client
2402
2769
  * // Full example with optional parameters
2403
- * 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
+ * });
2404
2776
  *
2405
2777
  * // Handle response with warnings
2406
2778
  * if (result.success) {
@@ -2413,16 +2785,10 @@ class BrokersWrapper {
2413
2785
  * }
2414
2786
  * ```
2415
2787
  */
2416
- async getOrderFills(orderId, connectionId, limit, offset, includeMetadata) {
2417
- // Construct params object from individual parameters
2418
- const params = {
2419
- orderId: orderId,
2420
- connectionId: connectionId,
2421
- limit: limit,
2422
- offset: offset,
2423
- includeMetadata: includeMetadata
2424
- }; // Authentication check
2425
- 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) {
2426
2792
  throw new Error('Session not initialized. Call startSession() first.');
2427
2793
  }
2428
2794
  // Generate request ID
@@ -2433,7 +2799,7 @@ class BrokersWrapper {
2433
2799
  const shouldCache = true;
2434
2800
  const cache = getCache(this.sdkConfig);
2435
2801
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2436
- 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);
2437
2803
  const cached = cache.get(cacheKey);
2438
2804
  if (cached) {
2439
2805
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2445,12 +2811,12 @@ class BrokersWrapper {
2445
2811
  request_id: requestId,
2446
2812
  method: 'GET',
2447
2813
  path: '/api/v1/brokers/data/orders/{order_id}/fills',
2448
- params: params,
2814
+ params: resolvedParams,
2449
2815
  action: 'getOrderFills'
2450
2816
  });
2451
2817
  try {
2452
2818
  const response = await retryApiCall(async () => {
2453
- 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 } : {}) } : {}) } });
2454
2820
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2455
2821
  }, {}, this.sdkConfig);
2456
2822
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2459,9 +2825,27 @@ class BrokersWrapper {
2459
2825
  throw new Error('Unexpected response shape: missing success field');
2460
2826
  }
2461
2827
  // Convert response to plain object, removing _id fields recursively
2828
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2462
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
+ }
2463
2847
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2464
- 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);
2465
2849
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2466
2850
  }
2467
2851
  this.logger.debug('Get Order Fills completed', {
@@ -2469,6 +2853,7 @@ class BrokersWrapper {
2469
2853
  action: 'getOrderFills'
2470
2854
  });
2471
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)
2472
2857
  return standardResponse;
2473
2858
  }
2474
2859
  catch (error) {
@@ -2544,12 +2929,12 @@ class BrokersWrapper {
2544
2929
  * Get order events for a specific order.
2545
2930
  *
2546
2931
  * This endpoint returns all lifecycle events for the specified order.
2547
- * @param orderId {string}
2548
- * @param connectionId {string} (optional)
2549
- * @param limit {number} (optional)
2550
- * @param offset {number} (optional)
2551
- * @param includeMetadata {boolean} (optional)
2552
- * @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
2553
2938
  *
2554
2939
  * Generated from: GET /api/v1/brokers/data/orders/{order_id}/events
2555
2940
  * @methodId get_order_events_api_v1_brokers_data_orders__order_id__events_get
@@ -2557,7 +2942,9 @@ class BrokersWrapper {
2557
2942
  * @example
2558
2943
  * ```typescript-client
2559
2944
  * // Minimal example with required parameters only
2560
- * 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
+ * });
2561
2948
  *
2562
2949
  * // Access the response data
2563
2950
  * if (result.success) {
@@ -2569,7 +2956,12 @@ class BrokersWrapper {
2569
2956
  * @example
2570
2957
  * ```typescript-client
2571
2958
  * // Full example with optional parameters
2572
- * 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
+ * });
2573
2965
  *
2574
2966
  * // Handle response with warnings
2575
2967
  * if (result.success) {
@@ -2582,16 +2974,10 @@ class BrokersWrapper {
2582
2974
  * }
2583
2975
  * ```
2584
2976
  */
2585
- async getOrderEvents(orderId, connectionId, limit, offset, includeMetadata) {
2586
- // Construct params object from individual parameters
2587
- const params = {
2588
- orderId: orderId,
2589
- connectionId: connectionId,
2590
- limit: limit,
2591
- offset: offset,
2592
- includeMetadata: includeMetadata
2593
- }; // Authentication check
2594
- 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) {
2595
2981
  throw new Error('Session not initialized. Call startSession() first.');
2596
2982
  }
2597
2983
  // Generate request ID
@@ -2602,7 +2988,7 @@ class BrokersWrapper {
2602
2988
  const shouldCache = true;
2603
2989
  const cache = getCache(this.sdkConfig);
2604
2990
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2605
- 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);
2606
2992
  const cached = cache.get(cacheKey);
2607
2993
  if (cached) {
2608
2994
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2614,12 +3000,12 @@ class BrokersWrapper {
2614
3000
  request_id: requestId,
2615
3001
  method: 'GET',
2616
3002
  path: '/api/v1/brokers/data/orders/{order_id}/events',
2617
- params: params,
3003
+ params: resolvedParams,
2618
3004
  action: 'getOrderEvents'
2619
3005
  });
2620
3006
  try {
2621
3007
  const response = await retryApiCall(async () => {
2622
- 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 } : {}) } : {}) } });
2623
3009
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2624
3010
  }, {}, this.sdkConfig);
2625
3011
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2628,9 +3014,27 @@ class BrokersWrapper {
2628
3014
  throw new Error('Unexpected response shape: missing success field');
2629
3015
  }
2630
3016
  // Convert response to plain object, removing _id fields recursively
3017
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2631
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
+ }
2632
3036
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2633
- 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);
2634
3038
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2635
3039
  }
2636
3040
  this.logger.debug('Get Order Events completed', {
@@ -2638,6 +3042,7 @@ class BrokersWrapper {
2638
3042
  action: 'getOrderEvents'
2639
3043
  });
2640
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)
2641
3046
  return standardResponse;
2642
3047
  }
2643
3048
  catch (error) {
@@ -2713,14 +3118,14 @@ class BrokersWrapper {
2713
3118
  * Get order groups.
2714
3119
  *
2715
3120
  * This endpoint returns order groups that contain multiple orders.
2716
- * @param brokerId {string} (optional)
2717
- * @param connectionId {string} (optional)
2718
- * @param limit {number} (optional)
2719
- * @param offset {number} (optional)
2720
- * @param createdAfter {string} (optional)
2721
- * @param createdBefore {string} (optional)
2722
- * @param includeMetadata {boolean} (optional)
2723
- * @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
2724
3129
  *
2725
3130
  * Generated from: GET /api/v1/brokers/data/orders/groups
2726
3131
  * @methodId get_order_groups_api_v1_brokers_data_orders_groups_get
@@ -2728,7 +3133,7 @@ class BrokersWrapper {
2728
3133
  * @example
2729
3134
  * ```typescript-client
2730
3135
  * // Example with no parameters
2731
- * const result = await finatic.getOrderGroups();
3136
+ * const result = await finatic.getOrderGroups({});
2732
3137
  *
2733
3138
  * // Access the response data
2734
3139
  * if (result.success) {
@@ -2738,7 +3143,11 @@ class BrokersWrapper {
2738
3143
  * @example
2739
3144
  * ```typescript-client
2740
3145
  * // Full example with optional parameters
2741
- * 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
+ * });
2742
3151
  *
2743
3152
  * // Handle response with warnings
2744
3153
  * if (result.success) {
@@ -2751,18 +3160,10 @@ class BrokersWrapper {
2751
3160
  * }
2752
3161
  * ```
2753
3162
  */
2754
- async getOrderGroups(brokerId, connectionId, limit, offset, createdAfter, createdBefore, includeMetadata) {
2755
- // Construct params object from individual parameters
2756
- const params = {
2757
- brokerId: brokerId,
2758
- connectionId: connectionId,
2759
- limit: limit,
2760
- offset: offset,
2761
- createdAfter: createdAfter,
2762
- createdBefore: createdBefore,
2763
- includeMetadata: includeMetadata
2764
- }; // Authentication check
2765
- 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) {
2766
3167
  throw new Error('Session not initialized. Call startSession() first.');
2767
3168
  }
2768
3169
  // Generate request ID
@@ -2773,7 +3174,7 @@ class BrokersWrapper {
2773
3174
  const shouldCache = true;
2774
3175
  const cache = getCache(this.sdkConfig);
2775
3176
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2776
- 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);
2777
3178
  const cached = cache.get(cacheKey);
2778
3179
  if (cached) {
2779
3180
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2785,12 +3186,12 @@ class BrokersWrapper {
2785
3186
  request_id: requestId,
2786
3187
  method: 'GET',
2787
3188
  path: '/api/v1/brokers/data/orders/groups',
2788
- params: params,
3189
+ params: resolvedParams,
2789
3190
  action: 'getOrderGroups'
2790
3191
  });
2791
3192
  try {
2792
3193
  const response = await retryApiCall(async () => {
2793
- 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 } : {}) } : {}) } });
2794
3195
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2795
3196
  }, {}, this.sdkConfig);
2796
3197
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2799,9 +3200,27 @@ class BrokersWrapper {
2799
3200
  throw new Error('Unexpected response shape: missing success field');
2800
3201
  }
2801
3202
  // Convert response to plain object, removing _id fields recursively
3203
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2802
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
+ }
2803
3222
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2804
- 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);
2805
3224
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2806
3225
  }
2807
3226
  this.logger.debug('Get Order Groups completed', {
@@ -2809,6 +3228,7 @@ class BrokersWrapper {
2809
3228
  action: 'getOrderGroups'
2810
3229
  });
2811
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)
2812
3232
  return standardResponse;
2813
3233
  }
2814
3234
  catch (error) {
@@ -2885,14 +3305,14 @@ class BrokersWrapper {
2885
3305
  *
2886
3306
  * This endpoint returns tax lots for positions, which are used for tax reporting.
2887
3307
  * Each lot tracks when a position was opened/closed and at what prices.
2888
- * @param brokerId {string} (optional)
2889
- * @param connectionId {string} (optional)
2890
- * @param accountId {string} (optional)
2891
- * @param symbol {string} (optional)
2892
- * @param positionId {string} (optional)
2893
- * @param limit {number} (optional)
2894
- * @param offset {number} (optional)
2895
- * @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
2896
3316
  *
2897
3317
  * Generated from: GET /api/v1/brokers/data/positions/lots
2898
3318
  * @methodId get_position_lots_api_v1_brokers_data_positions_lots_get
@@ -2900,7 +3320,7 @@ class BrokersWrapper {
2900
3320
  * @example
2901
3321
  * ```typescript-client
2902
3322
  * // Example with no parameters
2903
- * const result = await finatic.getPositionLots();
3323
+ * const result = await finatic.getPositionLots({});
2904
3324
  *
2905
3325
  * // Access the response data
2906
3326
  * if (result.success) {
@@ -2910,7 +3330,11 @@ class BrokersWrapper {
2910
3330
  * @example
2911
3331
  * ```typescript-client
2912
3332
  * // Full example with optional parameters
2913
- * 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
+ * });
2914
3338
  *
2915
3339
  * // Handle response with warnings
2916
3340
  * if (result.success) {
@@ -2923,18 +3347,10 @@ class BrokersWrapper {
2923
3347
  * }
2924
3348
  * ```
2925
3349
  */
2926
- async getPositionLots(brokerId, connectionId, accountId, symbol, positionId, limit, offset) {
2927
- // Construct params object from individual parameters
2928
- const params = {
2929
- brokerId: brokerId,
2930
- connectionId: connectionId,
2931
- accountId: accountId,
2932
- symbol: symbol,
2933
- positionId: positionId,
2934
- limit: limit,
2935
- offset: offset
2936
- }; // Authentication check
2937
- 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) {
2938
3354
  throw new Error('Session not initialized. Call startSession() first.');
2939
3355
  }
2940
3356
  // Generate request ID
@@ -2945,7 +3361,7 @@ class BrokersWrapper {
2945
3361
  const shouldCache = true;
2946
3362
  const cache = getCache(this.sdkConfig);
2947
3363
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2948
- 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);
2949
3365
  const cached = cache.get(cacheKey);
2950
3366
  if (cached) {
2951
3367
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -2957,12 +3373,12 @@ class BrokersWrapper {
2957
3373
  request_id: requestId,
2958
3374
  method: 'GET',
2959
3375
  path: '/api/v1/brokers/data/positions/lots',
2960
- params: params,
3376
+ params: resolvedParams,
2961
3377
  action: 'getPositionLots'
2962
3378
  });
2963
3379
  try {
2964
3380
  const response = await retryApiCall(async () => {
2965
- 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 } : {}) } : {}) } });
2966
3382
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
2967
3383
  }, {}, this.sdkConfig);
2968
3384
  // Unwrap axios response immediately - get FinaticResponse object
@@ -2971,9 +3387,27 @@ class BrokersWrapper {
2971
3387
  throw new Error('Unexpected response shape: missing success field');
2972
3388
  }
2973
3389
  // Convert response to plain object, removing _id fields recursively
3390
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
2974
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
+ }
2975
3409
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
2976
- 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);
2977
3411
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
2978
3412
  }
2979
3413
  this.logger.debug('Get Position Lots completed', {
@@ -2981,6 +3415,7 @@ class BrokersWrapper {
2981
3415
  action: 'getPositionLots'
2982
3416
  });
2983
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)
2984
3419
  return standardResponse;
2985
3420
  }
2986
3421
  catch (error) {
@@ -3056,11 +3491,11 @@ class BrokersWrapper {
3056
3491
  * Get position lot fills for a specific lot.
3057
3492
  *
3058
3493
  * This endpoint returns all fills associated with a specific position lot.
3059
- * @param lotId {string}
3060
- * @param connectionId {string} (optional)
3061
- * @param limit {number} (optional)
3062
- * @param offset {number} (optional)
3063
- * @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
3064
3499
  *
3065
3500
  * Generated from: GET /api/v1/brokers/data/positions/lots/{lot_id}/fills
3066
3501
  * @methodId get_position_lot_fills_api_v1_brokers_data_positions_lots__lot_id__fills_get
@@ -3068,7 +3503,9 @@ class BrokersWrapper {
3068
3503
  * @example
3069
3504
  * ```typescript-client
3070
3505
  * // Minimal example with required parameters only
3071
- * 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
+ * });
3072
3509
  *
3073
3510
  * // Access the response data
3074
3511
  * if (result.success) {
@@ -3080,7 +3517,12 @@ class BrokersWrapper {
3080
3517
  * @example
3081
3518
  * ```typescript-client
3082
3519
  * // Full example with optional parameters
3083
- * 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
+ * });
3084
3526
  *
3085
3527
  * // Handle response with warnings
3086
3528
  * if (result.success) {
@@ -3093,15 +3535,10 @@ class BrokersWrapper {
3093
3535
  * }
3094
3536
  * ```
3095
3537
  */
3096
- async getPositionLotFills(lotId, connectionId, limit, offset) {
3097
- // Construct params object from individual parameters
3098
- const params = {
3099
- lotId: lotId,
3100
- connectionId: connectionId,
3101
- limit: limit,
3102
- offset: offset
3103
- }; // Authentication check
3104
- 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) {
3105
3542
  throw new Error('Session not initialized. Call startSession() first.');
3106
3543
  }
3107
3544
  // Generate request ID
@@ -3112,7 +3549,7 @@ class BrokersWrapper {
3112
3549
  const shouldCache = true;
3113
3550
  const cache = getCache(this.sdkConfig);
3114
3551
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3115
- 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);
3116
3553
  const cached = cache.get(cacheKey);
3117
3554
  if (cached) {
3118
3555
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3124,12 +3561,12 @@ class BrokersWrapper {
3124
3561
  request_id: requestId,
3125
3562
  method: 'GET',
3126
3563
  path: '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
3127
- params: params,
3564
+ params: resolvedParams,
3128
3565
  action: 'getPositionLotFills'
3129
3566
  });
3130
3567
  try {
3131
3568
  const response = await retryApiCall(async () => {
3132
- 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 } : {}) } : {}) } });
3133
3570
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3134
3571
  }, {}, this.sdkConfig);
3135
3572
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3138,9 +3575,27 @@ class BrokersWrapper {
3138
3575
  throw new Error('Unexpected response shape: missing success field');
3139
3576
  }
3140
3577
  // Convert response to plain object, removing _id fields recursively
3578
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3141
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
+ }
3142
3597
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3143
- 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);
3144
3599
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3145
3600
  }
3146
3601
  this.logger.debug('Get Position Lot Fills completed', {
@@ -3148,6 +3603,7 @@ class BrokersWrapper {
3148
3603
  action: 'getPositionLotFills'
3149
3604
  });
3150
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)
3151
3607
  return standardResponse;
3152
3608
  }
3153
3609
  catch (error) {
@@ -3260,7 +3716,7 @@ class CompanyWrapper {
3260
3716
  * Get Company
3261
3717
  *
3262
3718
  * Get public company details by ID (no user check, no sensitive data).
3263
- * @param companyId {string}
3719
+ * @param params.companyId {string} Company ID
3264
3720
  * @returns {Promise<FinaticResponse<CompanyResponse>>} Standard response with success/Error/Warning structure
3265
3721
  *
3266
3722
  * Generated from: GET /api/v1/company/{company_id}
@@ -3269,7 +3725,9 @@ class CompanyWrapper {
3269
3725
  * @example
3270
3726
  * ```typescript-client
3271
3727
  * // Minimal example with required parameters only
3272
- * 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
+ * });
3273
3731
  *
3274
3732
  * // Access the response data
3275
3733
  * if (result.success) {
@@ -3279,11 +3737,9 @@ class CompanyWrapper {
3279
3737
  * }
3280
3738
  * ```
3281
3739
  */
3282
- async getCompany(companyId) {
3283
- // Construct params object from individual parameters
3284
- const params = {
3285
- companyId: companyId
3286
- }; // Generate request ID
3740
+ async getCompany(params) {
3741
+ // Use params object (required parameters present)
3742
+ const resolvedParams = params; // Generate request ID
3287
3743
  const requestId = this._generateRequestId();
3288
3744
  // Input validation (Phase 2B: zod)
3289
3745
  if (this.sdkConfig?.validationEnabled) ;
@@ -3291,7 +3747,7 @@ class CompanyWrapper {
3291
3747
  const shouldCache = true;
3292
3748
  const cache = getCache(this.sdkConfig);
3293
3749
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3294
- 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);
3295
3751
  const cached = cache.get(cacheKey);
3296
3752
  if (cached) {
3297
3753
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3303,12 +3759,12 @@ class CompanyWrapper {
3303
3759
  request_id: requestId,
3304
3760
  method: 'GET',
3305
3761
  path: '/api/v1/company/{company_id}',
3306
- params: params,
3762
+ params: resolvedParams,
3307
3763
  action: 'getCompany'
3308
3764
  });
3309
3765
  try {
3310
3766
  const response = await retryApiCall(async () => {
3311
- 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 } });
3312
3768
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3313
3769
  }, {}, this.sdkConfig);
3314
3770
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3317,9 +3773,15 @@ class CompanyWrapper {
3317
3773
  throw new Error('Unexpected response shape: missing success field');
3318
3774
  }
3319
3775
  // Convert response to plain object, removing _id fields recursively
3776
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3320
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) ;
3321
3783
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3322
- 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);
3323
3785
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3324
3786
  }
3325
3787
  this.logger.debug('Get Company completed', {
@@ -3327,6 +3789,7 @@ class CompanyWrapper {
3327
3789
  action: 'getCompany'
3328
3790
  });
3329
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)
3330
3793
  return standardResponse;
3331
3794
  }
3332
3795
  catch (error) {
@@ -3439,7 +3902,7 @@ class SessionWrapper {
3439
3902
  * Init Session
3440
3903
  *
3441
3904
  * Initialize a new session with company API key.
3442
- * @param xApiKey {string}
3905
+ * @param params.xApiKey {string} Company API key
3443
3906
  * @returns {Promise<FinaticResponse<TokenResponseData>>} Standard response with success/Error/Warning structure
3444
3907
  *
3445
3908
  * Generated from: POST /api/v1/session/init
@@ -3448,7 +3911,7 @@ class SessionWrapper {
3448
3911
  * @example
3449
3912
  * ```typescript-client
3450
3913
  * // Example with no parameters
3451
- * const result = await finatic.initSession();
3914
+ * const result = await finatic.initSession({});
3452
3915
  *
3453
3916
  * // Access the response data
3454
3917
  * if (result.success) {
@@ -3456,11 +3919,9 @@ class SessionWrapper {
3456
3919
  * }
3457
3920
  * ```
3458
3921
  */
3459
- async initSession(xApiKey) {
3460
- // Construct params object from individual parameters
3461
- const params = {
3462
- xApiKey: xApiKey
3463
- }; // Generate request ID
3922
+ async initSession(params) {
3923
+ // Use params object (required parameters present)
3924
+ const resolvedParams = params; // Generate request ID
3464
3925
  const requestId = this._generateRequestId();
3465
3926
  // Input validation (Phase 2B: zod)
3466
3927
  if (this.sdkConfig?.validationEnabled) ;
@@ -3468,7 +3929,7 @@ class SessionWrapper {
3468
3929
  const shouldCache = true;
3469
3930
  const cache = getCache(this.sdkConfig);
3470
3931
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3471
- const cacheKey = generateCacheKey('POST', '/api/v1/session/init', params, this.sdkConfig);
3932
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
3472
3933
  const cached = cache.get(cacheKey);
3473
3934
  if (cached) {
3474
3935
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3480,12 +3941,12 @@ class SessionWrapper {
3480
3941
  request_id: requestId,
3481
3942
  method: 'POST',
3482
3943
  path: '/api/v1/session/init',
3483
- params: params,
3944
+ params: resolvedParams,
3484
3945
  action: 'initSession'
3485
3946
  });
3486
3947
  try {
3487
3948
  const response = await retryApiCall(async () => {
3488
- 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 } });
3489
3950
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3490
3951
  }, {}, this.sdkConfig);
3491
3952
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3494,9 +3955,15 @@ class SessionWrapper {
3494
3955
  throw new Error('Unexpected response shape: missing success field');
3495
3956
  }
3496
3957
  // Convert response to plain object, removing _id fields recursively
3958
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3497
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) ;
3498
3965
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3499
- const cacheKey = generateCacheKey('POST', '/api/v1/session/init', params, this.sdkConfig);
3966
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
3500
3967
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3501
3968
  }
3502
3969
  this.logger.debug('Init Session completed', {
@@ -3504,6 +3971,7 @@ class SessionWrapper {
3504
3971
  action: 'initSession'
3505
3972
  });
3506
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)
3507
3975
  return standardResponse;
3508
3976
  }
3509
3977
  catch (error) {
@@ -3577,8 +4045,8 @@ class SessionWrapper {
3577
4045
  * Start Session
3578
4046
  *
3579
4047
  * Start a session with a one-time token.
3580
- * @param OneTimeToken {string}
3581
- * @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
3582
4050
  * @returns {Promise<FinaticResponse<SessionResponseData>>} Standard response with success/Error/Warning structure
3583
4051
  *
3584
4052
  * Generated from: POST /api/v1/session/start
@@ -3587,7 +4055,7 @@ class SessionWrapper {
3587
4055
  * @example
3588
4056
  * ```typescript-client
3589
4057
  * // Example with no parameters
3590
- * const result = await finatic.startSession();
4058
+ * const result = await finatic.startSession({});
3591
4059
  *
3592
4060
  * // Access the response data
3593
4061
  * if (result.success) {
@@ -3595,12 +4063,9 @@ class SessionWrapper {
3595
4063
  * }
3596
4064
  * ```
3597
4065
  */
3598
- async startSession(OneTimeToken, body) {
3599
- // Construct params object from individual parameters
3600
- const params = {
3601
- OneTimeToken: OneTimeToken,
3602
- body: body
3603
- }; // Generate request ID
4066
+ async startSession(params) {
4067
+ // Use params object (required parameters present)
4068
+ const resolvedParams = params; // Generate request ID
3604
4069
  const requestId = this._generateRequestId();
3605
4070
  // Input validation (Phase 2B: zod)
3606
4071
  if (this.sdkConfig?.validationEnabled) ;
@@ -3608,7 +4073,7 @@ class SessionWrapper {
3608
4073
  const shouldCache = true;
3609
4074
  const cache = getCache(this.sdkConfig);
3610
4075
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3611
- const cacheKey = generateCacheKey('POST', '/api/v1/session/start', params, this.sdkConfig);
4076
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
3612
4077
  const cached = cache.get(cacheKey);
3613
4078
  if (cached) {
3614
4079
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3620,12 +4085,12 @@ class SessionWrapper {
3620
4085
  request_id: requestId,
3621
4086
  method: 'POST',
3622
4087
  path: '/api/v1/session/start',
3623
- params: params,
4088
+ params: resolvedParams,
3624
4089
  action: 'startSession'
3625
4090
  });
3626
4091
  try {
3627
4092
  const response = await retryApiCall(async () => {
3628
- 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 } });
3629
4094
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3630
4095
  }, {}, this.sdkConfig);
3631
4096
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3634,9 +4099,15 @@ class SessionWrapper {
3634
4099
  throw new Error('Unexpected response shape: missing success field');
3635
4100
  }
3636
4101
  // Convert response to plain object, removing _id fields recursively
4102
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3637
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) ;
3638
4109
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3639
- const cacheKey = generateCacheKey('POST', '/api/v1/session/start', params, this.sdkConfig);
4110
+ const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
3640
4111
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3641
4112
  }
3642
4113
  this.logger.debug('Start Session completed', {
@@ -3644,6 +4115,7 @@ class SessionWrapper {
3644
4115
  action: 'startSession'
3645
4116
  });
3646
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)
3647
4119
  return standardResponse;
3648
4120
  }
3649
4121
  catch (error) {
@@ -3720,7 +4192,7 @@ class SessionWrapper {
3720
4192
  *
3721
4193
  * The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device
3722
4194
  * that initiated the session. Device info is automatically validated from the request.
3723
- * @param No parameters required for this method
4195
+ * @param params No parameters required for this method
3724
4196
  * @returns {Promise<FinaticResponse<PortalUrlResponse>>} Standard response with success/Error/Warning structure
3725
4197
  *
3726
4198
  * Generated from: GET /api/v1/session/portal
@@ -3729,7 +4201,7 @@ class SessionWrapper {
3729
4201
  * @example
3730
4202
  * ```typescript-client
3731
4203
  * // Example with no parameters
3732
- * const result = await finatic.getPortalUrl();
4204
+ * const result = await finatic.getPortalUrl({});
3733
4205
  *
3734
4206
  * // Access the response data
3735
4207
  * if (result.success) {
@@ -3737,10 +4209,10 @@ class SessionWrapper {
3737
4209
  * }
3738
4210
  * ```
3739
4211
  */
3740
- async getPortalUrl() {
4212
+ async getPortalUrl(params) {
3741
4213
  // No parameters - use empty params object
3742
- const params = {}; // Authentication check
3743
- if (!this.sessionId) {
4214
+ const resolvedParams = params || {}; // Authentication check
4215
+ if (!this.sessionId || !this.companyId) {
3744
4216
  throw new Error('Session not initialized. Call startSession() first.');
3745
4217
  }
3746
4218
  // Generate request ID
@@ -3751,7 +4223,7 @@ class SessionWrapper {
3751
4223
  const shouldCache = true;
3752
4224
  const cache = getCache(this.sdkConfig);
3753
4225
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3754
- const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', params, this.sdkConfig);
4226
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
3755
4227
  const cached = cache.get(cacheKey);
3756
4228
  if (cached) {
3757
4229
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3763,12 +4235,12 @@ class SessionWrapper {
3763
4235
  request_id: requestId,
3764
4236
  method: 'GET',
3765
4237
  path: '/api/v1/session/portal',
3766
- params: params,
4238
+ params: resolvedParams,
3767
4239
  action: 'getPortalUrl'
3768
4240
  });
3769
4241
  try {
3770
4242
  const response = await retryApiCall(async () => {
3771
- 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 } : {}) } : {}) } });
3772
4244
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3773
4245
  }, {}, this.sdkConfig);
3774
4246
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3777,9 +4249,15 @@ class SessionWrapper {
3777
4249
  throw new Error('Unexpected response shape: missing success field');
3778
4250
  }
3779
4251
  // Convert response to plain object, removing _id fields recursively
4252
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3780
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) ;
3781
4259
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3782
- const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', params, this.sdkConfig);
4260
+ const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
3783
4261
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3784
4262
  }
3785
4263
  this.logger.debug('Get Portal Url completed', {
@@ -3787,6 +4265,7 @@ class SessionWrapper {
3787
4265
  action: 'getPortalUrl'
3788
4266
  });
3789
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)
3790
4269
  return standardResponse;
3791
4270
  }
3792
4271
  catch (error) {
@@ -3871,7 +4350,7 @@ class SessionWrapper {
3871
4350
  * - Generates fresh tokens (not returning stored ones)
3872
4351
  * - Only accessible to authenticated sessions with user_id
3873
4352
  * - Validates that header session_id matches path session_id
3874
- * @param sessionId {string}
4353
+ * @param params.sessionId {string} Session ID
3875
4354
  * @returns {Promise<FinaticResponse<SessionUserResponse>>} Standard response with success/Error/Warning structure
3876
4355
  *
3877
4356
  * Generated from: GET /api/v1/session/{session_id}/user
@@ -3880,7 +4359,9 @@ class SessionWrapper {
3880
4359
  * @example
3881
4360
  * ```typescript-client
3882
4361
  * // Minimal example with required parameters only
3883
- * const result = await finatic.getSessionUser(sessionId: 'sess_1234567890abcdef');
4362
+ * const result = await finatic.getSessionUser({
4363
+ sessionId: 'sess_1234567890abcdef'
4364
+ * });
3884
4365
  *
3885
4366
  * // Access the response data
3886
4367
  * if (result.success) {
@@ -3890,12 +4371,10 @@ class SessionWrapper {
3890
4371
  * }
3891
4372
  * ```
3892
4373
  */
3893
- async getSessionUser(sessionId) {
3894
- // Construct params object from individual parameters
3895
- const params = {
3896
- sessionId: sessionId
3897
- }; // Authentication check
3898
- 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) {
3899
4378
  throw new Error('Session not initialized. Call startSession() first.');
3900
4379
  }
3901
4380
  // Generate request ID
@@ -3906,7 +4385,7 @@ class SessionWrapper {
3906
4385
  const shouldCache = true;
3907
4386
  const cache = getCache(this.sdkConfig);
3908
4387
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3909
- 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);
3910
4389
  const cached = cache.get(cacheKey);
3911
4390
  if (cached) {
3912
4391
  this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
@@ -3918,12 +4397,12 @@ class SessionWrapper {
3918
4397
  request_id: requestId,
3919
4398
  method: 'GET',
3920
4399
  path: '/api/v1/session/{session_id}/user',
3921
- params: params,
4400
+ params: resolvedParams,
3922
4401
  action: 'getSessionUser'
3923
4402
  });
3924
4403
  try {
3925
4404
  const response = await retryApiCall(async () => {
3926
- 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 } });
3927
4406
  return await applyResponseInterceptors(apiResponse, this.sdkConfig);
3928
4407
  }, {}, this.sdkConfig);
3929
4408
  // Unwrap axios response immediately - get FinaticResponse object
@@ -3932,9 +4411,15 @@ class SessionWrapper {
3932
4411
  throw new Error('Unexpected response shape: missing success field');
3933
4412
  }
3934
4413
  // Convert response to plain object, removing _id fields recursively
4414
+ // Use 'any' for initial type to allow PaginatedData assignment, then assert final type
3935
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) ;
3936
4421
  if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
3937
- 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);
3938
4423
  cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
3939
4424
  }
3940
4425
  this.logger.debug('Get Session User completed', {
@@ -3942,6 +4427,7 @@ class SessionWrapper {
3942
4427
  action: 'getSessionUser'
3943
4428
  });
3944
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)
3945
4431
  return standardResponse;
3946
4432
  }
3947
4433
  catch (error) {
@@ -4690,8 +5176,8 @@ const SessionApiAxiosParamCreator = function (configuration) {
4690
5176
  /**
4691
5177
  * Start a session with a one-time token.
4692
5178
  * @summary Start Session
4693
- * @param {string} oneTimeToken
4694
- * @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
4695
5181
  * @param {*} [options] Override http request option.
4696
5182
  * @throws {RequiredError}
4697
5183
  */
@@ -4774,8 +5260,8 @@ const SessionApiFp = function (configuration) {
4774
5260
  /**
4775
5261
  * Start a session with a one-time token.
4776
5262
  * @summary Start Session
4777
- * @param {string} oneTimeToken
4778
- * @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
4779
5265
  * @param {*} [options] Override http request option.
4780
5266
  * @throws {RequiredError}
4781
5267
  */
@@ -6310,11 +6796,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6310
6796
  }
6311
6797
  const sessionId = data?.session_id || '';
6312
6798
  const companyId = data?.company_id || '';
6799
+ const responseUserId = data?.user_id || '';
6313
6800
  // csrf_token is not in SessionResponseData, get from response headers if available
6314
6801
  const csrfToken = data?.csrf_token || '';
6315
6802
  this.logger.debug?.('_startSession extracted data', {
6316
6803
  sessionId,
6317
6804
  companyId,
6805
+ responseUserId,
6318
6806
  csrfToken,
6319
6807
  fullData: data,
6320
6808
  dataKeys: data ? Object.keys(data) : []
@@ -6336,6 +6824,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6336
6824
  responseKeys: response ? Object.keys(response) : []
6337
6825
  });
6338
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
+ }
6339
6834
  return { session_id: sessionId, company_id: companyId };
6340
6835
  }
6341
6836
  /**
@@ -6347,28 +6842,30 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6347
6842
  *
6348
6843
  * @methodId get_portal_url_api_v1_session_portal_get
6349
6844
  * @category session
6350
- * @param theme - Optional theme preset or custom theme object
6351
- * @param brokers - Optional array of broker IDs to filter
6352
- * @param email - Optional email address
6353
- * @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')
6354
6850
  * @returns Portal URL string
6355
6851
  * @example
6356
6852
  * ```typescript-client
6357
- * 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' });
6358
6854
  * ```
6359
6855
  * @example
6360
6856
  * ```typescript-server
6361
- * 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' });
6362
6858
  * ```
6363
6859
  * @example
6364
6860
  * ```python
6365
- * 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')
6366
6862
  * ```
6367
6863
  */
6368
- async getPortalUrl(theme, brokers, email, mode) {
6864
+ async getPortalUrl(params) {
6369
6865
  if (!this.sessionId) {
6370
6866
  throw new Error('Session not initialized. Call startSession() first.');
6371
6867
  }
6868
+ const { theme, brokers, email, mode } = params || {};
6372
6869
  // Get raw portal URL from SessionApi directly (not a wrapper)
6373
6870
  const axiosResponse = await this.sessionApi.getPortalUrlApiV1SessionPortalGet({
6374
6871
  sessionId: this.sessionId,
@@ -6442,29 +6939,35 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6442
6939
  *
6443
6940
  * @methodId open_portal_client_sdk
6444
6941
  * @category session
6445
- * @param theme - Optional theme preset or custom theme object
6446
- * @param brokers - Optional array of broker IDs to filter
6447
- * @param email - Optional email address
6448
- * @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')
6449
6947
  * @param onSuccess - Optional callback when portal authentication succeeds
6450
6948
  * @param onError - Optional callback when portal authentication fails
6451
6949
  * @param onClose - Optional callback when portal is closed
6452
6950
  * @returns Promise that resolves when portal is opened
6453
6951
  * @example
6454
6952
  * ```typescript-client
6455
- * 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
+ * },
6456
6959
  * (userId) => console.log('User authenticated:', userId),
6457
6960
  * (error) => console.error('Portal error:', error),
6458
6961
  * () => console.log('Portal closed')
6459
6962
  * );
6460
6963
  * ```
6461
6964
  */
6462
- async openPortal(theme, brokers, email, mode, onSuccess, onError, onClose) {
6965
+ async openPortal(params, onSuccess, onError, onClose) {
6463
6966
  if (!this.sessionId) {
6464
6967
  throw new Error('Session not initialized. Call startSession() first.');
6465
6968
  }
6466
6969
  // Get portal URL with all parameters
6467
- const portalUrl = await this.getPortalUrl(theme, brokers, email, mode);
6970
+ const portalUrl = await this.getPortalUrl(params);
6468
6971
  // Create portal UI if not exists
6469
6972
  if (!this.portalUI) {
6470
6973
  this.portalUI = new PortalUI(this.sdkConfig.baseUrl || 'https://api.finatic.dev');
@@ -6651,7 +7154,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6651
7154
  * ```
6652
7155
  */
6653
7156
  async getCompany(params) {
6654
- return await this.company.getCompany(params?.companyId);
7157
+ return await this.company.getCompany(params);
6655
7158
  }
6656
7159
  /**
6657
7160
  * Get Brokers
@@ -6809,7 +7312,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6809
7312
  * ```
6810
7313
  */
6811
7314
  async disconnectCompanyFromBroker(params) {
6812
- return await this.brokers.disconnectCompanyFromBroker(params?.connectionId);
7315
+ return await this.brokers.disconnectCompanyFromBroker(params);
6813
7316
  }
6814
7317
  /**
6815
7318
  * Get Orders
@@ -6889,7 +7392,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6889
7392
  * ```
6890
7393
  */
6891
7394
  async getOrders(params) {
6892
- 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);
6893
7396
  }
6894
7397
  /**
6895
7398
  * Get Positions
@@ -6969,7 +7472,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
6969
7472
  * ```
6970
7473
  */
6971
7474
  async getPositions(params) {
6972
- 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);
6973
7476
  }
6974
7477
  /**
6975
7478
  * Get Balances
@@ -7049,7 +7552,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7049
7552
  * ```
7050
7553
  */
7051
7554
  async getBalances(params) {
7052
- 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);
7053
7556
  }
7054
7557
  /**
7055
7558
  * Get Accounts
@@ -7129,7 +7632,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7129
7632
  * ```
7130
7633
  */
7131
7634
  async getAccounts(params) {
7132
- 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);
7133
7636
  }
7134
7637
  /**
7135
7638
  * Get Order Fills
@@ -7217,7 +7720,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7217
7720
  * ```
7218
7721
  */
7219
7722
  async getOrderFills(params) {
7220
- return await this.brokers.getOrderFills(params?.orderId, params?.connectionId, params?.limit, params?.offset, params?.includeMetadata);
7723
+ return await this.brokers.getOrderFills(params);
7221
7724
  }
7222
7725
  /**
7223
7726
  * Get Order Events
@@ -7305,7 +7808,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7305
7808
  * ```
7306
7809
  */
7307
7810
  async getOrderEvents(params) {
7308
- return await this.brokers.getOrderEvents(params?.orderId, params?.connectionId, params?.limit, params?.offset, params?.includeMetadata);
7811
+ return await this.brokers.getOrderEvents(params);
7309
7812
  }
7310
7813
  /**
7311
7814
  * Get Order Groups
@@ -7384,7 +7887,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7384
7887
  * ```
7385
7888
  */
7386
7889
  async getOrderGroups(params) {
7387
- 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);
7388
7891
  }
7389
7892
  /**
7390
7893
  * Get Position Lots
@@ -7464,7 +7967,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7464
7967
  * ```
7465
7968
  */
7466
7969
  async getPositionLots(params) {
7467
- 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);
7468
7971
  }
7469
7972
  /**
7470
7973
  * Get Position Lot Fills
@@ -7552,7 +8055,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7552
8055
  * ```
7553
8056
  */
7554
8057
  async getPositionLotFills(params) {
7555
- return await this.brokers.getPositionLotFills(params?.lotId, params?.connectionId, params?.limit, params?.offset);
8058
+ return await this.brokers.getPositionLotFills(params);
7556
8059
  }
7557
8060
  /**
7558
8061
  * Get all Orders across all pages.
@@ -7623,7 +8126,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7623
8126
  let lastError = null;
7624
8127
  let warnings = [];
7625
8128
  while (true) {
7626
- 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 });
7627
8130
  // Collect warnings from each page
7628
8131
  if (response.warning && Array.isArray(response.warning)) {
7629
8132
  warnings.push(...response.warning);
@@ -7633,10 +8136,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7633
8136
  break;
7634
8137
  }
7635
8138
  const result = response.success?.data || [];
7636
- 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)
7637
8145
  break;
7638
- allData.push(...(Array.isArray(result) ? result : [result]));
7639
- 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)
7640
8149
  break;
7641
8150
  offset += limit;
7642
8151
  }
@@ -7728,7 +8237,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7728
8237
  let lastError = null;
7729
8238
  let warnings = [];
7730
8239
  while (true) {
7731
- 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 });
7732
8241
  // Collect warnings from each page
7733
8242
  if (response.warning && Array.isArray(response.warning)) {
7734
8243
  warnings.push(...response.warning);
@@ -7738,10 +8247,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7738
8247
  break;
7739
8248
  }
7740
8249
  const result = response.success?.data || [];
7741
- 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)
7742
8256
  break;
7743
- allData.push(...(Array.isArray(result) ? result : [result]));
7744
- 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)
7745
8260
  break;
7746
8261
  offset += limit;
7747
8262
  }
@@ -7833,7 +8348,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7833
8348
  let lastError = null;
7834
8349
  let warnings = [];
7835
8350
  while (true) {
7836
- 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 });
7837
8352
  // Collect warnings from each page
7838
8353
  if (response.warning && Array.isArray(response.warning)) {
7839
8354
  warnings.push(...response.warning);
@@ -7843,10 +8358,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7843
8358
  break;
7844
8359
  }
7845
8360
  const result = response.success?.data || [];
7846
- 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)
7847
8367
  break;
7848
- allData.push(...(Array.isArray(result) ? result : [result]));
7849
- 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)
7850
8371
  break;
7851
8372
  offset += limit;
7852
8373
  }
@@ -7938,7 +8459,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7938
8459
  let lastError = null;
7939
8460
  let warnings = [];
7940
8461
  while (true) {
7941
- 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 });
7942
8463
  // Collect warnings from each page
7943
8464
  if (response.warning && Array.isArray(response.warning)) {
7944
8465
  warnings.push(...response.warning);
@@ -7948,10 +8469,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
7948
8469
  break;
7949
8470
  }
7950
8471
  const result = response.success?.data || [];
7951
- 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)
7952
8478
  break;
7953
- allData.push(...(Array.isArray(result) ? result : [result]));
7954
- 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)
7955
8482
  break;
7956
8483
  offset += limit;
7957
8484
  }
@@ -8042,7 +8569,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8042
8569
  let lastError = null;
8043
8570
  let warnings = [];
8044
8571
  while (true) {
8045
- const response = await this.brokers.getOrderFills(filterParams?.orderId, filterParams?.connectionId, limit, offset, filterParams?.includeMetadata);
8572
+ const response = await this.brokers.getOrderFills({ ...filterParams, limit, offset });
8046
8573
  // Collect warnings from each page
8047
8574
  if (response.warning && Array.isArray(response.warning)) {
8048
8575
  warnings.push(...response.warning);
@@ -8052,10 +8579,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8052
8579
  break;
8053
8580
  }
8054
8581
  const result = response.success?.data || [];
8055
- 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)
8056
8588
  break;
8057
- allData.push(...(Array.isArray(result) ? result : [result]));
8058
- 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)
8059
8592
  break;
8060
8593
  offset += limit;
8061
8594
  }
@@ -8146,7 +8679,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8146
8679
  let lastError = null;
8147
8680
  let warnings = [];
8148
8681
  while (true) {
8149
- const response = await this.brokers.getOrderEvents(filterParams?.orderId, filterParams?.connectionId, limit, offset, filterParams?.includeMetadata);
8682
+ const response = await this.brokers.getOrderEvents({ ...filterParams, limit, offset });
8150
8683
  // Collect warnings from each page
8151
8684
  if (response.warning && Array.isArray(response.warning)) {
8152
8685
  warnings.push(...response.warning);
@@ -8156,10 +8689,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8156
8689
  break;
8157
8690
  }
8158
8691
  const result = response.success?.data || [];
8159
- 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)
8160
8698
  break;
8161
- allData.push(...(Array.isArray(result) ? result : [result]));
8162
- 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)
8163
8702
  break;
8164
8703
  offset += limit;
8165
8704
  }
@@ -8251,7 +8790,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8251
8790
  let lastError = null;
8252
8791
  let warnings = [];
8253
8792
  while (true) {
8254
- 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 });
8255
8794
  // Collect warnings from each page
8256
8795
  if (response.warning && Array.isArray(response.warning)) {
8257
8796
  warnings.push(...response.warning);
@@ -8261,10 +8800,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8261
8800
  break;
8262
8801
  }
8263
8802
  const result = response.success?.data || [];
8264
- 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)
8265
8809
  break;
8266
- allData.push(...(Array.isArray(result) ? result : [result]));
8267
- 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)
8268
8813
  break;
8269
8814
  offset += limit;
8270
8815
  }
@@ -8356,7 +8901,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8356
8901
  let lastError = null;
8357
8902
  let warnings = [];
8358
8903
  while (true) {
8359
- 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 });
8360
8905
  // Collect warnings from each page
8361
8906
  if (response.warning && Array.isArray(response.warning)) {
8362
8907
  warnings.push(...response.warning);
@@ -8366,10 +8911,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8366
8911
  break;
8367
8912
  }
8368
8913
  const result = response.success?.data || [];
8369
- 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)
8370
8920
  break;
8371
- allData.push(...(Array.isArray(result) ? result : [result]));
8372
- 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)
8373
8924
  break;
8374
8925
  offset += limit;
8375
8926
  }
@@ -8459,7 +9010,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8459
9010
  let lastError = null;
8460
9011
  let warnings = [];
8461
9012
  while (true) {
8462
- const response = await this.brokers.getPositionLotFills(filterParams?.lotId, filterParams?.connectionId, limit, offset);
9013
+ const response = await this.brokers.getPositionLotFills({ ...filterParams, limit, offset });
8463
9014
  // Collect warnings from each page
8464
9015
  if (response.warning && Array.isArray(response.warning)) {
8465
9016
  warnings.push(...response.warning);
@@ -8469,10 +9020,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
8469
9020
  break;
8470
9021
  }
8471
9022
  const result = response.success?.data || [];
8472
- 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)
8473
9029
  break;
8474
- allData.push(...(Array.isArray(result) ? result : [result]));
8475
- 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)
8476
9033
  break;
8477
9034
  offset += limit;
8478
9035
  }
@@ -8517,5 +9074,5 @@ class FinaticConnect extends FinaticConnect$1 {
8517
9074
  // Marker to verify custom class is being used
8518
9075
  FinaticConnect.__CUSTOM_CLASS__ = true;
8519
9076
 
8520
- 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 };
8521
9078
  //# sourceMappingURL=index.mjs.map