@constructive-io/sheets 0.13.0 → 0.13.1
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/advanced.cjs +42 -5
- package/dist/advanced.cjs.map +1 -1
- package/dist/advanced.js +2 -2
- package/dist/{chunk-CBXNKMN6.js → chunk-5QPNOKMA.js} +2 -2
- package/dist/{chunk-26J3DVW7.js → chunk-AYMXT3ME.js} +43 -6
- package/dist/chunk-AYMXT3ME.js.map +1 -0
- package/dist/{chunk-HETVHNMD.js → chunk-ZKANUG3F.js} +2 -2
- package/dist/index.cjs +42 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/testing.cjs +42 -5
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +2 -2
- package/package.json +4 -4
- package/dist/chunk-26J3DVW7.js.map +0 -1
- /package/dist/{chunk-CBXNKMN6.js.map → chunk-5QPNOKMA.js.map} +0 -0
- /package/dist/{chunk-HETVHNMD.js.map → chunk-ZKANUG3F.js.map} +0 -0
package/dist/advanced.cjs
CHANGED
|
@@ -2492,11 +2492,39 @@ function resolveUploadCapability(schema) {
|
|
|
2492
2492
|
throw import_data8.createError.badRequest("Uploads are not enabled for this endpoint.");
|
|
2493
2493
|
}
|
|
2494
2494
|
const downloadById = resolveDownloadByIdField(schema, typeByName, queryType, upload.uploadFieldName);
|
|
2495
|
+
const uploadedTypeName = upload.uploadFieldName.replace(/^upload/, "");
|
|
2496
|
+
const fileTypeName = typeByName.has(uploadedTypeName) ? uploadedTypeName : downloadById.fileTypeName;
|
|
2497
|
+
let remove = {};
|
|
2498
|
+
for (const field of mutationType?.fields ?? []) {
|
|
2499
|
+
const inputArg = field.args.find((a) => a.name === "input");
|
|
2500
|
+
const inputTypeName = namedTypeName(inputArg?.type);
|
|
2501
|
+
const inputFields = inputTypeName ? typeByName.get(inputTypeName)?.inputFields : null;
|
|
2502
|
+
if (!inputTypeName || !inputFields?.some((f) => f.name === PK_FIELD_NAME)) continue;
|
|
2503
|
+
if (!inputFields.every((f) => f.name === PK_FIELD_NAME || f.name === "clientMutationId")) continue;
|
|
2504
|
+
const payload = typeByName.get(namedTypeName(field.type) ?? "");
|
|
2505
|
+
if (payload?.fields?.some((f) => namedTypeName(f.type) === fileTypeName)) {
|
|
2506
|
+
remove = { deleteFieldName: field.name, deleteInputTypeName: inputTypeName };
|
|
2507
|
+
break;
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2495
2510
|
return {
|
|
2496
2511
|
...upload,
|
|
2497
|
-
...downloadById
|
|
2512
|
+
...downloadById,
|
|
2513
|
+
...remove
|
|
2498
2514
|
};
|
|
2499
2515
|
}
|
|
2516
|
+
async function deleteUploadedFileRow(execute, cap, fileId) {
|
|
2517
|
+
if (!cap.deleteFieldName || !cap.deleteInputTypeName) return;
|
|
2518
|
+
const mutation = `
|
|
2519
|
+
mutation SheetsUploadCleanup($input: ${cap.deleteInputTypeName}!) {
|
|
2520
|
+
${cap.deleteFieldName}(input: $input) { __typename }
|
|
2521
|
+
}
|
|
2522
|
+
`.trim();
|
|
2523
|
+
try {
|
|
2524
|
+
await execute(mutation, { input: { [PK_FIELD_NAME]: fileId } });
|
|
2525
|
+
} catch {
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2500
2528
|
function resolveDownloadByIdField(schema, typeByName, queryType, uploadFieldName) {
|
|
2501
2529
|
const fileTypesWithDownloadUrl = /* @__PURE__ */ new Set();
|
|
2502
2530
|
for (const t of schema.types) {
|
|
@@ -2614,6 +2642,10 @@ async function callUploadOp(execute, cap, input) {
|
|
|
2614
2642
|
}
|
|
2615
2643
|
return payload;
|
|
2616
2644
|
}
|
|
2645
|
+
var STORAGE_UPLOAD_BLOCKED_MESSAGE = "Upload failed: the storage server didn't accept the upload from this site. Check the bucket's allowed origins (CORS) and your connection.";
|
|
2646
|
+
function storageUnreachableError() {
|
|
2647
|
+
return import_data8.createError.graphql(STORAGE_UPLOAD_BLOCKED_MESSAGE, "STORAGE_UPLOAD_BLOCKED");
|
|
2648
|
+
}
|
|
2617
2649
|
async function presignedPut(url, buffer, contentType, onProgress) {
|
|
2618
2650
|
const total = buffer.byteLength;
|
|
2619
2651
|
if (onProgress && typeof XMLHttpRequest !== "undefined") {
|
|
@@ -2627,8 +2659,8 @@ async function presignedPut(url, buffer, contentType, onProgress) {
|
|
|
2627
2659
|
headers: { "Content-Type": contentType },
|
|
2628
2660
|
body: buffer
|
|
2629
2661
|
});
|
|
2630
|
-
} catch
|
|
2631
|
-
throw
|
|
2662
|
+
} catch {
|
|
2663
|
+
throw storageUnreachableError();
|
|
2632
2664
|
}
|
|
2633
2665
|
if (!response.ok) {
|
|
2634
2666
|
const body = await response.text().catch(() => "");
|
|
@@ -2658,7 +2690,7 @@ function putWithXHR(url, buffer, contentType, total, onProgress) {
|
|
|
2658
2690
|
reject(import_data8.createError.badRequest(`Upload failed: ${xhr.status} ${xhr.statusText}${xhr.responseText ? ` \u2014 ${xhr.responseText}` : ""}`));
|
|
2659
2691
|
}
|
|
2660
2692
|
});
|
|
2661
|
-
xhr.addEventListener("error", () => reject(
|
|
2693
|
+
xhr.addEventListener("error", () => reject(storageUnreachableError()));
|
|
2662
2694
|
xhr.send(buffer);
|
|
2663
2695
|
});
|
|
2664
2696
|
}
|
|
@@ -2842,7 +2874,12 @@ function createSheetsUpload(config, getToken) {
|
|
|
2842
2874
|
if (!payload.uploadUrl) {
|
|
2843
2875
|
throw import_data9.createError.badRequest("Upload failed: server returned no uploadUrl for a non-deduplicated file.");
|
|
2844
2876
|
}
|
|
2845
|
-
|
|
2877
|
+
try {
|
|
2878
|
+
await presignedPut(payload.uploadUrl, buffer, contentType, options?.onProgress);
|
|
2879
|
+
} catch (error) {
|
|
2880
|
+
await deleteUploadedFileRow(execute, cap, payload.fileId);
|
|
2881
|
+
throw error;
|
|
2882
|
+
}
|
|
2846
2883
|
} else {
|
|
2847
2884
|
options?.onProgress?.({ loaded: file.size, total: file.size, percentage: 100 });
|
|
2848
2885
|
}
|