@uploadista/client-core 0.0.6 → 0.0.7

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/client-core",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "description": "Platform-agnostic core upload client logic for Uploadista",
6
6
  "license": "MIT",
7
7
  "author": "Uploadista",
@@ -26,12 +26,12 @@
26
26
  "dependencies": {
27
27
  "js-base64": "3.7.8",
28
28
  "zod": "4.1.12",
29
- "@uploadista/core": "0.0.6"
29
+ "@uploadista/core": "0.0.7"
30
30
  },
31
31
  "devDependencies": {
32
32
  "tsdown": "0.15.9",
33
33
  "vitest": "3.2.4",
34
- "@uploadista/typescript-config": "0.0.6"
34
+ "@uploadista/typescript-config": "0.0.7"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsdown",
@@ -1,10 +1,10 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { HttpClient } from "../../http-client";
2
+ import type { HttpClient } from "../../services";
3
3
  import { AuthHttpClient } from "../auth-http-client";
4
4
  import { DirectAuthManager } from "../direct-auth";
5
5
  import { NoAuthManager } from "../no-auth";
6
- import { SaasAuthManager } from "../saas-auth";
7
- import type { DirectAuthConfig, SaasAuthConfig } from "../types";
6
+ import type { DirectAuthConfig, UploadistaCloudAuthConfig } from "../types";
7
+ import { UploadistaCloudAuthManager } from "../uploadista-cloud-auth";
8
8
 
9
9
  // Mock fetch globally
10
10
  global.fetch = vi.fn();
@@ -74,10 +74,10 @@ describe("AuthHttpClient", () => {
74
74
 
75
75
  expect(mockHttpClient.request).toHaveBeenCalledWith(
76
76
  "https://api.example.com/upload",
77
- {
77
+ expect.objectContaining({
78
78
  method: "POST",
79
79
  headers: { "Content-Type": "application/json" },
80
- },
80
+ }),
81
81
  );
82
82
  });
83
83
  });
@@ -100,13 +100,13 @@ describe("AuthHttpClient", () => {
100
100
 
101
101
  expect(mockHttpClient.request).toHaveBeenCalledWith(
102
102
  "https://api.example.com/upload",
103
- {
103
+ expect.objectContaining({
104
104
  method: "POST",
105
- headers: {
105
+ headers: expect.objectContaining({
106
106
  "Content-Type": "application/json",
107
107
  Authorization: "Bearer direct-token",
108
- },
109
- },
108
+ }),
109
+ }),
110
110
  );
111
111
  });
112
112
 
@@ -125,27 +125,72 @@ describe("AuthHttpClient", () => {
125
125
 
126
126
  expect(mockHttpClient.request).toHaveBeenCalledWith(
127
127
  "https://api.example.com/upload",
128
- {
128
+ expect.objectContaining({
129
129
  headers: { Authorization: "Bearer async-token" },
130
- },
130
+ }),
131
131
  );
132
132
  });
133
133
  });
134
134
 
