@oxyhq/core 3.4.7 → 3.4.8
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/package.json
CHANGED
package/src/HttpService.ts
CHANGED
|
@@ -756,7 +756,9 @@ export class HttpService {
|
|
|
756
756
|
* Build full URL with query params
|
|
757
757
|
*/
|
|
758
758
|
private buildURL(url: string, params?: Record<string, unknown>): string {
|
|
759
|
-
const base =
|
|
759
|
+
const base = /^https?:\/\//i.test(url)
|
|
760
|
+
? url
|
|
761
|
+
: `${this.baseURL.replace(/\/+$/, '')}/${url.replace(/^\/+/, '')}`;
|
|
760
762
|
|
|
761
763
|
if (!params || Object.keys(params).length === 0) {
|
|
762
764
|
return base;
|
|
@@ -4,6 +4,13 @@ function createServices(): OxyServices {
|
|
|
4
4
|
return new OxyServices({ baseURL: 'https://api.oxy.so' });
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
function jsonResponse(data: unknown): Response {
|
|
8
|
+
return new Response(JSON.stringify({ data }), {
|
|
9
|
+
status: 200,
|
|
10
|
+
headers: { 'content-type': 'application/json' },
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
describe('OxyServices.createLinkedClient', () => {
|
|
8
15
|
it('mirrors token changes from the session owner', () => {
|
|
9
16
|
const oxy = createServices();
|
|
@@ -89,4 +96,24 @@ describe('OxyServices.createLinkedClient', () => {
|
|
|
89
96
|
|
|
90
97
|
expect(linked.client.getAccessToken()).toBeNull();
|
|
91
98
|
});
|
|
99
|
+
|
|
100
|
+
it('joins linked base URLs with relative paths that omit the leading slash', async () => {
|
|
101
|
+
const originalFetch = globalThis.fetch;
|
|
102
|
+
const fetchMock = jest.fn(async () => jsonResponse({ ok: true }));
|
|
103
|
+
globalThis.fetch = fetchMock as unknown as typeof globalThis.fetch;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const oxy = createServices();
|
|
107
|
+
const linked = oxy.createLinkedClient({ baseURL: 'https://api.mention.earth' });
|
|
108
|
+
|
|
109
|
+
await linked.client.get('profile/settings/me');
|
|
110
|
+
|
|
111
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
112
|
+
expect(String(fetchMock.mock.calls[0]?.[0])).toBe('https://api.mention.earth/profile/settings/me');
|
|
113
|
+
|
|
114
|
+
linked.dispose();
|
|
115
|
+
} finally {
|
|
116
|
+
globalThis.fetch = originalFetch;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
92
119
|
});
|