@uploadista/client-core 0.0.6 → 0.0.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/client-core",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
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.8"
30
30
  },
31
31
  "devDependencies": {
32
- "tsdown": "0.15.9",
33
- "vitest": "3.2.4",
34
- "@uploadista/typescript-config": "0.0.6"
32
+ "tsdown": "0.15.10",
33
+ "vitest": "4.0.3",
34
+ "@uploadista/typescript-config": "0.0.8"
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(