@oxyhq/core 3.4.19 → 3.6.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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/mixins/OxyServices.user.js +63 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/mixins/OxyServices.user.js +63 -3
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mixins/OxyServices.user.d.ts +58 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/mixins/OxyServices.user.ts +99 -3
- package/src/mixins/__tests__/followCacheInvalidation.test.ts +168 -0
|
@@ -321,11 +321,68 @@ function OxyServicesUserMixin(Base) {
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
324
|
-
* Follow a user
|
|
324
|
+
* Follow a user.
|
|
325
|
+
*
|
|
326
|
+
* Invalidates the cached `GET /users/<id>/follow-status` response after
|
|
327
|
+
* the write. `getFollowStatus` caches for ~1 minute (identity-scoped);
|
|
328
|
+
* without busting that entry, a `FollowButton` that remounts within the
|
|
329
|
+
* TTL window re-reads the STALE pre-write status and reverts the optimistic
|
|
330
|
+
* UI (the "follow resets after navigating away and back" bug).
|
|
331
|
+
* `clearCacheEntry` deletes every identity-scoped variant of the key.
|
|
325
332
|
*/
|
|
326
333
|
async followUser(userId) {
|
|
327
334
|
try {
|
|
328
|
-
|
|
335
|
+
const result = await this.makeRequest('POST', `/users/${userId}/follow`, undefined, { cache: false });
|
|
336
|
+
this.clearCacheEntry(`GET:/users/${userId}/follow-status`);
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
throw this.handleError(error);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Follow multiple users in a single request.
|
|
345
|
+
*
|
|
346
|
+
* POSTs `/users/follow/bulk` with `{ userIds }` (server caps the batch at
|
|
347
|
+
* 200). Returns the per-user outcomes and the count of users newly
|
|
348
|
+
* followed. An empty `userIds` array resolves immediately with an empty
|
|
349
|
+
* result and performs no network call.
|
|
350
|
+
*/
|
|
351
|
+
async followUsers(userIds) {
|
|
352
|
+
if (userIds.length === 0) {
|
|
353
|
+
return { results: [], followedCount: 0 };
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const result = await this.makeRequest('POST', '/users/follow/bulk', { userIds }, { cache: false });
|
|
357
|
+
// Bust each affected user's cached follow-status (see `followUser`).
|
|
358
|
+
for (const id of userIds) {
|
|
359
|
+
this.clearCacheEntry(`GET:/users/${id}/follow-status`);
|
|
360
|
+
}
|
|
361
|
+
return result;
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
throw this.handleError(error);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Unfollow multiple users in a single request.
|
|
369
|
+
*
|
|
370
|
+
* POSTs `/users/unfollow/bulk` with `{ userIds }` (server caps the batch at
|
|
371
|
+
* 200). Returns the per-user outcomes and the count of users newly
|
|
372
|
+
* unfollowed. An empty `userIds` array resolves immediately with an empty
|
|
373
|
+
* result and performs no network call.
|
|
374
|
+
*/
|
|
375
|
+
async unfollowUsers(userIds) {
|
|
376
|
+
if (userIds.length === 0) {
|
|
377
|
+
return { results: [], unfollowedCount: 0 };
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
const result = await this.makeRequest('POST', '/users/unfollow/bulk', { userIds }, { cache: false });
|
|
381
|
+
// Bust each affected user's cached follow-status (see `followUser`).
|
|
382
|
+
for (const id of userIds) {
|
|
383
|
+
this.clearCacheEntry(`GET:/users/${id}/follow-status`);
|
|
384
|
+
}
|
|
385
|
+
return result;
|
|
329
386
|
}
|
|
330
387
|
catch (error) {
|
|
331
388
|
throw this.handleError(error);
|
|
@@ -336,7 +393,10 @@ function OxyServicesUserMixin(Base) {
|
|
|
336
393
|
*/
|
|
337
394
|
async unfollowUser(userId) {
|
|
338
395
|
try {
|
|
339
|
-
|
|
396
|
+
const result = await this.makeRequest('DELETE', `/users/${userId}/follow`, undefined, { cache: false });
|
|
397
|
+
// Bust the cached follow-status so a remount reads fresh truth (see `followUser`).
|
|
398
|
+
this.clearCacheEntry(`GET:/users/${userId}/follow-status`);
|
|
399
|
+
return result;
|
|
340
400
|
}
|
|
341
401
|
catch (error) {
|
|
342
402
|
throw this.handleError(error);
|