@oxyhq/core 3.4.6 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/core",
3
- "version": "3.4.6",
3
+ "version": "3.4.8",
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",
@@ -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 = url.startsWith('http') ? url : `${this.baseURL}${url}`;
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;
@@ -151,6 +151,13 @@ export class OxyServicesBase {
151
151
  const unsubscribe = this.onTokensChanged(syncToken);
152
152
  client.setAuthRefreshHandler(async (reason: AuthRefreshReason) => {
153
153
  const refreshed = await this.httpService.refreshAccessToken(reason);
154
+ if (!refreshed) {
155
+ if (reason === 'response-401') {
156
+ this.clearTokens();
157
+ }
158
+ return null;
159
+ }
160
+
154
161
  syncToken(refreshed);
155
162
  return refreshed;
156
163
  });
@@ -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();
@@ -49,6 +56,34 @@ describe('OxyServices.createLinkedClient', () => {
49
56
  linked.dispose();
50
57
  });
51
58
 
59
+ it('clears the session owner when a linked response 401 cannot refresh', async () => {
60
+ const oxy = createServices();
61
+ oxy.setTokens('stale_access');
62
+ const linked = oxy.createLinkedClient({ baseURL: 'https://api.syra.fm' });
63
+
64
+ const refreshed = await linked.client.refreshAccessToken('response-401');
65
+
66
+ expect(refreshed).toBeNull();
67
+ expect(oxy.getAccessToken()).toBeNull();
68
+ expect(linked.client.getAccessToken()).toBeNull();
69
+
70
+ linked.dispose();
71
+ });
72
+
73
+ it('keeps the session owner intact when linked preflight refresh cannot refresh', async () => {
74
+ const oxy = createServices();
75
+ oxy.setTokens('existing_access');
76
+ const linked = oxy.createLinkedClient({ baseURL: 'https://api.syra.fm' });
77
+
78
+ const refreshed = await linked.client.refreshAccessToken('preflight');
79
+
80
+ expect(refreshed).toBeNull();
81
+ expect(oxy.getAccessToken()).toBe('existing_access');
82
+ expect(linked.client.getAccessToken()).toBe('existing_access');
83
+
84
+ linked.dispose();
85
+ });
86
+
52
87
  it('stops mirroring after dispose', () => {
53
88
  const oxy = createServices();
54
89
  const linked = oxy.createLinkedClient({ baseURL: 'https://api.syra.fm' });
@@ -61,4 +96,24 @@ describe('OxyServices.createLinkedClient', () => {
61
96
 
62
97
  expect(linked.client.getAccessToken()).toBeNull();
63
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
+ });
64
119
  });