@gemina/sdk 0.3.1 → 0.3.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 CHANGED
@@ -10067,6 +10067,51 @@ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
10067
10067
  ResponseStatus.Empty,
10068
10068
  ResponseStatus.Failed
10069
10069
  ]);
10070
+ var FTYP_BRAND_FORMATS = {
10071
+ heic: { ext: ".heic", type: "image/heic" },
10072
+ heix: { ext: ".heic", type: "image/heic" },
10073
+ mif1: { ext: ".heif", type: "image/heif" },
10074
+ heim: { ext: ".heif", type: "image/heif" },
10075
+ heis: { ext: ".heif", type: "image/heif" },
10076
+ avif: { ext: ".avif", type: "image/avif" },
10077
+ // avis (animated AVIF) is deliberately mapped, unlike the HEIF sequence
10078
+ // brands: the API accepts animated AVIF and processes its first frame.
10079
+ avis: { ext: ".avif", type: "image/avif" }
10080
+ };
10081
+ function sniffFormat(bytes) {
10082
+ const ascii = (start, end) => bytes.length >= end ? String.fromCharCode(...bytes.subarray(start, end)) : "";
10083
+ if (ascii(0, 4) === "%PDF") return { ext: ".pdf", type: "application/pdf" };
10084
+ if (bytes[0] === 137 && ascii(1, 4) === "PNG") return { ext: ".png", type: "image/png" };
10085
+ if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) {
10086
+ return { ext: ".jpg", type: "image/jpeg" };
10087
+ }
10088
+ if (ascii(0, 4) === "GIF8") return { ext: ".gif", type: "image/gif" };
10089
+ if (ascii(0, 4) === "RIFF" && ascii(8, 12) === "WEBP") {
10090
+ return { ext: ".webp", type: "image/webp" };
10091
+ }
10092
+ if (ascii(4, 8) === "ftyp") return FTYP_BRAND_FORMATS[ascii(8, 12)];
10093
+ return void 0;
10094
+ }
10095
+ function hasUsefulType(type) {
10096
+ return type !== "" && type !== "application/octet-stream";
10097
+ }
10098
+ async function normalizeBlobSource(source) {
10099
+ if (typeof File === "undefined") {
10100
+ return source;
10101
+ }
10102
+ const isFile = source instanceof File;
10103
+ if (isFile && hasUsefulType(source.type)) {
10104
+ return source;
10105
+ }
10106
+ const head = new Uint8Array(await source.slice(0, 32).arrayBuffer());
10107
+ const sniffed = sniffFormat(head);
10108
+ if (sniffed === void 0) {
10109
+ return source;
10110
+ }
10111
+ const name = isFile && source.name !== "" ? source.name : `document${sniffed.ext}`;
10112
+ const type = hasUsefulType(source.type) ? source.type : sniffed.type;
10113
+ return new File([source], name, { type });
10114
+ }
10070
10115
  function defaultSleep(seconds) {
10071
10116
  return new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
10072
10117
  }
@@ -10231,7 +10276,7 @@ var GeminaClient = class _GeminaClient {
10231
10276
  if (typeof Blob !== "undefined" && source instanceof Blob) {
10232
10277
  try {
10233
10278
  submitted = await this.documents.createDocumentProcessingRequest({
10234
- file: source,
10279
+ file: await normalizeBlobSource(source),
10235
10280
  externalId,
10236
10281
  extractionTypes,
10237
10282
  templateId: options.templateId,
@@ -10352,7 +10397,7 @@ async function asProcessingErrorIfFailedResult(error) {
10352
10397
  }
10353
10398
 
10354
10399
  // src/version.ts
10355
- var VERSION = "0.3.1";
10400
+ var VERSION = "0.3.2";
10356
10401
  // Annotate the CommonJS export names for ESM import in node:
10357
10402
  0 && (module.exports = {
10358
10403
  AggregateMetaDTOFromJSON,