@adaptic/utils 0.0.960 → 0.0.961
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.cjs +20 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +21 -3
- package/dist/index.mjs.map +1 -1
- package/dist/types/adaptic.d.ts +9 -0
- package/dist/types/adaptic.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/price-utils.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import adaptic$1, { setTokenProvider, getApolloClient } from '@adaptic/backend-legacy';
|
|
1
|
+
import adaptic$1, { stopClient, setTokenProvider, getApolloClient } from '@adaptic/backend-legacy';
|
|
2
2
|
import { format, sub, set, add, startOfDay, endOfDay, isBefore, differenceInMilliseconds } from 'date-fns';
|
|
3
3
|
import { formatInTimeZone, toZonedTime, fromZonedTime } from 'date-fns-tz';
|
|
4
4
|
import require$$0$4, { EventEmitter } from 'events';
|
|
@@ -307,6 +307,22 @@ const fetchAssetOverview = async (symbol) => {
|
|
|
307
307
|
};
|
|
308
308
|
}
|
|
309
309
|
};
|
|
310
|
+
/**
|
|
311
|
+
* Gracefully disconnects the shared Apollo client and releases its resources.
|
|
312
|
+
* Call this during process shutdown to close keep-alive HTTP connections
|
|
313
|
+
* and drain in-flight operations.
|
|
314
|
+
*
|
|
315
|
+
* After calling `disconnectClient()`, the next call to `getSharedApolloClient()`
|
|
316
|
+
* will create a fresh instance.
|
|
317
|
+
*/
|
|
318
|
+
const disconnectClient = () => {
|
|
319
|
+
if (apolloClientInstance) {
|
|
320
|
+
apolloClientInstance = null;
|
|
321
|
+
getLogger().info("[adaptic] Shared Apollo client reference cleared");
|
|
322
|
+
}
|
|
323
|
+
// Delegate to backend-legacy's stopClient() which calls .stop() on the underlying singleton
|
|
324
|
+
stopClient();
|
|
325
|
+
};
|
|
310
326
|
|
|
311
327
|
const ANSI_BACKGROUND_OFFSET = 10;
|
|
312
328
|
|
|
@@ -8838,10 +8854,11 @@ const calculateFees = async (action, trade, alpacaAccount) => {
|
|
|
8838
8854
|
};
|
|
8839
8855
|
const computeTotalFees = async (trade) => {
|
|
8840
8856
|
let totalFees = 0;
|
|
8841
|
-
//
|
|
8857
|
+
// Use the shared singleton Apollo client to avoid creating orphaned connections
|
|
8858
|
+
const client = await getSharedApolloClient();
|
|
8842
8859
|
const alpacaAccount = (await adaptic$1.alpacaAccount.get({
|
|
8843
8860
|
id: trade.alpacaAccountId,
|
|
8844
|
-
}));
|
|
8861
|
+
}, client));
|
|
8845
8862
|
if (!alpacaAccount)
|
|
8846
8863
|
return totalFees;
|
|
8847
8864
|
const feePromises = trade?.actions?.map((action) => calculateFees(action, trade, alpacaAccount));
|
|
@@ -67896,6 +67913,7 @@ const adaptic = {
|
|
|
67896
67913
|
getApolloClient: getSharedApolloClient,
|
|
67897
67914
|
configureAuth: configureAuth,
|
|
67898
67915
|
isAuthConfigured: isAuthConfigured,
|
|
67916
|
+
disconnectClient: disconnectClient,
|
|
67899
67917
|
},
|
|
67900
67918
|
alpaca: {
|
|
67901
67919
|
// New SDK-based client factory (RECOMMENDED)
|