@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/dist/index.d.ts +53 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/auth/__tests__/auth-http-client.test.ts +95 -41
- package/src/auth/__tests__/{saas-auth.test.ts → uploadista-cloud-auth.test.ts} +129 -92
- package/src/auth/auth-http-client.ts +10 -7
- package/src/auth/index.ts +1 -1
- package/src/auth/types.ts +9 -14
- package/src/auth/{saas-auth.ts → uploadista-cloud-auth.ts} +5 -5
- package/src/client/create-uploadista-client.ts +44 -13
- package/src/client/uploadista-api.ts +97 -12
- package/src/error.ts +3 -1
- package/src/upload/flow-upload.ts +2 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadista/client-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
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.
|
|
29
|
+
"@uploadista/core": "0.0.8"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"tsdown": "0.15.
|
|
33
|
-
"vitest": "
|
|
34
|
-
"@uploadista/typescript-config": "0.0.
|
|
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 "../../
|
|
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 {
|
|
7
|
-
import
|
|
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
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
182
|
+
clientId: "client-id-123",
|
|
141
183
|
};
|
|
142
184
|
|
|
143
|
-
vi.mocked(
|
|
185
|
+
vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
|
|
144
186
|
ok: true,
|
|
145
187
|
json: async () => ({ token: "jwt-token-123" }),
|
|
146
|
-
} as
|
|
188
|
+
} as any);
|
|
147
189
|
|
|
148
|
-
const authManager = new
|
|
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:
|
|
170
|
-
mode: "
|
|
214
|
+
const config: UploadistaCloudAuthConfig = {
|
|
215
|
+
mode: "uploadista-cloud",
|
|
171
216
|
authServerUrl: "https://auth.example.com/token",
|
|
172
|
-
|
|
217
|
+
clientId: "client-id-123",
|
|
173
218
|
};
|
|
174
219
|
|
|
175
|
-
vi.mocked(
|
|
220
|
+
vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
|
|
176
221
|
ok: true,
|
|
177
222
|
json: async () => ({ token: "jwt-token-for-upload-123" }),
|
|
178
|
-
} as
|
|
223
|
+
} as any);
|
|
179
224
|
|
|
180
|
-
const authManager = new
|
|
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:
|
|
195
|
-
mode: "
|
|
242
|
+
const config: UploadistaCloudAuthConfig = {
|
|
243
|
+
mode: "uploadista-cloud",
|
|
196
244
|
authServerUrl: "https://auth.example.com/token",
|
|
197
|
-
|
|
245
|
+
clientId: "client-id-123",
|
|
198
246
|
};
|
|
199
247
|
|
|
200
|
-
vi.mocked(
|
|
248
|
+
vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
|
|
201
249
|
ok: true,
|
|
202
250
|
json: async () => ({ token: "jwt-token-for-flow-456" }),
|
|
203
|
-
} as
|
|
251
|
+
} as any);
|
|
204
252
|
|
|
205
|
-
const authManager = new
|
|
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:
|
|
220
|
-
mode: "
|
|
270
|
+
const config: UploadistaCloudAuthConfig = {
|
|
271
|
+
mode: "uploadista-cloud",
|
|
221
272
|
authServerUrl: "https://auth.example.com/token",
|
|
222
|
-
|
|
273
|
+
clientId: "client-id-123",
|
|
223
274
|
};
|
|
224
275
|
|
|
225
|
-
vi.mocked(
|
|
276
|
+
vi.mocked(uploadAuthMockHttpClient.request).mockResolvedValueOnce({
|
|
226
277
|
ok: true,
|
|
227
278
|
json: async () => ({ token: "jwt-token-for-job-789" }),
|
|
228
|
-
} as
|
|
279
|
+
} as any);
|
|
229
280
|
|
|
230
|
-
const authManager = new
|
|
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(
|