@oxyhq/core 3.4.18 → 3.5.0

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.
@@ -103,6 +103,7 @@ class HttpService {
103
103
  this.tokenRefreshPromise = null;
104
104
  this.tokenRefreshCooldownUntil = 0;
105
105
  this.authRefreshHandler = null;
106
+ this.accessTokenProvider = null;
106
107
  /**
107
108
  * Fan-out listeners notified on EVERY access-token change on this instance:
108
109
  * explicit `setTokens`, `clearTokens`, an AuthManager-owned refresh, and the
@@ -133,6 +134,24 @@ class HttpService {
133
134
  this.deduplicator = new requestUtils_1.RequestDeduplicator();
134
135
  this.requestQueue = new requestUtils_1.RequestQueue(config.maxConcurrentRequests || 10, config.requestQueueSize || 100);
135
136
  }
137
+ syncAccessTokenFromProvider() {
138
+ if (!this.accessTokenProvider) {
139
+ return this.tokenStore.getAccessToken();
140
+ }
141
+ const providedToken = this.accessTokenProvider();
142
+ const currentToken = this.tokenStore.getAccessToken();
143
+ if (providedToken) {
144
+ if (providedToken !== currentToken) {
145
+ this.tokenStore.setTokens(providedToken);
146
+ this.notifyTokenChange();
147
+ }
148
+ return providedToken;
149
+ }
150
+ if (currentToken) {
151
+ this.clearTokens();
152
+ }
153
+ return null;
154
+ }
136
155
  /**
137
156
  * Robust FormData detection that works in browser, React Native, and
138
157
  * Node.js polyfill environments.
@@ -688,7 +707,7 @@ class HttpService {
688
707
  * Get auth header with automatic token refresh
689
708
  */
690
709
  async getAuthHeader() {
691
- const accessToken = this.tokenStore.getAccessToken();
710
+ const accessToken = this.syncAccessTokenFromProvider();
692
711
  if (!accessToken) {
693
712
  return null;
694
713
  }
@@ -806,6 +825,9 @@ class HttpService {
806
825
  setAuthRefreshHandler(handler) {
807
826
  this.authRefreshHandler = handler;
808
827
  }
828
+ setAccessTokenProvider(provider) {
829
+ this.accessTokenProvider = provider;
830
+ }
809
831
  clearTokens() {
810
832
  this.tokenStore.clearTokens();
811
833
  this.tokenStore.clearCsrfToken();
@@ -113,12 +113,10 @@ class OxyServicesBase {
113
113
  };
114
114
  syncToken(this.getAccessToken());
115
115
  const unsubscribe = this.onTokensChanged(syncToken);
116
+ client.setAccessTokenProvider(() => this.getAccessToken());
116
117
  client.setAuthRefreshHandler(async (reason) => {
117
118
  const refreshed = await this.httpService.refreshAccessToken(reason);
118
119
  if (!refreshed) {
119
- if (reason === 'response-401') {
120
- this.clearTokens();
121
- }
122
120
  return null;
123
121
  }
124
122
  syncToken(refreshed);
@@ -129,6 +127,7 @@ class OxyServicesBase {
129
127
  dispose: () => {
130
128
  unsubscribe();
131
129
  client.setAuthRefreshHandler(null);
130
+ client.setAccessTokenProvider(null);
132
131
  client.clearTokens();
133
132
  },
134
133
  };
@@ -331,6 +331,25 @@ function OxyServicesUserMixin(Base) {
331
331
  throw this.handleError(error);
332
332
  }
333
333
  }
334
+ /**
335
+ * Follow multiple users in a single request.
336
+ *
337
+ * POSTs `/users/follow/bulk` with `{ userIds }` (server caps the batch at
338
+ * 200). Returns the per-user outcomes and the count of users newly
339
+ * followed. An empty `userIds` array resolves immediately with an empty
340
+ * result and performs no network call.
341
+ */
342
+ async followUsers(userIds) {
343
+ if (userIds.length === 0) {
344
+ return { results: [], followedCount: 0 };
345
+ }
346
+ try {
347
+ return await this.makeRequest('POST', '/users/follow/bulk', { userIds }, { cache: false });
348
+ }
349
+ catch (error) {
350
+ throw this.handleError(error);
351
+ }
352
+ }
334
353
  /**
335
354
  * Unfollow a user
336
355
  */