@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.cjs
CHANGED
|
@@ -67,6 +67,39 @@ async function parseHttpError(res) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// package.json
|
|
71
|
+
var package_default = {
|
|
72
|
+
name: "@cubis/vfsclient",
|
|
73
|
+
version: "0.0.2"};
|
|
74
|
+
|
|
75
|
+
// src/version.ts
|
|
76
|
+
var SDK_NAME = package_default.name;
|
|
77
|
+
var SDK_VERSION = package_default.version;
|
|
78
|
+
function getRuntimeInfo() {
|
|
79
|
+
if (typeof process !== "undefined" && process.versions) {
|
|
80
|
+
const platform = process.platform ? `; ${process.platform}-${process.arch || "unknown"}` : "";
|
|
81
|
+
if (process.versions.bun) {
|
|
82
|
+
return `Bun/${process.versions.bun}${platform}`;
|
|
83
|
+
}
|
|
84
|
+
if (process.versions.node) {
|
|
85
|
+
return `Node.js/${process.versions.node}${platform}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
89
|
+
const deno = globalThis.Deno;
|
|
90
|
+
const version = deno.version?.deno || "unknown";
|
|
91
|
+
return `Deno/${version}`;
|
|
92
|
+
}
|
|
93
|
+
if (typeof window !== "undefined") {
|
|
94
|
+
return "Browser";
|
|
95
|
+
}
|
|
96
|
+
return "Unknown";
|
|
97
|
+
}
|
|
98
|
+
function getUserAgent() {
|
|
99
|
+
const runtime = getRuntimeInfo();
|
|
100
|
+
return `${SDK_NAME}/${SDK_VERSION} (${runtime})`;
|
|
101
|
+
}
|
|
102
|
+
|
|
70
103
|
// src/http/client.ts
|
|
71
104
|
var HttpClient = class {
|
|
72
105
|
endpoint;
|
|
@@ -86,7 +119,8 @@ var HttpClient = class {
|
|
|
86
119
|
this.apiKey = options.apiKey;
|
|
87
120
|
this.apiHash = options.apiHash;
|
|
88
121
|
this.defaultTimeout = options.timeout ?? 3e4;
|
|
89
|
-
|
|
122
|
+
const rawFetch = options.fetch ?? globalThis.fetch;
|
|
123
|
+
this.fetchImpl = typeof rawFetch === "function" ? rawFetch.bind(globalThis) : rawFetch;
|
|
90
124
|
if (typeof options.debug === "function") {
|
|
91
125
|
this.debug = options.debug;
|
|
92
126
|
} else if (options.debug === true) {
|
|
@@ -119,6 +153,12 @@ var HttpClient = class {
|
|
|
119
153
|
}
|
|
120
154
|
buildHeaders(customHeaders, skipAuth) {
|
|
121
155
|
const headers = new Headers();
|
|
156
|
+
const ua = getUserAgent();
|
|
157
|
+
try {
|
|
158
|
+
headers.set("User-Agent", ua);
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
headers.set("x-user-agent", ua);
|
|
122
162
|
if (!skipAuth) {
|
|
123
163
|
if (this.apiKey) {
|
|
124
164
|
headers.set("x-api-key", this.apiKey);
|
|
@@ -896,13 +936,19 @@ async function uploadSessionFile(http, input, defaultBucket = "default") {
|
|
|
896
936
|
if (err.status === 410) {
|
|
897
937
|
throw new VFSError("The upload session has expired. Start a new session.", { status: 410, cause: err });
|
|
898
938
|
}
|
|
899
|
-
if ([400, 401, 403, 409, 413, 422].includes(err.status)) {
|
|
939
|
+
if ([400, 401, 403, 409, 413, 422, 503].includes(err.status)) {
|
|
900
940
|
throw err;
|
|
901
941
|
}
|
|
902
942
|
}
|
|
903
943
|
failures++;
|
|
904
944
|
if (failures >= 5) {
|
|
905
|
-
|
|
945
|
+
if (err instanceof VFSError) {
|
|
946
|
+
throw err;
|
|
947
|
+
}
|
|
948
|
+
throw new VFSError(
|
|
949
|
+
`Failed to initialize upload session: ${err instanceof Error ? err.message : String(err)}`,
|
|
950
|
+
{ cause: err }
|
|
951
|
+
);
|
|
906
952
|
}
|
|
907
953
|
await delay(500 * Math.pow(2, failures - 1));
|
|
908
954
|
}
|
|
@@ -1562,12 +1608,16 @@ exports.BrowserCacheAdapter = BrowserCacheAdapter;
|
|
|
1562
1608
|
exports.FileSystemCacheAdapter = FileSystemCacheAdapter;
|
|
1563
1609
|
exports.HttpClient = HttpClient;
|
|
1564
1610
|
exports.MemoryCacheAdapter = MemoryCacheAdapter;
|
|
1611
|
+
exports.SDK_NAME = SDK_NAME;
|
|
1612
|
+
exports.SDK_VERSION = SDK_VERSION;
|
|
1565
1613
|
exports.VFSClient = VFSClient;
|
|
1566
1614
|
exports.VFSError = VFSError;
|
|
1567
1615
|
exports.calculateBlobSHA256 = calculateBlobSHA256;
|
|
1568
1616
|
exports.calculateSHA256 = calculateSHA256;
|
|
1569
1617
|
exports.createDefaultCache = createDefaultCache;
|
|
1570
1618
|
exports.executePreflight = executePreflight;
|
|
1619
|
+
exports.getRuntimeInfo = getRuntimeInfo;
|
|
1620
|
+
exports.getUserAgent = getUserAgent;
|
|
1571
1621
|
exports.guessContentType = guessContentType;
|
|
1572
1622
|
exports.normalizeUploadInput = normalizeUploadInput;
|
|
1573
1623
|
exports.uploadMultipleFiles = uploadMultipleFiles;
|