@cubis/vfsclient 0.0.1 → 0.0.2
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.cjs +53 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +50 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -646,4 +646,17 @@ declare function calculateSHA256(data: ArrayBuffer | Uint8Array | string): Promi
|
|
|
646
646
|
*/
|
|
647
647
|
declare function calculateBlobSHA256(blob: Blob): Promise<string>;
|
|
648
648
|
|
|
649
|
-
|
|
649
|
+
declare const SDK_NAME: string;
|
|
650
|
+
declare const SDK_VERSION: string;
|
|
651
|
+
/**
|
|
652
|
+
* Returns the detected runtime name and version.
|
|
653
|
+
* e.g. "Bun/1.4.3 (darwin-arm64)", "Node.js/v22.2.0 (darwin-arm64)", or "Browser"
|
|
654
|
+
*/
|
|
655
|
+
declare function getRuntimeInfo(): string;
|
|
656
|
+
/**
|
|
657
|
+
* Builds standard User-Agent string:
|
|
658
|
+
* e.g. "@cubis/vfsclient/1.0.0 (Bun/1.4.3; darwin-arm64)"
|
|
659
|
+
*/
|
|
660
|
+
declare function getUserAgent(): string;
|
|
661
|
+
|
|
662
|
+
export { type AttachmentResponse, BackgroundUploadQueue, BrowserCacheAdapter, type BrowserCacheOptions, type BucketMetricsByDate, type BucketStat, type BucketStatSummary, type BucketStatsListResponse, FileSystemCacheAdapter, type FileSystemCacheOptions, type GetFileOptions, type GetUrlOptions, HttpClient, type ImgProxyOptions, type ListFilesOptions, MemoryCacheAdapter, type MemoryCacheOptions, type ObjectManifestResponse, type PreflightRequest, type PreflightResponse, type ProblemDetails, type QueueItem, type QueueListener, type QueueProgress, SDK_NAME, SDK_VERSION, type SessionView, type SupportedBinaryInput, type UploadInput, type UploadMultipleInput, type UploadProgress, type VFSCacheAdapter, type VFSCacheEntry, VFSClient, type VFSClientOptions, VFSError, calculateBlobSHA256, calculateSHA256, createDefaultCache, executePreflight, getRuntimeInfo, getUserAgent, guessContentType, normalizeUploadInput, uploadMultipleFiles, uploadSessionFile, uploadSingleFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -646,4 +646,17 @@ declare function calculateSHA256(data: ArrayBuffer | Uint8Array | string): Promi
|
|
|
646
646
|
*/
|
|
647
647
|
declare function calculateBlobSHA256(blob: Blob): Promise<string>;
|
|
648
648
|
|
|
649
|
-
|
|
649
|
+
declare const SDK_NAME: string;
|
|
650
|
+
declare const SDK_VERSION: string;
|
|
651
|
+
/**
|
|
652
|
+
* Returns the detected runtime name and version.
|
|
653
|
+
* e.g. "Bun/1.4.3 (darwin-arm64)", "Node.js/v22.2.0 (darwin-arm64)", or "Browser"
|
|
654
|
+
*/
|
|
655
|
+
declare function getRuntimeInfo(): string;
|
|
656
|
+
/**
|
|
657
|
+
* Builds standard User-Agent string:
|
|
658
|
+
* e.g. "@cubis/vfsclient/1.0.0 (Bun/1.4.3; darwin-arm64)"
|
|
659
|
+
*/
|
|
660
|
+
declare function getUserAgent(): string;
|
|
661
|
+
|
|
662
|
+
export { type AttachmentResponse, BackgroundUploadQueue, BrowserCacheAdapter, type BrowserCacheOptions, type BucketMetricsByDate, type BucketStat, type BucketStatSummary, type BucketStatsListResponse, FileSystemCacheAdapter, type FileSystemCacheOptions, type GetFileOptions, type GetUrlOptions, HttpClient, type ImgProxyOptions, type ListFilesOptions, MemoryCacheAdapter, type MemoryCacheOptions, type ObjectManifestResponse, type PreflightRequest, type PreflightResponse, type ProblemDetails, type QueueItem, type QueueListener, type QueueProgress, SDK_NAME, SDK_VERSION, type SessionView, type SupportedBinaryInput, type UploadInput, type UploadMultipleInput, type UploadProgress, type VFSCacheAdapter, type VFSCacheEntry, VFSClient, type VFSClientOptions, VFSError, calculateBlobSHA256, calculateSHA256, createDefaultCache, executePreflight, getRuntimeInfo, getUserAgent, guessContentType, normalizeUploadInput, uploadMultipleFiles, uploadSessionFile, uploadSingleFile };
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,39 @@ async function parseHttpError(res) {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// package.json
|
|
69
|
+
var package_default = {
|
|
70
|
+
name: "@cubis/vfsclient",
|
|
71
|
+
version: "0.0.2"};
|
|
72
|
+
|
|
73
|
+
// src/version.ts
|
|
74
|
+
var SDK_NAME = package_default.name;
|
|
75
|
+
var SDK_VERSION = package_default.version;
|
|
76
|
+
function getRuntimeInfo() {
|
|
77
|
+
if (typeof process !== "undefined" && process.versions) {
|
|
78
|
+
const platform = process.platform ? `; ${process.platform}-${process.arch || "unknown"}` : "";
|
|
79
|
+
if (process.versions.bun) {
|
|
80
|
+
return `Bun/${process.versions.bun}${platform}`;
|
|
81
|
+
}
|
|
82
|
+
if (process.versions.node) {
|
|
83
|
+
return `Node.js/${process.versions.node}${platform}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
87
|
+
const deno = globalThis.Deno;
|
|
88
|
+
const version = deno.version?.deno || "unknown";
|
|
89
|
+
return `Deno/${version}`;
|
|
90
|
+
}
|
|
91
|
+
if (typeof window !== "undefined") {
|
|
92
|
+
return "Browser";
|
|
93
|
+
}
|
|
94
|
+
return "Unknown";
|
|
95
|
+
}
|
|
96
|
+
function getUserAgent() {
|
|
97
|
+
const runtime = getRuntimeInfo();
|
|
98
|
+
return `${SDK_NAME}/${SDK_VERSION} (${runtime})`;
|
|
99
|
+
}
|
|
100
|
+
|
|
68
101
|
// src/http/client.ts
|
|
69
102
|
var HttpClient = class {
|
|
70
103
|
endpoint;
|
|
@@ -84,7 +117,8 @@ var HttpClient = class {
|
|
|
84
117
|
this.apiKey = options.apiKey;
|
|
85
118
|
this.apiHash = options.apiHash;
|
|
86
119
|
this.defaultTimeout = options.timeout ?? 3e4;
|
|
87
|
-
|
|
120
|
+
const rawFetch = options.fetch ?? globalThis.fetch;
|
|
121
|
+
this.fetchImpl = typeof rawFetch === "function" ? rawFetch.bind(globalThis) : rawFetch;
|
|
88
122
|
if (typeof options.debug === "function") {
|
|
89
123
|
this.debug = options.debug;
|
|
90
124
|
} else if (options.debug === true) {
|
|
@@ -117,6 +151,12 @@ var HttpClient = class {
|
|
|
117
151
|
}
|
|
118
152
|
buildHeaders(customHeaders, skipAuth) {
|
|
119
153
|
const headers = new Headers();
|
|
154
|
+
const ua = getUserAgent();
|
|
155
|
+
try {
|
|
156
|
+
headers.set("User-Agent", ua);
|
|
157
|
+
} catch {
|
|
158
|
+
}
|
|
159
|
+
headers.set("x-user-agent", ua);
|
|
120
160
|
if (!skipAuth) {
|
|
121
161
|
if (this.apiKey) {
|
|
122
162
|
headers.set("x-api-key", this.apiKey);
|
|
@@ -894,13 +934,19 @@ async function uploadSessionFile(http, input, defaultBucket = "default") {
|
|
|
894
934
|
if (err.status === 410) {
|
|
895
935
|
throw new VFSError("The upload session has expired. Start a new session.", { status: 410, cause: err });
|
|
896
936
|
}
|
|
897
|
-
if ([400, 401, 403, 409, 413, 422].includes(err.status)) {
|
|
937
|
+
if ([400, 401, 403, 409, 413, 422, 503].includes(err.status)) {
|
|
898
938
|
throw err;
|
|
899
939
|
}
|
|
900
940
|
}
|
|
901
941
|
failures++;
|
|
902
942
|
if (failures >= 5) {
|
|
903
|
-
|
|
943
|
+
if (err instanceof VFSError) {
|
|
944
|
+
throw err;
|
|
945
|
+
}
|
|
946
|
+
throw new VFSError(
|
|
947
|
+
`Failed to initialize upload session: ${err instanceof Error ? err.message : String(err)}`,
|
|
948
|
+
{ cause: err }
|
|
949
|
+
);
|
|
904
950
|
}
|
|
905
951
|
await delay(500 * Math.pow(2, failures - 1));
|
|
906
952
|
}
|
|
@@ -1555,6 +1601,6 @@ var VFSClient = class {
|
|
|
1555
1601
|
}
|
|
1556
1602
|
};
|
|
1557
1603
|
|
|
1558
|
-
export { BackgroundUploadQueue, BrowserCacheAdapter, FileSystemCacheAdapter, HttpClient, MemoryCacheAdapter, VFSClient, VFSError, calculateBlobSHA256, calculateSHA256, createDefaultCache, executePreflight, guessContentType, normalizeUploadInput, uploadMultipleFiles, uploadSessionFile, uploadSingleFile };
|
|
1604
|
+
export { BackgroundUploadQueue, BrowserCacheAdapter, FileSystemCacheAdapter, HttpClient, MemoryCacheAdapter, SDK_NAME, SDK_VERSION, VFSClient, VFSError, calculateBlobSHA256, calculateSHA256, createDefaultCache, executePreflight, getRuntimeInfo, getUserAgent, guessContentType, normalizeUploadInput, uploadMultipleFiles, uploadSessionFile, uploadSingleFile };
|
|
1559
1605
|
//# sourceMappingURL=index.js.map
|
|
1560
1606
|
//# sourceMappingURL=index.js.map
|