UNPKG

flatfile-csv-importer

Version:

A simple adapter for elegantly importing CSV files via flatfile.io (Typescript, ES6, Browser)

1 lines 27.3 kB
var FlatfileImporter=function(){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};var t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function f(n,r){var o,i,a,e,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,i&&(a=2&t[0]?i.return:t[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,t[1])).done)return a;switch(i=0,a&&(t=[2&t[0],a.value]),t[0]){case 0:case 1:a=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,i=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!a||t[1]>a[0]&&t[1]<a[3])){u.label=t[1];break}if(6===t[0]&&u.label<a[1]){u.label=a[1],a=t;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(t);break}a[2]&&u.ops.pop(),u.trys.pop();continue}t=r.call(n,u)}catch(e){t=[6,e],i=0}finally{o=a=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}var p="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(e,t){return e(t={exports:{}},t.exports),t.exports}e(function(e,t){!function(){"use strict";var t=setTimeout;function r(){}function o(e,t){return function(){e.apply(t,arguments)}}function i(e){if(!(this instanceof i))throw new TypeError("Promises must be constructed via new");if(typeof e!=="function")throw new TypeError("not a function");this._state=0;this._handled=false;this._value=undefined;this._deferreds=[];f(e,this)}function a(n,r){while(n._state===3){n=n._value}if(n._state===0){n._deferreds.push(r);return}n._handled=true;i._immediateFn(function(){var e=n._state===1?r.onFulfilled:r.onRejected;if(e===null){(n._state===1?u:c)(r.promise,n._value);return}var t;try{t=e(n._value)}catch(e){c(r.promise,e);return}u(r.promise,t)})}function u(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&(typeof e==="object"||typeof e==="function")){var n=e.then;if(e instanceof i){t._state=3;t._value=e;s(t);return}else if(typeof n==="function"){f(o(n,e),t);return}}t._state=1;t._value=e;s(t)}catch(e){c(t,e)}}function c(e,t){e._state=2;e._value=t;s(e)}function s(e){if(e._state===2&&e._deferreds.length===0){i._immediateFn(function(){if(!e._handled){i._unhandledRejectionFn(e._value)}})}for(var t=0,n=e._deferreds.length;t<n;t++){a(e,e._deferreds[t])}e._deferreds=null}function l(e,t,n){this.onFulfilled=typeof e==="function"?e:null;this.onRejected=typeof t==="function"?t:null;this.promise=n}function f(e,t){var n=false;try{e(function(e){if(n)return;n=true;u(t,e)},function(e){if(n)return;n=true;c(t,e)})}catch(e){if(n)return;n=true;c(t,e)}}i.prototype["catch"]=function(e){return this.then(null,e)},i.prototype.then=function(e,t){var n=new this.constructor(r);a(this,new l(e,t,n));return n},i.prototype["finally"]=function(t){var n=this.constructor;return this.then(function(e){return n.resolve(t()).then(function(){return e})},function(e){return n.resolve(t()).then(function(){return n.reject(e)})})},i.all=function(t){return new i(function(r,o){if(!t||typeof t.length==="undefined")throw new TypeError("Promise.all accepts an array");var i=Array.prototype.slice.call(t);if(i.length===0)return r([]);var a=i.length;function u(t,e){try{if(e&&(typeof e==="object"||typeof e==="function")){var n=e.then;if(typeof n==="function"){n.call(e,function(e){u(t,e)},o);return}}i[t]=e;if(--a===0){r(i)}}catch(e){o(e)}}for(var e=0;e<i.length;e++){u(e,i[e])}})},i.resolve=function(t){if(t&&typeof t==="object"&&t.constructor===i){return t}return new i(function(e){e(t)})},i.reject=function(n){return new i(function(e,t){t(n)})},i.race=function(o){return new i(function(e,t){for(var n=0,r=o.length;n<r;n++){o[n].then(e,t)}})},i._immediateFn=typeof setImmediate==="function"&&function(e){setImmediate(e)}||function(e){t(e,0)},i._unhandledRejectionFn=function e(t){if(typeof console!=="undefined"&&console){console.warn("Possible Unhandled Promise Rejection:",t)}};var e=function(){if(typeof self!=="undefined"){return self}if(typeof window!=="undefined"){return window}if(typeof p!=="undefined"){return p}throw new Error("unable to locate global object")}();if(!e.Promise){e.Promise=i}}()});function o(n,r){return new Promise(function(e){n&&"function"!=typeof n&&(r=n,n=null),r=r||window.document;function t(){return e(void(n&&setTimeout(n)))}-1!==i.indexOf(r.readyState)?t():r.addEventListener("DOMContentLoaded",t)})}var r=e(function(e){var r=Object.prototype.hasOwnProperty,d="~";function n(){}function u(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,r,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var i=new u(n,r||e,o),a=d?d+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],i]:e._events[a].push(i):(e._events[a]=i,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function t(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(d=!1)),t.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)r.call(e,t)&&n.push(d?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},t.prototype.listeners=function(e){var t=d?d+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,o=n.length,i=new Array(o);r<o;r++)i[r]=n[r].fn;return i},t.prototype.listenerCount=function(e){var t=d?d+e:e,n=this._events[t];return n?n.fn?1:n.length:0},t.prototype.emit=function(e,t,n,r,o,i){var a=d?d+e:e;if(!this._events[a])return!1;var u,c,s=this._events[a],l=arguments.length;if(s.fn){switch(s.once&&this.removeListener(e,s.fn,void 0,!0),l){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,t),!0;case 3:return s.fn.call(s.context,t,n),!0;case 4:return s.fn.call(s.context,t,n,r),!0;case 5:return s.fn.call(s.context,t,n,r,o),!0;case 6:return s.fn.call(s.context,t,n,r,o,i),!0}for(c=1,u=new Array(l-1);c<l;c++)u[c-1]=arguments[c];s.fn.apply(s.context,u)}else{var f,p=s.length;for(c=0;c<p;c++)switch(s[c].once&&this.removeListener(e,s[c].fn,void 0,!0),l){case 1:s[c].fn.call(s[c].context);break;case 2:s[c].fn.call(s[c].context,t);break;case 3:s[c].fn.call(s[c].context,t,n);break;case 4:s[c].fn.call(s[c].context,t,n,r);break;default:if(!u)for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];s[c].fn.apply(s[c].context,u)}}return!0},t.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},t.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},t.prototype.removeListener=function(e,t,n,r){var o=d?d+e:e;if(!this._events[o])return this;if(!t)return s(this,o),this;var i=this._events[o];if(i.fn)i.fn!==t||r&&!i.once||n&&i.context!==n||s(this,o);else{for(var a=0,u=[],c=i.length;a<c;a++)(i[a].fn!==t||r&&!i[a].once||n&&i[a].context!==n)&&u.push(i[a]);u.length?this._events[o]=1===u.length?u[0]:u:s(this,o)}return this},t.prototype.removeAllListeners=function(e){var t;return e?(t=d?d+e:e,this._events[t]&&s(this,t)):(this._events=new n,this._eventsCount=0),this},t.prototype.off=t.prototype.removeListener,t.prototype.addListener=t.prototype.on,t.prefixed=d,t.EventEmitter=t,e.exports=t}).EventEmitter,i=["interactive","complete"];o.resume=function(t){return function(e){return o(t).then(function(){return e})}};var u=[],c=[];function a(e,t){if(t=t||{},void 0===e)throw new Error("insert-css: You need to provide a CSS string. Usage: insertCss(cssString[, options]).");var n,r,o=!0===t.prepend?"prepend":"append",i=void 0!==t.container?t.container:document.querySelector("head"),a=u.indexOf(i);return-1===a&&(a=u.push(i)-1,c[a]={}),void 0!==c[a]&&void 0!==c[a][o]?n=c[a][o]:(n=c[a][o]=((r=document.createElement("style")).setAttribute("type","text/css"),r),"prepend"==o?i.insertBefore(n,i.childNodes[0]):i.appendChild(n)),65279===e.charCodeAt(0)&&(e=e.substr(1,e.length)),n.styleSheet?n.styleSheet.cssText+=e:n.textContent+=e,n}var s=a,l=a;s.insertCss=l;function d(e){return new m(e)}function h(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}function m(e){if(!(this instanceof m))return new m(e);(e=e||{}).nodeType&&(e={el:e}),this.opts=e,this.el=e.el||document.body,"object"!=typeof this.el&&(this.el=document.querySelector(this.el))}m.prototype.add=function(e){var t=this.el;if(t){if(""===t.className)return t.className=e;var n=t.className.split(" ");return-1<h(n,e)?n:(n.push(e),t.className=n.join(" "),n)}},m.prototype.remove=function(e){var t=this.el;if(t&&""!==t.className){var n=t.className.split(" "),r=h(n,e);return-1<r&&n.splice(r,1),t.className=n.join(" "),n}},m.prototype.has=function(e){var t=this.el;if(t)return-1<h(t.className.split(" "),e)},m.prototype.toggle=function(e){this.el&&(this.has(e)?this.remove(e):this.add(e))};var y,b=e(function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.ERR_IFRAME_ALREADY_ATTACHED_TO_DOM=t.ERR_NOT_IN_IFRAME=t.ERR_CONNECTION_TIMEOUT=t.ERR_CONNECTION_DESTROYED=void 0;var b="handshake",v="handshake-reply",d="reply",h="fulfilled",f="rejected",g="message",w="ConnectionDestroyed";t.ERR_CONNECTION_DESTROYED=w;var _="ConnectionTimeout";t.ERR_CONNECTION_TIMEOUT=_;var o="NotInIframe";t.ERR_NOT_IN_IFRAME=o;var i="IframeAlreadyAttachedToDom";t.ERR_IFRAME_ALREADY_ATTACHED_TO_DOM=i;function O(){if(k.debug){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(e=console).log.apply(e,["[Penpal]"].concat(n))}}function $(e){var t=[];return e(function(){t.forEach(function(e){e()})}),{then:function(e){t.push(e)}}}function p(e){return{name:e.name,message:e.message,stack:e.stack}}function E(e,t,n,o,r){var s=t.localName,l=t.local,f=t.remote,p=t.remoteOrigin,i=!1;function a(c){return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if(O("".concat(s,": Sending ").concat(c,"() call")),f.closed&&o(),i){var r=new Error("Unable to send ".concat(c,"() call due ")+"to destroyed connection");throw r.code=w,r}return new k.Promise(function(i,a){var u=m();l.addEventListener(g,function e(t){if(t.source===f&&t.origin===p&&t.data.penpal===d&&t.data.id===u){O("".concat(s,": Received ").concat(c,"() reply")),l.removeEventListener(g,e);var n=t.data.returnValue;t.data.returnValueIsError&&(r=n,o=new Error,Object.keys(r).forEach(function(e){return o[e]=r[e]}),n=o),(t.data.resolution===h?i:a)(n)}var r,o}),f.postMessage({penpal:"call",id:u,methodName:c,args:t},p)})}}O("".concat(s,": Connecting call sender")),r.then(function(){i=!0}),n.reduce(function(e,t){return e[t]=a(t),e},e)}function P(e,a,t){var u=e.localName,n=e.local,c=e.remote,s=e.remoteOrigin,l=!1;function r(e){if(e.source===c&&e.origin===s&&"call"===e.data.penpal){var t=e.data,r=t.methodName,n=t.args,o=t.id;if(O("".concat(u,": Received ").concat(r,"() call")),r in a){var i=function(n){return function(e){if(O("".concat(u,": Sending ").concat(r,"() reply")),l)O("".concat(u,": Unable to send ").concat(r,"() reply due to destroyed connection"));else{var t={penpal:d,id:o,resolution:n,returnValue:e};n===f&&e instanceof Error&&(t.returnValue=p(e),t.returnValueIsError=!0);try{c.postMessage(t,s)}catch(e){throw"DataCloneError"===e.name&&c.postMessage({penpal:d,id:o,resolution:f,returnValue:p(e),returnValueIsError:!0},s),e}}}};new k.Promise(function(e){return e(a[r].apply(a,n))}).then(i(h),i(f))}}}O("".concat(u,": Connecting call receiver")),n.addEventListener(g,r),t.then(function(){l=!0,n.removeEventListener(g,r)})}var n,u={"http:":"80","https:":"443"},c=/^(https?:|file:)?\/\/([^/:]+)?(:(\d+))?/,k={ERR_CONNECTION_DESTROYED:w,ERR_CONNECTION_TIMEOUT:_,ERR_NOT_IN_IFRAME:o,ERR_IFRAME_ALREADY_ATTACHED_TO_DOM:i,Promise:function(){try{return window?window.Promise:null}catch(e){return null}}(),debug:!1},m=(n=0,function(){return++n});k.connectToChild=function(e){var l,t=e.url,o=e.appendTo,f=e.iframe,n=e.methods,p=void 0===n?{}:n,d=e.timeout;if(f&&f.parentNode){var r=new Error("connectToChild() must not be called with an iframe already attached to DOM");throw r.code=i,r}var h=new $(function(e){l=e}),m=window,y=function(e){var t,n,r,o=document.location,i=c.exec(e);if(r=i?(t=i[1]?i[1]:o.protocol,n=i[2],i[4]):(t=o.protocol,n=o.hostname,o.port),"file:"===t)return"null";var a=r&&r!==u[t]?":".concat(r):"";return"".concat(t,"//").concat(n).concat(a)}((f=f||document.createElement("iframe")).src=t);return{promise:new k.Promise(function(i,t){var a;void 0!==d&&(a=setTimeout(function(){var e=new Error("Connection to child timed out after ".concat(d,"ms"));e.code=_,t(e),l()},d));function n(e){var t=f.contentWindow;if(e.source===t&&e.origin===y&&e.data.penpal===b){O("Parent: Received handshake, sending reply");var n="null"===e.origin?"*":e.origin;e.source.postMessage({penpal:v,methodNames:Object.keys(p)},n);var r={localName:"Parent",local:m,remote:t,remoteOrigin:n};c&&c();var o=new $(function(e){h.then(e),c=e});P(r,p,o),u&&u.forEach(function(e){delete s[e]}),u=e.data.methodNames,E(s,r,u,l,h),clearTimeout(a),i(s)}}var u,c,s={};m.addEventListener(g,n),O("Parent: Loading iframe"),(o||document.body).appendChild(f);var r=setInterval(function(){document.contains(f)||(clearInterval(r),l())},6e4);h.then(function(){f.parentNode&&f.parentNode.removeChild(f),m.removeEventListener(g,n),clearInterval(r);var e=new Error("Connection destroyed");e.code=w,t(e)})}),iframe:f,destroy:l}},k.connectToParent=function(){var a,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=e.parentOrigin,u=void 0===t?"*":t,n=e.methods,c=void 0===n?{}:n,s=e.timeout;if(window===window.top){var r=new Error("connectToParent() must be called within an iframe");throw r.code=o,r}var l=new $(function(e){a=e}),f=window,p=f.parent;return{promise:new k.Promise(function(r,t){var o;void 0!==s&&(o=setTimeout(function(){var e=new Error("Connection to parent timed out after ".concat(s,"ms"));e.code=_,t(e),a()},s));function i(e){if(("*"===u||u===e.origin)&&e.source===p&&e.data.penpal===v){O("Child: Received handshake reply"),f.removeEventListener(g,i);var t={localName:"Child",local:f,remote:p,remoteOrigin:e.origin},n={};P(t,c,l),E(n,t,e.data.methodNames,a,l),clearTimeout(o),r(n)}}f.addEventListener(g,i),l.then(function(){f.removeEventListener(g,i);var e=new Error("Connection destroyed");e.code=w,t(e)}),O("Child: Sending handshake"),p.postMessage({penpal:b,methodNames:Object.keys(c)},u)}),destroy:a}};var r=k;t.default=r}),v=(y=b)&&y.__esModule&&Object.prototype.hasOwnProperty.call(y,"default")?y.default:y,g=(Object.defineProperty(w.prototype,"originalRows",{get:function(){return this.$meta.count_rows},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"acceptedRows",{get:function(){return this.$meta.count_rows_accepted||null},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"originalColumns",{get:function(){return this.$meta.count_columns||null},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"matchedColumns",{get:function(){return this.$meta.count_columns_matched||null},enumerable:!0,configurable:!0}),w);function w(e){this.$meta=e}var _=(Object.defineProperty(O.prototype,"id",{get:function(){return this.$user.id},enumerable:!0,configurable:!0}),Object.defineProperty(O.prototype,"userId",{get:function(){return this.$user.userId},enumerable:!0,configurable:!0}),Object.defineProperty(O.prototype,"name",{get:function(){return this.$user.name},enumerable:!0,configurable:!0}),Object.defineProperty(O.prototype,"email",{get:function(){return this.$user.name},enumerable:!0,configurable:!0}),Object.defineProperty(O.prototype,"companyName",{get:function(){return this.$user.companyName},enumerable:!0,configurable:!0}),Object.defineProperty(O.prototype,"companyId",{get:function(){return this.$user.companyId},enumerable:!0,configurable:!0}),O);function O(e){this.$user=e}var $=(Object.defineProperty(E.prototype,"id",{get:function(){return this.$file.id},enumerable:!0,configurable:!0}),Object.defineProperty(E.prototype,"filename",{get:function(){return this.$file.filename},enumerable:!0,configurable:!0}),Object.defineProperty(E.prototype,"filesize",{get:function(){return this.$file.filesize},enumerable:!0,configurable:!0}),Object.defineProperty(E.prototype,"filetype",{get:function(){return this.$file.filetype},enumerable:!0,configurable:!0}),Object.defineProperty(E.prototype,"url",{get:function(){return this.$file.url},enumerable:!0,configurable:!0}),E);function E(e){this.$file=e}var P=(Object.defineProperty(k.prototype,"rawOutput",{get:function(){return this.$data},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"data",{get:function(){return this.validData},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"validData",{get:function(){return this.$data.filter(function(e){return e.valid}).filter(function(e){return!e.deleted}).map(function(e){return e.data})},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"deletedData",{get:function(){return this.$data.filter(function(e){return e.deleted}).map(function(e){return e.data})},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"allData",{get:function(){return this.$data.map(function(e){return e.data})},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"remainingChunks",{get:function(){return Math.ceil((this.totalChunks-this.currentChunk)/this.$meta.inChunks)},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"totalChunks",{get:function(){return Math.ceil(this.$meta.count_rows_accepted/this.$meta.inChunks)},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"chunkSize",{get:function(){return this.$meta.inChunks},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"currentChunk",{get:function(){return(this.$meta.pointer+this.chunkSize)/this.chunkSize},enumerable:!0,configurable:!0}),Object.defineProperty(k.prototype,"hasMore",{get:function(){return this.$meta.hasMore},enumerable:!0,configurable:!0}),k);function k(e,t){this.$meta=t,this.$data=e}var C,j,R,T=(Object.defineProperty(N.prototype,"rawOutput",{get:function(){return this.blobOnly(this.$data,"rawOutput")},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"data",{get:function(){return this.blobOnly(this.validData,"data")},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"validData",{get:function(){var e=this.$data.filter(function(e){return e.valid}).filter(function(e){return!e.deleted}).map(function(e){return e.data});return this.blobOnly(e,"validData")},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"deletedData",{get:function(){var e=this.$data.filter(function(e){return e.deleted}).map(function(e){return e.data});return this.blobOnly(e,"deletedData")},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"allData",{get:function(){return this.blobOnly(this.$data.map(function(e){return e.data}),"allData")},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"batchId",{get:function(){return this.$meta.batchID},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"stats",{get:function(){return new g(this.$meta)},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"customer",{get:function(){return this.$meta.endUser?new _(this.$meta.endUser):null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"originalFile",{get:function(){return this.$meta.originalFile?new $(this.$meta.originalFile):null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"csvFile",{get:function(){if(this.$meta.originalFile){if("csv"===this.$meta.originalFile.filetype)return new $(this.$meta.originalFile);if(this.$meta.csvFile)return new $(this.$meta.csvFile)}return null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"fileName",{get:function(){return this.$meta.filename||null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"managed",{get:function(){return this.$meta.managed||!1},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"manual",{get:function(){return this.$meta.manual},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"config",{get:function(){return this.$meta.config},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"parsingConfig",{get:function(){return this.$meta.parsing_config},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"skippedRows",{get:function(){return this.$meta.skipped_rows||null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"headersRaw",{get:function(){return this.$meta.headers_raw||null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"headersMatched",{get:function(){return this.$meta.headers_matched||null},enumerable:!0,configurable:!0}),N.prototype.nextChunk=function(){var n=this;return new Promise(function(t,e){if(!n.$meta.inChunks)return e('"nextChunk()" is only accessible when using "inChunks". Please see docs for "requestDataFromUser".');n.$importer.$ready.then(function(e){console.log("child.nextChunk()"),e.nextChunk().then(function(e){console.log("nextChunk()",e),t(e.results.length?new P(e.results,e.meta):null)},function(e){console.log("nextChunk(err)",e)})})})},Object.defineProperty(N.prototype,"customColumns",{get:function(){return this.$meta.custom_columns},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"failureReason",{get:function(){return this.$meta.failure_reason||null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"submittedAt",{get:function(){return this.$meta.submitted_at||null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"failedAt",{get:function(){return this.$meta.failed_at||null},enumerable:!0,configurable:!0}),Object.defineProperty(N.prototype,"createdAt",{get:function(){return this.$meta.created_at},enumerable:!0,configurable:!0}),N.prototype.blobOnly=function(e,t,n){if(void 0===n&&(n="nextChunk()"),this.$meta.inChunks)throw new Error('"'+t+'" is not accessible when using "inChunks". Please see docs for "'+n+'" instead.');return e},N);function N(e,t,n){this.$meta=t,this.$data=e,this.$importer=n}function x(){this.constructor=j}function I(e,t,n){var r=C.call(this)||this;return r.$fieldHooks=[],r.apiKey=e,r.options=t,r.customer=n,r.uuid=r.$generateUuid(),r.$ready=new I.Promise(function(e,t){r.$resolver=e,r.$rejecter=t}),o(function(){r.initialize()}),r}return n(j=I,R=C=r),j.prototype=null===R?Object.create(R):(x.prototype=R.prototype,new x),I.setMountUrl=function(e){this.MOUNT_URL=e},I.setVersion=function(e){switch(e){case 1:this.MOUNT_URL="https://kiosk-lite.flatfile.io/?key=:key";break;case 2:this.MOUNT_URL="https://portal-2.flatfile.io/?key=:key";break;default:throw new Error(e+" is not a valid version")}},I.prototype.open=function(n){var r=this;void 0===n&&(n={}),n=t({},n,{hasRecordHook:!!this.$recordHook,fieldHooks:this.$fieldHooks.map(function(e){return e.field}),endUser:this.customer}),this.$ready.then(function(e){d(document.body).add("flatfile-active");var t=document.getElementById("flatfile-"+r.uuid);t&&(t.style.display="block"),e.open(n)})},I.prototype.load=function(){var i=this;return new I.Promise(function(t,n){i.open();var r=function(){i.removeListener("close",o),i.removeListener("complete",e)};function e(e){t(e),r()}function o(e){n(e),r()}i.on("close",o),i.on("complete",e)})},I.prototype.requestDataFromUser=function(e){return void 0===e&&(e={}),this.open(t({},e,{inChunks:e.inChunks||null,expectsExpandedResults:!0})),this.responsePromise()},I.prototype.displayLoader=function(t){this.$ready.then(function(e){e.displayLoader(t)})},I.prototype.displayError=function(t){this.$ready.then(function(e){e.displayError(t)})},I.prototype.requestCorrectionsFromUser=function(t){return this.$ready.then(function(e){e.displayError(t)}),this.responsePromise()},I.prototype.displaySuccess=function(t){this.$ready.then(function(e){e.displaySuccess(t)})},I.prototype.getMeta=function(){var e=this;return new Promise(function(t,n){e.$ready.then(function(e){e.getMeta().then(t).catch(n)}).catch(n)})},I.prototype.setCustomer=function(e){this.customer=e},I.prototype.registerValidatorCallback=function(e){this.$validatorCallback=e,this.$ready.then(function(e){e.parentHasValidator()})},I.prototype.registerRecordHook=function(e){this.$recordHook=e},I.prototype.registerFieldHook=function(e,t){this.$fieldHooks.push({field:e,cb:t})},I.prototype.close=function(){this.$ready.then(function(e){e.close()})},I.prototype.handleClose=function(){d(document.body).remove("flatfile-active");var e=document.getElementById("flatfile-"+this.uuid);e&&(e.style.display="none")},I.prototype.initialize=function(){var r=this;s("\n .flatfile-component {\n position: fixed;\n top: 0;\n bottom: 0;\n right: 0;\n left: 0;\n display: none;\n z-index: 100000;\n }\n .flatfile-component iframe {\n width: 100%;\n height: 100%;\n position: absolute;\n border-width: 0;\n }\n body.flatfile-active {\n overflow: hidden;\n overscroll-behavior-x: none;\n }\n "),document.body.insertAdjacentHTML("beforeend",'<div id="flatfile-'+this.uuid+'" class="flatfile-component"></div>'),this.handshake=v.connectToChild({appendTo:document.getElementById("flatfile-"+this.uuid)||void 0,url:I.MOUNT_URL.replace(":key",this.apiKey),methods:{results:function(e){r.emit("results",e.results,e.meta)},complete:function(e){r.emit("complete",e.rows,e.meta)},close:function(){r.emit("close"),r.handleClose()},validatorCallback:function(e){return r.$validatorCallback?r.$validatorCallback(e):void 0},dataHookCallback:function(e,t,n){return r.$recordHook?r.$recordHook(e,t,n):void 0},fieldHookCallback:function(e,t){var n=r.$fieldHooks.find(function(e){return e.field===t.field});if(n)return n.cb(e,t)},ready:function(){return r.handshake.promise.then(function(e){r.$resolver(e),r.customer&&e.setUser(r.customer)}).catch(function(e){console.error(e)}),r.options}}}),this.handshake.promise.catch(function(e){r.$rejecter(e)})},I.prototype.$generateUuid=function(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)},I.prototype.responsePromise=function(){var l=this;return new Promise(function(o,t){var e=function(n,r){return i=l,c=function(){var t;return f(this,function(e){return t=new T(n,r,this),o(t),s(),[2]})},new(u=(u=a=void 0)||Promise)(function(e,t){function n(e){try{o(c.next(e))}catch(e){t(e)}}function r(e){try{o(c.throw(e))}catch(e){t(e)}}function o(t){t.done?e(t.value):new u(function(e){e(t.value)}).then(n,r)}o((c=c.apply(i,a||[])).next())});var i,a,u,c};function n(e){t(e),s()}var r=l;function s(){r.removeListener("close",n),r.removeListener("results",e)}l.on("close",n),l.on("results",e)})},I.Promise=Promise,I.MOUNT_URL="https://kiosk-lite.flatfile.io/?key=:key",I}();