@adaptic/utils 0.0.377 → 0.0.378

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 CHANGED
@@ -40,6 +40,54 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
40
40
 
41
41
  // Keep track of a single instance of Apollo client
42
42
  let apolloClientInstance = null;
43
+ // Track if auth has been configured
44
+ let authConfigured = false;
45
+ /**
46
+ * Configure the Apollo client authentication with a dynamic token provider.
47
+ * This should be called once during app initialization before making any
48
+ * @adaptic/backend-legacy API calls.
49
+ *
50
+ * The token provider function will be called for each GraphQL request,
51
+ * allowing for dynamic token retrieval (e.g., from session storage, SecretsManager, etc.)
52
+ *
53
+ * @param provider - Function that returns the auth token (sync or async)
54
+ *
55
+ * @example
56
+ * // Configure with an environment variable
57
+ * configureAuth(() => process.env.GRAPHQL_API_KEY || '');
58
+ *
59
+ * @example
60
+ * // Configure with NextAuth session token (async)
61
+ * configureAuth(async () => {
62
+ * const session = await auth();
63
+ * return session?.accessToken || '';
64
+ * });
65
+ *
66
+ * @example
67
+ * // Configure with SecretsManager
68
+ * configureAuth(() => {
69
+ * const secrets = getSecretsManager();
70
+ * return secrets.getGraphQLConfig().apiKey || '';
71
+ * });
72
+ */
73
+ const configureAuth = (provider) => {
74
+ if (authConfigured) {
75
+ console.warn('[adaptic] Auth provider already configured. Calling configureAuth again will reset the client.');
76
+ }
77
+ adaptic$1.setTokenProvider(provider);
78
+ authConfigured = true;
79
+ // Reset the cached client so it picks up the new auth on next request
80
+ if (apolloClientInstance) {
81
+ apolloClientInstance = null;
82
+ console.log('[adaptic] Apollo client reset due to auth configuration change');
83
+ }
84
+ };
85
+ /**
86
+ * Check if Apollo auth has been configured.
87
+ */
88
+ const isAuthConfigured = () => {
89
+ return authConfigured;
90
+ };
43
91
  /**
44
92
  * Returns a shared Apollo client instance with connection pooling.
45
93
  * This should be used for all @adaptic/backend-legacy operations.
@@ -16813,6 +16861,8 @@ const adaptic = {
16813
16861
  backend: {
16814
16862
  fetchAssetOverview: fetchAssetOverview,
16815
16863
  getApolloClient: getSharedApolloClient,
16864
+ configureAuth: configureAuth,
16865
+ isAuthConfigured: isAuthConfigured,
16816
16866
  },
16817
16867
  alpaca: {
16818
16868
  TradingAPI: AlpacaTradingAPI,