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