@3dverse/api 0.12.0 → 0.13.0

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.
@@ -1716,6 +1716,15 @@ export type Import = {
1716
1716
  status: ('waiting' | 'downloading' | 'extracting' | 'pending' | 'converting' | 'error' | 'success' | 'rejected') & string;
1717
1717
  conversions: Array<Conversion>;
1718
1718
  };
1719
+ /** A file an import downloads, given by its URL */
1720
+ export type RemoteFile = {
1721
+ /** The name of the file */
1722
+ name: string;
1723
+ /** The URL of the file, which must be public, unless an Authorization header is given */
1724
+ url: string;
1725
+ /** The value of the Authorization header of the download, when it needs one */
1726
+ authorization?: string;
1727
+ };
1719
1728
  /** A line a conversion task logged, as logged */
1720
1729
  export type ConversionLogLine = {
1721
1730
  /**
@@ -8718,7 +8727,8 @@ export declare function listSourceFileAssets({ source_file_id, }: {
8718
8727
  }, headers?: RawAxiosRequestHeaders | AxiosRequestHeaders): AxiosPromise<AssetList>;
8719
8728
  /**
8720
8729
  * Imports files into a folder: source files, converted into assets, or asset packages, imported as they are. The
8721
- * files are sent in the request, or given by URL, for the import to download them. The accepted extensions, their
8730
+ * files are sent in a multipart body, or given by URL, for the import to download them: in a JSON body when none is
8731
+ * sent. The accepted extensions, their
8722
8732
  * conversion type and per-converter options are listed by `GET /source-files/supported-formats` and documented at
8723
8733
  * https://docs.3dverse.com/references/supported-file-formats.
8724
8734
  * The folder is given in the query, so that a request the folder's permission refuses is refused before any of its
@@ -8759,17 +8769,10 @@ export declare function createImport({ folder_id, files, conversion_pipeline, re
8759
8769
  files?: Array<Blob>;
8760
8770
  conversion_pipeline: ConversionPipeline;
8761
8771
  /**
8762
- * Files the import downloads, given by URL, in place of or along with the files sent: those already on a
8763
- * storage service, or too large to send through the API.
8772
+ * Files the import downloads, given by URL, along with the files sent: those already on a storage
8773
+ * service, or too large to send through the API.
8764
8774
  */
8765
- remote_files?: Array<{
8766
- /** The name of the file */
8767
- name: string;
8768
- /** The URL of the file, which must be public, unless an Authorization header is given */
8769
- url: string;
8770
- /** The value of the Authorization header of the download, when it needs one */
8771
- authorization?: string;
8772
- }>;
8775
+ remote_files?: Array<RemoteFile>;
8773
8776
  /** Options for the conversion pipeline. For future use. */
8774
8777
  options?: {
8775
8778
  [_additionalproperties_: string]: any;
package/dist/index.js CHANGED
@@ -180,6 +180,13 @@ function multipartBody(fields, files) {
180
180
  }
181
181
  return form;
182
182
  }
183
+ function jsonOrMultipartBody(fields, files) {
184
+ const hasFile = Object.values(files).some((value) => Array.isArray(value) ? value.length > 0 : value !== void 0);
185
+ if (hasFile) {
186
+ return multipartBody(fields, files);
187
+ }
188
+ return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== void 0));
189
+ }
183
190
  function plainHeaders(headers) {
184
191
  return headers instanceof import_axios.AxiosHeaders ? headers.toJSON() : { ...headers };
185
192
  }
@@ -898,7 +905,7 @@ function createImport({
898
905
  params: {
899
906
  folder_id
900
907
  },
901
- data: multipartBody(
908
+ data: jsonOrMultipartBody(
902
909
  {
903
910
  conversion_pipeline,
904
911
  remote_files,
@@ -909,10 +916,7 @@ function createImport({
909
916
  }
910
917
  ),
911
918
  onUploadProgress,
912
- headers: {
913
- "Content-Type": "multipart/form-data",
914
- ...plainHeaders(headers)
915
- }
919
+ headers
916
920
  });
917
921
  }
918
922
  function listImports({