@ai4b-team/fsaos-gateway-sdk 4.3.0 → 4.3.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/index.d.cts CHANGED
@@ -3142,6 +3142,8 @@ interface UploadOptions {
3142
3142
  parentPath: string;
3143
3143
  /** Override the file name (defaults to File.name). */
3144
3144
  name?: string;
3145
+ /** On a name collision, save a numbered sibling (default) or return NAME_TAKEN. */
3146
+ collisionPolicy?: 'keep_both' | 'fail';
3145
3147
  /** Override item_type (defaults to 'file'). */
3146
3148
  itemType?: string;
3147
3149
  /** Additional type_data fields to merge onto the created item. */
package/dist/index.d.ts CHANGED
@@ -3142,6 +3142,8 @@ interface UploadOptions {
3142
3142
  parentPath: string;
3143
3143
  /** Override the file name (defaults to File.name). */
3144
3144
  name?: string;
3145
+ /** On a name collision, save a numbered sibling (default) or return NAME_TAKEN. */
3146
+ collisionPolicy?: 'keep_both' | 'fail';
3145
3147
  /** Override item_type (defaults to 'file'). */
3146
3148
  itemType?: string;
3147
3149
  /** Additional type_data fields to merge onto the created item. */
package/dist/index.js CHANGED
@@ -5634,14 +5634,27 @@ function getRequiredFormFields(typeDef) {
5634
5634
  (f) => required.has(f.key) || f.default_value === void 0
5635
5635
  );
5636
5636
  }
5637
- var _idCounter = 0;
5638
5637
  function generateUploadId() {
5639
- return `upload_${Date.now()}_${++_idCounter}`;
5638
+ if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
5639
+ const bytes = new Uint8Array(16);
5640
+ if (globalThis.crypto?.getRandomValues) {
5641
+ globalThis.crypto.getRandomValues(bytes);
5642
+ bytes[6] = bytes[6] & 15 | 64;
5643
+ bytes[8] = bytes[8] & 63 | 128;
5644
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
5645
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
5646
+ }
5647
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
5648
+ const n = Math.floor(Math.random() * 16);
5649
+ return (c === "x" ? n : n & 3 | 8).toString(16);
5650
+ });
5640
5651
  }
5641
5652
  async function uploadFile(file, options, onProgress, signal2) {
5642
5653
  const fileName = options.name || (file instanceof File ? file.name : `file-${Date.now()}`);
5643
5654
  const contentType = file.type || "application/octet-stream";
5644
5655
  const itemType = options.itemType || "file";
5656
+ const collisionPolicy = options.collisionPolicy || "keep_both";
5657
+ const uploadId = collisionPolicy === "keep_both" ? generateUploadId() : void 0;
5645
5658
  const createParams = {
5646
5659
  parent_path: options.parentPath,
5647
5660
  item_type: itemType,
@@ -5650,7 +5663,9 @@ async function uploadFile(file, options, onProgress, signal2) {
5650
5663
  ...options.typeData || {},
5651
5664
  file_source: {
5652
5665
  type: "upload",
5653
- content_type: contentType
5666
+ content_type: contentType,
5667
+ collision_policy: collisionPolicy,
5668
+ ...uploadId ? { upload_id: uploadId } : {}
5654
5669
  }
5655
5670
  }
5656
5671
  };
@@ -5752,6 +5767,7 @@ function useFileUpload() {
5752
5767
  const fileName = options.name || file.name;
5753
5768
  const contentType = file.type || "application/octet-stream";
5754
5769
  const itemType = options.itemType || "file";
5770
+ const collisionPolicy = options.collisionPolicy || "keep_both";
5755
5771
  let itemId = existingState?.itemId || null;
5756
5772
  let itemPath = existingState?.itemPath || null;
5757
5773
  let storageKey = existingState?.storageKey || null;
@@ -5768,7 +5784,9 @@ function useFileUpload() {
5768
5784
  ...options.typeData || {},
5769
5785
  file_source: {
5770
5786
  type: "upload",
5771
- content_type: contentType
5787
+ content_type: contentType,
5788
+ collision_policy: collisionPolicy,
5789
+ ...collisionPolicy === "keep_both" ? { upload_id: uploadId } : {}
5772
5790
  }
5773
5791
  }
5774
5792
  });