@oxyhq/core 3.17.0 → 3.17.1

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.
@@ -37,11 +37,15 @@ export declare function OxyServicesLinksMixin<T extends typeof OxyServicesBase>(
37
37
  * Resolve multiple link previews via `POST /links/previews` (body `{ urls }`).
38
38
  *
39
39
  * Inputs are de-duplicated and split into chunks of {@link LINK_PREVIEWS_CHUNK_SIZE}
40
- * (the server-side cap). Chunks run concurrently and their `data` maps are
40
+ * (the server-side cap). Chunks run concurrently and their result maps are
41
41
  * merged into a single result keyed by the REQUESTED url (the exact string
42
42
  * passed in `urls`) — matching the batch contract — so a caller can always
43
43
  * look its own input back up.
44
44
  *
45
+ * `makeRequest` unwraps the API's top-level `{ data }` envelope (same as
46
+ * `getUsersByIds`'s `makeServiceRequest<User[]>`), so each chunk response is
47
+ * already the `Record<url, LinkPreview>` map — merge it directly.
48
+ *
45
49
  * An empty / whitespace-only input resolves immediately with `{}` and
46
50
  * performs no network call. A failure in any chunk surfaces (via
47
51
  * `handleError`) rather than being swallowed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/core",
3
- "version": "3.17.0",
3
+ "version": "3.17.1",
4
4
  "description": "OxyHQ SDK Foundation — API client, authentication, cryptographic identity, and shared utilities",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -15,7 +15,7 @@
15
15
  * later read, so an SDK GET cache would pin the stale `'pending'` snapshot.
16
16
  * App-side caching (React Query / stores) owns this responsibility.
17
17
  */
18
- import type { LinkPreview, LinkPreviewBatchResponse } from '@oxyhq/contracts';
18
+ import type { LinkPreview } from '@oxyhq/contracts';
19
19
  import type { OxyServicesBase } from '../OxyServices.base';
20
20
  import { buildUrl } from '../utils/apiUtils';
21
21
 
@@ -57,11 +57,15 @@ export function OxyServicesLinksMixin<T extends typeof OxyServicesBase>(Base: T)
57
57
  * Resolve multiple link previews via `POST /links/previews` (body `{ urls }`).
58
58
  *
59
59
  * Inputs are de-duplicated and split into chunks of {@link LINK_PREVIEWS_CHUNK_SIZE}
60
- * (the server-side cap). Chunks run concurrently and their `data` maps are
60
+ * (the server-side cap). Chunks run concurrently and their result maps are
61
61
  * merged into a single result keyed by the REQUESTED url (the exact string
62
62
  * passed in `urls`) — matching the batch contract — so a caller can always
63
63
  * look its own input back up.
64
64
  *
65
+ * `makeRequest` unwraps the API's top-level `{ data }` envelope (same as
66
+ * `getUsersByIds`'s `makeServiceRequest<User[]>`), so each chunk response is
67
+ * already the `Record<url, LinkPreview>` map — merge it directly.
68
+ *
65
69
  * An empty / whitespace-only input resolves immediately with `{}` and
66
70
  * performs no network call. A failure in any chunk surfaces (via
67
71
  * `handleError`) rather than being swallowed.
@@ -82,7 +86,7 @@ export function OxyServicesLinksMixin<T extends typeof OxyServicesBase>(Base: T)
82
86
  try {
83
87
  const responses = await Promise.all(
84
88
  chunks.map((chunk) =>
85
- this.makeRequest<LinkPreviewBatchResponse>(
89
+ this.makeRequest<Record<string, LinkPreview>>(
86
90
  'POST',
87
91
  '/links/previews',
88
92
  { urls: chunk },
@@ -92,7 +96,7 @@ export function OxyServicesLinksMixin<T extends typeof OxyServicesBase>(Base: T)
92
96
  );
93
97
 
94
98
  return responses.reduce<Record<string, LinkPreview>>(
95
- (merged, response) => Object.assign(merged, response?.data ?? {}),
99
+ (merged, response) => Object.assign(merged, response ?? {}),
96
100
  {},
97
101
  );
98
102
  } catch (error) {
@@ -11,7 +11,7 @@
11
11
  * `data` map keyed by the requested url, and surfaces a chunk failure.
12
12
  */
13
13
 
14
- import type { LinkPreview, LinkPreviewBatchResponse } from '@oxyhq/contracts';
14
+ import type { LinkPreview } from '@oxyhq/contracts';
15
15
  import { OxyServices } from '../../OxyServices';
16
16
 
17
17
  const sampleResolved: LinkPreview = {
@@ -82,10 +82,10 @@ describe('OxyServices.links', () => {
82
82
  });
83
83
 
84
84
  it('de-duplicates and sends a single chunk for <= 50 unique URLs', async () => {
85
- const response: LinkPreviewBatchResponse = {
86
- data: { 'https://a.test/': sampleResolved },
87
- };
88
- makeRequestSpy.mockResolvedValueOnce(response);
85
+ // makeRequest unwraps the API's `{ data }` envelope, so the resolved value
86
+ // is the bare record (NOT `{ data: {...} }`) mirror that real shape here.
87
+ const record: Record<string, LinkPreview> = { 'https://a.test/': sampleResolved };
88
+ makeRequestSpy.mockResolvedValueOnce(record);
89
89
 
90
90
  const result = await oxy.getLinkPreviews([
91
91
  'https://a.test/',
@@ -93,7 +93,7 @@ describe('OxyServices.links', () => {
93
93
  ' ', // dropped
94
94
  ]);
95
95
 
96
- expect(result).toEqual(response.data);
96
+ expect(result).toEqual(record);
97
97
  expect(makeRequestSpy).toHaveBeenCalledTimes(1);
98
98
  expect(makeRequestSpy).toHaveBeenCalledWith(
99
99
  'POST',
@@ -111,13 +111,13 @@ describe('OxyServices.links', () => {
111
111
  _method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
112
112
  _url: string,
113
113
  data?: { urls: string[] },
114
- ): Promise<LinkPreviewBatchResponse> => {
114
+ ): Promise<Record<string, LinkPreview>> => {
115
115
  const chunkUrls = data?.urls ?? [];
116
116
  const dataMap: Record<string, LinkPreview> = {};
117
117
  for (const u of chunkUrls) {
118
118
  dataMap[u] = { url: u, status: 'resolved', title: `t-${u}` };
119
119
  }
120
- return { data: dataMap };
120
+ return dataMap;
121
121
  },
122
122
  );
123
123