@scalemule/sdk 0.0.71 → 0.0.72
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.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -12
- package/dist/index.mjs +22 -12
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -565,6 +565,8 @@ declare class ScaleMuleClient {
|
|
|
565
565
|
upload<T>(path: string, file: File | Blob, additionalFields?: Record<string, string>, options?: RequestOptions & {
|
|
566
566
|
onProgress?: (progress: number) => void;
|
|
567
567
|
}): Promise<ApiResponse<T>>;
|
|
568
|
+
/** Preserve forwarded reader/auth context for both multipart transports. */
|
|
569
|
+
private uploadHeaders;
|
|
568
570
|
/**
|
|
569
571
|
* Single upload with XMLHttpRequest for progress tracking.
|
|
570
572
|
* Supports abort via AbortSignal.
|
package/dist/index.d.ts
CHANGED
|
@@ -565,6 +565,8 @@ declare class ScaleMuleClient {
|
|
|
565
565
|
upload<T>(path: string, file: File | Blob, additionalFields?: Record<string, string>, options?: RequestOptions & {
|
|
566
566
|
onProgress?: (progress: number) => void;
|
|
567
567
|
}): Promise<ApiResponse<T>>;
|
|
568
|
+
/** Preserve forwarded reader/auth context for both multipart transports. */
|
|
569
|
+
private uploadHeaders;
|
|
568
570
|
/**
|
|
569
571
|
* Single upload with XMLHttpRequest for progress tracking.
|
|
570
572
|
* Supports abort via AbortSignal.
|
package/dist/index.js
CHANGED
|
@@ -1185,7 +1185,7 @@ var ScaleMuleClient = class {
|
|
|
1185
1185
|
if (this.workspaceId) {
|
|
1186
1186
|
headers["x-sm-workspace-id"] = this.workspaceId;
|
|
1187
1187
|
}
|
|
1188
|
-
if (!init.skipAuth && !this.sessionToken) {
|
|
1188
|
+
if (!init.skipAuth && !this.sessionToken && !Object.keys(headers).some((key) => key.toLowerCase() === "x-anonymous-id")) {
|
|
1189
1189
|
if (!this.anonymousId) {
|
|
1190
1190
|
try {
|
|
1191
1191
|
await this.ensureAnonymousId();
|
|
@@ -1382,14 +1382,12 @@ var ScaleMuleClient = class {
|
|
|
1382
1382
|
return { data: null, error: { code: "aborted", message: "Upload aborted", status: 0 } };
|
|
1383
1383
|
}
|
|
1384
1384
|
if (options?.onProgress && typeof XMLHttpRequest !== "undefined") {
|
|
1385
|
-
return this.uploadWithXHR(url, buildFormData, options.onProgress, options
|
|
1385
|
+
return this.uploadWithXHR(url, buildFormData, options.onProgress, options);
|
|
1386
1386
|
}
|
|
1387
1387
|
const maxRetries = options?.retries ?? this.maxRetries;
|
|
1388
1388
|
let lastError = null;
|
|
1389
1389
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1390
|
-
const headers =
|
|
1391
|
-
if (this.sessionToken) headers["Authorization"] = `Bearer ${this.sessionToken}`;
|
|
1392
|
-
if (this.workspaceId) headers["x-sm-workspace-id"] = this.workspaceId;
|
|
1390
|
+
const headers = await this.uploadHeaders(options);
|
|
1393
1391
|
try {
|
|
1394
1392
|
const response = await fetch(url, {
|
|
1395
1393
|
method: "POST",
|
|
@@ -1431,13 +1429,29 @@ var ScaleMuleClient = class {
|
|
|
1431
1429
|
}
|
|
1432
1430
|
return { data: null, error: lastError || { code: "upload_error", message: "Upload failed", status: 0 } };
|
|
1433
1431
|
}
|
|
1432
|
+
/** Preserve forwarded reader/auth context for both multipart transports. */
|
|
1433
|
+
async uploadHeaders(options) {
|
|
1434
|
+
const headers = { "x-api-key": this.apiKey, ...options?.headers };
|
|
1435
|
+
for (const name of Object.keys(headers)) {
|
|
1436
|
+
if (name.toLowerCase() === "content-type") delete headers[name];
|
|
1437
|
+
}
|
|
1438
|
+
if (this.sessionToken) headers["Authorization"] = `Bearer ${this.sessionToken}`;
|
|
1439
|
+
if (this.workspaceId) headers["x-sm-workspace-id"] = this.workspaceId;
|
|
1440
|
+
if (!this.sessionToken && !Object.keys(headers).some((key) => key.toLowerCase() === "x-anonymous-id")) {
|
|
1441
|
+
headers["x-anonymous-id"] = await this.ensureAnonymousId();
|
|
1442
|
+
}
|
|
1443
|
+
return headers;
|
|
1444
|
+
}
|
|
1434
1445
|
/**
|
|
1435
1446
|
* Single upload with XMLHttpRequest for progress tracking.
|
|
1436
1447
|
* Supports abort via AbortSignal.
|
|
1437
1448
|
*/
|
|
1438
|
-
async uploadWithXHR(url, buildFormData, onProgress,
|
|
1449
|
+
async uploadWithXHR(url, buildFormData, onProgress, options) {
|
|
1450
|
+
const signal = options?.signal;
|
|
1451
|
+
const maxRetries = options?.retries ?? this.maxRetries;
|
|
1439
1452
|
let lastError = null;
|
|
1440
1453
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1454
|
+
const headers = await this.uploadHeaders(options);
|
|
1441
1455
|
const result = await new Promise((res) => {
|
|
1442
1456
|
const xhr = new XMLHttpRequest();
|
|
1443
1457
|
if (signal) {
|
|
@@ -1480,12 +1494,8 @@ var ScaleMuleClient = class {
|
|
|
1480
1494
|
res({ data: null, error: { code: "aborted", message: "Upload aborted", status: 0 } });
|
|
1481
1495
|
});
|
|
1482
1496
|
xhr.open("POST", url);
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
xhr.setRequestHeader("Authorization", `Bearer ${this.sessionToken}`);
|
|
1486
|
-
}
|
|
1487
|
-
if (this.workspaceId) {
|
|
1488
|
-
xhr.setRequestHeader("x-sm-workspace-id", this.workspaceId);
|
|
1497
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
1498
|
+
xhr.setRequestHeader(name, value);
|
|
1489
1499
|
}
|
|
1490
1500
|
xhr.send(buildFormData());
|
|
1491
1501
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1073,7 +1073,7 @@ var ScaleMuleClient = class {
|
|
|
1073
1073
|
if (this.workspaceId) {
|
|
1074
1074
|
headers["x-sm-workspace-id"] = this.workspaceId;
|
|
1075
1075
|
}
|
|
1076
|
-
if (!init.skipAuth && !this.sessionToken) {
|
|
1076
|
+
if (!init.skipAuth && !this.sessionToken && !Object.keys(headers).some((key) => key.toLowerCase() === "x-anonymous-id")) {
|
|
1077
1077
|
if (!this.anonymousId) {
|
|
1078
1078
|
try {
|
|
1079
1079
|
await this.ensureAnonymousId();
|
|
@@ -1270,14 +1270,12 @@ var ScaleMuleClient = class {
|
|
|
1270
1270
|
return { data: null, error: { code: "aborted", message: "Upload aborted", status: 0 } };
|
|
1271
1271
|
}
|
|
1272
1272
|
if (options?.onProgress && typeof XMLHttpRequest !== "undefined") {
|
|
1273
|
-
return this.uploadWithXHR(url, buildFormData, options.onProgress, options
|
|
1273
|
+
return this.uploadWithXHR(url, buildFormData, options.onProgress, options);
|
|
1274
1274
|
}
|
|
1275
1275
|
const maxRetries = options?.retries ?? this.maxRetries;
|
|
1276
1276
|
let lastError = null;
|
|
1277
1277
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1278
|
-
const headers =
|
|
1279
|
-
if (this.sessionToken) headers["Authorization"] = `Bearer ${this.sessionToken}`;
|
|
1280
|
-
if (this.workspaceId) headers["x-sm-workspace-id"] = this.workspaceId;
|
|
1278
|
+
const headers = await this.uploadHeaders(options);
|
|
1281
1279
|
try {
|
|
1282
1280
|
const response = await fetch(url, {
|
|
1283
1281
|
method: "POST",
|
|
@@ -1319,13 +1317,29 @@ var ScaleMuleClient = class {
|
|
|
1319
1317
|
}
|
|
1320
1318
|
return { data: null, error: lastError || { code: "upload_error", message: "Upload failed", status: 0 } };
|
|
1321
1319
|
}
|
|
1320
|
+
/** Preserve forwarded reader/auth context for both multipart transports. */
|
|
1321
|
+
async uploadHeaders(options) {
|
|
1322
|
+
const headers = { "x-api-key": this.apiKey, ...options?.headers };
|
|
1323
|
+
for (const name of Object.keys(headers)) {
|
|
1324
|
+
if (name.toLowerCase() === "content-type") delete headers[name];
|
|
1325
|
+
}
|
|
1326
|
+
if (this.sessionToken) headers["Authorization"] = `Bearer ${this.sessionToken}`;
|
|
1327
|
+
if (this.workspaceId) headers["x-sm-workspace-id"] = this.workspaceId;
|
|
1328
|
+
if (!this.sessionToken && !Object.keys(headers).some((key) => key.toLowerCase() === "x-anonymous-id")) {
|
|
1329
|
+
headers["x-anonymous-id"] = await this.ensureAnonymousId();
|
|
1330
|
+
}
|
|
1331
|
+
return headers;
|
|
1332
|
+
}
|
|
1322
1333
|
/**
|
|
1323
1334
|
* Single upload with XMLHttpRequest for progress tracking.
|
|
1324
1335
|
* Supports abort via AbortSignal.
|
|
1325
1336
|
*/
|
|
1326
|
-
async uploadWithXHR(url, buildFormData, onProgress,
|
|
1337
|
+
async uploadWithXHR(url, buildFormData, onProgress, options) {
|
|
1338
|
+
const signal = options?.signal;
|
|
1339
|
+
const maxRetries = options?.retries ?? this.maxRetries;
|
|
1327
1340
|
let lastError = null;
|
|
1328
1341
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1342
|
+
const headers = await this.uploadHeaders(options);
|
|
1329
1343
|
const result = await new Promise((res) => {
|
|
1330
1344
|
const xhr = new XMLHttpRequest();
|
|
1331
1345
|
if (signal) {
|
|
@@ -1368,12 +1382,8 @@ var ScaleMuleClient = class {
|
|
|
1368
1382
|
res({ data: null, error: { code: "aborted", message: "Upload aborted", status: 0 } });
|
|
1369
1383
|
});
|
|
1370
1384
|
xhr.open("POST", url);
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
xhr.setRequestHeader("Authorization", `Bearer ${this.sessionToken}`);
|
|
1374
|
-
}
|
|
1375
|
-
if (this.workspaceId) {
|
|
1376
|
-
xhr.setRequestHeader("x-sm-workspace-id", this.workspaceId);
|
|
1385
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
1386
|
+
xhr.setRequestHeader(name, value);
|
|
1377
1387
|
}
|
|
1378
1388
|
xhr.send(buildFormData());
|
|
1379
1389
|
});
|