@uploadista/client-core 0.0.3 → 0.0.6
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 +2674 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -12
- package/dist/index.js.map +1 -0
- package/package.json +21 -8
- package/tsdown.config.ts +11 -0
- package/.turbo/turbo-build.log +0 -5
- package/dist/auth/auth-http-client.d.ts +0 -50
- package/dist/auth/auth-http-client.d.ts.map +0 -1
- package/dist/auth/auth-http-client.js +0 -110
- package/dist/auth/direct-auth.d.ts +0 -38
- package/dist/auth/direct-auth.d.ts.map +0 -1
- package/dist/auth/direct-auth.js +0 -95
- package/dist/auth/index.d.ts +0 -6
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -5
- package/dist/auth/no-auth.d.ts +0 -26
- package/dist/auth/no-auth.d.ts.map +0 -1
- package/dist/auth/no-auth.js +0 -33
- package/dist/auth/saas-auth.d.ts +0 -80
- package/dist/auth/saas-auth.d.ts.map +0 -1
- package/dist/auth/saas-auth.js +0 -167
- package/dist/auth/types.d.ts +0 -101
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -8
- package/dist/chunk-buffer.d.ts +0 -209
- package/dist/chunk-buffer.d.ts.map +0 -1
- package/dist/chunk-buffer.js +0 -236
- package/dist/client/create-uploadista-client.d.ts +0 -369
- package/dist/client/create-uploadista-client.d.ts.map +0 -1
- package/dist/client/create-uploadista-client.js +0 -518
- package/dist/client/index.d.ts +0 -4
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -3
- package/dist/client/uploadista-api.d.ts +0 -284
- package/dist/client/uploadista-api.d.ts.map +0 -1
- package/dist/client/uploadista-api.js +0 -444
- package/dist/client/uploadista-websocket-manager.d.ts +0 -110
- package/dist/client/uploadista-websocket-manager.d.ts.map +0 -1
- package/dist/client/uploadista-websocket-manager.js +0 -207
- package/dist/error.d.ts +0 -106
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -69
- package/dist/logger.d.ts +0 -70
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -59
- package/dist/mock-data-store.d.ts +0 -30
- package/dist/mock-data-store.d.ts.map +0 -1
- package/dist/mock-data-store.js +0 -88
- package/dist/network-monitor.d.ts +0 -262
- package/dist/network-monitor.d.ts.map +0 -1
- package/dist/network-monitor.js +0 -291
- package/dist/services/abort-controller-service.d.ts +0 -19
- package/dist/services/abort-controller-service.d.ts.map +0 -1
- package/dist/services/abort-controller-service.js +0 -4
- package/dist/services/checksum-service.d.ts +0 -4
- package/dist/services/checksum-service.d.ts.map +0 -1
- package/dist/services/checksum-service.js +0 -1
- package/dist/services/file-reader-service.d.ts +0 -38
- package/dist/services/file-reader-service.d.ts.map +0 -1
- package/dist/services/file-reader-service.js +0 -4
- package/dist/services/fingerprint-service.d.ts +0 -4
- package/dist/services/fingerprint-service.d.ts.map +0 -1
- package/dist/services/fingerprint-service.js +0 -1
- package/dist/services/http-client.d.ts +0 -182
- package/dist/services/http-client.d.ts.map +0 -1
- package/dist/services/http-client.js +0 -1
- package/dist/services/id-generation-service.d.ts +0 -10
- package/dist/services/id-generation-service.d.ts.map +0 -1
- package/dist/services/id-generation-service.js +0 -1
- package/dist/services/index.d.ts +0 -11
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/index.js +0 -10
- package/dist/services/platform-service.d.ts +0 -48
- package/dist/services/platform-service.d.ts.map +0 -1
- package/dist/services/platform-service.js +0 -10
- package/dist/services/service-container.d.ts +0 -25
- package/dist/services/service-container.d.ts.map +0 -1
- package/dist/services/service-container.js +0 -1
- package/dist/services/storage-service.d.ts +0 -26
- package/dist/services/storage-service.d.ts.map +0 -1
- package/dist/services/storage-service.js +0 -1
- package/dist/services/websocket-service.d.ts +0 -36
- package/dist/services/websocket-service.d.ts.map +0 -1
- package/dist/services/websocket-service.js +0 -4
- package/dist/smart-chunker.d.ts +0 -72
- package/dist/smart-chunker.d.ts.map +0 -1
- package/dist/smart-chunker.js +0 -317
- package/dist/storage/client-storage.d.ts +0 -148
- package/dist/storage/client-storage.d.ts.map +0 -1
- package/dist/storage/client-storage.js +0 -62
- package/dist/storage/in-memory-storage-service.d.ts +0 -7
- package/dist/storage/in-memory-storage-service.d.ts.map +0 -1
- package/dist/storage/in-memory-storage-service.js +0 -24
- package/dist/storage/index.d.ts +0 -3
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js +0 -2
- package/dist/types/buffered-chunk.d.ts +0 -6
- package/dist/types/buffered-chunk.d.ts.map +0 -1
- package/dist/types/buffered-chunk.js +0 -1
- package/dist/types/chunk-metrics.d.ts +0 -12
- package/dist/types/chunk-metrics.d.ts.map +0 -1
- package/dist/types/chunk-metrics.js +0 -1
- package/dist/types/flow-result.d.ts +0 -11
- package/dist/types/flow-result.d.ts.map +0 -1
- package/dist/types/flow-result.js +0 -1
- package/dist/types/flow-upload-config.d.ts +0 -54
- package/dist/types/flow-upload-config.d.ts.map +0 -1
- package/dist/types/flow-upload-config.js +0 -1
- package/dist/types/flow-upload-item.d.ts +0 -16
- package/dist/types/flow-upload-item.d.ts.map +0 -1
- package/dist/types/flow-upload-item.js +0 -1
- package/dist/types/flow-upload-options.d.ts +0 -41
- package/dist/types/flow-upload-options.d.ts.map +0 -1
- package/dist/types/flow-upload-options.js +0 -1
- package/dist/types/index.d.ts +0 -14
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -13
- package/dist/types/multi-flow-upload-options.d.ts +0 -33
- package/dist/types/multi-flow-upload-options.d.ts.map +0 -1
- package/dist/types/multi-flow-upload-options.js +0 -1
- package/dist/types/multi-flow-upload-state.d.ts +0 -9
- package/dist/types/multi-flow-upload-state.d.ts.map +0 -1
- package/dist/types/multi-flow-upload-state.js +0 -1
- package/dist/types/performance-insights.d.ts +0 -11
- package/dist/types/performance-insights.d.ts.map +0 -1
- package/dist/types/performance-insights.js +0 -1
- package/dist/types/previous-upload.d.ts +0 -20
- package/dist/types/previous-upload.d.ts.map +0 -1
- package/dist/types/previous-upload.js +0 -9
- package/dist/types/upload-options.d.ts +0 -40
- package/dist/types/upload-options.d.ts.map +0 -1
- package/dist/types/upload-options.js +0 -1
- package/dist/types/upload-response.d.ts +0 -6
- package/dist/types/upload-response.d.ts.map +0 -1
- package/dist/types/upload-response.js +0 -1
- package/dist/types/upload-result.d.ts +0 -57
- package/dist/types/upload-result.d.ts.map +0 -1
- package/dist/types/upload-result.js +0 -1
- package/dist/types/upload-session-metrics.d.ts +0 -16
- package/dist/types/upload-session-metrics.d.ts.map +0 -1
- package/dist/types/upload-session-metrics.js +0 -1
- package/dist/upload/chunk-upload.d.ts +0 -40
- package/dist/upload/chunk-upload.d.ts.map +0 -1
- package/dist/upload/chunk-upload.js +0 -82
- package/dist/upload/flow-upload.d.ts +0 -48
- package/dist/upload/flow-upload.d.ts.map +0 -1
- package/dist/upload/flow-upload.js +0 -240
- package/dist/upload/index.d.ts +0 -3
- package/dist/upload/index.d.ts.map +0 -1
- package/dist/upload/index.js +0 -2
- package/dist/upload/parallel-upload.d.ts +0 -65
- package/dist/upload/parallel-upload.d.ts.map +0 -1
- package/dist/upload/parallel-upload.js +0 -231
- package/dist/upload/single-upload.d.ts +0 -118
- package/dist/upload/single-upload.d.ts.map +0 -1
- package/dist/upload/single-upload.js +0 -332
- package/dist/upload/upload-manager.d.ts +0 -30
- package/dist/upload/upload-manager.d.ts.map +0 -1
- package/dist/upload/upload-manager.js +0 -57
- package/dist/upload/upload-metrics.d.ts +0 -37
- package/dist/upload/upload-metrics.d.ts.map +0 -1
- package/dist/upload/upload-metrics.js +0 -236
- package/dist/upload/upload-storage.d.ts +0 -32
- package/dist/upload/upload-storage.d.ts.map +0 -1
- package/dist/upload/upload-storage.js +0 -46
- package/dist/upload/upload-strategy.d.ts +0 -66
- package/dist/upload/upload-strategy.d.ts.map +0 -1
- package/dist/upload/upload-strategy.js +0 -171
- package/dist/upload/upload-utils.d.ts +0 -26
- package/dist/upload/upload-utils.d.ts.map +0 -1
- package/dist/upload/upload-utils.js +0 -80
- package/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -1,27 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadista/client-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"description": "Platform-agnostic core upload client logic for Uploadista",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Uploadista",
|
|
8
8
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./types": {
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
15
|
+
"import": "./dist/types/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./services": {
|
|
18
|
+
"types": "./dist/services/index.d.ts",
|
|
19
|
+
"import": "./dist/services/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./upload": {
|
|
22
|
+
"types": "./dist/upload/index.d.ts",
|
|
23
|
+
"import": "./dist/upload/index.js"
|
|
24
|
+
}
|
|
13
25
|
},
|
|
14
26
|
"dependencies": {
|
|
15
27
|
"js-base64": "3.7.8",
|
|
16
28
|
"zod": "4.1.12",
|
|
17
|
-
"@uploadista/core": "0.0.
|
|
29
|
+
"@uploadista/core": "0.0.6"
|
|
18
30
|
},
|
|
19
31
|
"devDependencies": {
|
|
32
|
+
"tsdown": "0.15.9",
|
|
20
33
|
"vitest": "3.2.4",
|
|
21
|
-
"@uploadista/typescript-config": "0.0.
|
|
34
|
+
"@uploadista/typescript-config": "0.0.6"
|
|
22
35
|
},
|
|
23
36
|
"scripts": {
|
|
24
|
-
"build": "
|
|
37
|
+
"build": "tsdown",
|
|
25
38
|
"format": "biome format --write ./src",
|
|
26
39
|
"lint": "biome lint --write ./src",
|
|
27
40
|
"check": "biome check --write ./src"
|
package/tsdown.config.ts
ADDED
package/.turbo/turbo-build.log
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { HttpClient, HttpRequestOptions, HttpResponse } from "../services/http-client";
|
|
2
|
-
import type { DirectAuthManager } from "./direct-auth";
|
|
3
|
-
import type { NoAuthManager } from "./no-auth";
|
|
4
|
-
import type { SaasAuthManager } from "./saas-auth";
|
|
5
|
-
/**
|
|
6
|
-
* Union type of all auth managers
|
|
7
|
-
*/
|
|
8
|
-
export type AuthManager = DirectAuthManager | SaasAuthManager | NoAuthManager;
|
|
9
|
-
/**
|
|
10
|
-
* Auth-aware HTTP client wrapper.
|
|
11
|
-
*
|
|
12
|
-
* Wraps a standard HttpClient and automatically attaches authentication
|
|
13
|
-
* credentials/tokens to all HTTP requests based on the configured auth manager.
|
|
14
|
-
*
|
|
15
|
-
* The wrapper delegates all non-auth concerns (connection pooling, metrics, etc.)
|
|
16
|
-
* to the underlying HttpClient and only adds the auth layer on top.
|
|
17
|
-
*/
|
|
18
|
-
export declare class AuthHttpClient implements HttpClient {
|
|
19
|
-
private httpClient;
|
|
20
|
-
private authManager;
|
|
21
|
-
constructor(httpClient: HttpClient, authManager: AuthManager);
|
|
22
|
-
/**
|
|
23
|
-
* Make an HTTP request with authentication credentials attached.
|
|
24
|
-
* Calls the auth manager to attach credentials before delegating to the underlying client.
|
|
25
|
-
*/
|
|
26
|
-
request(url: string, options?: HttpRequestOptions): Promise<HttpResponse>;
|
|
27
|
-
/**
|
|
28
|
-
* Attach authentication credentials to request headers.
|
|
29
|
-
* Delegates to the appropriate auth manager method.
|
|
30
|
-
*/
|
|
31
|
-
private attachAuthCredentials;
|
|
32
|
-
/**
|
|
33
|
-
* Extract job ID from URL for SaaS mode token caching.
|
|
34
|
-
* Looks for patterns like /upload/{id} or /jobs/{id} in the URL.
|
|
35
|
-
*/
|
|
36
|
-
private extractJobIdFromUrl;
|
|
37
|
-
/**
|
|
38
|
-
* Delegate metrics methods to underlying HTTP client
|
|
39
|
-
*/
|
|
40
|
-
getMetrics(): import("..").ConnectionMetrics;
|
|
41
|
-
getDetailedMetrics(): import("..").DetailedConnectionMetrics;
|
|
42
|
-
reset(): void;
|
|
43
|
-
close(): Promise<void>;
|
|
44
|
-
warmupConnections(urls: string[]): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Get the underlying auth manager for advanced use cases
|
|
47
|
-
*/
|
|
48
|
-
getAuthManager(): AuthManager;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=auth-http-client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-http-client.d.ts","sourceRoot":"","sources":["../../src/auth/auth-http-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,YAAY,EACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,iBAAiB,GAAG,eAAe,GAAG,aAAa,CAAC;AAE9E;;;;;;;;GAQG;AACH,qBAAa,cAAe,YAAW,UAAU;IAE7C,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,WAAW;gBADX,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW;IAGlC;;;OAGG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,YAAY,CAAC;IA8BxB;;;OAGG;YACW,qBAAqB;IAoBnC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IA0B3B;;OAEG;IACH,UAAU;IAIV,kBAAkB;IAIlB,KAAK;IAIC,KAAK;IAIL,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE;IAItC;;OAEG;IACH,cAAc,IAAI,WAAW;CAG9B"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth-aware HTTP client wrapper.
|
|
3
|
-
*
|
|
4
|
-
* Wraps a standard HttpClient and automatically attaches authentication
|
|
5
|
-
* credentials/tokens to all HTTP requests based on the configured auth manager.
|
|
6
|
-
*
|
|
7
|
-
* The wrapper delegates all non-auth concerns (connection pooling, metrics, etc.)
|
|
8
|
-
* to the underlying HttpClient and only adds the auth layer on top.
|
|
9
|
-
*/
|
|
10
|
-
export class AuthHttpClient {
|
|
11
|
-
constructor(httpClient, authManager) {
|
|
12
|
-
this.httpClient = httpClient;
|
|
13
|
-
this.authManager = authManager;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Make an HTTP request with authentication credentials attached.
|
|
17
|
-
* Calls the auth manager to attach credentials before delegating to the underlying client.
|
|
18
|
-
*/
|
|
19
|
-
async request(url, options = {}) {
|
|
20
|
-
try {
|
|
21
|
-
// Attach auth credentials to request headers
|
|
22
|
-
const authenticatedHeaders = await this.attachAuthCredentials(options.headers || {}, url);
|
|
23
|
-
// Delegate to underlying HTTP client with authenticated headers
|
|
24
|
-
return await this.httpClient.request(url, {
|
|
25
|
-
...options,
|
|
26
|
-
headers: authenticatedHeaders,
|
|
27
|
-
// include credentials for cors if needed
|
|
28
|
-
credentials: this.authManager.getType() === "no-auth" ||
|
|
29
|
-
this.authManager.getType() === "saas"
|
|
30
|
-
? "omit"
|
|
31
|
-
: (options.credentials ?? "include"),
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
// If auth fails, wrap error with context
|
|
36
|
-
if (error instanceof Error && error.message.includes("auth")) {
|
|
37
|
-
throw error; // Re-throw auth errors as-is
|
|
38
|
-
}
|
|
39
|
-
// For other errors, let them propagate
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Attach authentication credentials to request headers.
|
|
45
|
-
* Delegates to the appropriate auth manager method.
|
|
46
|
-
*/
|
|
47
|
-
async attachAuthCredentials(headers, url) {
|
|
48
|
-
// Check if this is a DirectAuthManager or SaasAuthManager
|
|
49
|
-
if ("attachCredentials" in this.authManager) {
|
|
50
|
-
// DirectAuthManager or NoAuthManager
|
|
51
|
-
return await this.authManager.attachCredentials(headers);
|
|
52
|
-
}
|
|
53
|
-
if ("attachToken" in this.authManager) {
|
|
54
|
-
// SaasAuthManager - extract job ID from URL if present
|
|
55
|
-
const jobId = this.extractJobIdFromUrl(url);
|
|
56
|
-
return await this.authManager.attachToken(headers, jobId);
|
|
57
|
-
}
|
|
58
|
-
// Fallback - return headers unchanged
|
|
59
|
-
return headers;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Extract job ID from URL for SaaS mode token caching.
|
|
63
|
-
* Looks for patterns like /upload/{id} or /jobs/{id} in the URL.
|
|
64
|
-
*/
|
|
65
|
-
extractJobIdFromUrl(url) {
|
|
66
|
-
// Match patterns like:
|
|
67
|
-
// - /api/upload/{uploadId}
|
|
68
|
-
// - /api/flow/{flowId}/{storageId}
|
|
69
|
-
// - /api/jobs/{jobId}/status
|
|
70
|
-
// - /api/jobs/{jobId}/continue/{nodeId}
|
|
71
|
-
const uploadMatch = url.match(/\/api\/upload\/([^/?]+)/);
|
|
72
|
-
if (uploadMatch) {
|
|
73
|
-
return uploadMatch[1];
|
|
74
|
-
}
|
|
75
|
-
const flowMatch = url.match(/\/api\/flow\/([^/?]+)/);
|
|
76
|
-
if (flowMatch) {
|
|
77
|
-
return flowMatch[1];
|
|
78
|
-
}
|
|
79
|
-
const jobMatch = url.match(/\/api\/jobs\/([^/?]+)/);
|
|
80
|
-
if (jobMatch) {
|
|
81
|
-
return jobMatch[1];
|
|
82
|
-
}
|
|
83
|
-
// No job ID found - SaaS mode will use global token
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Delegate metrics methods to underlying HTTP client
|
|
88
|
-
*/
|
|
89
|
-
getMetrics() {
|
|
90
|
-
return this.httpClient.getMetrics();
|
|
91
|
-
}
|
|
92
|
-
getDetailedMetrics() {
|
|
93
|
-
return this.httpClient.getDetailedMetrics();
|
|
94
|
-
}
|
|
95
|
-
reset() {
|
|
96
|
-
this.httpClient.reset();
|
|
97
|
-
}
|
|
98
|
-
async close() {
|
|
99
|
-
await this.httpClient.close();
|
|
100
|
-
}
|
|
101
|
-
async warmupConnections(urls) {
|
|
102
|
-
await this.httpClient.warmupConnections(urls);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Get the underlying auth manager for advanced use cases
|
|
106
|
-
*/
|
|
107
|
-
getAuthManager() {
|
|
108
|
-
return this.authManager;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Logger } from "../logger";
|
|
2
|
-
import type { PlatformService } from "../services/platform-service";
|
|
3
|
-
import type { DirectAuthConfig } from "./types";
|
|
4
|
-
import { BaseAuthManager } from "./types";
|
|
5
|
-
/**
|
|
6
|
-
* Direct auth manager - handles credential attachment for "bring your own auth" mode.
|
|
7
|
-
*
|
|
8
|
-
* This manager calls the user-provided getCredentials() function before each request
|
|
9
|
-
* and attaches the returned credentials (headers, cookies) to the HTTP request.
|
|
10
|
-
*
|
|
11
|
-
* Supports any authentication protocol: OAuth, JWT, API keys, session cookies, etc.
|
|
12
|
-
*/
|
|
13
|
-
export declare class DirectAuthManager extends BaseAuthManager {
|
|
14
|
-
private config;
|
|
15
|
-
private platformService;
|
|
16
|
-
private logger;
|
|
17
|
-
constructor(config: DirectAuthConfig, platformService: PlatformService, logger: Logger);
|
|
18
|
-
/**
|
|
19
|
-
* Attach credentials to an HTTP request by calling getCredentials() and
|
|
20
|
-
* merging the returned headers/cookies with the request.
|
|
21
|
-
*
|
|
22
|
-
* @param headers - Existing request headers
|
|
23
|
-
* @returns Updated headers with credentials attached
|
|
24
|
-
* @throws Error if getCredentials() throws or returns invalid data
|
|
25
|
-
*/
|
|
26
|
-
attachCredentials(headers?: Record<string, string>): Promise<Record<string, string>>;
|
|
27
|
-
/**
|
|
28
|
-
* Validate that headers is a valid object with string keys and values
|
|
29
|
-
*/
|
|
30
|
-
private validateHeaders;
|
|
31
|
-
/**
|
|
32
|
-
* Attach cookies to request headers.
|
|
33
|
-
* In browser environments, cookies are automatically handled by fetch().
|
|
34
|
-
* In Node.js, we need to manually add them to the Cookie header.
|
|
35
|
-
*/
|
|
36
|
-
private attachCookies;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=direct-auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"direct-auth.d.ts","sourceRoot":"","sources":["../../src/auth/direct-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;IAElD,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,MAAM;gBAFN,MAAM,EAAE,gBAAgB,EACxB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM;IAKxB;;;;;;;OAOG;IACG,iBAAiB,CACrB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAuClC;;OAEG;IACH,OAAO,CAAC,eAAe;IAcvB;;;;OAIG;IACH,OAAO,CAAC,aAAa;CA2BtB"}
|
package/dist/auth/direct-auth.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { BaseAuthManager } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Direct auth manager - handles credential attachment for "bring your own auth" mode.
|
|
4
|
-
*
|
|
5
|
-
* This manager calls the user-provided getCredentials() function before each request
|
|
6
|
-
* and attaches the returned credentials (headers, cookies) to the HTTP request.
|
|
7
|
-
*
|
|
8
|
-
* Supports any authentication protocol: OAuth, JWT, API keys, session cookies, etc.
|
|
9
|
-
*/
|
|
10
|
-
export class DirectAuthManager extends BaseAuthManager {
|
|
11
|
-
constructor(config, platformService, logger) {
|
|
12
|
-
super("direct");
|
|
13
|
-
this.config = config;
|
|
14
|
-
this.platformService = platformService;
|
|
15
|
-
this.logger = logger;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Attach credentials to an HTTP request by calling getCredentials() and
|
|
19
|
-
* merging the returned headers/cookies with the request.
|
|
20
|
-
*
|
|
21
|
-
* @param headers - Existing request headers
|
|
22
|
-
* @returns Updated headers with credentials attached
|
|
23
|
-
* @throws Error if getCredentials() throws or returns invalid data
|
|
24
|
-
*/
|
|
25
|
-
async attachCredentials(headers = {}) {
|
|
26
|
-
try {
|
|
27
|
-
if (!this.config.getCredentials) {
|
|
28
|
-
return headers;
|
|
29
|
-
}
|
|
30
|
-
// Call user's credential provider (may be async)
|
|
31
|
-
const credentials = await Promise.resolve(this.config.getCredentials());
|
|
32
|
-
// Validate credentials
|
|
33
|
-
if (!credentials || typeof credentials !== "object") {
|
|
34
|
-
throw new Error("getCredentials() must return an object with headers and/or cookies");
|
|
35
|
-
}
|
|
36
|
-
// Merge credential headers with existing headers
|
|
37
|
-
const updatedHeaders = { ...headers };
|
|
38
|
-
if (credentials.headers) {
|
|
39
|
-
this.validateHeaders(credentials.headers);
|
|
40
|
-
Object.assign(updatedHeaders, credentials.headers);
|
|
41
|
-
}
|
|
42
|
-
// Note: Cookie handling would be browser-specific
|
|
43
|
-
// For now, we only support headers as cookies are automatically
|
|
44
|
-
// handled by the browser when using fetch()
|
|
45
|
-
if (credentials.cookies) {
|
|
46
|
-
this.attachCookies(updatedHeaders, credentials.cookies);
|
|
47
|
-
}
|
|
48
|
-
return updatedHeaders;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
// Wrap errors with context
|
|
52
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
-
throw new Error(`Failed to attach auth credentials: ${message}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Validate that headers is a valid object with string keys and values
|
|
58
|
-
*/
|
|
59
|
-
validateHeaders(headers) {
|
|
60
|
-
if (typeof headers !== "object" || headers === null) {
|
|
61
|
-
throw new Error("headers must be an object");
|
|
62
|
-
}
|
|
63
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
64
|
-
if (typeof key !== "string" || typeof value !== "string") {
|
|
65
|
-
throw new Error(`Invalid header: key and value must be strings (got ${key}: ${typeof value})`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Attach cookies to request headers.
|
|
71
|
-
* In browser environments, cookies are automatically handled by fetch().
|
|
72
|
-
* In Node.js, we need to manually add them to the Cookie header.
|
|
73
|
-
*/
|
|
74
|
-
attachCookies(headers, cookies) {
|
|
75
|
-
// Check if we're in a browser environment
|
|
76
|
-
const isBrowser = this.platformService.isBrowser();
|
|
77
|
-
if (isBrowser) {
|
|
78
|
-
// In browsers, fetch() automatically sends cookies for same-origin requests
|
|
79
|
-
// For cross-origin, the server needs to set CORS headers and credentials: 'include'
|
|
80
|
-
// We can't manually set cookies in headers for security reasons
|
|
81
|
-
// So we just warn if cookies are provided in direct mode
|
|
82
|
-
this.logger.warn("DirectAuth: Cookies are automatically handled by the browser. " +
|
|
83
|
-
"Ensure your server has proper CORS configuration with credentials support.");
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
// In Node.js, we can manually build the Cookie header
|
|
87
|
-
const cookieString = Object.entries(cookies)
|
|
88
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
89
|
-
.join("; ");
|
|
90
|
-
if (cookieString) {
|
|
91
|
-
headers.Cookie = cookieString;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
package/dist/auth/index.d.ts
DELETED
package/dist/auth/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
package/dist/auth/index.js
DELETED
package/dist/auth/no-auth.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { BaseAuthManager } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* No-auth manager - pass-through implementation for backward compatibility.
|
|
4
|
-
*
|
|
5
|
-
* When no auth configuration is provided, this manager is used to maintain
|
|
6
|
-
* a consistent interface without adding any authentication to requests.
|
|
7
|
-
*/
|
|
8
|
-
export declare class NoAuthManager extends BaseAuthManager {
|
|
9
|
-
constructor();
|
|
10
|
-
/**
|
|
11
|
-
* Pass through headers without modification.
|
|
12
|
-
*
|
|
13
|
-
* @param headers - Existing request headers
|
|
14
|
-
* @returns Same headers unchanged
|
|
15
|
-
*/
|
|
16
|
-
attachCredentials(headers?: Record<string, string>): Promise<Record<string, string>>;
|
|
17
|
-
/**
|
|
18
|
-
* No-op for clearing tokens (NoAuthManager doesn't cache anything)
|
|
19
|
-
*/
|
|
20
|
-
clearToken(_jobId: string): void;
|
|
21
|
-
/**
|
|
22
|
-
* No-op for clearing all tokens
|
|
23
|
-
*/
|
|
24
|
-
clearAllTokens(): void;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=no-auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-auth.d.ts","sourceRoot":"","sources":["../../src/auth/no-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,eAAe;;IAKhD;;;;;OAKG;IACG,iBAAiB,CACrB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAIlC;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIhC;;OAEG;IACH,cAAc,IAAI,IAAI;CAGvB"}
|
package/dist/auth/no-auth.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BaseAuthManager } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* No-auth manager - pass-through implementation for backward compatibility.
|
|
4
|
-
*
|
|
5
|
-
* When no auth configuration is provided, this manager is used to maintain
|
|
6
|
-
* a consistent interface without adding any authentication to requests.
|
|
7
|
-
*/
|
|
8
|
-
export class NoAuthManager extends BaseAuthManager {
|
|
9
|
-
constructor() {
|
|
10
|
-
super("no-auth");
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Pass through headers without modification.
|
|
14
|
-
*
|
|
15
|
-
* @param headers - Existing request headers
|
|
16
|
-
* @returns Same headers unchanged
|
|
17
|
-
*/
|
|
18
|
-
async attachCredentials(headers = {}) {
|
|
19
|
-
return headers;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* No-op for clearing tokens (NoAuthManager doesn't cache anything)
|
|
23
|
-
*/
|
|
24
|
-
clearToken(_jobId) {
|
|
25
|
-
// No-op
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* No-op for clearing all tokens
|
|
29
|
-
*/
|
|
30
|
-
clearAllTokens() {
|
|
31
|
-
// No-op
|
|
32
|
-
}
|
|
33
|
-
}
|
package/dist/auth/saas-auth.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { HttpClient } from "../services/http-client";
|
|
2
|
-
import { BaseAuthManager, type SaasAuthConfig } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Token response from the auth server
|
|
5
|
-
*/
|
|
6
|
-
export type TokenResponse = {
|
|
7
|
-
/** JWT token to use for authentication */
|
|
8
|
-
token: string;
|
|
9
|
-
/** Token expiration time in seconds (optional) */
|
|
10
|
-
expiresIn?: number;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* SaaS auth manager - handles JWT token exchange with an auth server.
|
|
14
|
-
*
|
|
15
|
-
* Token exchange flow:
|
|
16
|
-
* 1. Client calls getCredentials() to get user credentials
|
|
17
|
-
* 2. Manager sends credentials to authServerUrl
|
|
18
|
-
* 3. Auth server validates credentials and returns JWT token
|
|
19
|
-
* 4. Manager caches token and attaches it to uploadista requests
|
|
20
|
-
* 5. Token is cached per job to minimize auth overhead
|
|
21
|
-
*
|
|
22
|
-
* Security: API keys are kept server-side in the auth server, never exposed to clients.
|
|
23
|
-
*/
|
|
24
|
-
export declare class SaasAuthManager extends BaseAuthManager {
|
|
25
|
-
private config;
|
|
26
|
-
private httpClient;
|
|
27
|
-
/** Token cache: maps job ID to cached token */
|
|
28
|
-
private tokenCache;
|
|
29
|
-
/** Global token for requests without a specific job ID */
|
|
30
|
-
private globalToken;
|
|
31
|
-
constructor(config: SaasAuthConfig, httpClient: HttpClient);
|
|
32
|
-
/**
|
|
33
|
-
* Fetch a JWT token from the auth server using user credentials.
|
|
34
|
-
*
|
|
35
|
-
* @returns Token response with JWT and optional expiry
|
|
36
|
-
* @throws Error if auth server is unreachable or returns an error
|
|
37
|
-
*/
|
|
38
|
-
fetchToken(): Promise<TokenResponse>;
|
|
39
|
-
/**
|
|
40
|
-
* Get a cached token for a specific job, or fetch a new one if not cached.
|
|
41
|
-
*
|
|
42
|
-
* @param jobId - Optional job ID to cache token for specific job
|
|
43
|
-
* @returns Cached or newly fetched token
|
|
44
|
-
*/
|
|
45
|
-
private getOrFetchToken;
|
|
46
|
-
/**
|
|
47
|
-
* Check if a cached token is expired.
|
|
48
|
-
* Adds a 60-second buffer to avoid using tokens that are about to expire.
|
|
49
|
-
*/
|
|
50
|
-
private isTokenExpired;
|
|
51
|
-
/**
|
|
52
|
-
* Attach JWT token to an HTTP request as Authorization Bearer header.
|
|
53
|
-
*
|
|
54
|
-
* @param headers - Existing request headers
|
|
55
|
-
* @param jobId - Optional job ID to use cached token for specific job
|
|
56
|
-
* @returns Updated headers with Authorization header
|
|
57
|
-
* @throws Error if token fetch fails
|
|
58
|
-
*/
|
|
59
|
-
attachToken(headers?: Record<string, string>, jobId?: string): Promise<Record<string, string>>;
|
|
60
|
-
/**
|
|
61
|
-
* Clear cached token for a specific job.
|
|
62
|
-
* Should be called when a job completes to free memory.
|
|
63
|
-
*
|
|
64
|
-
* @param jobId - Job ID to clear token for
|
|
65
|
-
*/
|
|
66
|
-
clearToken(jobId: string): void;
|
|
67
|
-
/**
|
|
68
|
-
* Clear all cached tokens.
|
|
69
|
-
* Useful for logout or when switching users.
|
|
70
|
-
*/
|
|
71
|
-
clearAllTokens(): void;
|
|
72
|
-
/**
|
|
73
|
-
* Get cache statistics for debugging and monitoring.
|
|
74
|
-
*/
|
|
75
|
-
getCacheStats(): {
|
|
76
|
-
cachedJobCount: number;
|
|
77
|
-
hasGlobalToken: boolean;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=saas-auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"saas-auth.d.ts","sourceRoot":"","sources":["../../src/auth/saas-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAUF;;;;;;;;;;;GAWG;AACH,qBAAa,eAAgB,SAAQ,eAAe;IAQhD,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IARpB,+CAA+C;IAC/C,OAAO,CAAC,UAAU,CAAkC;IAEpD,0DAA0D;IAC1D,OAAO,CAAC,WAAW,CAA4B;gBAGrC,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,UAAU;IAKhC;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC;IAgD1C;;;;;OAKG;YACW,eAAe;IAqC7B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAWtB;;;;;;;OAOG;IACG,WAAW,CACf,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAgBlC;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI/B;;;OAGG;IACH,cAAc,IAAI,IAAI;IAKtB;;OAEG;IACH,aAAa,IAAI;QACf,cAAc,EAAE,MAAM,CAAC;QACvB,cAAc,EAAE,OAAO,CAAC;KACzB;CAMF"}
|