135
- describe("with SaasAuthManager", () => {
136
- it("should attach JWT token from SaasAuthManager", async () => {
137
- const config: SaasAuthConfig = {
138
- mode: "saas",
135
+ describe("with UploadistaCloudAuthManager", () => {
136
+ let uploadAuthMockHttpClient: HttpClient;
137
+
138
+ beforeEach(() => {
139
+ // Create a separate mock HTTP client for auth requests
140
+ uploadAuthMockHttpClient = {
141
+ request: vi.fn(),
142
+ getMetrics: vi.fn(() => ({
143
+ activeConnections: 0,
144
+ totalConnections: 0,
145
+ reuseRate: 0,
146
+ averageConnectionTime: 0,
147
+ })),
148
+ getDetailedMetrics: vi.fn(() => ({
149
+ activeConnections: 0,
150
+ totalConnections: 0,
151
+ reuseRate: 0,
152
+ averageConnectionTime: 0,
153
+ health: {
154
+ status: "healthy" as const,
155
+ score: 100,
156
+ issues: [],
157
+ recommendations: [],
158
+ },
159
+ requestsPerSecond: 0,
160
+ errorRate: 0,
161
+ timeouts: 0,
162
+ retries: 0,
163
+ fastConnections: 0,
164
+ slowConnections: 0,
165
+ http2Info: {
166
+ supported: true,
167
+ detected: false,
168
+ version: "h2",
169
+ multiplexingActive: false,
170
+ },
171
+ })),
172
+ reset: vi.fn(),
173
+ close: vi.fn(async () => {}),
174
+ warmupConnections: vi.fn(async () => {}),
175
+ };
176
+ });
177
+
178
+ it("should attach JWT token from UploadistaCloudAuthManager", async () => {
179
+ const config: UploadistaCloudAuthConfig = {
180
+ mode: "uploadista-cloud",
139
181
  authServerUrl: "https://auth.example.com/token",
140
- getCredentials: () => ({ username: "user", password: "pass" }),
182
+ clientId: "client-id-123",
141
183
  };
142
184
 
143
- vi.mocked(global.fetch).mockResolvedValueOnce({
185
+ vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
144
186
  ok: true,
145
187
  json: async () => ({ token: "jwt-token-123" }),
146
- } as Response);
188
+ } as any);
147
189
 
148
- const authManager = new SaasAuthManager(config);
190
+ const authManager = new UploadistaCloudAuthManager(
191
+ config,
192
+ uploadAuthMockHttpClient,
193
+ );
149
194
  const authClient = new AuthHttpClient(mockHttpClient, authManager);
150
195
 
151
196
  await authClient.request("https://api.example.com/upload", {
@@ -155,29 +200,32 @@ describe("AuthHttpClient", () => {
155
200
 
156
201
  expect(mockHttpClient.request).toHaveBeenCalledWith(
157
202
  "https://api.example.com/upload",
158
- {
203
+ expect.objectContaining({
159
204
  method: "POST",
160
- headers: {
205
+ headers: expect.objectContaining({
161
206
  "Content-Type": "application/json",
162
207
  Authorization: "Bearer jwt-token-123",
163
- },
164
- },
208
+ }),
209
+ }),
165
210
  );
166
211
  });
167
212
 
168
213
  it("should extract job ID from upload URL", async () => {
169
- const config: SaasAuthConfig = {
170
- mode: "saas",
214
+ const config: UploadistaCloudAuthConfig = {
215
+ mode: "uploadista-cloud",
171
216
  authServerUrl: "https://auth.example.com/token",
172
- getCredentials: () => ({ username: "user", password: "pass" }),
217
+ clientId: "client-id-123",
173
218
  };
174
219
 
175
- vi.mocked(global.fetch).mockResolvedValueOnce({
220
+ vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
176
221
  ok: true,
177
222
  json: async () => ({ token: "jwt-token-for-upload-123" }),
178
- } as Response);
223
+ } as any);
179
224
 
180
- const authManager = new SaasAuthManager(config);
225
+ const authManager = new UploadistaCloudAuthManager(
226
+ config,
227
+ uploadAuthMockHttpClient,
228
+ );
181
229
  const authClient = new AuthHttpClient(mockHttpClient, authManager);
182
230
 
183
231
  await authClient.request(
@@ -191,18 +239,21 @@ describe("AuthHttpClient", () => {
191
239
  });
192
240
 
193
241
  it("should extract job ID from flow URL", async () => {
194
- const config: SaasAuthConfig = {
195
- mode: "saas",
242
+ const config: UploadistaCloudAuthConfig = {
243
+ mode: "uploadista-cloud",
196
244
  authServerUrl: "https://auth.example.com/token",
197
- getCredentials: () => ({ username: "user", password: "pass" }),
245
+ clientId: "client-id-123",
198
246
  };
199
247
 
200
- vi.mocked(global.fetch).mockResolvedValueOnce({
248
+ vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
201
249
  ok: true,
202
250
  json: async () => ({ token: "jwt-token-for-flow-456" }),
203
- } as Response);
251
+ } as any);
204
252
 
205
- const authManager = new SaasAuthManager(config);
253
+ const authManager = new UploadistaCloudAuthManager(
254
+ config,
255
+ uploadAuthMockHttpClient,
256
+ );
206
257
  const authClient = new AuthHttpClient(mockHttpClient, authManager);
207
258
 
208
259
  await authClient.request(
@@ -216,18 +267,21 @@ describe("AuthHttpClient", () => {
216
267
  });
217
268
 
218
269
  it("should extract job ID from jobs URL", async () => {
219
- const config: SaasAuthConfig = {
220
- mode: "saas",
270
+ const config: UploadistaCloudAuthConfig = {
271
+ mode: "uploadista-cloud",
221
272
  authServerUrl: "https://auth.example.com/token",
222
- getCredentials: () => ({ username: "user", password: "pass" }),
273
+ clientId: "client-id-123",
223
274
  };
224
275
 
225
- vi.mocked(global.fetch).mockResolvedValueOnce({
276
+ vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
226
277
  ok: true,
227
278
  json: async () => ({ token: "jwt-token-for-job-789" }),
228
- } as Response);
279
+ } as any);
229
280
 
230
- const authManager = new SaasAuthManager(config);
281
+ const authManager = new UploadistaCloudAuthManager(
282
+ config,
283
+ uploadAuthMockHttpClient,
284
+ );
231
285
  const authClient = new AuthHttpClient(mockHttpClient, authManager);
232
286
 
233
287
  await authClient.request(
@@ -1,35 +1,70 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import { SaasAuthManager } from "../saas-auth";
3
- import type { SaasAuthConfig } from "../types";
2
+ import type { HttpClient } from "../../services";
3
+ import type { UploadistaCloudAuthConfig } from "../types";
4
+ import { UploadistaCloudAuthManager } from "../uploadista-cloud-auth";
4
5
 
5
- // Mock fetch globally
6
- global.fetch = vi.fn();
6
+ describe("UploadistaCloudAuthManager", () => {
7
+ let mockHttpClient: HttpClient;
7
8
 
8
- describe("SaasAuthManager", () => {
9
9
  beforeEach(() => {
10
10
  vi.clearAllMocks();
11
+
12
+ // Create mock HTTP client
13
+ mockHttpClient = {
14
+ request: vi.fn(),
15
+ getMetrics: vi.fn(() => ({
16
+ activeConnections: 0,
17
+ totalConnections: 0,
18
+ reuseRate: 0,
19
+ averageConnectionTime: 0,
20
+ })),
21
+ getDetailedMetrics: vi.fn(() => ({
22
+ activeConnections: 0,
23
+ totalConnections: 0,
24
+ reuseRate: 0,
25
+ averageConnectionTime: 0,
26
+ health: {
27
+ status: "healthy" as const,
28
+ score: 100,
29
+ issues: [],
30
+ recommendations: [],
31
+ },
32
+ requestsPerSecond: 0,
33
+ errorRate: 0,
34
+ timeouts: 0,
35
+ retries: 0,
36
+ fastConnections: 0,
37
+ slowConnections: 0,
38
+ http2Info: {
39
+ supported: true,
40
+ detected: false,
41
+ version: "h2",
42
+ multiplexingActive: false,
43
+ },
44
+ })),
45
+ reset: vi.fn(),
46
+ close: vi.fn(async () => {}),
47
+ warmupConnections: vi.fn(async () => {}),
48
+ };
11
49
  });
12
50
 
13
51
  describe("fetchToken", () => {
14
52
  it("should fetch token from auth server", async () => {
15
- const config: SaasAuthConfig = {
16
- mode: "saas",
53
+ const config: UploadistaCloudAuthConfig = {
54
+ mode: "uploadista-cloud",
17
55
  authServerUrl: "https://auth.example.com/token",
18
- getCredentials: () => ({
19
- username: "user",
20
- password: "pass",
21
- }),
56
+ clientId: "client-id-123",
22
57
  };
23
58
 
24
- vi.mocked(global.fetch).mockResolvedValueOnce({
59
+ vi.mocked(mockHttpClient.request).mockResolvedValueOnce({
25
60
  ok: true,
26
61
  json: async () => ({
27
62
  token: "jwt-token-123",
28
63
  expiresIn: 3600,
29
64
  }),
30
- });
65
+ } as any);
31
66
 
32
- const manager = new SaasAuthManager(config);
67
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
33
68
  const result = await manager.fetchToken();
34
69
 
35
70
  expect(result).toEqual({
@@ -37,48 +72,50 @@ describe("SaasAuthManager", () => {
37
72
  expiresIn: 3600,
38
73
  });
39
74
 
40
- expect(global.fetch).toHaveBeenCalledWith(
41
- "https://auth.example.com/token",
75
+ expect(mockHttpClient.request).toHaveBeenCalledWith(
76
+ "https://auth.example.com/token/client-id-123",
42
77
  {
43
- method: "POST",
78
+ method: "GET",
44
79
  headers: {
45
80
  "Content-Type": "application/json",
46
81
  },
47
- body: JSON.stringify({ username: "user", password: "pass" }),
48
82
  },
49
83
  );
50
84
  });
51
85
 
52
86
  it("should handle auth server errors", async () => {
53
- const config: SaasAuthConfig = {
54
- mode: "saas",
87
+ const config: UploadistaCloudAuthConfig = {
88
+ mode: "uploadista-cloud",
55
89
  authServerUrl: "https://auth.example.com/token",
56
- getCredentials: () => ({ username: "user", password: "wrong" }),
90
+ clientId: "client-id-123",
57
91
  };
58
92
 
59
- vi.mocked(global.fetch).mockResolvedValueOnce({
93
+ vi.mocked(mockHttpClient.request).mockResolvedValueOnce({
60
94
  ok: false,
61
95
  status: 401,
96
+ statusText: "Unauthorized",
62
97
  text: async () => JSON.stringify({ error: "Invalid credentials" }),
63
- });
98
+ } as any);
64
99
 
65
- const manager = new SaasAuthManager(config);
100
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
66
101
 
67
102
  await expect(manager.fetchToken()).rejects.toThrow(
68
- "Failed to fetch auth token: Invalid credentials",
103
+ "Failed to fetch auth token",
69
104
  );
70
105
  });
71
106
 
72
107
  it("should handle network errors", async () => {
73
- const config: SaasAuthConfig = {
74
- mode: "saas",
108
+ const config: UploadistaCloudAuthConfig = {
109
+ mode: "uploadista-cloud",
75
110
  authServerUrl: "https://auth.example.com/token",
76
- getCredentials: () => ({ username: "user", password: "pass" }),
111
+ clientId: "client-id-123",
77
112
  };
78
113
 
79
- vi.mocked(global.fetch).mockRejectedValueOnce(new Error("Network error"));
114
+ vi.mocked(mockHttpClient.request).mockRejectedValueOnce(
115
+ new Error("Network error"),
116
+ );
80
117
 
81
- const manager = new SaasAuthManager(config);
118
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
82
119
 
83
120
  await expect(manager.fetchToken()).rejects.toThrow(
84
121
  "Failed to fetch auth token: Network error",
@@ -86,18 +123,18 @@ describe("SaasAuthManager", () => {
86
123
  });
87
124
 
88
125
  it("should validate token response format", async () => {
89
- const config: SaasAuthConfig = {
90
- mode: "saas",
126
+ const config: UploadistaCloudAuthConfig = {
127
+ mode: "uploadista-cloud",
91
128
  authServerUrl: "https://auth.example.com/token",
92
- getCredentials: () => ({ username: "user", password: "pass" }),
129
+ clientId: "client-id-123",
93
130
  };
94
131
 
95
- vi.mocked(global.fetch).mockResolvedValueOnce({
132
+ vi.mocked(mockHttpClient.request).mockResolvedValueOnce({
96
133
  ok: true,
97
134
  json: async () => ({ noToken: "here" }), // Missing token field
98
- });
135
+ } as any);
99
136
 
100
- const manager = new SaasAuthManager(config);
137
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
101
138
 
102
139
  await expect(manager.fetchToken()).rejects.toThrow(
103
140
  "Auth server response missing 'token' field",
@@ -107,18 +144,18 @@ describe("SaasAuthManager", () => {
107
144
 
108
145
  describe("attachToken", () => {
109
146
  it("should attach token as Bearer header", async () => {
110
- const config: SaasAuthConfig = {
111
- mode: "saas",
147
+ const config: UploadistaCloudAuthConfig = {
148
+ mode: "uploadista-cloud",
112
149
  authServerUrl: "https://auth.example.com/token",
113
- getCredentials: () => ({ username: "user", password: "pass" }),
150
+ clientId: "client-id-123",
114
151
  };
115
152
 
116
- vi.mocked(global.fetch).mockResolvedValueOnce({
153
+ vi.mocked(mockHttpClient.request).mockResolvedValueOnce({
117
154
  ok: true,
118
155
  json: async () => ({ token: "jwt-token-123" }),
119
- });
156
+ } as any);
120
157
 
121
- const manager = new SaasAuthManager(config);
158
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
122
159
  const result = await manager.attachToken({
123
160
  "Content-Type": "application/json",
124
161
  });
@@ -130,46 +167,46 @@ describe("SaasAuthManager", () => {
130
167
  });
131
168
 
132
169
  it("should cache token and reuse it", async () => {
133
- const config: SaasAuthConfig = {
134
- mode: "saas",
170
+ const config: UploadistaCloudAuthConfig = {
171
+ mode: "uploadista-cloud",
135
172
  authServerUrl: "https://auth.example.com/token",
136
- getCredentials: () => ({ username: "user", password: "pass" }),
173
+ clientId: "client-id-123",
137
174
  };
138
175
 
139
- vi.mocked(global.fetch).mockResolvedValueOnce({
176
+ vi.mocked(mockHttpClient.request).mockResolvedValueOnce({
140
177
  ok: true,
141
178
  json: async () => ({ token: "jwt-token-123" }),
142
- });
179
+ } as any);
143
180
 
144
- const manager = new SaasAuthManager(config);
181
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
145
182
 
146
183
  // First call - should fetch token
147
184
  await manager.attachToken();
148
- expect(global.fetch).toHaveBeenCalledTimes(1);
185
+ expect(mockHttpClient.request).toHaveBeenCalledTimes(1);
149
186
 
150
187
  // Second call - should use cached token
151
188
  await manager.attachToken();
152
- expect(global.fetch).toHaveBeenCalledTimes(1); // Still 1, not 2
189
+ expect(mockHttpClient.request).toHaveBeenCalledTimes(1); // Still 1, not 2
153
190
  });
154
191
 
155
192
  it("should cache tokens per job ID", async () => {
156
- const config: SaasAuthConfig = {
157
- mode: "saas",
193
+ const config: UploadistaCloudAuthConfig = {
194
+ mode: "uploadista-cloud",
158
195
  authServerUrl: "https://auth.example.com/token",
159
- getCredentials: () => ({ username: "user", password: "pass" }),
196
+ clientId: "client-id-123",
160
197
  };
161
198
 
162
- vi.mocked(global.fetch)
199
+ vi.mocked(mockHttpClient.request)
163
200
  .mockResolvedValueOnce({
164
201
  ok: true,
165
202
  json: async () => ({ token: "jwt-token-1" }),
166
- })
203
+ } as any)
167
204
  .mockResolvedValueOnce({
168
205
  ok: true,
169
206
  json: async () => ({ token: "jwt-token-2" }),
170
- });
207
+ } as any);
171
208
 
172
- const manager = new SaasAuthManager(config);
209
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
173
210
 
174
211
  // Fetch token for job 1
175
212
  const result1 = await manager.attachToken({}, "job-1");
@@ -184,31 +221,31 @@ describe("SaasAuthManager", () => {
184
221
  expect(result3.Authorization).toBe("Bearer jwt-token-1");
185
222
 
186
223
  // Should have fetched twice (once per job)
187
- expect(global.fetch).toHaveBeenCalledTimes(2);
224
+ expect(mockHttpClient.request).toHaveBeenCalledTimes(2);
188
225
  });
189
226
 
190
227
  it("should refetch expired tokens", async () => {
191
- const config: SaasAuthConfig = {
192
- mode: "saas",
228
+ const config: UploadistaCloudAuthConfig = {
229
+ mode: "uploadista-cloud",
193
230
  authServerUrl: "https://auth.example.com/token",
194
- getCredentials: () => ({ username: "user", password: "pass" }),
231
+ clientId: "client-id-123",
195
232
  };
196
233
 
197
234
  // First token expires in 1 second
198
- vi.mocked(global.fetch)
235
+ vi.mocked(mockHttpClient.request)
199
236
  .mockResolvedValueOnce({
200
237
  ok: true,
201
238
  json: async () => ({
202
239
  token: "jwt-token-old",
203
240
  expiresIn: 0.001, // Expires very soon
204
241
  }),
205
- })
242
+ } as any)
206
243
  .mockResolvedValueOnce({
207
244
  ok: true,
208
245
  json: async () => ({ token: "jwt-token-new" }),
209
- });
246
+ } as any);
210
247
 
211
- const manager = new SaasAuthManager(config);
248
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
212
249
 
213
250
  // First call - fetch initial token
214
251
  await manager.attachToken();
@@ -219,66 +256,66 @@ describe("SaasAuthManager", () => {
219
256
  // Second call - should fetch new token because old one expired
220
257
  const result = await manager.attachToken();
221
258
  expect(result.Authorization).toBe("Bearer jwt-token-new");
222
- expect(global.fetch).toHaveBeenCalledTimes(2);
259
+ expect(mockHttpClient.request).toHaveBeenCalledTimes(2);
223
260
  });
224
261
  });
225
262
 
226
263
  describe("clearToken", () => {
227
264
  it("should clear cached token for specific job", async () => {
228
- const config: SaasAuthConfig = {
229
- mode: "saas",
265
+ const config: UploadistaCloudAuthConfig = {
266
+ mode: "uploadista-cloud",
230
267
  authServerUrl: "https://auth.example.com/token",
231
- getCredentials: () => ({ username: "user", password: "pass" }),
268
+ clientId: "client-id-123",
232
269
  };
233
270
 
234
- vi.mocked(global.fetch)
271
+ vi.mocked(mockHttpClient.request)
235
272
  .mockResolvedValueOnce({
236
273
  ok: true,
237
274
  json: async () => ({ token: "jwt-token-1" }),
238
- })
275
+ } as any)
239
276
  .mockResolvedValueOnce({
240
277
  ok: true,
241
278
  json: async () => ({ token: "jwt-token-2" }),
242
- });
279
+ } as any);
243
280
 
244
- const manager = new SaasAuthManager(config);
281
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
245
282
 
246
283
  // Cache token for job
247
284
  await manager.attachToken({}, "job-1");
248
- expect(global.fetch).toHaveBeenCalledTimes(1);
285
+ expect(mockHttpClient.request).toHaveBeenCalledTimes(1);
249
286
 
250
287
  // Clear token
251
288
  manager.clearToken("job-1");
252
289
 
253
290
  // Next call should fetch new token
254
291
  await manager.attachToken({}, "job-1");
255
- expect(global.fetch).toHaveBeenCalledTimes(2);
292
+ expect(mockHttpClient.request).toHaveBeenCalledTimes(2);
256
293
  });
257
294
  });
258
295
 
259
296
  describe("clearAllTokens", () => {
260
297
  it("should clear all cached tokens", async () => {
261
- const config: SaasAuthConfig = {
262
- mode: "saas",
298
+ const config: UploadistaCloudAuthConfig = {
299
+ mode: "uploadista-cloud",
263
300
  authServerUrl: "https://auth.example.com/token",
264
- getCredentials: () => ({ username: "user", password: "pass" }),
301
+ clientId: "client-id-123",
265
302
  };
266
303
 
267
- vi.mocked(global.fetch)
304
+ vi.mocked(mockHttpClient.request)
268
305
  .mockResolvedValueOnce({
269
306
  ok: true,
270
307
  json: async () => ({ token: "jwt-token-1" }),
271
- })
308
+ } as any)
272
309
  .mockResolvedValueOnce({
273
310
  ok: true,
274
311
  json: async () => ({ token: "jwt-token-2" }),
275
- })
312
+ } as any)
276
313
  .mockResolvedValueOnce({
277
314
  ok: true,
278
315
  json: async () => ({ token: "jwt-token-3" }),
279
- });
316
+ } as any);
280
317
 
281
- const manager = new SaasAuthManager(config);
318
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
282
319
 
283
320
  // Cache tokens for multiple jobs
284
321
  await manager.attachToken({}, "job-1");
@@ -289,33 +326,33 @@ describe("SaasAuthManager", () => {
289
326
 
290
327
  // Next calls should fetch new tokens
291
328
  await manager.attachToken();
292
- expect(global.fetch).toHaveBeenCalledTimes(3);
329
+ expect(mockHttpClient.request).toHaveBeenCalledTimes(3);
293
330
  });
294
331
  });
295
332
 
296
333
  describe("getCacheStats", () => {
297
334
  it("should return cache statistics", async () => {
298
- const config: SaasAuthConfig = {
299
- mode: "saas",
335
+ const config: UploadistaCloudAuthConfig = {
336
+ mode: "uploadista-cloud",
300
337
  authServerUrl: "https://auth.example.com/token",
301
- getCredentials: () => ({ username: "user", password: "pass" }),
338
+ clientId: "client-id-123",
302
339
  };
303
340
 
304
- vi.mocked(global.fetch)
341
+ vi.mocked(mockHttpClient.request)
305
342
  .mockResolvedValueOnce({
306
343
  ok: true,
307
344
  json: async () => ({ token: "jwt-token-1" }),
308
- })
345
+ } as any)
309
346
  .mockResolvedValueOnce({
310
347
  ok: true,
311
348
  json: async () => ({ token: "jwt-token-2" }),
312
- })
349
+ } as any)
313
350
  .mockResolvedValueOnce({
314
351
  ok: true,
315
352
  json: async () => ({ token: "jwt-token-3" }),
316
- });
353
+ } as any);
317
354
 
318
- const manager = new SaasAuthManager(config);
355
+ const manager = new UploadistaCloudAuthManager(config, mockHttpClient);
319
356
 
320
357
  // Initially empty
321
358
  expect(manager.getCacheStats()).toEqual({