@oxyhq/core 3.7.1 → 3.8.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 +52 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/mixins/OxyServices.user.js +52 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/mixins/OxyServices.user.d.ts +21 -0
- package/package.json +1 -1
- package/src/mixins/OxyServices.user.ts +60 -0
|
@@ -5,6 +5,11 @@ import { SignatureService } from '../crypto/signatureService.js';
|
|
|
5
5
|
import { normalizeUserIdentity, normalizeUserIdentityOrNull } from '../utils/userIdentity.js';
|
|
6
6
|
import { logger } from '../utils/loggerUtils.js';
|
|
7
7
|
import { extractErrorStatus } from '../utils/errorUtils.js';
|
|
8
|
+
/**
|
|
9
|
+
* Maximum number of ids sent per `POST /users/by-ids` request. Matches the
|
|
10
|
+
* server-side batch cap; larger inputs are split into multiple chunked calls.
|
|
11
|
+
*/
|
|
12
|
+
const USERS_BY_IDS_CHUNK_SIZE = 100;
|
|
8
13
|
export function OxyServicesUserMixin(Base) {
|
|
9
14
|
return class extends Base {
|
|
10
15
|
constructor(...args) {
|
|
@@ -213,6 +218,53 @@ export function OxyServicesUserMixin(Base) {
|
|
|
213
218
|
throw this.handleError(error);
|
|
214
219
|
}
|
|
215
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Fetch many users by id in one round-trip per chunk.
|
|
223
|
+
*
|
|
224
|
+
* Built for feed/hydration call sites that would otherwise issue one
|
|
225
|
+
* `getUserById` request per unique author (the classic M+1). Ids are
|
|
226
|
+
* deduplicated and validated (empty/blank ids dropped) before being split
|
|
227
|
+
* into chunks of {@link USERS_BY_IDS_CHUNK_SIZE} and POSTed to
|
|
228
|
+
* `/users/by-ids` as `{ ids }`. The server returns the matched users as a
|
|
229
|
+
* flat `User[]` (order is not guaranteed and the caller is expected to map
|
|
230
|
+
* by `id`); each is run through `normalizeUserIdentity`, matching
|
|
231
|
+
* `getUserById`.
|
|
232
|
+
*
|
|
233
|
+
* Resilience: chunks are independent. A failed chunk is logged and skipped
|
|
234
|
+
* — the method returns every user that resolved successfully rather than
|
|
235
|
+
* discarding the whole call on one chunk's failure. An empty/whitespace-only
|
|
236
|
+
* input resolves immediately with `[]` and performs no network call.
|
|
237
|
+
*
|
|
238
|
+
* Not cached at the SDK layer: the response is keyed on a multi-id POST body
|
|
239
|
+
* (low hit rate) and the backend maintains its own per-id Redis cache.
|
|
240
|
+
*/
|
|
241
|
+
async getUsersByIds(ids) {
|
|
242
|
+
const uniqueIds = Array.from(new Set(ids.filter((id) => typeof id === 'string' && id.trim().length > 0)));
|
|
243
|
+
if (uniqueIds.length === 0) {
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
const chunks = [];
|
|
247
|
+
for (let i = 0; i < uniqueIds.length; i += USERS_BY_IDS_CHUNK_SIZE) {
|
|
248
|
+
chunks.push(uniqueIds.slice(i, i + USERS_BY_IDS_CHUNK_SIZE));
|
|
249
|
+
}
|
|
250
|
+
// Run chunks concurrently; a single chunk failure must not sink the rest.
|
|
251
|
+
const settled = await Promise.all(chunks.map(async (chunk) => {
|
|
252
|
+
try {
|
|
253
|
+
const users = await this.makeRequest('POST', '/users/by-ids', { ids: chunk }, { cache: false });
|
|
254
|
+
return Array.isArray(users) ? users.map((user) => normalizeUserIdentity(user)) : [];
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
logger.warn('getUsersByIds: chunk failed, continuing with remaining chunks', {
|
|
258
|
+
method: 'getUsersByIds',
|
|
259
|
+
chunkSize: chunk.length,
|
|
260
|
+
status: extractErrorStatus(error),
|
|
261
|
+
error: error instanceof Error ? error.message : String(error),
|
|
262
|
+
});
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
return settled.flat();
|
|
267
|
+
}
|
|
216
268
|
/**
|
|
217
269
|
* Get current user
|
|
218
270
|
*/
|