@nuclia/core
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -0,1 +1,11 @@ | ||
# 1.1.4 (2023-03-01) | ||
### Improvements | ||
- Add `fieldData` to `Search.SmartResult` | ||
- Add `fields` in `SearchOptions` | ||
- Add `ResourceFieldProperties` enum in kb models | ||
- Add `show` and `extracted` params to `getField` method in `Resource` | ||
- Add `origin` param to `createLinkResource` | ||
# 1.1.3 (2023-02-08) | ||
@@ -2,0 +12,0 @@ |
@@ -1,1 +0,1 @@ | ||
var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)};function r(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function u(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}function o(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function u(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function a(t){return this instanceof a?(this.v=t,this):new a(t)}function c(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(t,e||[]),o=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(t){i[t]&&(r[t]=function(e){return new Promise((function(n,r){o.push([t,e,n,r])>1||u(t,e)}))})}function u(t,e){try{(n=i[t](e)).value instanceof a?Promise.resolve(n.value.v).then(c,l):h(o[0][2],n)}catch(t){h(o[0][3],t)}var n}function c(t){u("next",t)}function l(t){u("throw",t)}function h(t,e){t(e),o.shift(),o.length&&u(o[0][0],o[0][1])}}function l(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=o(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,i){(function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)})(r,i,(e=t[n](e)).done,e.value)}))}}}function h(t){return"function"==typeof t}function d(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var f=d((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function p(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var v=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}var e;return t.prototype.unsubscribe=function(){var t,e,n,r,i;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var c=o(a),l=c.next();!l.done;l=c.next()){l.value.remove(this)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else a.remove(this);var d=this.initialTeardown;if(h(d))try{d()}catch(t){i=t instanceof f?t.errors:[t]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var v=o(p),b=v.next();!b.done;b=v.next()){var g=b.value;try{y(g)}catch(t){i=null!=i?i:[],t instanceof f?i=u(u([],s(i)),s(t.errors)):i.push(t)}}}catch(t){n={error:t}}finally{try{b&&!b.done&&(r=v.return)&&r.call(v)}finally{if(n)throw n.error}}}if(i)throw new f(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)y(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&p(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&p(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t}(),b=v.EMPTY;function g(t){return t instanceof v||t&&"closed"in t&&h(t.remove)&&h(t.add)&&h(t.unsubscribe)}function y(t){h(t)?t():t.unsubscribe()}var m={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},w={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=w.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,u([t,e],s(n))):setTimeout.apply(void 0,u([t,e],s(n)))},clearTimeout:function(t){var e=w.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function E(t){w.setTimeout((function(){throw t}))}function k(){}var S=_("C",void 0,void 0);function _(t,e,n){return{kind:t,value:e,error:n}}var x=null;function A(t){if(m.useDeprecatedSynchronousErrorHandling){var e=!x;if(e&&(x={errorThrown:!1,error:null}),t(),e){var n=x,r=n.errorThrown,i=n.error;if(x=null,r)throw i}}else t()}var $=function(t){function n(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,g(e)&&e.add(n)):n.destination=N,n}return e(n,t),n.create=function(t,e,n){return new R(t,e,n)},n.prototype.next=function(t){this.isStopped?C(function(t){return _("N",t,void 0)}(t),this):this._next(t)},n.prototype.error=function(t){this.isStopped?C(_("E",void 0,t),this):(this.isStopped=!0,this._error(t))},n.prototype.complete=function(){this.isStopped?C(S,this):(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(t){this.destination.next(t)},n.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n}(v),T=Function.prototype.bind;function O(t,e){return T.call(t,e)}var I=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){j(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){j(t)}else j(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){j(t)}},t}(),R=function(t){function n(e,n,r){var i,o,s=t.call(this)||this;h(e)||!e?i={next:null!=e?e:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:s&&m.useDeprecatedNextContext?((o=Object.create(e)).unsubscribe=function(){return s.unsubscribe()},i={next:e.next&&O(e.next,o),error:e.error&&O(e.error,o),complete:e.complete&&O(e.complete,o)}):i=e;return s.destination=new I(i),s}return e(n,t),n}($);function j(t){E(t)}function C(t,e){var n=m.onStoppedNotification;n&&w.setTimeout((function(){return n(t,e)}))}var N={closed:!0,next:k,error:function(t){throw t},complete:k},P="function"==typeof Symbol&&Symbol.observable||"@@observable";function U(t){return t}function D(t){return 0===t.length?U:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var L=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(t,e,n){var r,i=this,o=(r=t)&&r instanceof $||function(t){return t&&h(t.next)&&h(t.error)&&h(t.complete)}(r)&&g(r)?t:new R(t,e,n);return A((function(){var t=i,e=t.operator,n=t.source;o.add(e?e.call(o,n):n?i._subscribe(o):i._trySubscribe(o))})),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var n=this;return new(e=B(e))((function(e,r){var i=new R({next:function(e){try{t(e)}catch(t){r(t),i.unsubscribe()}},error:r,complete:e});n.subscribe(i)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[P]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return D(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=B(t))((function(t,n){var r;e.subscribe((function(t){return r=t}),(function(t){return n(t)}),(function(){return t(r)}))}))},t.create=function(e){return new t(e)},t}();function B(t){var e;return null!==(e=null!=t?t:m.Promise)&&void 0!==e?e:Promise}function F(t){return function(e){if(function(t){return h(null==t?void 0:t.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function z(t,e,n,r,i){return new H(t,e,n,r,i)}var H=function(t){function n(e,n,r,i,o,s){var u=t.call(this,e)||this;return u.onFinalize=o,u.shouldUnsubscribe=s,u._next=n?function(t){try{n(t)}catch(t){e.error(t)}}:t.prototype._next,u._error=i?function(t){try{i(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=r?function(){try{r()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,u}return e(n,t),n.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},n}($),W=d((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),K=function(t){function n(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return e(n,t),n.prototype.lift=function(t){var e=new M(this,this);return e.operator=t,e},n.prototype._throwIfClosed=function(){if(this.closed)throw new W},n.prototype.next=function(t){var e=this;A((function(){var n,r;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var i=o(e.currentObservers),s=i.next();!s.done;s=i.next()){s.value.next(t)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}}))},n.prototype.error=function(t){var e=this;A((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var n=e.observers;n.length;)n.shift().error(t)}}))},n.prototype.complete=function(){var t=this;A((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},n.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(n.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),n.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},n.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},n.prototype._innerSubscribe=function(t){var e=this,n=this,r=n.hasError,i=n.isStopped,o=n.observers;return r||i?b:(this.currentObservers=null,o.push(t),new v((function(){e.currentObservers=null,p(o,t)})))},n.prototype._checkFinalizedStatuses=function(t){var e=this,n=e.hasError,r=e.thrownError,i=e.isStopped;n?t.error(r):i&&t.complete()},n.prototype.asObservable=function(){var t=new L;return t.source=this,t},n.create=function(t,e){return new M(t,e)},n}(L),M=function(t){function n(e,n){var r=t.call(this)||this;return r.destination=e,r.source=n,r}return e(n,t),n.prototype.next=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===n||n.call(e,t)},n.prototype.error=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===n||n.call(e,t)},n.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},n.prototype._subscribe=function(t){var e,n;return null!==(n=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==n?n:b},n}(K),G={now:function(){return(G.delegate||Date).now()},delegate:void 0},J=function(t){function n(e,n,r){void 0===e&&(e=1/0),void 0===n&&(n=1/0),void 0===r&&(r=G);var i=t.call(this)||this;return i._bufferSize=e,i._windowTime=n,i._timestampProvider=r,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=n===1/0,i._bufferSize=Math.max(1,e),i._windowTime=Math.max(1,n),i}return e(n,t),n.prototype.next=function(e){var n=this,r=n.isStopped,i=n._buffer,o=n._infiniteTimeWindow,s=n._timestampProvider,u=n._windowTime;r||(i.push(e),!o&&i.push(s.now()+u)),this._trimBuffer(),t.prototype.next.call(this,e)},n.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var e=this._innerSubscribe(t),n=this._infiniteTimeWindow,r=this._buffer.slice(),i=0;i<r.length&&!t.closed;i+=n?1:2)t.next(r[i]);return this._checkFinalizedStatuses(t),e},n.prototype._trimBuffer=function(){var t=this,e=t._bufferSize,n=t._timestampProvider,r=t._buffer,i=t._infiniteTimeWindow,o=(i?1:2)*e;if(e<1/0&&o<r.length&&r.splice(0,r.length-o),!i){for(var s=n.now(),u=0,a=1;a<r.length&&r[a]<=s;a+=2)u=a;u&&r.splice(0,u+1)}},n}(K),V=function(t){function n(e,n){return t.call(this)||this}return e(n,t),n.prototype.schedule=function(t,e){return this},n}(v),X={setInterval:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=X.delegate;return(null==i?void 0:i.setInterval)?i.setInterval.apply(i,u([t,e],s(n))):setInterval.apply(void 0,u([t,e],s(n)))},clearInterval:function(t){var e=X.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},Y=function(t){function n(e,n){var r=t.call(this,e,n)||this;return r.scheduler=e,r.work=n,r.pending=!1,r}return e(n,t),n.prototype.schedule=function(t,e){if(void 0===e&&(e=0),this.closed)return this;this.state=t;var n=this.id,r=this.scheduler;return null!=n&&(this.id=this.recycleAsyncId(r,n,e)),this.pending=!0,this.delay=e,this.id=this.id||this.requestAsyncId(r,this.id,e),this},n.prototype.requestAsyncId=function(t,e,n){return void 0===n&&(n=0),X.setInterval(t.flush.bind(t,this),n)},n.prototype.recycleAsyncId=function(t,e,n){if(void 0===n&&(n=0),null!=n&&this.delay===n&&!1===this.pending)return e;X.clearInterval(e)},n.prototype.execute=function(t,e){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var n=this._execute(t,e);if(n)return n;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},n.prototype._execute=function(t,e){var n,r=!1;try{this.work(t)}catch(t){r=!0,n=t||new Error("Scheduled action threw falsy error")}if(r)return this.unsubscribe(),n},n.prototype.unsubscribe=function(){if(!this.closed){var e=this.id,n=this.scheduler,r=n.actions;this.work=this.state=this.scheduler=null,this.pending=!1,p(r,this),null!=e&&(this.id=this.recycleAsyncId(n,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},n}(V),q=function(){function t(e,n){void 0===n&&(n=t.now),this.schedulerActionCtor=e,this.now=n}return t.prototype.schedule=function(t,e,n){return void 0===e&&(e=0),new this.schedulerActionCtor(this,t).schedule(n,e)},t.now=G.now,t}(),Z=new(function(t){function n(e,n){void 0===n&&(n=q.now);var r=t.call(this,e,n)||this;return r.actions=[],r._active=!1,r._scheduled=void 0,r}return e(n,t),n.prototype.flush=function(t){var e=this.actions;if(this._active)e.push(t);else{var n;this._active=!0;do{if(n=t.execute(t.state,t.delay))break}while(t=e.shift());if(this._active=!1,n){for(;t=e.shift();)t.unsubscribe();throw n}}},n}(q))(Y),Q=new L((function(t){return t.complete()}));function tt(t){return t&&h(t.schedule)}function et(t){return t[t.length-1]}function nt(t){return h(et(t))?t.pop():void 0}function rt(t){return tt(et(t))?t.pop():void 0}function it(t,e){return"number"==typeof et(t)?t.pop():e}var ot=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function st(t){return h(null==t?void 0:t.then)}function ut(t){return h(t[P])}function at(t){return Symbol.asyncIterator&&h(null==t?void 0:t[Symbol.asyncIterator])}function ct(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var lt="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ht(t){return h(null==t?void 0:t[lt])}function dt(t){return c(this,arguments,(function(){var e,n,r;return i(this,(function(i){switch(i.label){case 0:e=t.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,a(e.read())];case 3:return n=i.sent(),r=n.value,n.done?[4,a(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,a(r)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}function ft(t){return h(null==t?void 0:t.getReader)}function pt(t){if(t instanceof L)return t;if(null!=t){if(ut(t))return i=t,new L((function(t){var e=i[P]();if(h(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(ot(t))return r=t,new L((function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()}));if(st(t))return n=t,new L((function(t){n.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,E)}));if(at(t))return vt(t);if(ht(t))return e=t,new L((function(t){var n,r;try{for(var i=o(e),s=i.next();!s.done;s=i.next()){var u=s.value;if(t.next(u),t.closed)return}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}t.complete()}));if(ft(t))return vt(dt(t))}var e,n,r,i;throw ct(t)}function vt(t){return new L((function(e){(function(t,e){var n,o,s,u;return r(this,void 0,void 0,(function(){var r,a;return i(this,(function(i){switch(i.label){case 0:i.trys.push([0,5,6,11]),n=l(t),i.label=1;case 1:return[4,n.next()];case 2:if((o=i.sent()).done)return[3,4];if(r=o.value,e.next(r),e.closed)return[2];i.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=i.sent(),s={error:a},[3,11];case 6:return i.trys.push([6,,9,10]),o&&!o.done&&(u=n.return)?[4,u.call(n)]:[3,8];case 7:i.sent(),i.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))}))})(t,e).catch((function(t){return e.error(t)}))}))}function bt(t,e,n,r,i){void 0===r&&(r=0),void 0===i&&(i=!1);var o=e.schedule((function(){n(),i?t.add(this.schedule(null,r)):this.unsubscribe()}),r);if(t.add(o),!i)return o}function gt(t,e){return void 0===e&&(e=0),F((function(n,r){n.subscribe(z(r,(function(n){return bt(r,t,(function(){return r.next(n)}),e)}),(function(){return bt(r,t,(function(){return r.complete()}),e)}),(function(n){return bt(r,t,(function(){return r.error(n)}),e)})))}))}function yt(t,e){return void 0===e&&(e=0),F((function(n,r){r.add(t.schedule((function(){return n.subscribe(r)}),e))}))}function mt(t,e){if(!t)throw new Error("Iterable cannot be null");return new L((function(n){bt(n,e,(function(){var r=t[Symbol.asyncIterator]();bt(n,e,(function(){r.next().then((function(t){t.done?n.complete():n.next(t.value)}))}),0,!0)}))}))}function wt(t,e){if(null!=t){if(ut(t))return function(t,e){return pt(t).pipe(yt(e),gt(e))}(t,e);if(ot(t))return function(t,e){return new L((function(n){var r=0;return e.schedule((function(){r===t.length?n.complete():(n.next(t[r++]),n.closed||this.schedule())}))}))}(t,e);if(st(t))return function(t,e){return pt(t).pipe(yt(e),gt(e))}(t,e);if(at(t))return mt(t,e);if(ht(t))return function(t,e){return new L((function(n){var r;return bt(n,e,(function(){r=t[lt](),bt(n,e,(function(){var t,e,i;try{e=(t=r.next()).value,i=t.done}catch(t){return void n.error(t)}i?n.complete():n.next(e)}),0,!0)})),function(){return h(null==r?void 0:r.return)&&r.return()}}))}(t,e);if(ft(t))return function(t,e){return mt(dt(t),e)}(t,e)}throw ct(t)}function Et(t,e){return e?wt(t,e):pt(t)}function kt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return Et(t,n)}function St(t,e){var n=h(t)?t:function(){return t},r=function(t){return t.error(n())};return new L(e?function(t){return e.schedule(r,0,t)}:r)}var _t=d((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function xt(t,e){return F((function(n,r){var i=0;n.subscribe(z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var At=Array.isArray;function $t(t){return xt((function(e){return function(t,e){return At(e)?t.apply(void 0,u([],s(e))):t(e)}(t,e)}))}var Tt=Array.isArray,Ot=Object.getPrototypeOf,It=Object.prototype,Rt=Object.keys;function jt(t){if(1===t.length){var e=t[0];if(Tt(e))return{args:e,keys:null};if((r=e)&&"object"==typeof r&&Ot(r)===It){var n=Rt(e);return{args:n.map((function(t){return e[t]})),keys:n}}}var r;return{args:t,keys:null}}function Ct(t,e){return t.reduce((function(t,n,r){return t[n]=e[r],t}),{})}function Nt(t,e,n){return void 0===n&&(n=1/0),h(e)?Nt((function(n,r){return xt((function(t,i){return e(n,t,r,i)}))(pt(t(n,r)))}),n):("number"==typeof e&&(n=e),F((function(e,r){return function(t,e,n,r,i,o,s,u){var a=[],c=0,l=0,h=!1,d=function(){!h||a.length||c||e.complete()},f=function(t){return c<r?p(t):a.push(t)},p=function(t){o&&e.next(t),c++;var u=!1;pt(n(t,l++)).subscribe(z(e,(function(t){null==i||i(t),o?f(t):e.next(t)}),(function(){u=!0}),void 0,(function(){if(u)try{c--;for(var t=function(){var t=a.shift();s?bt(e,s,(function(){return p(t)})):p(t)};a.length&&c<r;)t();d()}catch(t){e.error(t)}})))};return t.subscribe(z(e,f,(function(){h=!0,d()}))),function(){null==u||u()}}(e,r,t,n)})))}function Pt(t){return void 0===t&&(t=1/0),Nt(U,t)}function Ut(){return Pt(1)}function Dt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ut()(Et(t,rt(t)))}function Lt(t,e,n){void 0===t&&(t=0),void 0===n&&(n=Z);var r=-1;return null!=e&&(tt(e)?n=e:r=e),new L((function(e){var i,o=(i=t)instanceof Date&&!isNaN(i)?+t-n.now():t;o<0&&(o=0);var s=0;return n.schedule((function(){e.closed||(e.next(s++),0<=r?this.schedule(void 0,r):e.complete())}),o)}))}function Bt(t,e){return F((function(n,r){var i=0;n.subscribe(z(r,(function(n){return t.call(e,n,i++)&&r.next(n)})))}))}function Ft(t){return F((function(e,n){var r,i=null,o=!1;i=e.subscribe(z(n,void 0,void 0,(function(s){r=pt(t(s,Ft(t)(e))),i?(i.unsubscribe(),i=null,r.subscribe(n)):o=!0}))),o&&(i.unsubscribe(),i=null,r.subscribe(n))}))}function zt(t,e){return h(e)?Nt(t,e,1):Nt(t,1)}function Ht(t){return t<=0?function(){return Q}:F((function(e,n){var r=0;e.subscribe(z(n,(function(e){++r<=t&&(n.next(e),t<=r&&n.complete())})))}))}function Wt(t){var e,n,r=1/0;return null!=t&&("object"==typeof t?(e=t.count,r=void 0===e?1/0:e,n=t.delay):r=t),r<=0?function(){return Q}:F((function(t,e){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=n){var t="number"==typeof n?Lt(n):pt(n(o)),r=z(e,(function(){r.unsubscribe(),u()}));t.subscribe(r)}else u()},u=function(){var n=!1;i=t.subscribe(z(e,void 0,(function(){++o<r?i?s():n=!0:e.complete()}))),n&&s()};u()}))}function Kt(t,e){return F((function(n,r){var i=null,o=0,s=!1,u=function(){return s&&!i&&r.complete()};n.subscribe(z(r,(function(n){null==i||i.unsubscribe();var s=0,a=o++;pt(t(n,a)).subscribe(i=z(r,(function(t){return r.next(e?e(n,t,a,s++):t)}),(function(){i=null,u()})))}),(function(){s=!0,u()})))}))}function Mt(t,e,n){var r=h(t)||e||n?{next:t,error:e,complete:n}:t;return r?F((function(t,e){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var i=!0;t.subscribe(z(e,(function(t){var n;null===(n=r.next)||void 0===n||n.call(r,t),e.next(t)}),(function(){var t;i=!1,null===(t=r.complete)||void 0===t||t.call(r),e.complete()}),(function(t){var n;i=!1,null===(n=r.error)||void 0===n||n.call(r,t),e.error(t)}),(function(){var t,e;i&&(null===(t=r.unsubscribe)||void 0===t||t.call(r)),null===(e=r.finalize)||void 0===e||e.call(r)})))})):U}const Gt="NUCLIA_NUA_KEY",Jt="NUCLIA_NUA_CLIENT";var Vt,Xt,Yt,qt,Zt,Qt,te;!function(t){t.DAY="day",t.WEEK="week",t.MONTH="month",t.YEAR="year"}(Vt||(Vt={})),function(t){t.anHour="1h",t.twoHours="2h",t.threeHours="3h",t.sixHours="6h",t.twelveHours="12h",t.twentyFourHours="24h",t.fortyHeightHours="48h"}(Xt||(Xt={})),function(t){t.PROCESSING_TIME="processing_time",t.SEARCHES="searches",t.CHARS="chars",t.MEDIA_SECONDS="media_seconds",t.BYTES="bytes",t.RESOURCES="resources",t.PAGES="pages",t.TRAIN_SECONDS="train_seconds",t.SUGGESTIONS="suggestions",t.DOCS_NO_MEDIA="docs_no_media"}(Yt||(Yt={})),function(t){t.BASIC="basic",t.ORIGIN="origin",t.RELATIONS="relations",t.VALUES="values",t.EXTRACTED="extracted",t.ERRORS="errors"}(qt||(qt={})),function(t){t.TEXT="text",t.METADATA="metadata",t.LARGE_METADATA="large_metadata",t.VECTOR="vectors",t.LINK="link",t.FILE="file"}(Zt||(Zt={})),function(t){t.RESOURCES="RESOURCES",t.PARAGRAPHS="PARAGRAPHS"}(Qt||(Qt={})),function(t){t.VISITED="VISITED",t.MODIFIED="MODIFIED",t.DELETED="DELETED",t.NEW="NEW",t.STARTED="STARTED",t.STOPPED="STOPPED",t.SEARCH="SEARCH",t.PROCESSED="PROCESSED"}(te||(te={}));const ee=524288,ne=new RegExp(/[^a-z0-9_-]/g),re=(t,e,n,r,i={})=>(i.contentType||n instanceof ArrayBuffer||(i.contentType=null==n?void 0:n.type),i.filename||n instanceof ArrayBuffer||(i.filename=null==n?void 0:n.name),i.lang||n instanceof ArrayBuffer||(i.lang=n.lang),i.md5||n instanceof ArrayBuffer||(i.md5=n.md5),(n instanceof ArrayBuffer?kt(n):Et(n.arrayBuffer())).pipe(Kt((o=>r?oe(t,e,o,i,n.payload):ie(t,e,o,i))))),ie=(t,e,n,r)=>{const i=Object.assign({"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},ae(r));let o=1;return t.rest.post(`${e}/upload`,n,i).pipe(Wt(),Bt((t=>0==o--||503!==t.status)),Ht(1),Kt((t=>{switch(t.status){case 201:return Et(t.json()).pipe(xt((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return kt({conflict:!0});default:return kt({failed:!0})}})))},oe=(t,e,n,r,i)=>{let o=0,s=!1;const u=n.byteLength,a=Math.ceil(u/ee),c={"upload-length":`${u}`,"tus-resumable":"1.0.0"},l=[];(null==r?void 0:r.filename)&&l.push(`filename ${btoa(encodeURIComponent(r.filename))}`),(null==r?void 0:r.lang)&&l.push(`language ${btoa(r.lang)}`),(null==r?void 0:r.md5)&&l.push(`md5 ${btoa(r.md5)}`),l.push(`content_type ${btoa((null==r?void 0:r.contentType)||"application/octet-stream")}`),l.length>0&&(c["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,c,!0).pipe(Wt(),Bt((t=>0==h--||503!==t.status)),Ft((t=>kt(t))),Ht(1),zt((e=>function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t),r=it(t,1/0),i=t;return i.length?1===i.length?pt(i[0]):Pt(r)(Et(i,n)):Q}(kt(e).pipe(Bt((t=>201!==t.status||!t.headers.get("location"))),xt((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),kt(e).pipe(Bt((t=>201===t.status&&!!t.headers.get("location"))),xt((t=>t.headers.get("location"))),zt((e=>function(t,e,n){if(null==e&&(e=t,t=0),e<=0)return Q;var r=e+t;return new L(n?function(e){var i=t;return n.schedule((function(){i<r?(e.next(i++),this.schedule()):e.complete()}))}:function(e){for(var n=t;n<r&&!e.closed;)e.next(n++);e.complete()})}(0,a).pipe(zt((()=>{const i=n.slice(o,o+ee);return s?kt({failed:s}):t.rest.patch(e,i,{"content-type":(null==r?void 0:r.contentType)||"application/octet-stream","upload-offset":`${o}`,"content-length":`${i.byteLength}`},!0).pipe(xt((t=>200!==t.status?(s=!0,{failed:s}):(o+=ee,{completed:o>=u,progress:o>=u?100:Math.min(Math.floor(o/u*100),100)}))),Ft((()=>kt({failed:!0}))))}))))))))))},se=(t,e,n,r=!1)=>{const i=Array.from(n),o=i.reduce(((t,e)=>t+(e.size||0)),0),s=[],u=i.map((t=>({file:t,progress:0,uploaded:!1,failed:!1})));return Et(i.map((n=>{let i=e;if(r){let t=n.name.toLowerCase().replace(ne,"_");s.includes(t)&&(t+="_"+s.filter((e=>e.startsWith(t))).length),s.push(t),i=`${i}/file/${t}`}const o=n.lang;if(o){const t=n.payload||{};n.payload=Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},null==t?void 0:t.metadata),{language:o})})}return re(t,i,n,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return F((function(e,r){(n?Dt(t,e,n):Dt(t,e)).subscribe(r)}))}({progress:0,completed:!1}),xt((t=>({status:t,file:n}))))}))).pipe(Nt((t=>t),6),xt((t=>{const e=u.find((e=>e.file===t.file));t.status.failed&&(e.failed=!0),t.status.conflict&&(e.conflicts=!0),t.status.completed&&(e.uploaded=!0),t.status.failed||t.status.conflict||t.status.completed?e.progress=100:e.progress=t.status.progress||0;const n=u.filter((t=>t.failed)).length,r=u.filter((t=>t.conflicts)).length,i=u.filter((t=>t.uploaded)).length,s=i+n===u.length,a=Math.round(u.reduce(((t,e)=>t+e.file.size*e.progress/100),0)/o*100);return{files:u,progress:a,completed:s,uploaded:i,failed:n,conflicts:r}})))},ue=(t,e,n)=>{const r=Object.assign({"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`,"content-type":(null==n?void 0:n.contentType)||"application/octet-stream"},ae(n));return t.rest.post("/processing/upload",e,r)},ae=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=encodeURIComponent(t.filename)),(null==t?void 0:t.md5)&&(e["x-md5"]=t.md5),(null==t?void 0:t.lang)&&(e["x-language"]=t.lang),e};function ce(t){return`/l/${t.labelset}/${t.label}`}function le(t){const e=t.split("/");return{labelset:e[2],label:e[3]}}var he,de;!function(t){t.layout="l",t.text="t",t.file="f",t.link="u",t.datetime="d",t.keywordset="k",t.generic="a",t.conversation="c"}(he||(he={})),function(t){var e,n;(e=t.Features||(t.Features={})).PARAGRAPH="paragraph",e.DOCUMENT="document",e.RELATIONS="relations",e.VECTOR="vector",(n=t.ResourceFeatures||(t.ResourceFeatures={})).PARAGRAPH="paragraph",n.RELATIONS="relations",n.VECTOR="vector"}(de||(de={}));const fe=(t,e,n,r,i=[],o,s)=>{var u;const a={};a.query=r||"",a.features=i;const c=o||{},{inTitleOnly:l}=c,h=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(c,["inTitleOnly"]);l&&(a.fields=["a/title"]),a.shards=(null===(u=t.currentShards)||void 0===u?void 0:u[e])||[];return(s?t.rest.get(`${n}/search?${ve(a,h)}`):t.rest.post(`${n}/search`,Object.assign(Object.assign({},a),h))).pipe(Ft((()=>kt({error:!0}))),xt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((n=>{n.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:n.shards}))})))},pe=(t,e,n,r)=>{var i;const o={};o.query=n||"",o.shards=(null===(i=t.currentShards)||void 0===i?void 0:i[e])||[];return t.rest.get(`/kb/${e}/catalog?${r?ve(o,r):""}`).pipe(Ft((()=>kt({error:!0}))),xt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((n=>{n.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:n.shards}))})))},ve=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{null!=n&&(Array.isArray(n)?t[e]=n.map((t=>`${t}`)):"object"==typeof n?Object.entries(n).forEach((([n,r])=>t[`${e}_${n}`]=`${r}`)):t[e]=`${n}`)}));const n=new URLSearchParams;return Object.entries(t).forEach((([t,e])=>Array.isArray(e)?e.forEach((e=>n.append(t,e))):n.append(t,e))),n.toString()},be=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ge=(t,e,n,r,i)=>{const o=be(i.filter((n=>me(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=be(i.filter((n=>we(n,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])).filter((t=>t.key!==n)),u=i.filter((n=>n.field.field!==t||n.field.field_type!==e)),a=r.length>0?[...s,{key:n,classifications:r}]:s;return o.length>0||a.length>0?[...u,{field:{field:t,field_type:e},token:o.length>0?o:void 0,paragraphs:a.length>0?a:void 0}]:u},ye=(t,e,n,r)=>{const i=be(r.filter((n=>we(n,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])),o=r.filter((n=>n.field.field!==t||n.field.field_type!==e));return n.length>0||i.length>0?[...o,{field:{field:t,field_type:e},token:n.length>0?n:void 0,paragraphs:i.length>0?i:void 0}]:o},me=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,we=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0,Ee=(t,e,n)=>t?(Array.isArray(t)||(t=Array.from(t)),t.slice(e,n).join("")):"",ke=t=>t?Array.from(t).length:0;class Se{constructor(t){this.data={},this.fieldTextsCache={},t.data||(t.data={}),Object.assign(this,Object.assign(Object.assign({},t),{title:this.formatTitle(t.title)}))}getFields(t=["files","links","texts","keywordsets"]){return Object.entries(this.data).filter((([e])=>t.includes(e))).map((([,t])=>t)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}getFieldData(t,e){var n;const r=null===(n=this.data[t])||void 0===n?void 0:n[e];return r||void 0}getExtractedSummaries(){return this.getFields().filter((t=>{var e,n,r;return null===(r=null===(n=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===n?void 0:n.metadata)||void 0===r?void 0:r.summary})).map((t=>t.extracted.metadata.metadata.summary))}getExtractedTexts(){return this.getFields().filter((t=>{var e;return null===(e=t.extracted)||void 0===e?void 0:e.text})).map((t=>t.extracted.text))}getFiles(){return this.getFields(["files"]).filter((t=>!!t&&!!t.value&&!!t.value.file)).map((t=>t.value.file))}getThumbnails(){return this.getFields(["files"]).map((t=>{var e,n;return null===(n=null===(e=t.extracted)||void 0===e?void 0:e.file)||void 0===n?void 0:n.file_thumbnail})).concat(this.getFields(["links"]).map((t=>{var e,n;return null===(n=null===(e=t.extracted)||void 0===e?void 0:e.link)||void 0===n?void 0:n.link_thumbnail}))).filter((t=>!!t))}getAnnotatedEntities(){return(this.fieldmetadata||[]).filter((t=>t.token&&t.token.length>0)).map((t=>t.token)).reduce(((t,e)=>(e.filter((t=>!t.cancelled_by_user)).forEach((e=>{t[e.klass]||(t[e.klass]=[]),t[e.klass].push(e.token)})),t)),{})}getNamedEntities(){return this.getFields().filter((t=>{var e,n,r;return null===(r=null===(n=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===n?void 0:n.metadata)||void 0===r?void 0:r.ner})).map((t=>Object.entries(t.extracted.metadata.metadata.ner).reduce(((t,[e,n])=>(t[n]=(t[n]||[]).concat([e]),t)),{}))).reduce(((t,e)=>(Object.entries(e).forEach((([e,n])=>{t[e]=(t[e]||[]).concat(n)})),t)),{})}getClassifications(){var t,e,n;const r=((null===(t=this.usermetadata)||void 0===t?void 0:t.classifications)||[]).filter((t=>!t.cancelled_by_user)),i=((null===(e=this.usermetadata)||void 0===e?void 0:e.classifications)||[]).filter((t=>t.cancelled_by_user));return((null===(n=this.computedmetadata)||void 0===n?void 0:n.field_classifications)||[]).reduce(((t,e)=>(e.classifications.forEach((e=>{const n=t.find((t=>t.label===e.label&&t.labelset===e.labelset)),r=i.find((t=>t.label===e.label&&t.labelset===e.labelset));n||r||t.push(Object.assign(Object.assign({},e),{immutable:!0}))})),t)),r)}getPositionedNamedEntities(t,e){var n,r,i,o;const s=null===(o=null===(i=null===(r=null===(n=this.data[t])||void 0===n?void 0:n[e])||void 0===r?void 0:r.extracted)||void 0===i?void 0:i.metadata)||void 0===o?void 0:o.metadata.positions;return s?Object.entries(s).reduce(((t,[e,n])=>{const r=e.split("/")[0];return n.position.forEach((e=>{t.push(Object.assign({entity:n.entity,family:r},e))})),t}),[]):[]}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}getParagraphText(t,e,n){return Ee(this.getFieldText(t,e),n.start,n.end)}getSentenceText(t,e,n){return Ee(this.getFieldText(t,e),n.start,n.end)}getFieldText(t,e){var n,r;const i=`${t}-${e}`;if(!this.fieldTextsCache[i]){const o=this.getFieldData(`${t}s`,e);this.fieldTextsCache[i]=Array.from((null===(r=null===(n=null==o?void 0:o.extracted)||void 0===n?void 0:n.text)||void 0===r?void 0:r.text)||"")}return this.fieldTextsCache[i]}}class _e extends Se{constructor(t,e,n){super(n),this.nuclia=t,this.kb=e,this.uuid=n.id}get path(){if(!this.uuid&&!this.slug)throw new Error("Resource must have either uuid or slug");return this.uuid?`/kb/${this.kb}/resource/${this.uuid}`:`/kb/${this.kb}/slug/${this.slug}`}modify(t,e=!0){return this.nuclia.rest.patch(this.path,t,void 0,void 0,e)}delete(t=!0){return this.nuclia.rest.delete(this.path,void 0,t)}reprocess(){return this.nuclia.rest.post(`${this.path}/reprocess`,{},void 0,void 0,!0)}getField(t,e){return this.nuclia.rest.get(`${this.path}/${t}/${e}`)}getThumbnailsUrl(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t),r=jt(t),i=r.args,o=r.keys,s=new L((function(t){var e=i.length;if(e)for(var n=new Array(e),r=e,s=e,u=function(e){var u=!1;pt(i[e]).subscribe(z(t,(function(t){u||(u=!0,s--),n[e]=t}),(function(){return r--}),void 0,(function(){r&&u||(s||t.next(o?Ct(o,n):n),t.complete())})))},a=0;a<e;a++)u(a);else t.complete()}));return n?s.pipe($t(n)):s}(this.getThumbnails().filter((t=>t.uri)).map((t=>this.nuclia.rest.getObjectURL(t.uri))))}deleteField(t,e){return this.nuclia.rest.delete(`${this.path}/${t}/${e}`)}addField(t,e,n){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,n)}updateField(t,e,n){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,n)}upload(t,e,n,r){return re(this.nuclia,`${this.path}/file/${t}`,e,!!n,r)}batchUpload(t){return se(this.nuclia,this.path,t,!0)}search(t,e=[],n){return fe(this.nuclia,this.kb,this.path,t,e,n,!0)}setLabels(t,e,n,r){const i=ge(t,e,n,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Mt((()=>this.fieldmetadata=i)))}setEntities(t,e,n){const r=ye(t,e,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:r}).pipe(Mt((()=>this.fieldmetadata=r)))}}var xe,Ae;!function(t){t.text="text",t.file="file",t.link="link",t.layout="layout",t.conversation="conversation",t.keywordset="keywordset",t.datetime="datetime"}(xe||(xe={})),function(t){t.PENDING="PENDING",t.PROCESSED="PROCESSED",t.ERROR="ERROR"}(Ae||(Ae={}));class $e{}class Te{}class Oe{}class Ie{}const Re=(t,e)=>{const n={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};t.getClassifications().forEach((t=>{t.labelset&&t.label&&(n[t.labelset]=t.label)}));const r=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},n),{images:r}),t.getNamedEntities())},je=t=>{switch(t){case xe.text:case xe.file:case xe.link:case xe.keywordset:return`${t}s`;default:return null}};function Ce(t){return he[t]}function Ne(t){switch(t){case he.conversation:return xe.conversation;case he.datetime:return xe.datetime;case he.file:return xe.file;case he.layout:return xe.layout;case he.keywordset:return xe.keywordset;case he.link:return xe.link;case he.text:return xe.text;default:return null}}var Pe,Ue,De;!function(t){t.classifier="classifier",t.resource_labeler="resource-labeler",t.paragraph_labeler="paragraph-labeler",t.ner="ner"}(Pe||(Pe={})),function(t){t.finished="finished",t.not_running="not_running",t.running="running",t.started="started",t.stopped="stopped"}(Ue||(Ue={})),function(t){t.succeeded="succeeded",t.failed="failed",t.stopped="stopped"}(De||(De={}));class Le{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e||{})}stop(t){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/stop`,{})}getStatus(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/inspect`).pipe(Ft((()=>kt({task:"",status:Ue.not_running}))))}getExecutions(t=0){return this.nuclia.rest.get(`${this.kb.path}/train/executions?page=${t}`)}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/json_models/nuclia.json`).pipe(xt((()=>!0)),Ft((()=>kt(!1))))}}class Be{constructor(t,e,n){this.nuclia=t,this.account=e,Object.assign(this,n)}get path(){return`/kb/${this.id}`}get fullpath(){return`${this.nuclia.regionalBackend}/v1/kb/${this.id}`}getEntities(t=!1){return this.nuclia.rest.get(`${this.path}/entitiesgroups?show_entities=${t}`).pipe(xt((t=>t.groups)))}getEntitiesGroup(t){return this.nuclia.rest.get(`${this.path}/entitiesgroup/${t}`)}getLabels(){return this.nuclia.rest.get(`${this.path}/labelsets`).pipe(xt((t=>(null==t?void 0:t.labelsets)||{})))}getResource(t,e=[qt.BASIC,qt.ORIGIN,qt.RELATIONS,qt.VALUES,qt.EXTRACTED,qt.ERRORS],n=[Zt.TEXT,Zt.METADATA,Zt.LINK,Zt.FILE]){return this._getResource(t,void 0,e,n)}getResourceBySlug(t,e=[qt.BASIC,qt.ORIGIN,qt.RELATIONS,qt.VALUES,qt.EXTRACTED,qt.ERRORS],n=[Zt.TEXT,Zt.METADATA,Zt.LINK,Zt.FILE]){return this._getResource(void 0,t,e,n)}_getResource(t,e,n=[qt.BASIC,qt.ORIGIN,qt.RELATIONS,qt.VALUES,qt.EXTRACTED,qt.ERRORS],r=[Zt.TEXT,Zt.METADATA,Zt.LINK,Zt.FILE]){const i=[...n.map((t=>`show=${t}`)),...r.map((t=>`extracted=${t}`))],o=t?`${this.path}/resource/${t}`:`${this.path}/slug/${e}`;return this.nuclia.rest.get(`${o}?${i.join("&")}`).pipe(xt((t=>new _e(this.nuclia,this.id,t))))}getResourceFromData(t){return new _e(this.nuclia,this.id,t)}search(t,e=[],n){return fe(this.nuclia,this.id,this.path,t,e,n)}catalog(t,e){return pe(this.nuclia,this.id,t,e)}suggest(t,e=!1){const n=`query=${encodeURIComponent(t)}${e?"&fields=a/title":""}`;return this.nuclia.rest.get(`${this.path}/suggest?${n}`).pipe(Ft((()=>kt({error:!0}))),xt((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}counters(){return this.nuclia.rest.get(`/kb/${this.id}/counters`)}listResources(t,e){const n=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${n?"?"+n:""}`).pipe(xt((t=>({resources:t.resources.map((t=>new _e(this.nuclia,this.id,t))),pagination:t.pagination}))))}getTempToken(){if(!this.nuclia.options.account||!this.nuclia.options.kbSlug)throw new Error("Account and KB slug are required to get a temp token");return this.nuclia.rest.post(`/account/${this.nuclia.options.account}/kb/${this.nuclia.options.kbSlug}/ephemeral_tokens`,{}).pipe(xt((t=>t.token)))}listActivity(t,e,n){const r=[t?`type=${t}`:"",e?`page=${e}`:"",n?`size=${n}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/activity${r?"?"+r:""}`)}}class Fe extends Be{get training(){return this._training||(this._training=new Le(this,this.nuclia)),this._training}modify(t){return this.nuclia.rest.patch(`/account/${this.account}/kb/${this.slug}`,t)}publish(t){return this.modify({state:t?"PUBLISHED":"PRIVATE"})}delete(){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}`)}setEntitiesGroup(t,e){return this.nuclia.rest.post(`${this.path}/entitiesgroup/${t}`,e)}deleteEntitiesGroup(t){return this.nuclia.rest.delete(`${this.path}/entitiesgroup/${t}`)}setLabelSet(t,e){return this.nuclia.rest.post(`${this.path}/labelset/${t}`,e)}deleteLabelSet(t){return this.nuclia.rest.delete(`${this.path}/labelset/${t}`)}createResource(t,e=!0){return this.nuclia.rest.post(`${this.path}/resources`,t,void 0,void 0,e)}createLinkResource(t,e,n=!0){return this.createResource({links:{link:t},usermetadata:e,title:t.uri,icon:"application/stf-link"},n)}hasResource(t){return this.nuclia.rest.get(`${this.path}/slug/${t}`).pipe(xt((()=>!0)),Ft((()=>kt(!1))))}createOrUpdateResource(t,e=!0){return(t.slug?this.hasResource(t.slug):kt(!1)).pipe(Kt((n=>n?this.getResourceFromData({id:"",slug:t.slug}).modify(t,e):this.createResource(t,e))))}upload(t,e,n){return re(this.nuclia,`/kb/${this.id}`,t,!!e,n)}batchUpload(t){return se(this.nuclia,`/kb/${this.id}`,t,!1)}getServiceAccounts(){return this.nuclia.rest.get(`/account/${this.account}/kb/${this.slug}/service_accounts`)}createServiceAccount(t){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_accounts`,t)}deleteServiceAccount(t){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}`)}createKey(t,e){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_account/${t}/keys`,{expires:e})}deleteKey(t,e){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}/key/${e}`)}}class ze{constructor(t){this.nuclia=t}getAccounts(){return this.nuclia.rest.get("/accounts")}createAccount(t){return this.nuclia.rest.post("/accounts",t)}modifyAccount(t,e){return this.nuclia.rest.patch(`/account/${t}`,e)}deleteAccount(t){return this.nuclia.rest.delete(`/account/${t}`)}getAccountStatus(t){return this.nuclia.rest.get(`/account/${t}/status`)}getWelcome(){return this.nuclia.rest.get("/user/welcome")}getAccount(t){if(!(t=t||this.nuclia.options.account))throw new Error("Account is not set");return this.nuclia.rest.get(`/account/${t}`)}getKnowledgeBoxes(t){return this.nuclia.rest.get(`/account/${t}/kbs`)}getKnowledgeBox(t,e){if(t=t||this.nuclia.options.account){const n=e||this.nuclia.options.knowledgeBox||this.nuclia.options.kbSlug;if(!n)throw new Error("account and knowledgeBox must be defined in the Nuclia options");return this.nuclia.rest.get(`/account/${t}/kb/${n}`).pipe(Kt((t=>this.nuclia.options.zone?kt(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Mt((t=>this.nuclia.options.zone=t)),xt((()=>t))))),xt((e=>new Fe(this.nuclia,t,e))))}if(!this.nuclia.options.knowledgeBox||!this.nuclia.options.zone)throw new Error("zone must be defined in the Nuclia options");return kt(new Fe(this.nuclia,"",{id:this.nuclia.options.knowledgeBox,zone:this.nuclia.options.zone}))}createKnowledgeBox(t,e){return this.nuclia.rest.post(`/account/${t}/kbs`,e).pipe(Mt((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Kt((()=>this.getKnowledgeBox(t,e.slug))))}getStats(t,e,n,r=Vt.DAY,i){const o=[`period=${r}`,`stats=${e}`];return i&&o.push(`utctime=${i}`),n&&o.push(`knowledgebox=${n}`),this.nuclia.rest.get(`/account/${t}/stats?${o.join("&")}`).pipe(xt((t=>t.data)),Bt((t=>!!t)))}upload(t){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return ue(this.nuclia,t,{md5:t.md5}).pipe(Kt((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},this.getNUAHeader()))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /processing");return this.nuclia.rest.get("/processing/pull",this.getNUAHeader())}getProcessingStatus(t){if(!t){if(!this.hasNUAClient())throw new Error("NUA key or account id is needed to be able to call /processing/status")}const e=t?`/processing/status?account_id=${t}`:"/processing/status",n=t?void 0:this.getNUAHeader();return this.nuclia.rest.get(e,n)}getProcessingStats(t,e){const n=this.hasNUAClient();if(!e&&!n)throw new Error("NUA key or account id is needed to be able to call /processing/stats");const r=n?"/processing/stats"+(t?"?period="+t:""):`/processing/stats?account_id=${e}${t?"&period="+t:""}`,i=n?this.getNUAHeader():void 0;return this.nuclia.rest.get(r,i).pipe(xt((t=>t.data)))}getNUAActivity(t,e,n=0){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}/activity?page=${n}`)}getNUAClients(t){return this.nuclia.rest.get(`/account/${t}/nua_clients`).pipe(xt((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(Jt)&&!!localStorage.getItem(Gt)}getNUAHeader(){return{"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`}}createNUAClient(t,e){const n=Object.assign({},e);return n.webhook&&(n.processing_webhook={uri:n.webhook},delete n.webhook),this.nuclia.rest.post(`/account/${t}/nua_clients`,n).pipe(Ft((n=>{if(409===n.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw n})),Mt((t=>{"desktop"===this.nuclia.options.client&&(localStorage.setItem(Gt,t.token),localStorage.setItem(Jt,t.client_id))})))}renewNUAClient(t,e){return this.nuclia.rest.put(`/account/${t}/nua_client/${e}/key`,{})}deleteNUAClient(t,e){return this.nuclia.rest.delete(`/account/${t}/nua_client/${e}`)}}function He(t,e){void 0===e&&(e={});var r=e.selector,i=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(e,["selector"]);return new L((function(e){var o=new AbortController,s=o.signal,u=!0,a=i.signal;if(a)if(a.aborted)o.abort();else{var c=function(){s.aborted||o.abort()};a.addEventListener("abort",c),e.add((function(){return a.removeEventListener("abort",c)}))}var l=n(n({},i),{signal:s}),h=function(t){u=!1,e.error(t)};return fetch(t,l).then((function(t){r?pt(r(t)).subscribe(z(e,void 0,(function(){u=!1,e.complete()}),h)):(u=!1,e.next(t),e.complete())})).catch(h),function(){u&&o.abort()}}))}class We{constructor(t){this.token=t}urlBase64Decode(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("Illegal base64url string!")}return this.b64DecodeUnicode(e)}b64decode(t){let e="";if((t=String(t).replace(/=+$/,"")).length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let n,r,i=0,o=0;r=t.charAt(o++);~r&&(n=i%4?64*n+r:r,i++%4)?e+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return e}b64DecodeUnicode(t){return decodeURIComponent(Array.prototype.map.call(this.b64decode(t),(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2))).join(""))}decodeToken(t=this.token){if(null===t)return null;const e=t.split(".");if(3!==e.length)throw new Error("The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.");const n=this.urlBase64Decode(e[1]);if(!n)throw new Error("Cannot decode the token.");return JSON.parse(n)}getJWTUser(t=this.token){let e;try{e=this.decodeToken(t)}catch(t){return null}return e}getTokenExpirationDate(t=this.token){const e=this.getJWTUser(t);if(!e)return null;const n=new Date(0);return n.setUTCSeconds(e.exp),n}isTokenExpired(t=this.token,e){if(null===t||""===t)return!0;const n=this.getTokenExpirationDate(t);return e=e||0,null===n||n.valueOf()<=(new Date).valueOf()+1e3*e}}const Ke="JWT_KEY",Me="JWT_REFRESH_KEY",Ge=216e5;class Je{constructor(t){this._isAuthenticated=new J(1),this.nuclia=t,this.nuclia.options.knowledgeBox?this._isAuthenticated.next(!0):this.checkTokenExpiration()}getAuthHeaders(){return this.nuclia.options.standalone?{"X-NUCLIADB-ROLES":"READER"}:this.nuclia.options.apiKey?{"X-STF-Serviceaccount":`Bearer ${this.nuclia.options.apiKey}`}:this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{}}isAuthenticated(){return this._isAuthenticated.asObservable()}hasLoggedOut(){return this.isAuthenticated().pipe((t=1,Bt((function(e,n){return t<=n}))),Bt((t=>!t)));var t}login(t,e,n){return this.fetch("/auth/login",{username:t,password:e},!1,n?{"X-STF-VALIDATION":n}:{}).pipe(xt((t=>this.authenticate(t))))}authenticate(t){return t.access_token?(this.storeTokens(t),this._isAuthenticated.next(!0),!0):(this._isAuthenticated.next(!1),!1)}logout(){this.fetch("/auth/logout",{},!0,{}).subscribe(),localStorage.removeItem(Ke),localStorage.removeItem(Me),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Ft((t=>(this.logout(),St(t)))),xt((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return this.nuclia.options.public?"":localStorage.getItem(Ke)||""}setPassword(t){return this.fetch("/auth/setpassword",{password:t},!0,{}).pipe(xt((t=>this.authenticate(t))))}deleteAuthenticatedUser(){return this.nuclia.rest.delete("/user").pipe(Mt((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new We(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(Me)||""}storeTokens(t){localStorage.setItem(Ke,t.access_token),localStorage.setItem(Me,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const n=this.getToken();if(n){const r=null===(t=new We(n).getTokenExpirationDate())||void 0===t?void 0:t.getTime();if(r){const t=(new Date).getTime();if(r<t)this.logout();else{this._isAuthenticated.next(!0);const n=r-t<Ge?0:Ge;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Lt(n).pipe(Kt((()=>this.refresh()))).subscribe()}}else this._isAuthenticated.next(!1)}else this._isAuthenticated.next(!1)}fetch(t,e,n,r){const i=Object.assign({"content-type":"application/json"},r);return n&&(i.Authorization=`Bearer ${this.getToken()}`),He(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Kt((t=>t.ok?Et(t.clone().json()):St(t))))}}class Ve{constructor(t){this.nuclia=t}get(t,e,n){return this.fetch("GET",t,void 0,e,n)}post(t,e,n,r,i){return this.fetch("POST",t,e,n,r,i)}put(t,e,n,r,i){return this.fetch("PUT",t,e,n,r,i)}patch(t,e,n,r,i){return this.fetch("PATCH",t,e,n,r,i)}delete(t,e,n){return this.fetch("DELETE",t,void 0,e,!0,n)}head(t,e){return this.fetch("HEAD",t,void 0,e,!0)}getHeaders(t,e=!1){const n=t&&t["x-stf-nuakey"]?{}:this.nuclia.auth.getAuthHeaders(),r=Object.assign({"content-type":"application/json","x-ndb-client":this.nuclia.options.client||"web"},n);return e&&(r["x-synchronous"]=`${e}`),Object.assign(Object.assign({},r),t)}fetch(t,e,n,r,i,o=!1){const s=r&&r["content-type"];return He(this.getFullUrl(e),{selector:t=>Promise.resolve(t),headers:this.getHeaders(r,o),method:t,body:s?n:JSON.stringify(n)}).pipe(Kt((t=>t.ok?i?kt(t):Et(t.clone().json().catch((()=>t.text()))):St((()=>t)))))}getFullUrl(t){return`${t.startsWith("/account")||t.startsWith("/user")||t.startsWith("/auth")||t.startsWith("/zones")||t.includes("/activity")||this.nuclia.options.standalone?this.nuclia.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")||t.startsWith("/export")?"":"/v1"}${t}`}getZones(){return this.zones?kt(this.zones):this.get("/zones").pipe(xt((t=>{const e=t.reduce(((t,e)=>(t[e.id]=e.slug,t)),{});return this.zones=e,e})))}getZoneSlug(t){return this.getZones().pipe(xt((e=>e[t])))}getObjectURL(t){return this.get(t,void 0,!0).pipe(Kt((t=>Et(t.blob()))),xt((t=>URL.createObjectURL(t))))}}class Xe{constructor(t){this.currentShards={},this.options=t,this.auth=new Je(this),this.rest=new Ve(this),this.db=new ze(this)}get backend(){return this.options.backend}get regionalBackend(){return this.options.backend.replace("//",`//${this.options.zone}.`)}get knowledgeBox(){if(!this.options.knowledgeBox||!this.options.zone)throw new Error("zone and knowledge box id must be defined in the Nuclia options");return this.readKb||(this.readKb=new Be(this,"",{id:this.options.knowledgeBox,zone:this.options.zone})),this.readKb}get asyncKnowledgeBox(){return new Proxy(this.knowledgeBox,{get(t,e){const n=Reflect.get(t,e);return"function"==typeof n?(...e)=>function(t,e){var n="object"==typeof e;return new Promise((function(r,i){var o=new R({next:function(t){r(t),o.unsubscribe()},error:i,complete:function(){n?r(e.defaultValue):i(new _t)}});t.subscribe(o)}))}(n.bind(t)(...e)):n}})}}export{Je as Authentication,ze as Db,te as EventType,Zt as ExtractedDataTypes,xe as FIELD_TYPE,$e as FileFieldData,We as JwtHelper,Oe as KeywordSetFieldData,Be as KnowledgeBox,Qt as LabelSetKind,Ie as LinkFieldData,Jt as NUA_CLIENT,Gt as NUA_KEY,Xe as Nuclia,Ae as RESOURCE_STATUS,Se as ReadableResource,_e as Resource,qt as ResourceProperties,Ve as Rest,he as SHORT_FIELD_TYPE,de as Search,Vt as StatsPeriod,Xt as StatsRange,Yt as StatsType,oe as TUSuploadFile,Te as TextFieldData,Le as Training,De as TrainingExecutionStatus,Ue as TrainingStatus,Pe as TrainingType,Fe as WritableKnowledgeBox,se as batchUpload,pe as catalog,be as deDuplicateList,je as getDataKeyFromFieldType,ae as getFileMetadata,ce as getFilterFromLabel,le as getLabelFromFilter,ke as lengthUnicode,Ce as longToShortFieldType,Re as resourceToAlgoliaFormat,fe as search,ye as setEntities,ge as setLabels,Ne as shortToLongFieldType,Ee as sliceUnicode,re as upload,ie as uploadFile,ue as uploadToProcess}; | ||
var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)};function r(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function u(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}function o(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function u(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function a(t){return this instanceof a?(this.v=t,this):new a(t)}function c(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(t,e||[]),o=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(t){i[t]&&(r[t]=function(e){return new Promise((function(n,r){o.push([t,e,n,r])>1||u(t,e)}))})}function u(t,e){try{(n=i[t](e)).value instanceof a?Promise.resolve(n.value.v).then(c,l):h(o[0][2],n)}catch(t){h(o[0][3],t)}var n}function c(t){u("next",t)}function l(t){u("throw",t)}function h(t,e){t(e),o.shift(),o.length&&u(o[0][0],o[0][1])}}function l(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=o(t),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,i){(function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)})(r,i,(e=t[n](e)).done,e.value)}))}}}function h(t){return"function"==typeof t}function d(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var f=d((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function p(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var v=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}var e;return t.prototype.unsubscribe=function(){var t,e,n,r,i;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var c=o(a),l=c.next();!l.done;l=c.next()){l.value.remove(this)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else a.remove(this);var d=this.initialTeardown;if(h(d))try{d()}catch(t){i=t instanceof f?t.errors:[t]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var v=o(p),b=v.next();!b.done;b=v.next()){var g=b.value;try{y(g)}catch(t){i=null!=i?i:[],t instanceof f?i=u(u([],s(i)),s(t.errors)):i.push(t)}}}catch(t){n={error:t}}finally{try{b&&!b.done&&(r=v.return)&&r.call(v)}finally{if(n)throw n.error}}}if(i)throw new f(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)y(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&p(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&p(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t}(),b=v.EMPTY;function g(t){return t instanceof v||t&&"closed"in t&&h(t.remove)&&h(t.add)&&h(t.unsubscribe)}function y(t){h(t)?t():t.unsubscribe()}var m={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},w={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=w.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,u([t,e],s(n))):setTimeout.apply(void 0,u([t,e],s(n)))},clearTimeout:function(t){var e=w.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function E(t){w.setTimeout((function(){throw t}))}function k(){}var x=S("C",void 0,void 0);function S(t,e,n){return{kind:t,value:e,error:n}}var _=null;function A(t){if(m.useDeprecatedSynchronousErrorHandling){var e=!_;if(e&&(_={errorThrown:!1,error:null}),t(),e){var n=_,r=n.errorThrown,i=n.error;if(_=null,r)throw i}}else t()}var $=function(t){function n(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,g(e)&&e.add(n)):n.destination=N,n}return e(n,t),n.create=function(t,e,n){return new I(t,e,n)},n.prototype.next=function(t){this.isStopped?C(function(t){return S("N",t,void 0)}(t),this):this._next(t)},n.prototype.error=function(t){this.isStopped?C(S("E",void 0,t),this):(this.isStopped=!0,this._error(t))},n.prototype.complete=function(){this.isStopped?C(x,this):(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(t){this.destination.next(t)},n.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n}(v),T=Function.prototype.bind;function O(t,e){return T.call(t,e)}var R=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){j(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){j(t)}else j(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){j(t)}},t}(),I=function(t){function n(e,n,r){var i,o,s=t.call(this)||this;h(e)||!e?i={next:null!=e?e:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:s&&m.useDeprecatedNextContext?((o=Object.create(e)).unsubscribe=function(){return s.unsubscribe()},i={next:e.next&&O(e.next,o),error:e.error&&O(e.error,o),complete:e.complete&&O(e.complete,o)}):i=e;return s.destination=new R(i),s}return e(n,t),n}($);function j(t){E(t)}function C(t,e){var n=m.onStoppedNotification;n&&w.setTimeout((function(){return n(t,e)}))}var N={closed:!0,next:k,error:function(t){throw t},complete:k},P="function"==typeof Symbol&&Symbol.observable||"@@observable";function U(t){return t}function D(t){return 0===t.length?U:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var L=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(t,e,n){var r,i=this,o=(r=t)&&r instanceof $||function(t){return t&&h(t.next)&&h(t.error)&&h(t.complete)}(r)&&g(r)?t:new I(t,e,n);return A((function(){var t=i,e=t.operator,n=t.source;o.add(e?e.call(o,n):n?i._subscribe(o):i._trySubscribe(o))})),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var n=this;return new(e=B(e))((function(e,r){var i=new I({next:function(e){try{t(e)}catch(t){r(t),i.unsubscribe()}},error:r,complete:e});n.subscribe(i)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[P]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return D(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=B(t))((function(t,n){var r;e.subscribe((function(t){return r=t}),(function(t){return n(t)}),(function(){return t(r)}))}))},t.create=function(e){return new t(e)},t}();function B(t){var e;return null!==(e=null!=t?t:m.Promise)&&void 0!==e?e:Promise}function F(t){return function(e){if(function(t){return h(null==t?void 0:t.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function z(t,e,n,r,i){return new H(t,e,n,r,i)}var H=function(t){function n(e,n,r,i,o,s){var u=t.call(this,e)||this;return u.onFinalize=o,u.shouldUnsubscribe=s,u._next=n?function(t){try{n(t)}catch(t){e.error(t)}}:t.prototype._next,u._error=i?function(t){try{i(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=r?function(){try{r()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,u}return e(n,t),n.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},n}($),K=d((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),W=function(t){function n(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return e(n,t),n.prototype.lift=function(t){var e=new M(this,this);return e.operator=t,e},n.prototype._throwIfClosed=function(){if(this.closed)throw new K},n.prototype.next=function(t){var e=this;A((function(){var n,r;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var i=o(e.currentObservers),s=i.next();!s.done;s=i.next()){s.value.next(t)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}}))},n.prototype.error=function(t){var e=this;A((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var n=e.observers;n.length;)n.shift().error(t)}}))},n.prototype.complete=function(){var t=this;A((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},n.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(n.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),n.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},n.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},n.prototype._innerSubscribe=function(t){var e=this,n=this,r=n.hasError,i=n.isStopped,o=n.observers;return r||i?b:(this.currentObservers=null,o.push(t),new v((function(){e.currentObservers=null,p(o,t)})))},n.prototype._checkFinalizedStatuses=function(t){var e=this,n=e.hasError,r=e.thrownError,i=e.isStopped;n?t.error(r):i&&t.complete()},n.prototype.asObservable=function(){var t=new L;return t.source=this,t},n.create=function(t,e){return new M(t,e)},n}(L),M=function(t){function n(e,n){var r=t.call(this)||this;return r.destination=e,r.source=n,r}return e(n,t),n.prototype.next=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===n||n.call(e,t)},n.prototype.error=function(t){var e,n;null===(n=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===n||n.call(e,t)},n.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},n.prototype._subscribe=function(t){var e,n;return null!==(n=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==n?n:b},n}(W),G={now:function(){return(G.delegate||Date).now()},delegate:void 0},V=function(t){function n(e,n,r){void 0===e&&(e=1/0),void 0===n&&(n=1/0),void 0===r&&(r=G);var i=t.call(this)||this;return i._bufferSize=e,i._windowTime=n,i._timestampProvider=r,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=n===1/0,i._bufferSize=Math.max(1,e),i._windowTime=Math.max(1,n),i}return e(n,t),n.prototype.next=function(e){var n=this,r=n.isStopped,i=n._buffer,o=n._infiniteTimeWindow,s=n._timestampProvider,u=n._windowTime;r||(i.push(e),!o&&i.push(s.now()+u)),this._trimBuffer(),t.prototype.next.call(this,e)},n.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var e=this._innerSubscribe(t),n=this._infiniteTimeWindow,r=this._buffer.slice(),i=0;i<r.length&&!t.closed;i+=n?1:2)t.next(r[i]);return this._checkFinalizedStatuses(t),e},n.prototype._trimBuffer=function(){var t=this,e=t._bufferSize,n=t._timestampProvider,r=t._buffer,i=t._infiniteTimeWindow,o=(i?1:2)*e;if(e<1/0&&o<r.length&&r.splice(0,r.length-o),!i){for(var s=n.now(),u=0,a=1;a<r.length&&r[a]<=s;a+=2)u=a;u&&r.splice(0,u+1)}},n}(W),X=function(t){function n(e,n){return t.call(this)||this}return e(n,t),n.prototype.schedule=function(t,e){return this},n}(v),J={setInterval:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=J.delegate;return(null==i?void 0:i.setInterval)?i.setInterval.apply(i,u([t,e],s(n))):setInterval.apply(void 0,u([t,e],s(n)))},clearInterval:function(t){var e=J.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},Y=function(t){function n(e,n){var r=t.call(this,e,n)||this;return r.scheduler=e,r.work=n,r.pending=!1,r}return e(n,t),n.prototype.schedule=function(t,e){if(void 0===e&&(e=0),this.closed)return this;this.state=t;var n=this.id,r=this.scheduler;return null!=n&&(this.id=this.recycleAsyncId(r,n,e)),this.pending=!0,this.delay=e,this.id=this.id||this.requestAsyncId(r,this.id,e),this},n.prototype.requestAsyncId=function(t,e,n){return void 0===n&&(n=0),J.setInterval(t.flush.bind(t,this),n)},n.prototype.recycleAsyncId=function(t,e,n){if(void 0===n&&(n=0),null!=n&&this.delay===n&&!1===this.pending)return e;J.clearInterval(e)},n.prototype.execute=function(t,e){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var n=this._execute(t,e);if(n)return n;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},n.prototype._execute=function(t,e){var n,r=!1;try{this.work(t)}catch(t){r=!0,n=t||new Error("Scheduled action threw falsy error")}if(r)return this.unsubscribe(),n},n.prototype.unsubscribe=function(){if(!this.closed){var e=this.id,n=this.scheduler,r=n.actions;this.work=this.state=this.scheduler=null,this.pending=!1,p(r,this),null!=e&&(this.id=this.recycleAsyncId(n,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},n}(X),q=function(){function t(e,n){void 0===n&&(n=t.now),this.schedulerActionCtor=e,this.now=n}return t.prototype.schedule=function(t,e,n){return void 0===e&&(e=0),new this.schedulerActionCtor(this,t).schedule(n,e)},t.now=G.now,t}(),Z=new(function(t){function n(e,n){void 0===n&&(n=q.now);var r=t.call(this,e,n)||this;return r.actions=[],r._active=!1,r._scheduled=void 0,r}return e(n,t),n.prototype.flush=function(t){var e=this.actions;if(this._active)e.push(t);else{var n;this._active=!0;do{if(n=t.execute(t.state,t.delay))break}while(t=e.shift());if(this._active=!1,n){for(;t=e.shift();)t.unsubscribe();throw n}}},n}(q))(Y),Q=new L((function(t){return t.complete()}));function tt(t){return t&&h(t.schedule)}function et(t){return t[t.length-1]}function nt(t){return h(et(t))?t.pop():void 0}function rt(t){return tt(et(t))?t.pop():void 0}function it(t,e){return"number"==typeof et(t)?t.pop():e}var ot=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function st(t){return h(null==t?void 0:t.then)}function ut(t){return h(t[P])}function at(t){return Symbol.asyncIterator&&h(null==t?void 0:t[Symbol.asyncIterator])}function ct(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var lt="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ht(t){return h(null==t?void 0:t[lt])}function dt(t){return c(this,arguments,(function(){var e,n,r;return i(this,(function(i){switch(i.label){case 0:e=t.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,a(e.read())];case 3:return n=i.sent(),r=n.value,n.done?[4,a(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,a(r)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}function ft(t){return h(null==t?void 0:t.getReader)}function pt(t){if(t instanceof L)return t;if(null!=t){if(ut(t))return i=t,new L((function(t){var e=i[P]();if(h(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(ot(t))return r=t,new L((function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()}));if(st(t))return n=t,new L((function(t){n.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,E)}));if(at(t))return vt(t);if(ht(t))return e=t,new L((function(t){var n,r;try{for(var i=o(e),s=i.next();!s.done;s=i.next()){var u=s.value;if(t.next(u),t.closed)return}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}t.complete()}));if(ft(t))return vt(dt(t))}var e,n,r,i;throw ct(t)}function vt(t){return new L((function(e){(function(t,e){var n,o,s,u;return r(this,void 0,void 0,(function(){var r,a;return i(this,(function(i){switch(i.label){case 0:i.trys.push([0,5,6,11]),n=l(t),i.label=1;case 1:return[4,n.next()];case 2:if((o=i.sent()).done)return[3,4];if(r=o.value,e.next(r),e.closed)return[2];i.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=i.sent(),s={error:a},[3,11];case 6:return i.trys.push([6,,9,10]),o&&!o.done&&(u=n.return)?[4,u.call(n)]:[3,8];case 7:i.sent(),i.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))}))})(t,e).catch((function(t){return e.error(t)}))}))}function bt(t,e,n,r,i){void 0===r&&(r=0),void 0===i&&(i=!1);var o=e.schedule((function(){n(),i?t.add(this.schedule(null,r)):this.unsubscribe()}),r);if(t.add(o),!i)return o}function gt(t,e){return void 0===e&&(e=0),F((function(n,r){n.subscribe(z(r,(function(n){return bt(r,t,(function(){return r.next(n)}),e)}),(function(){return bt(r,t,(function(){return r.complete()}),e)}),(function(n){return bt(r,t,(function(){return r.error(n)}),e)})))}))}function yt(t,e){return void 0===e&&(e=0),F((function(n,r){r.add(t.schedule((function(){return n.subscribe(r)}),e))}))}function mt(t,e){if(!t)throw new Error("Iterable cannot be null");return new L((function(n){bt(n,e,(function(){var r=t[Symbol.asyncIterator]();bt(n,e,(function(){r.next().then((function(t){t.done?n.complete():n.next(t.value)}))}),0,!0)}))}))}function wt(t,e){if(null!=t){if(ut(t))return function(t,e){return pt(t).pipe(yt(e),gt(e))}(t,e);if(ot(t))return function(t,e){return new L((function(n){var r=0;return e.schedule((function(){r===t.length?n.complete():(n.next(t[r++]),n.closed||this.schedule())}))}))}(t,e);if(st(t))return function(t,e){return pt(t).pipe(yt(e),gt(e))}(t,e);if(at(t))return mt(t,e);if(ht(t))return function(t,e){return new L((function(n){var r;return bt(n,e,(function(){r=t[lt](),bt(n,e,(function(){var t,e,i;try{e=(t=r.next()).value,i=t.done}catch(t){return void n.error(t)}i?n.complete():n.next(e)}),0,!0)})),function(){return h(null==r?void 0:r.return)&&r.return()}}))}(t,e);if(ft(t))return function(t,e){return mt(dt(t),e)}(t,e)}throw ct(t)}function Et(t,e){return e?wt(t,e):pt(t)}function kt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return Et(t,n)}function xt(t,e){var n=h(t)?t:function(){return t},r=function(t){return t.error(n())};return new L(e?function(t){return e.schedule(r,0,t)}:r)}var St=d((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function _t(t,e){return F((function(n,r){var i=0;n.subscribe(z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var At=Array.isArray;function $t(t){return _t((function(e){return function(t,e){return At(e)?t.apply(void 0,u([],s(e))):t(e)}(t,e)}))}var Tt=Array.isArray,Ot=Object.getPrototypeOf,Rt=Object.prototype,It=Object.keys;function jt(t){if(1===t.length){var e=t[0];if(Tt(e))return{args:e,keys:null};if((r=e)&&"object"==typeof r&&Ot(r)===Rt){var n=It(e);return{args:n.map((function(t){return e[t]})),keys:n}}}var r;return{args:t,keys:null}}function Ct(t,e){return t.reduce((function(t,n,r){return t[n]=e[r],t}),{})}function Nt(t,e,n){return void 0===n&&(n=1/0),h(e)?Nt((function(n,r){return _t((function(t,i){return e(n,t,r,i)}))(pt(t(n,r)))}),n):("number"==typeof e&&(n=e),F((function(e,r){return function(t,e,n,r,i,o,s,u){var a=[],c=0,l=0,h=!1,d=function(){!h||a.length||c||e.complete()},f=function(t){return c<r?p(t):a.push(t)},p=function(t){o&&e.next(t),c++;var u=!1;pt(n(t,l++)).subscribe(z(e,(function(t){null==i||i(t),o?f(t):e.next(t)}),(function(){u=!0}),void 0,(function(){if(u)try{c--;for(var t=function(){var t=a.shift();s?bt(e,s,(function(){return p(t)})):p(t)};a.length&&c<r;)t();d()}catch(t){e.error(t)}})))};return t.subscribe(z(e,f,(function(){h=!0,d()}))),function(){null==u||u()}}(e,r,t,n)})))}function Pt(t){return void 0===t&&(t=1/0),Nt(U,t)}function Ut(){return Pt(1)}function Dt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ut()(Et(t,rt(t)))}function Lt(t,e,n){void 0===t&&(t=0),void 0===n&&(n=Z);var r=-1;return null!=e&&(tt(e)?n=e:r=e),new L((function(e){var i,o=(i=t)instanceof Date&&!isNaN(i)?+t-n.now():t;o<0&&(o=0);var s=0;return n.schedule((function(){e.closed||(e.next(s++),0<=r?this.schedule(void 0,r):e.complete())}),o)}))}function Bt(t,e){return F((function(n,r){var i=0;n.subscribe(z(r,(function(n){return t.call(e,n,i++)&&r.next(n)})))}))}function Ft(t){return F((function(e,n){var r,i=null,o=!1;i=e.subscribe(z(n,void 0,void 0,(function(s){r=pt(t(s,Ft(t)(e))),i?(i.unsubscribe(),i=null,r.subscribe(n)):o=!0}))),o&&(i.unsubscribe(),i=null,r.subscribe(n))}))}function zt(t,e){return h(e)?Nt(t,e,1):Nt(t,1)}function Ht(t){return t<=0?function(){return Q}:F((function(e,n){var r=0;e.subscribe(z(n,(function(e){++r<=t&&(n.next(e),t<=r&&n.complete())})))}))}function Kt(t){var e,n,r=1/0;return null!=t&&("object"==typeof t?(e=t.count,r=void 0===e?1/0:e,n=t.delay):r=t),r<=0?function(){return Q}:F((function(t,e){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=n){var t="number"==typeof n?Lt(n):pt(n(o)),r=z(e,(function(){r.unsubscribe(),u()}));t.subscribe(r)}else u()},u=function(){var n=!1;i=t.subscribe(z(e,void 0,(function(){++o<r?i?s():n=!0:e.complete()}))),n&&s()};u()}))}function Wt(t,e){return F((function(n,r){var i=null,o=0,s=!1,u=function(){return s&&!i&&r.complete()};n.subscribe(z(r,(function(n){null==i||i.unsubscribe();var s=0,a=o++;pt(t(n,a)).subscribe(i=z(r,(function(t){return r.next(e?e(n,t,a,s++):t)}),(function(){i=null,u()})))}),(function(){s=!0,u()})))}))}function Mt(t,e,n){var r=h(t)||e||n?{next:t,error:e,complete:n}:t;return r?F((function(t,e){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var i=!0;t.subscribe(z(e,(function(t){var n;null===(n=r.next)||void 0===n||n.call(r,t),e.next(t)}),(function(){var t;i=!1,null===(t=r.complete)||void 0===t||t.call(r),e.complete()}),(function(t){var n;i=!1,null===(n=r.error)||void 0===n||n.call(r,t),e.error(t)}),(function(){var t,e;i&&(null===(t=r.unsubscribe)||void 0===t||t.call(r)),null===(e=r.finalize)||void 0===e||e.call(r)})))})):U}function Gt(t,e){void 0===e&&(e={});var r=e.selector,i=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(e,["selector"]);return new L((function(e){var o=new AbortController,s=o.signal,u=!0,a=i.signal;if(a)if(a.aborted)o.abort();else{var c=function(){s.aborted||o.abort()};a.addEventListener("abort",c),e.add((function(){return a.removeEventListener("abort",c)}))}var l=n(n({},i),{signal:s}),h=function(t){u=!1,e.error(t)};return fetch(t,l).then((function(t){r?pt(r(t)).subscribe(z(e,void 0,(function(){u=!1,e.complete()}),h)):(u=!1,e.next(t),e.complete())})).catch(h),function(){u&&o.abort()}}))}class Vt{constructor(t){this.token=t}urlBase64Decode(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("Illegal base64url string!")}return this.b64DecodeUnicode(e)}b64decode(t){let e="";if((t=String(t).replace(/=+$/,"")).length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let n,r,i=0,o=0;r=t.charAt(o++);~r&&(n=i%4?64*n+r:r,i++%4)?e+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return e}b64DecodeUnicode(t){return decodeURIComponent(Array.prototype.map.call(this.b64decode(t),(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2))).join(""))}decodeToken(t=this.token){if(null===t)return null;const e=t.split(".");if(3!==e.length)throw new Error("The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.");const n=this.urlBase64Decode(e[1]);if(!n)throw new Error("Cannot decode the token.");return JSON.parse(n)}getJWTUser(t=this.token){let e;try{e=this.decodeToken(t)}catch(t){return null}return e}getTokenExpirationDate(t=this.token){const e=this.getJWTUser(t);if(!e)return null;const n=new Date(0);return n.setUTCSeconds(e.exp),n}isTokenExpired(t=this.token,e){if(null===t||""===t)return!0;const n=this.getTokenExpirationDate(t);return e=e||0,null===n||n.valueOf()<=(new Date).valueOf()+1e3*e}}const Xt="JWT_KEY",Jt="JWT_REFRESH_KEY",Yt=216e5;class qt{constructor(t){this._isAuthenticated=new V(1),this.nuclia=t,this.nuclia.options.knowledgeBox?this._isAuthenticated.next(!0):this.checkTokenExpiration()}getAuthHeaders(){return this.nuclia.options.standalone?{"X-NUCLIADB-ROLES":"READER"}:this.nuclia.options.apiKey?{"X-STF-Serviceaccount":`Bearer ${this.nuclia.options.apiKey}`}:this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{}}isAuthenticated(){return this._isAuthenticated.asObservable()}hasLoggedOut(){return this.isAuthenticated().pipe((t=1,Bt((function(e,n){return t<=n}))),Bt((t=>!t)));var t}login(t,e,n){return this.fetch("/auth/login",{username:t,password:e},!1,n?{"X-STF-VALIDATION":n}:{}).pipe(_t((t=>this.authenticate(t))))}authenticate(t){return t.access_token?(this.storeTokens(t),this._isAuthenticated.next(!0),!0):(this._isAuthenticated.next(!1),!1)}logout(){this.fetch("/auth/logout",{},!0,{}).subscribe(),localStorage.removeItem(Xt),localStorage.removeItem(Jt),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Ft((t=>(this.logout(),xt(t)))),_t((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return this.nuclia.options.public?"":localStorage.getItem(Xt)||""}setPassword(t){return this.fetch("/auth/setpassword",{password:t},!0,{}).pipe(_t((t=>this.authenticate(t))))}deleteAuthenticatedUser(){return this.nuclia.rest.delete("/user").pipe(Mt((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new Vt(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(Jt)||""}storeTokens(t){localStorage.setItem(Xt,t.access_token),localStorage.setItem(Jt,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const n=this.getToken();if(n){const r=null===(t=new Vt(n).getTokenExpirationDate())||void 0===t?void 0:t.getTime();if(r){const t=(new Date).getTime();if(r<t)this.logout();else{this._isAuthenticated.next(!0);const n=r-t<Yt?0:Yt;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Lt(n).pipe(Wt((()=>this.refresh()))).subscribe()}}else this._isAuthenticated.next(!1)}else this._isAuthenticated.next(!1)}fetch(t,e,n,r){const i=Object.assign({"content-type":"application/json"},r);return n&&(i.Authorization=`Bearer ${this.getToken()}`),Gt(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Wt((t=>t.ok?Et(t.clone().json()):xt(t))))}}const Zt="NUCLIA_NUA_KEY",Qt="NUCLIA_NUA_CLIENT";var te,ee,ne,re,ie,oe,se,ue;!function(t){t.DAY="day",t.WEEK="week",t.MONTH="month",t.YEAR="year"}(te||(te={})),function(t){t.anHour="1h",t.twoHours="2h",t.threeHours="3h",t.sixHours="6h",t.twelveHours="12h",t.twentyFourHours="24h",t.fortyHeightHours="48h"}(ee||(ee={})),function(t){t.PROCESSING_TIME="processing_time",t.SEARCHES="searches",t.CHARS="chars",t.MEDIA_SECONDS="media_seconds",t.BYTES="bytes",t.RESOURCES="resources",t.PAGES="pages",t.TRAIN_SECONDS="train_seconds",t.SUGGESTIONS="suggestions",t.DOCS_NO_MEDIA="docs_no_media"}(ne||(ne={})),function(t){t.BASIC="basic",t.ORIGIN="origin",t.RELATIONS="relations",t.VALUES="values",t.EXTRACTED="extracted",t.ERRORS="errors"}(re||(re={})),function(t){t.VALUE="value",t.EXTRACTED="extracted",t.ERROR="error"}(ie||(ie={})),function(t){t.TEXT="text",t.METADATA="metadata",t.LARGE_METADATA="large_metadata",t.VECTOR="vectors",t.LINK="link",t.FILE="file"}(oe||(oe={})),function(t){t.RESOURCES="RESOURCES",t.PARAGRAPHS="PARAGRAPHS"}(se||(se={})),function(t){t.VISITED="VISITED",t.MODIFIED="MODIFIED",t.DELETED="DELETED",t.NEW="NEW",t.STARTED="STARTED",t.STOPPED="STOPPED",t.SEARCH="SEARCH",t.PROCESSED="PROCESSED"}(ue||(ue={}));const ae=524288,ce=new RegExp(/[^a-z0-9_-]/g),le=(t,e,n,r,i={})=>(i.contentType||n instanceof ArrayBuffer||(i.contentType=null==n?void 0:n.type),i.filename||n instanceof ArrayBuffer||(i.filename=null==n?void 0:n.name),i.lang||n instanceof ArrayBuffer||(i.lang=n.lang),i.md5||n instanceof ArrayBuffer||(i.md5=n.md5),(n instanceof ArrayBuffer?kt(n):Et(n.arrayBuffer())).pipe(Wt((o=>r?de(t,e,o,i,n.payload):he(t,e,o,i))))),he=(t,e,n,r)=>{const i=Object.assign({"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},ve(r));let o=1;const s=(null==r?void 0:r.rslug)?`?rslug=${r.rslug}`:"";return t.rest.post(`${e}/upload${s}`,n,i).pipe(Kt(),Bt((t=>0==o--||503!==t.status)),Ht(1),Wt((t=>{switch(t.status){case 201:return Et(t.json()).pipe(_t((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return kt({conflict:!0});default:return kt({failed:!0})}})))},de=(t,e,n,r,i)=>{let o=0,s=!1;const u=n.byteLength,a=Math.ceil(u/ae),c={"upload-length":`${u}`,"tus-resumable":"1.0.0"},l=[];(null==r?void 0:r.filename)&&l.push(`filename ${btoa(encodeURIComponent(r.filename))}`),(null==r?void 0:r.lang)&&l.push(`language ${btoa(r.lang)}`),(null==r?void 0:r.md5)&&l.push(`md5 ${btoa(r.md5)}`),l.push(`content_type ${btoa((null==r?void 0:r.contentType)||"application/octet-stream")}`),l.length>0&&(c["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,c,!0).pipe(Kt(),Bt((t=>0==h--||503!==t.status)),Ft((t=>kt(t))),Ht(1),zt((e=>function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t),r=it(t,1/0),i=t;return i.length?1===i.length?pt(i[0]):Pt(r)(Et(i,n)):Q}(kt(e).pipe(Bt((t=>201!==t.status||!t.headers.get("location"))),_t((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),kt(e).pipe(Bt((t=>201===t.status&&!!t.headers.get("location"))),_t((t=>t.headers.get("location"))),zt((e=>function(t,e,n){if(null==e&&(e=t,t=0),e<=0)return Q;var r=e+t;return new L(n?function(e){var i=t;return n.schedule((function(){i<r?(e.next(i++),this.schedule()):e.complete()}))}:function(e){for(var n=t;n<r&&!e.closed;)e.next(n++);e.complete()})}(0,a).pipe(zt((()=>{const i=n.slice(o,o+ae);return s?kt({failed:s}):t.rest.patch(e,i,{"content-type":(null==r?void 0:r.contentType)||"application/octet-stream","upload-offset":`${o}`,"content-length":`${i.byteLength}`},!0).pipe(_t((t=>200!==t.status?(s=!0,{failed:s}):(o+=ae,{completed:o>=u,progress:o>=u?100:Math.min(Math.floor(o/u*100),100)}))),Ft((()=>kt({failed:!0}))))}))))))))))},fe=(t,e,n,r=!1)=>{const i=Array.from(n),o=i.reduce(((t,e)=>t+(e.size||0)),0),s=[],u=i.map((t=>({file:t,progress:0,uploaded:!1,failed:!1})));return Et(i.map((n=>{let i=e;if(r){let t=n.name.toLowerCase().replace(ce,"_");s.includes(t)&&(t+="_"+s.filter((e=>e.startsWith(t))).length),s.push(t),i=`${i}/file/${t}`}const o=n.lang;if(o){const t=n.payload||{};n.payload=Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},null==t?void 0:t.metadata),{language:o})})}return le(t,i,n,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return F((function(e,r){(n?Dt(t,e,n):Dt(t,e)).subscribe(r)}))}({progress:0,completed:!1}),_t((t=>({status:t,file:n}))))}))).pipe(Nt((t=>t),6),_t((t=>{const e=u.find((e=>e.file===t.file));t.status.failed&&(e.failed=!0),t.status.conflict&&(e.conflicts=!0),t.status.completed&&(e.uploaded=!0),t.status.failed||t.status.conflict||t.status.completed?e.progress=100:e.progress=t.status.progress||0;const n=u.filter((t=>t.failed)).length,r=u.filter((t=>t.conflicts)).length,i=u.filter((t=>t.uploaded)).length,s=i+n===u.length,a=Math.round(u.reduce(((t,e)=>t+e.file.size*e.progress/100),0)/o*100);return{files:u,progress:a,completed:s,uploaded:i,failed:n,conflicts:r}})))},pe=(t,e,n)=>{const r=Object.assign({"x-stf-nuakey":`Bearer ${localStorage.getItem(Zt)}`,"content-type":(null==n?void 0:n.contentType)||"application/octet-stream"},ve(n));return t.rest.post("/processing/upload",e,r)},ve=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=encodeURIComponent(t.filename)),(null==t?void 0:t.md5)&&(e["x-md5"]=t.md5),(null==t?void 0:t.lang)&&(e["x-language"]=t.lang),e};function be(t){return`/l/${t.labelset}/${t.label}`}function ge(t){const e=t.split("/");return{labelset:e[2],label:e[3]}}var ye,me;!function(t){t.layout="l",t.text="t",t.file="f",t.link="u",t.datetime="d",t.keywordset="k",t.generic="a",t.conversation="c"}(ye||(ye={})),function(t){var e,n;(e=t.Features||(t.Features={})).PARAGRAPH="paragraph",e.DOCUMENT="document",e.RELATIONS="relations",e.VECTOR="vector",(n=t.ResourceFeatures||(t.ResourceFeatures={})).PARAGRAPH="paragraph",n.RELATIONS="relations",n.VECTOR="vector"}(me||(me={}));const we=(t,e,n,r,i=[],o,s)=>{var u;const a={};a.query=r||"",a.features=i;const c=o||{},{inTitleOnly:l}=c,h=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(c,["inTitleOnly"]);l&&(a.fields=["a/title"]),a.shards=(null===(u=t.currentShards)||void 0===u?void 0:u[e])||[];return(s?t.rest.get(`${n}/search?${ke(a,h)}`):t.rest.post(`${n}/search`,Object.assign(Object.assign({},a),h))).pipe(Ft((()=>kt({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((n=>{n.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:n.shards}))})))},Ee=(t,e,n,r)=>{var i;const o={};o.query=n||"",o.shards=(null===(i=t.currentShards)||void 0===i?void 0:i[e])||[];return t.rest.get(`/kb/${e}/catalog?${r?ke(o,r):""}`).pipe(Ft((()=>kt({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((n=>{n.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:n.shards}))})))},ke=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{null!=n&&(Array.isArray(n)?t[e]=n.map((t=>`${t}`)):"object"==typeof n?Object.entries(n).forEach((([n,r])=>t[`${e}_${n}`]=`${r}`)):t[e]=`${n}`)}));const n=new URLSearchParams;return Object.entries(t).forEach((([t,e])=>Array.isArray(e)?e.forEach((e=>n.append(t,e))):n.append(t,e))),n.toString()},xe=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),Se=(t,e,n,r,i)=>{const o=xe(i.filter((n=>Ae(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=xe(i.filter((n=>$e(n,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])).filter((t=>t.key!==n)),u=i.filter((n=>n.field.field!==t||n.field.field_type!==e)),a=r.length>0?[...s,{key:n,classifications:r}]:s;return o.length>0||a.length>0?[...u,{field:{field:t,field_type:e},token:o.length>0?o:void 0,paragraphs:a.length>0?a:void 0}]:u},_e=(t,e,n,r)=>{const i=xe(r.filter((n=>$e(n,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])),o=r.filter((n=>n.field.field!==t||n.field.field_type!==e));return n.length>0||i.length>0?[...o,{field:{field:t,field_type:e},token:n.length>0?n:void 0,paragraphs:i.length>0?i:void 0}]:o},Ae=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,$e=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0,Te=(t,e,n)=>t?(Array.isArray(t)||(t=Array.from(t)),t.slice(e,n).join("")):"",Oe=t=>t?Array.from(t).length:0;class Re{constructor(t){this.data={},this.fieldTextsCache={},t.data||(t.data={}),Object.assign(this,Object.assign(Object.assign({},t),{title:this.formatTitle(t.title)}))}getFields(t=["files","links","texts","keywordsets"]){return Object.entries(this.data).filter((([e])=>t.includes(e))).map((([,t])=>t)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}getFieldData(t,e){var n;const r=null===(n=this.data[t])||void 0===n?void 0:n[e];return r||void 0}getExtractedSummaries(){return this.getFields().filter((t=>{var e,n,r;return null===(r=null===(n=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===n?void 0:n.metadata)||void 0===r?void 0:r.summary})).map((t=>t.extracted.metadata.metadata.summary))}getExtractedTexts(){return this.getFields().filter((t=>{var e;return null===(e=t.extracted)||void 0===e?void 0:e.text})).map((t=>t.extracted.text))}getFiles(){return this.getFields(["files"]).filter((t=>!!t&&!!t.value&&!!t.value.file)).map((t=>t.value.file))}getThumbnails(){return this.getFields(["files"]).map((t=>{var e,n;return null===(n=null===(e=t.extracted)||void 0===e?void 0:e.file)||void 0===n?void 0:n.file_thumbnail})).concat(this.getFields(["links"]).map((t=>{var e,n;return null===(n=null===(e=t.extracted)||void 0===e?void 0:e.link)||void 0===n?void 0:n.link_thumbnail}))).filter((t=>!!t))}getAnnotatedEntities(){return(this.fieldmetadata||[]).filter((t=>t.token&&t.token.length>0)).map((t=>t.token)).reduce(((t,e)=>(e.filter((t=>!t.cancelled_by_user)).forEach((e=>{t[e.klass]||(t[e.klass]=[]),t[e.klass].push(e.token)})),t)),{})}getNamedEntities(){return this.getFields().filter((t=>{var e,n,r;return null===(r=null===(n=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===n?void 0:n.metadata)||void 0===r?void 0:r.ner})).map((t=>Object.entries(t.extracted.metadata.metadata.ner).reduce(((t,[e,n])=>(t[n]=(t[n]||[]).concat([e]),t)),{}))).reduce(((t,e)=>(Object.entries(e).forEach((([e,n])=>{t[e]=(t[e]||[]).concat(n)})),t)),{})}getClassifications(){var t,e,n;const r=((null===(t=this.usermetadata)||void 0===t?void 0:t.classifications)||[]).filter((t=>!t.cancelled_by_user)),i=((null===(e=this.usermetadata)||void 0===e?void 0:e.classifications)||[]).filter((t=>t.cancelled_by_user));return((null===(n=this.computedmetadata)||void 0===n?void 0:n.field_classifications)||[]).reduce(((t,e)=>(e.classifications.forEach((e=>{const n=t.find((t=>t.label===e.label&&t.labelset===e.labelset)),r=i.find((t=>t.label===e.label&&t.labelset===e.labelset));n||r||t.push(Object.assign(Object.assign({},e),{immutable:!0}))})),t)),r)}getPositionedNamedEntities(t,e){var n,r,i,o;const s=null===(o=null===(i=null===(r=null===(n=this.data[t])||void 0===n?void 0:n[e])||void 0===r?void 0:r.extracted)||void 0===i?void 0:i.metadata)||void 0===o?void 0:o.metadata.positions;return s?Object.entries(s).reduce(((t,[e,n])=>{const r=e.split("/")[0];return n.position.forEach((e=>{t.push(Object.assign({entity:n.entity,family:r},e))})),t}),[]):[]}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}getParagraphText(t,e,n){return Te(this.getFieldText(t,e),n.start,n.end)}getSentenceText(t,e,n){return Te(this.getFieldText(t,e),n.start,n.end)}getFieldText(t,e){var n,r;const i=`${t}-${e}`;if(!this.fieldTextsCache[i]){const o=this.getFieldData(`${t}s`,e);this.fieldTextsCache[i]=Array.from((null===(r=null===(n=null==o?void 0:o.extracted)||void 0===n?void 0:n.text)||void 0===r?void 0:r.text)||"")}return this.fieldTextsCache[i]}}class Ie extends Re{constructor(t,e,n){super(n),this.nuclia=t,this.kb=e,this.uuid=n.id}get path(){if(!this.uuid&&!this.slug)throw new Error("Resource must have either uuid or slug");return this.uuid?`/kb/${this.kb}/resource/${this.uuid}`:`/kb/${this.kb}/slug/${this.slug}`}modify(t,e=!0){return this.nuclia.rest.patch(this.path,t,void 0,void 0,e)}delete(t=!0){return this.nuclia.rest.delete(this.path,void 0,t)}reprocess(){return this.nuclia.rest.post(`${this.path}/reprocess`,{},void 0,void 0,!0)}getField(t,e,n=[ie.VALUE],r=[oe.TEXT,oe.METADATA,oe.LINK,oe.FILE]){const i=[...n.map((t=>`show=${t}`)),...r.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this.path}/${t}/${e}?${i.join("&")}`)}getThumbnailsUrl(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t),r=jt(t),i=r.args,o=r.keys,s=new L((function(t){var e=i.length;if(e)for(var n=new Array(e),r=e,s=e,u=function(e){var u=!1;pt(i[e]).subscribe(z(t,(function(t){u||(u=!0,s--),n[e]=t}),(function(){return r--}),void 0,(function(){r&&u||(s||t.next(o?Ct(o,n):n),t.complete())})))},a=0;a<e;a++)u(a);else t.complete()}));return n?s.pipe($t(n)):s}(this.getThumbnails().filter((t=>t.uri)).map((t=>this.nuclia.rest.getObjectURL(t.uri))))}deleteField(t,e){return this.nuclia.rest.delete(`${this.path}/${t}/${e}`)}addField(t,e,n){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,n)}updateField(t,e,n){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,n)}upload(t,e,n,r){return le(this.nuclia,`${this.path}/file/${t}`,e,!!n,r)}batchUpload(t){return fe(this.nuclia,this.path,t,!0)}search(t,e=[],n){return we(this.nuclia,this.kb,this.path,t,e,n,!0)}setLabels(t,e,n,r){const i=Se(t,e,n,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Mt((()=>this.fieldmetadata=i)))}setEntities(t,e,n){const r=_e(t,e,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:r}).pipe(Mt((()=>this.fieldmetadata=r)))}}var je,Ce;!function(t){t.text="text",t.file="file",t.link="link",t.layout="layout",t.conversation="conversation",t.keywordset="keywordset",t.datetime="datetime"}(je||(je={})),function(t){t.PENDING="PENDING",t.PROCESSED="PROCESSED",t.ERROR="ERROR"}(Ce||(Ce={}));class Ne{}class Pe{}class Ue{}class De{}const Le=(t,e)=>{const n={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};t.getClassifications().forEach((t=>{t.labelset&&t.label&&(n[t.labelset]=t.label)}));const r=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},n),{images:r}),t.getNamedEntities())},Be=t=>{switch(t){case je.text:case je.file:case je.link:case je.keywordset:return`${t}s`;default:return null}};function Fe(t){return ye[t]}function ze(t){switch(t){case ye.conversation:return je.conversation;case ye.datetime:return je.datetime;case ye.file:return je.file;case ye.layout:return je.layout;case ye.keywordset:return je.keywordset;case ye.link:return je.link;case ye.text:return je.text;default:return null}}function He(t){switch(t){case je.file:return je.file;case je.link:return je.link;case je.text:return je.text;case je.layout:return je.layout;case je.conversation:return je.conversation;case je.datetime:return je.datetime;default:return null}}var Ke,We,Me;!function(t){t.classifier="classifier",t.resource_labeler="resource-labeler",t.paragraph_labeler="paragraph-labeler",t.ner="ner"}(Ke||(Ke={})),function(t){t.finished="finished",t.not_running="not_running",t.running="running",t.started="started",t.stopped="stopped"}(We||(We={})),function(t){t.succeeded="succeeded",t.failed="failed",t.stopped="stopped"}(Me||(Me={}));class Ge{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e||{})}stop(t){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/stop`,{})}getStatus(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/inspect`).pipe(Ft((()=>kt({task:"",status:We.not_running}))))}getExecutions(t=0){return this.nuclia.rest.get(`${this.kb.path}/train/executions?page=${t}`)}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/model/nuclia.json`).pipe(_t((()=>!0)),Ft((()=>kt(!1))))}}class Ve{constructor(t,e,n){this.nuclia=t,this.account=e,Object.assign(this,n)}get path(){return`/kb/${this.id}`}get fullpath(){return`${this.nuclia.regionalBackend}/v1/kb/${this.id}`}getEntities(t=!1){return this.nuclia.rest.get(`${this.path}/entitiesgroups?show_entities=${t}`).pipe(_t((t=>t.groups)))}getEntitiesGroup(t){return this.nuclia.rest.get(`${this.path}/entitiesgroup/${t}`)}getLabels(){return this.nuclia.rest.get(`${this.path}/labelsets`).pipe(_t((t=>(null==t?void 0:t.labelsets)||{})))}getResource(t,e=[re.BASIC,re.ORIGIN,re.RELATIONS,re.VALUES,re.EXTRACTED,re.ERRORS],n=[oe.TEXT,oe.METADATA,oe.LINK,oe.FILE]){return this._getResource(t,void 0,e,n)}getResourceBySlug(t,e=[re.BASIC,re.ORIGIN,re.RELATIONS,re.VALUES,re.EXTRACTED,re.ERRORS],n=[oe.TEXT,oe.METADATA,oe.LINK,oe.FILE]){return this._getResource(void 0,t,e,n)}_getResource(t,e,n=[re.BASIC,re.ORIGIN,re.RELATIONS,re.VALUES,re.EXTRACTED,re.ERRORS],r=[oe.TEXT,oe.METADATA,oe.LINK,oe.FILE]){const i=[...n.map((t=>`show=${t}`)),...r.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this._getPath(t,e)}?${i.join("&")}`).pipe(_t((t=>new Ie(this.nuclia,this.id,t))))}_getPath(t,e){return t?`${this.path}/resource/${t}`:`${this.path}/slug/${e}`}getResourceFromData(t){return new Ie(this.nuclia,this.id,t)}search(t,e=[],n){return we(this.nuclia,this.id,this.path,t,e,n)}catalog(t,e){return Ee(this.nuclia,this.id,t,e)}suggest(t,e=!1){const n=`query=${encodeURIComponent(t)}${e?"&fields=a/title":""}`;return this.nuclia.rest.get(`${this.path}/suggest?${n}`).pipe(Ft((()=>kt({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}counters(){return this.nuclia.rest.get(`/kb/${this.id}/counters`)}listResources(t,e){const n=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${n?"?"+n:""}`).pipe(_t((t=>({resources:t.resources.map((t=>new Ie(this.nuclia,this.id,t))),pagination:t.pagination}))))}getTempToken(){if(!this.nuclia.options.account||!this.nuclia.options.kbSlug)throw new Error("Account and KB slug are required to get a temp token");return this.nuclia.rest.post(`/account/${this.nuclia.options.account}/kb/${this.nuclia.options.kbSlug}/ephemeral_tokens`,{}).pipe(_t((t=>t.token)))}listActivity(t,e,n){const r=[t?`type=${t}`:"",e?`page=${e}`:"",n?`size=${n}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/activity${r?"?"+r:""}`)}}class Xe extends Ve{get training(){return this._training||(this._training=new Ge(this,this.nuclia)),this._training}modify(t){return this.nuclia.rest.patch(`/account/${this.account}/kb/${this.slug}`,t)}publish(t){return this.modify({state:t?"PUBLISHED":"PRIVATE"})}delete(){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}`)}setEntitiesGroup(t,e){return this.nuclia.rest.post(`${this.path}/entitiesgroup/${t}`,e)}deleteEntitiesGroup(t){return this.nuclia.rest.delete(`${this.path}/entitiesgroup/${t}`)}setLabelSet(t,e){return this.nuclia.rest.post(`${this.path}/labelset/${t}`,e)}deleteLabelSet(t){return this.nuclia.rest.delete(`${this.path}/labelset/${t}`)}createResource(t,e=!0){return this.nuclia.rest.post(`${this.path}/resources`,t,void 0,void 0,e)}createLinkResource(t,e,n=!0,r){return this.createResource(Object.assign({links:{link:t},usermetadata:e,title:t.uri,icon:"application/stf-link"},r?{origin:r}:{}),n)}hasResource(t){return this.nuclia.rest.get(`${this.path}/slug/${t}`).pipe(_t((()=>!0)),Ft((()=>kt(!1))))}createOrUpdateResource(t,e=!0){return(t.slug?this.hasResource(t.slug):kt(!1)).pipe(Wt((n=>n?this.getResourceFromData({id:"",slug:t.slug}).modify(t,e):this.createResource(t,e))))}upload(t,e,n){return le(this.nuclia,`/kb/${this.id}`,t,!!e,n)}batchUpload(t){return fe(this.nuclia,`/kb/${this.id}`,t,!1)}getServiceAccounts(){return this.nuclia.rest.get(`/account/${this.account}/kb/${this.slug}/service_accounts`)}createServiceAccount(t){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_accounts`,t)}deleteServiceAccount(t){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}`)}createKey(t,e){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_account/${t}/keys`,{expires:e})}deleteKey(t,e){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}/key/${e}`)}}class Je{constructor(t){this.nuclia=t}getAccounts(){return this.nuclia.rest.get("/accounts")}createAccount(t){return this.nuclia.rest.post("/accounts",t)}modifyAccount(t,e){return this.nuclia.rest.patch(`/account/${t}`,e)}deleteAccount(t){return this.nuclia.rest.delete(`/account/${t}`)}getAccountStatus(t){return this.nuclia.rest.get(`/account/${t}/status`)}getWelcome(){return this.nuclia.rest.get("/user/welcome")}getAccount(t){if(!(t=t||this.nuclia.options.account))throw new Error("Account is not set");return this.nuclia.rest.get(`/account/${t}`)}getKnowledgeBoxes(t){return this.nuclia.rest.get(`/account/${t}/kbs`)}getKnowledgeBox(t,e){if(t=t||this.nuclia.options.account){const n=e||this.nuclia.options.knowledgeBox||this.nuclia.options.kbSlug;if(!n)throw new Error("account and knowledgeBox must be defined in the Nuclia options");return this.nuclia.rest.get(`/account/${t}/kb/${n}`).pipe(Wt((t=>this.nuclia.options.zone?kt(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Mt((t=>this.nuclia.options.zone=t)),_t((()=>t))))),_t((e=>new Xe(this.nuclia,t,e))))}if(!this.nuclia.options.knowledgeBox||!this.nuclia.options.zone)throw new Error("zone must be defined in the Nuclia options");return kt(new Xe(this.nuclia,"",{id:this.nuclia.options.knowledgeBox,zone:this.nuclia.options.zone}))}createKnowledgeBox(t,e){return this.nuclia.rest.post(`/account/${t}/kbs`,e).pipe(Mt((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Wt((()=>this.getKnowledgeBox(t,e.slug))))}getStats(t,e,n,r=te.DAY,i){const o=[`period=${r}`,`stats=${e}`];return i&&o.push(`utctime=${i}`),n&&o.push(`knowledgebox=${n}`),this.nuclia.rest.get(`/account/${t}/stats?${o.join("&")}`).pipe(_t((t=>t.data)),Bt((t=>!!t)))}upload(t){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return pe(this.nuclia,t,{md5:t.md5}).pipe(Wt((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},this.getNUAHeader()))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /processing");return this.nuclia.rest.get("/processing/pull",this.getNUAHeader())}getProcessingStatus(t){if(!t){if(!this.hasNUAClient())throw new Error("NUA key or account id is needed to be able to call /processing/status")}const e=t?`/processing/status?account_id=${t}`:"/processing/status",n=t?void 0:this.getNUAHeader();return this.nuclia.rest.get(e,n)}getProcessingStats(t,e){const n=this.hasNUAClient();if(!e&&!n)throw new Error("NUA key or account id is needed to be able to call /processing/stats");const r=n?"/processing/stats"+(t?"?period="+t:""):`/processing/stats?account_id=${e}${t?"&period="+t:""}`,i=n?this.getNUAHeader():void 0;return this.nuclia.rest.get(r,i).pipe(_t((t=>t.data)))}getNUAActivity(t,e,n=0){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}/activity?page=${n}`)}getNUAClients(t){return this.nuclia.rest.get(`/account/${t}/nua_clients`).pipe(_t((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(Qt)&&!!localStorage.getItem(Zt)}getNUAHeader(){return{"x-stf-nuakey":`Bearer ${localStorage.getItem(Zt)}`}}createNUAClient(t,e){const n=Object.assign({},e);return n.webhook&&(n.processing_webhook={uri:n.webhook},delete n.webhook),this.nuclia.rest.post(`/account/${t}/nua_clients`,n).pipe(Ft((n=>{if(409===n.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw n})),Mt((t=>{"desktop"===this.nuclia.options.client&&(localStorage.setItem(Zt,t.token),localStorage.setItem(Qt,t.client_id))})))}renewNUAClient(t,e){return this.nuclia.rest.put(`/account/${t}/nua_client/${e}/key`,{})}deleteNUAClient(t,e){return this.nuclia.rest.delete(`/account/${t}/nua_client/${e}`)}}class Ye{constructor(t){this.nuclia=t}get(t,e,n){return this.fetch("GET",t,void 0,e,n)}post(t,e,n,r,i){return this.fetch("POST",t,e,n,r,i)}put(t,e,n,r,i){return this.fetch("PUT",t,e,n,r,i)}patch(t,e,n,r,i){return this.fetch("PATCH",t,e,n,r,i)}delete(t,e,n){return this.fetch("DELETE",t,void 0,e,!0,n)}head(t,e){return this.fetch("HEAD",t,void 0,e,!0)}getHeaders(t,e=!1){const n=t&&t["x-stf-nuakey"]?{}:this.nuclia.auth.getAuthHeaders(),r=Object.assign({"content-type":"application/json","x-ndb-client":this.nuclia.options.client||"web"},n);return e&&(r["x-synchronous"]=`${e}`),Object.assign(Object.assign({},r),t)}fetch(t,e,n,r,i,o=!1){const s=r&&r["content-type"];return Gt(this.getFullUrl(e),{selector:t=>Promise.resolve(t),headers:this.getHeaders(r,o),method:t,body:s?n:JSON.stringify(n)}).pipe(Wt((t=>t.ok?i?kt(t):Et(t.clone().json().catch((()=>t.text()))):xt((()=>t)))))}getFullUrl(t){return`${t.startsWith("/account")||t.startsWith("/user")||t.startsWith("/auth")||t.startsWith("/zones")||t.includes("/activity")||this.nuclia.options.standalone?this.nuclia.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")||t.startsWith("/export")?"":"/v1"}${t}`}getZones(){return this.zones?kt(this.zones):this.get("/zones").pipe(_t((t=>{const e=t.reduce(((t,e)=>(t[e.id]=e.slug,t)),{});return this.zones=e,e})))}getZoneSlug(t){return this.getZones().pipe(_t((e=>e[t])))}getObjectURL(t){return this.get(t,void 0,!0).pipe(Wt((t=>Et(t.blob()))),_t((t=>URL.createObjectURL(t))))}}class qe{constructor(t){this.currentShards={},this.options=t,this.auth=new qt(this),this.rest=new Ye(this),this.db=new Je(this)}get backend(){return this.options.backend}get regionalBackend(){return this.options.backend.replace("//",`//${this.options.zone}.`)}get knowledgeBox(){if(!this.options.knowledgeBox||!this.options.zone)throw new Error("zone and knowledge box id must be defined in the Nuclia options");return this.readKb||(this.readKb=new Ve(this,"",{id:this.options.knowledgeBox,zone:this.options.zone})),this.readKb}get asyncKnowledgeBox(){return new Proxy(this.knowledgeBox,{get(t,e){const n=Reflect.get(t,e);return"function"==typeof n?(...e)=>function(t,e){var n="object"==typeof e;return new Promise((function(r,i){var o=new I({next:function(t){r(t),o.unsubscribe()},error:i,complete:function(){n?r(e.defaultValue):i(new St)}});t.subscribe(o)}))}(n.bind(t)(...e)):n}})}}export{qt as Authentication,Je as Db,ue as EventType,oe as ExtractedDataTypes,je as FIELD_TYPE,Ne as FileFieldData,Vt as JwtHelper,Ue as KeywordSetFieldData,Ve as KnowledgeBox,se as LabelSetKind,De as LinkFieldData,Qt as NUA_CLIENT,Zt as NUA_KEY,qe as Nuclia,Ce as RESOURCE_STATUS,Re as ReadableResource,Ie as Resource,ie as ResourceFieldProperties,re as ResourceProperties,Ye as Rest,ye as SHORT_FIELD_TYPE,me as Search,te as StatsPeriod,ee as StatsRange,ne as StatsType,de as TUSuploadFile,Pe as TextFieldData,Ge as Training,Me as TrainingExecutionStatus,We as TrainingStatus,Ke as TrainingType,Xe as WritableKnowledgeBox,fe as batchUpload,Ee as catalog,xe as deDuplicateList,Be as getDataKeyFromFieldType,He as getFieldTypeFromString,ve as getFileMetadata,be as getFilterFromLabel,ge as getLabelFromFilter,Oe as lengthUnicode,Fe as longToShortFieldType,Le as resourceToAlgoliaFormat,we as search,_e as setEntities,Se as setLabels,ze as shortToLongFieldType,Te as sliceUnicode,le as upload,he as uploadFile,pe as uploadToProcess}; |
@@ -0,5 +1,5 @@ | ||
export * from './lib/auth'; | ||
export * from './lib/core'; | ||
export * from './lib/db'; | ||
export * from './lib/models'; | ||
export * from './lib/auth'; | ||
export * from './lib/db'; | ||
export * from './lib/rest'; |
@@ -5,3 +5,3 @@ import { Observable } from 'rxjs'; | ||
import type { INuclia } from '../../models'; | ||
import type { ICreateResource, IResource, LinkField, UserMetadata } from '../resource'; | ||
import type { ICreateResource, IResource, LinkField, Origin, UserMetadata } from '../resource'; | ||
import { Resource } from '../resource'; | ||
@@ -26,2 +26,3 @@ import type { UploadResponse } from '../upload'; | ||
private _getResource; | ||
private _getPath; | ||
getResourceFromData(data: IResource): Resource; | ||
@@ -51,3 +52,3 @@ search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
}>; | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean): Observable<{ | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean, origin?: Origin): Observable<{ | ||
uuid: string; | ||
@@ -54,0 +55,0 @@ }>; |
import type { Observable } from 'rxjs'; | ||
import type { IResource, LinkField, Resource, UserMetadata } from '../resource'; | ||
import type { IResource, LinkField, Origin, Resource, UserMetadata } from '../resource'; | ||
import type { FileMetadata, FileWithMetadata, UploadResponse, UploadStatus } from '../upload'; | ||
@@ -15,2 +15,7 @@ import type { Search, SearchOptions } from '../search'; | ||
} | ||
export declare enum ResourceFieldProperties { | ||
VALUE = "value", | ||
EXTRACTED = "extracted", | ||
ERROR = "error" | ||
} | ||
export declare enum ExtractedDataTypes { | ||
@@ -55,3 +60,4 @@ TEXT = "text", | ||
getLabels(): Observable<LabelSets>; | ||
getResource(uuid: string): Observable<IResource>; | ||
getResource(uuid: string, show?: ResourceProperties[], extracted?: ExtractedDataTypes[]): Observable<IResource>; | ||
getResourceBySlug(slug: string, show?: ResourceProperties[], extracted?: ExtractedDataTypes[]): Observable<IResource>; | ||
search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
@@ -78,3 +84,3 @@ catalog(query: string, options?: SearchOptions): Observable<Search.Results>; | ||
}>; | ||
createLinkResource(link: LinkField, metadata?: UserMetadata): Observable<{ | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean, origin?: Origin): Observable<{ | ||
uuid: string; | ||
@@ -81,0 +87,0 @@ }>; |
@@ -7,2 +7,3 @@ import { Observable } from 'rxjs'; | ||
import type { Search, SearchOptions } from '../search'; | ||
import { ExtractedDataTypes, ResourceFieldProperties } from '../kb'; | ||
export interface ReadableResource extends IResource { | ||
@@ -42,3 +43,3 @@ } | ||
reprocess(): Observable<void>; | ||
getField(type: FIELD_TYPE, field: string): Observable<ResourceField>; | ||
getField(type: FIELD_TYPE, field: string, show?: ResourceFieldProperties[], extracted?: ExtractedDataTypes[]): Observable<ResourceField>; | ||
getThumbnailsUrl(): Observable<string[]>; | ||
@@ -45,0 +46,0 @@ deleteField(type: FIELD_TYPE, field: string): Observable<void>; |
@@ -16,2 +16,3 @@ import type { Resource } from './resource'; | ||
export declare function shortToLongFieldType(shortType: SHORT_FIELD_TYPE): FIELD_TYPE | null; | ||
export declare function getFieldTypeFromString(type: string): FIELD_TYPE | null; | ||
export {}; |
@@ -101,3 +101,3 @@ export interface IResource { | ||
tags?: string[]; | ||
colaborators?: string[]; | ||
collaborators?: string[]; | ||
filename?: string; | ||
@@ -104,0 +104,0 @@ related?: string[]; |
import type { ExtractedDataTypes, ResourceProperties } from '../kb'; | ||
import type { FIELD_TYPE, FieldId, IResource, RelationEntityType, RelationType } from '../resource'; | ||
import type { FIELD_TYPE, FieldId, IFieldData, IResource, RelationEntityType, RelationType } from '../resource'; | ||
export declare type ResourceStatus = 'PENDING' | 'PROCESSED' | 'ERROR'; | ||
@@ -15,2 +15,3 @@ export declare type SortOrder = 'asc' | 'desc'; | ||
filters?: string[]; | ||
fields?: string[]; | ||
sort?: SortOption; | ||
@@ -72,2 +73,3 @@ page_number?: number; | ||
field?: FieldId; | ||
fieldData?: IFieldData; | ||
} | ||
@@ -74,0 +76,0 @@ interface SmartParagraph extends Paragraph { |
@@ -37,2 +37,3 @@ import { Observable } from 'rxjs'; | ||
md5?: string; | ||
rslug?: string; | ||
} | ||
@@ -39,0 +40,0 @@ export declare const upload: (nuclia: INuclia, path: string, data: File | FileWithMetadata | ArrayBuffer, TUS: boolean, metadata?: FileMetadata) => Observable<UploadResponse>; |
{ | ||
"name": "@nuclia/core", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "SDK allowing to integrate Nuclia services in your frontend application", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -30,132 +30,2 @@ import * as rxjs from 'rxjs'; | ||
interface AuthTokens { | ||
access_token: string; | ||
refresh_token: string; | ||
} | ||
declare class Authentication implements IAuthentication { | ||
private nuclia; | ||
private _isAuthenticated; | ||
private timerSubscription?; | ||
constructor(nuclia: INuclia); | ||
getAuthHeaders(): { | ||
[key: string]: string; | ||
}; | ||
isAuthenticated(): Observable<boolean>; | ||
hasLoggedOut(): Observable<boolean>; | ||
login(username: string, password: string, validation?: string): Observable<boolean>; | ||
authenticate(tokens: AuthTokens): boolean; | ||
logout(): void; | ||
refresh(): Observable<boolean>; | ||
getToken(): string; | ||
setPassword(password: string): Observable<boolean>; | ||
deleteAuthenticatedUser(): Observable<void>; | ||
getJWTUser(): JwtUser | null; | ||
getRefreshToken(): string; | ||
private storeTokens; | ||
private checkTokenExpiration; | ||
private fetch; | ||
} | ||
interface INuclia { | ||
options: NucliaOptions; | ||
auth: IAuthentication; | ||
rest: IRest; | ||
db: IDb; | ||
currentShards?: { | ||
[kb: string]: string[]; | ||
}; | ||
get backend(): string; | ||
get regionalBackend(): string; | ||
get knowledgeBox(): KnowledgeBox; | ||
} | ||
interface IAuthentication { | ||
isAuthenticated(): Observable<boolean>; | ||
hasLoggedOut(): Observable<boolean>; | ||
login(username: string, password: string, validation?: string): Observable<boolean>; | ||
logout(): void; | ||
getAuthHeaders(): { | ||
[key: string]: string; | ||
}; | ||
getToken(): string; | ||
getRefreshToken(): string; | ||
authenticate(tokens: AuthTokens): boolean; | ||
setPassword(password: string): Observable<boolean>; | ||
deleteAuthenticatedUser(): Observable<void>; | ||
getJWTUser(): JwtUser | null; | ||
} | ||
interface IRest { | ||
get<T>(path: string, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean): Observable<T>; | ||
post<T>(path: string, body: any, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean, synchronous?: boolean): Observable<T>; | ||
put<T>(path: string, body: any, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean, synchronous?: boolean): Observable<T>; | ||
patch<T>(path: string, body: any, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean, synchronous?: boolean): Observable<T>; | ||
delete(path: string, extraHeaders?: { | ||
[key: string]: string; | ||
}, synchronous?: boolean): Observable<void>; | ||
head(path: string, extraHeaders?: { | ||
[key: string]: string; | ||
}): Observable<Response>; | ||
getZones(): Observable<{ | ||
[key: string]: string; | ||
}>; | ||
getZoneSlug(zoneId: string): Observable<string>; | ||
getFullUrl(path: string): string; | ||
getObjectURL(path: string): Observable<string>; | ||
} | ||
interface IDb { | ||
getAccounts(): Observable<Account[]>; | ||
createAccount(account: AccountCreation): Observable<Account>; | ||
getAccountStatus(account: string): Observable<AccountStatus>; | ||
modifyAccount(account: string, data: Partial<Account>): Observable<void>; | ||
deleteAccount(account: string): Observable<void>; | ||
getWelcome(): Observable<Welcome>; | ||
getAccount(): Observable<Account>; | ||
getAccount(account?: string): Observable<Account>; | ||
getKnowledgeBoxes(account: string): Observable<IKnowledgeBoxItem[]>; | ||
getKnowledgeBox(): Observable<WritableKnowledgeBox>; | ||
getKnowledgeBox(account: string, knowledgeBox: string): Observable<WritableKnowledgeBox>; | ||
createKnowledgeBox(account: string, knowledgeBox: KnowledgeBoxCreation): Observable<WritableKnowledgeBox>; | ||
getStats(account: string, type: StatsType, knowledgeBox?: string, period?: StatsPeriod, utctime?: string): Observable<ProcessingStat[]>; | ||
upload(file: File): Observable<ProcessingPushResponse>; | ||
getProcessingStatus(accountId?: string): Observable<ProcessingStatusResponse>; | ||
getProcessingStats(range?: StatsRange, accountId?: string): Observable<ProcessingStat[]>; | ||
pull(): Observable<ProcessingPullResponse>; | ||
getNUAClients(account: string): Observable<NUAClient[]>; | ||
getNUAClient(account: string, client_id: string): Observable<NUAClient>; | ||
createNUAClient(account: string, data: NUAClientPayload): Observable<{ | ||
client_id: string; | ||
token: string; | ||
}>; | ||
renewNUAClient(account: string, client_id: string): Observable<{ | ||
client_id: string; | ||
token: string; | ||
}>; | ||
deleteNUAClient(account: string, client_id: string): Observable<void>; | ||
hasNUAClient(): boolean; | ||
getNUAActivity(accountSlug: string, client_id: string, pageIndex?: number): Observable<EventList>; | ||
} | ||
interface NucliaOptions { | ||
backend: string; | ||
zone?: string; | ||
apiKey?: string; | ||
account?: string; | ||
accountType?: AccountTypes; | ||
knowledgeBox?: string; | ||
kbSlug?: string; | ||
client?: string; | ||
standalone?: boolean; | ||
public?: boolean; | ||
} | ||
declare type PromiseMapper<T> = { | ||
[K in keyof T]: T[K] extends (...args: infer A) => Observable<infer V> ? (...args: A) => Promise<V> : T[K]; | ||
}; | ||
declare type AccountTypes = 'stash-basic' | 'stash-team' | 'stash-enterprise'; | ||
@@ -317,2 +187,3 @@ declare const NUA_KEY = "NUCLIA_NUA_KEY"; | ||
md5?: string; | ||
rslug?: string; | ||
} | ||
@@ -428,3 +299,3 @@ declare const upload: (nuclia: INuclia, path: string, data: File | FileWithMetadata | ArrayBuffer, TUS: boolean, metadata?: FileMetadata) => Observable<UploadResponse>; | ||
tags?: string[]; | ||
colaborators?: string[]; | ||
collaborators?: string[]; | ||
filename?: string; | ||
@@ -693,2 +564,3 @@ related?: string[]; | ||
filters?: string[]; | ||
fields?: string[]; | ||
sort?: SortOption; | ||
@@ -750,2 +622,3 @@ page_number?: number; | ||
field?: FieldId; | ||
fieldData?: IFieldData; | ||
} | ||
@@ -862,3 +735,3 @@ interface SmartParagraph extends Paragraph { | ||
reprocess(): Observable<void>; | ||
getField(type: FIELD_TYPE, field: string): Observable<ResourceField>; | ||
getField(type: FIELD_TYPE, field: string, show?: ResourceFieldProperties[], extracted?: ExtractedDataTypes[]): Observable<ResourceField>; | ||
getThumbnailsUrl(): Observable<string[]>; | ||
@@ -896,2 +769,3 @@ deleteField(type: FIELD_TYPE, field: string): Observable<void>; | ||
declare function shortToLongFieldType(shortType: SHORT_FIELD_TYPE): FIELD_TYPE | null; | ||
declare function getFieldTypeFromString(type: string): FIELD_TYPE | null; | ||
@@ -908,2 +782,7 @@ declare type KBStates = 'PUBLISHED' | 'PRIVATE'; | ||
} | ||
declare enum ResourceFieldProperties { | ||
VALUE = "value", | ||
EXTRACTED = "extracted", | ||
ERROR = "error" | ||
} | ||
declare enum ExtractedDataTypes { | ||
@@ -948,3 +827,4 @@ TEXT = "text", | ||
getLabels(): Observable<LabelSets>; | ||
getResource(uuid: string): Observable<IResource>; | ||
getResource(uuid: string, show?: ResourceProperties[], extracted?: ExtractedDataTypes[]): Observable<IResource>; | ||
getResourceBySlug(slug: string, show?: ResourceProperties[], extracted?: ExtractedDataTypes[]): Observable<IResource>; | ||
search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
@@ -971,3 +851,3 @@ catalog(query: string, options?: SearchOptions): Observable<Search.Results>; | ||
}>; | ||
createLinkResource(link: LinkField, metadata?: UserMetadata): Observable<{ | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean, origin?: Origin): Observable<{ | ||
uuid: string; | ||
@@ -1148,2 +1028,3 @@ }>; | ||
private _getResource; | ||
private _getPath; | ||
getResourceFromData(data: IResource): Resource; | ||
@@ -1173,3 +1054,3 @@ search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
}>; | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean): Observable<{ | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean, origin?: Origin): Observable<{ | ||
uuid: string; | ||
@@ -1230,2 +1111,132 @@ }>; | ||
interface INuclia { | ||
options: NucliaOptions; | ||
auth: IAuthentication; | ||
rest: IRest; | ||
db: IDb; | ||
currentShards?: { | ||
[kb: string]: string[]; | ||
}; | ||
get backend(): string; | ||
get regionalBackend(): string; | ||
get knowledgeBox(): KnowledgeBox; | ||
} | ||
interface IAuthentication { | ||
isAuthenticated(): Observable<boolean>; | ||
hasLoggedOut(): Observable<boolean>; | ||
login(username: string, password: string, validation?: string): Observable<boolean>; | ||
logout(): void; | ||
getAuthHeaders(): { | ||
[key: string]: string; | ||
}; | ||
getToken(): string; | ||
getRefreshToken(): string; | ||
authenticate(tokens: AuthTokens): boolean; | ||
setPassword(password: string): Observable<boolean>; | ||
deleteAuthenticatedUser(): Observable<void>; | ||
getJWTUser(): JwtUser | null; | ||
} | ||
interface IRest { | ||
get<T>(path: string, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean): Observable<T>; | ||
post<T>(path: string, body: any, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean, synchronous?: boolean): Observable<T>; | ||
put<T>(path: string, body: any, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean, synchronous?: boolean): Observable<T>; | ||
patch<T>(path: string, body: any, extraHeaders?: { | ||
[key: string]: string; | ||
}, doNotParse?: boolean, synchronous?: boolean): Observable<T>; | ||
delete(path: string, extraHeaders?: { | ||
[key: string]: string; | ||
}, synchronous?: boolean): Observable<void>; | ||
head(path: string, extraHeaders?: { | ||
[key: string]: string; | ||
}): Observable<Response>; | ||
getZones(): Observable<{ | ||
[key: string]: string; | ||
}>; | ||
getZoneSlug(zoneId: string): Observable<string>; | ||
getFullUrl(path: string): string; | ||
getObjectURL(path: string): Observable<string>; | ||
} | ||
interface IDb { | ||
getAccounts(): Observable<Account[]>; | ||
createAccount(account: AccountCreation): Observable<Account>; | ||
getAccountStatus(account: string): Observable<AccountStatus>; | ||
modifyAccount(account: string, data: Partial<Account>): Observable<void>; | ||
deleteAccount(account: string): Observable<void>; | ||
getWelcome(): Observable<Welcome>; | ||
getAccount(): Observable<Account>; | ||
getAccount(account?: string): Observable<Account>; | ||
getKnowledgeBoxes(account: string): Observable<IKnowledgeBoxItem[]>; | ||
getKnowledgeBox(): Observable<WritableKnowledgeBox>; | ||
getKnowledgeBox(account: string, knowledgeBox: string): Observable<WritableKnowledgeBox>; | ||
createKnowledgeBox(account: string, knowledgeBox: KnowledgeBoxCreation): Observable<WritableKnowledgeBox>; | ||
getStats(account: string, type: StatsType, knowledgeBox?: string, period?: StatsPeriod, utctime?: string): Observable<ProcessingStat[]>; | ||
upload(file: File): Observable<ProcessingPushResponse>; | ||
getProcessingStatus(accountId?: string): Observable<ProcessingStatusResponse>; | ||
getProcessingStats(range?: StatsRange, accountId?: string): Observable<ProcessingStat[]>; | ||
pull(): Observable<ProcessingPullResponse>; | ||
getNUAClients(account: string): Observable<NUAClient[]>; | ||
getNUAClient(account: string, client_id: string): Observable<NUAClient>; | ||
createNUAClient(account: string, data: NUAClientPayload): Observable<{ | ||
client_id: string; | ||
token: string; | ||
}>; | ||
renewNUAClient(account: string, client_id: string): Observable<{ | ||
client_id: string; | ||
token: string; | ||
}>; | ||
deleteNUAClient(account: string, client_id: string): Observable<void>; | ||
hasNUAClient(): boolean; | ||
getNUAActivity(accountSlug: string, client_id: string, pageIndex?: number): Observable<EventList>; | ||
} | ||
interface NucliaOptions { | ||
backend: string; | ||
zone?: string; | ||
apiKey?: string; | ||
account?: string; | ||
accountType?: AccountTypes; | ||
knowledgeBox?: string; | ||
kbSlug?: string; | ||
client?: string; | ||
standalone?: boolean; | ||
public?: boolean; | ||
} | ||
declare type PromiseMapper<T> = { | ||
[K in keyof T]: T[K] extends (...args: infer A) => Observable<infer V> ? (...args: A) => Promise<V> : T[K]; | ||
}; | ||
interface AuthTokens { | ||
access_token: string; | ||
refresh_token: string; | ||
} | ||
declare class Authentication implements IAuthentication { | ||
private nuclia; | ||
private _isAuthenticated; | ||
private timerSubscription?; | ||
constructor(nuclia: INuclia); | ||
getAuthHeaders(): { | ||
[key: string]: string; | ||
}; | ||
isAuthenticated(): Observable<boolean>; | ||
hasLoggedOut(): Observable<boolean>; | ||
login(username: string, password: string, validation?: string): Observable<boolean>; | ||
authenticate(tokens: AuthTokens): boolean; | ||
logout(): void; | ||
refresh(): Observable<boolean>; | ||
getToken(): string; | ||
setPassword(password: string): Observable<boolean>; | ||
deleteAuthenticatedUser(): Observable<void>; | ||
getJWTUser(): JwtUser | null; | ||
getRefreshToken(): string; | ||
private storeTokens; | ||
private checkTokenExpiration; | ||
private fetch; | ||
} | ||
declare class Nuclia implements INuclia { | ||
@@ -1279,2 +1290,2 @@ options: NucliaOptions; | ||
export { Account, AccountConfig, AccountCreation, AccountLimits, AccountStatus, AccountTypes, AuthTokens, Authentication, Classification, CloudLink, ComputedMetadata, Counters, Db, Entities, EntitiesGroup, Entity, EntityPositions, Event, EventList, EventType, ExtractedData, ExtractedDataTypes, ExtractedText, FIELD_TYPE, FieldClassification, FieldComputedMetadata, FieldId, FieldMetadata, FileB64, FileExtractedData, FileField, FileFieldData, FileFieldExtractedData, FileMetadata, FilePages, FileUploadStatus, FileWithMetadata, IAuthentication, ICreateResource, IDb, IFieldData, IKnowledgeBox, IKnowledgeBoxCreation, IKnowledgeBoxItem, INuclia, IResource, IRest, IWritableKnowledgeBox, JwtHelper, JwtUser, KBRoles, KBStates, KeywordSetField, KeywordSetFieldData, KnowledgeBox, KnowledgeBoxCreation, Label, LabelSet, LabelSetKind, LabelSets, Language, LinkExtractedData, LinkField, LinkFieldData, LinkFieldExtractedData, Metadata, NUAClient, NUAClientPayload, NUA_CLIENT, NUA_KEY, NestedPosition, Nuclia, NucliaOptions, Origin, PagePositions, Paragraph, ParagraphClassification, PositionedNER, ProcessingPullResponse, ProcessingPushResponse, ProcessingStat, ProcessingStatusResponse, PromiseMapper, RESOURCE_STATUS, ReadableResource, Relation, RelationEntity, RelationEntityType, RelationType, Resource, ResourceData, ResourceField, ResourceList, ResourcePagination, ResourceProperties, ResourceStatus, Rest, Row, RowsPreview, SHORT_FIELD_TYPE, Search, SearchOptions, Sentence, ServiceAccount, ServiceAccountCreation, ServiceAccountKey, Sheet, SortOption, SortOrder, StatsPeriod, StatsRange, StatsType, TUSuploadFile, TextField, TextFieldData, TextFieldFormat, TokenAnnotation, Training, TrainingExecution, TrainingExecutionStatus, TrainingExecutions, TrainingLastExecution, TrainingStatus, TrainingTask, TrainingType, TypeParagraph, UploadResponse, UploadStatus, UserClassification, UserFieldMetadata, UserMetadata, UserTokenAnnotation, UserType, Welcome, WelcomeUser, WidgetFeatures, WritableKnowledgeBox, WriteFileField, batchUpload, catalog, deDuplicateList, getDataKeyFromFieldType, getFileMetadata, getFilterFromLabel, getLabelFromFilter, lengthUnicode, longToShortFieldType, resourceToAlgoliaFormat, search, setEntities, setLabels, shortToLongFieldType, sliceUnicode, upload, uploadFile, uploadToProcess }; | ||
export { Account, AccountConfig, AccountCreation, AccountLimits, AccountStatus, AccountTypes, AuthTokens, Authentication, Classification, CloudLink, ComputedMetadata, Counters, Db, Entities, EntitiesGroup, Entity, EntityPositions, Event, EventList, EventType, ExtractedData, ExtractedDataTypes, ExtractedText, FIELD_TYPE, FieldClassification, FieldComputedMetadata, FieldId, FieldMetadata, FileB64, FileExtractedData, FileField, FileFieldData, FileFieldExtractedData, FileMetadata, FilePages, FileUploadStatus, FileWithMetadata, IAuthentication, ICreateResource, IDb, IFieldData, IKnowledgeBox, IKnowledgeBoxCreation, IKnowledgeBoxItem, INuclia, IResource, IRest, IWritableKnowledgeBox, JwtHelper, JwtUser, KBRoles, KBStates, KeywordSetField, KeywordSetFieldData, KnowledgeBox, KnowledgeBoxCreation, Label, LabelSet, LabelSetKind, LabelSets, Language, LinkExtractedData, LinkField, LinkFieldData, LinkFieldExtractedData, Metadata, NUAClient, NUAClientPayload, NUA_CLIENT, NUA_KEY, NestedPosition, Nuclia, NucliaOptions, Origin, PagePositions, Paragraph, ParagraphClassification, PositionedNER, ProcessingPullResponse, ProcessingPushResponse, ProcessingStat, ProcessingStatusResponse, PromiseMapper, RESOURCE_STATUS, ReadableResource, Relation, RelationEntity, RelationEntityType, RelationType, Resource, ResourceData, ResourceField, ResourceFieldProperties, ResourceList, ResourcePagination, ResourceProperties, ResourceStatus, Rest, Row, RowsPreview, SHORT_FIELD_TYPE, Search, SearchOptions, Sentence, ServiceAccount, ServiceAccountCreation, ServiceAccountKey, Sheet, SortOption, SortOrder, StatsPeriod, StatsRange, StatsType, TUSuploadFile, TextField, TextFieldData, TextFieldFormat, TokenAnnotation, Training, TrainingExecution, TrainingExecutionStatus, TrainingExecutions, TrainingLastExecution, TrainingStatus, TrainingTask, TrainingType, TypeParagraph, UploadResponse, UploadStatus, UserClassification, UserFieldMetadata, UserMetadata, UserTokenAnnotation, UserType, Welcome, WelcomeUser, WidgetFeatures, WritableKnowledgeBox, WriteFileField, batchUpload, catalog, deDuplicateList, getDataKeyFromFieldType, getFieldTypeFromString, getFileMetadata, getFilterFromLabel, getLabelFromFilter, lengthUnicode, longToShortFieldType, resourceToAlgoliaFormat, search, setEntities, setLabels, shortToLongFieldType, sliceUnicode, upload, uploadFile, uploadToProcess }; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).NucliaSDK={})}(this,(function(t){"use strict";var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},e(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)};function i(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function u(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function c(t){return this instanceof c?(this.v=t,this):new c(t)}function l(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(t,e||[]),o=[];return n={},s("next"),s("throw"),s("return"),n[Symbol.asyncIterator]=function(){return this},n;function s(t){i[t]&&(n[t]=function(e){return new Promise((function(r,n){o.push([t,e,r,n])>1||a(t,e)}))})}function a(t,e){try{(r=i[t](e)).value instanceof c?Promise.resolve(r.value.v).then(u,l):h(o[0][2],r)}catch(t){h(o[0][3],t)}var r}function u(t){a("next",t)}function l(t){a("throw",t)}function h(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}function h(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=s(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise((function(n,i){(function(t,e,r,n){Promise.resolve(n).then((function(e){t({value:e,done:r})}),e)})(n,i,(e=t[r](e)).done,e.value)}))}}}function d(t){return"function"==typeof t}function f(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var p=f((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function v(t,e){if(t){var r=t.indexOf(e);0<=r&&t.splice(r,1)}}var b=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}var e;return t.prototype.unsubscribe=function(){var t,e,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var c=s(o),l=c.next();!l.done;l=c.next()){l.value.remove(this)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(d(h))try{h()}catch(t){i=t instanceof p?t.errors:[t]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var v=s(f),b=v.next();!b.done;b=v.next()){var g=b.value;try{m(g)}catch(t){i=null!=i?i:[],t instanceof p?i=u(u([],a(i)),a(t.errors)):i.push(t)}}}catch(t){r={error:t}}finally{try{b&&!b.done&&(n=v.return)&&n.call(v)}finally{if(r)throw r.error}}}if(i)throw new p(i)}},t.prototype.add=function(e){var r;if(e&&e!==this)if(this.closed)m(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&v(e,t)},t.prototype.remove=function(e){var r=this._finalizers;r&&v(r,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t}(),g=b.EMPTY;function y(t){return t instanceof b||t&&"closed"in t&&d(t.remove)&&d(t.add)&&d(t.unsubscribe)}function m(t){d(t)?t():t.unsubscribe()}var E={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},T={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=T.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,u([t,e],a(r))):setTimeout.apply(void 0,u([t,e],a(r)))},clearTimeout:function(t){var e=T.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function w(t){T.setTimeout((function(){throw t}))}function S(){}var _=x("C",void 0,void 0);function x(t,e,r){return{kind:t,value:e,error:r}}var k=null;function A(t){if(E.useDeprecatedSynchronousErrorHandling){var e=!k;if(e&&(k={errorThrown:!1,error:null}),t(),e){var r=k,n=r.errorThrown,i=r.error;if(k=null,n)throw i}}else t()}var $=function(t){function e(e){var r=t.call(this)||this;return r.isStopped=!1,e?(r.destination=e,y(e)&&e.add(r)):r.destination=F,r}return r(e,t),e.create=function(t,e,r){return new P(t,e,r)},e.prototype.next=function(t){this.isStopped?j(function(t){return x("N",t,void 0)}(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?j(x("E",void 0,t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?j(_,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(b),O=Function.prototype.bind;function R(t,e){return O.call(t,e)}var I=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){D(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){D(t)}else D(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){D(t)}},t}(),P=function(t){function e(e,r,n){var i,o,s=t.call(this)||this;d(e)||!e?i={next:null!=e?e:void 0,error:null!=r?r:void 0,complete:null!=n?n:void 0}:s&&E.useDeprecatedNextContext?((o=Object.create(e)).unsubscribe=function(){return s.unsubscribe()},i={next:e.next&&R(e.next,o),error:e.error&&R(e.error,o),complete:e.complete&&R(e.complete,o)}):i=e;return s.destination=new I(i),s}return r(e,t),e}($);function D(t){w(t)}function j(t,e){var r=E.onStoppedNotification;r&&T.setTimeout((function(){return r(t,e)}))}var F={closed:!0,next:S,error:function(t){throw t},complete:S},L="function"==typeof Symbol&&Symbol.observable||"@@observable";function U(t){return t}function C(t){return 0===t.length?U:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var N=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(t,e,r){var n,i=this,o=(n=t)&&n instanceof $||function(t){return t&&d(t.next)&&d(t.error)&&d(t.complete)}(n)&&y(n)?t:new P(t,e,r);return A((function(){var t=i,e=t.operator,r=t.source;o.add(e?e.call(o,r):r?i._subscribe(o):i._trySubscribe(o))})),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var r=this;return new(e=B(e))((function(e,n){var i=new P({next:function(e){try{t(e)}catch(t){n(t),i.unsubscribe()}},error:n,complete:e});r.subscribe(i)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[L]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return C(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=B(t))((function(t,r){var n;e.subscribe((function(t){return n=t}),(function(t){return r(t)}),(function(){return t(n)}))}))},t.create=function(e){return new t(e)},t}();function B(t){var e;return null!==(e=null!=t?t:E.Promise)&&void 0!==e?e:Promise}function H(t){return function(e){if(function(t){return d(null==t?void 0:t.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function z(t,e,r,n,i){return new Y(t,e,r,n,i)}var Y=function(t){function e(e,r,n,i,o,s){var a=t.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=s,a._next=r?function(t){try{r(t)}catch(t){e.error(t)}}:t.prototype._next,a._error=i?function(t){try{i(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,a._complete=n?function(){try{n()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,a}return r(e,t),e.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},e}($),K=f((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),W=function(t){function e(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return r(e,t),e.prototype.lift=function(t){var e=new M(this,this);return e.operator=t,e},e.prototype._throwIfClosed=function(){if(this.closed)throw new K},e.prototype.next=function(t){var e=this;A((function(){var r,n;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var i=s(e.currentObservers),o=i.next();!o.done;o=i.next()){o.value.next(t)}}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}}}))},e.prototype.error=function(t){var e=this;A((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var r=e.observers;r.length;)r.shift().error(t)}}))},e.prototype.complete=function(){var t=this;A((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var e=this,r=this,n=r.hasError,i=r.isStopped,o=r.observers;return n||i?g:(this.currentObservers=null,o.push(t),new b((function(){e.currentObservers=null,v(o,t)})))},e.prototype._checkFinalizedStatuses=function(t){var e=this,r=e.hasError,n=e.thrownError,i=e.isStopped;r?t.error(n):i&&t.complete()},e.prototype.asObservable=function(){var t=new N;return t.source=this,t},e.create=function(t,e){return new M(t,e)},e}(N),M=function(t){function e(e,r){var n=t.call(this)||this;return n.destination=e,n.source=r,n}return r(e,t),e.prototype.next=function(t){var e,r;null===(r=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===r||r.call(e,t)},e.prototype.error=function(t){var e,r;null===(r=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===r||r.call(e,t)},e.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},e.prototype._subscribe=function(t){var e,r;return null!==(r=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==r?r:g},e}(W),G={now:function(){return(G.delegate||Date).now()},delegate:void 0},J=function(t){function e(e,r,n){void 0===e&&(e=1/0),void 0===r&&(r=1/0),void 0===n&&(n=G);var i=t.call(this)||this;return i._bufferSize=e,i._windowTime=r,i._timestampProvider=n,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=r===1/0,i._bufferSize=Math.max(1,e),i._windowTime=Math.max(1,r),i}return r(e,t),e.prototype.next=function(e){var r=this,n=r.isStopped,i=r._buffer,o=r._infiniteTimeWindow,s=r._timestampProvider,a=r._windowTime;n||(i.push(e),!o&&i.push(s.now()+a)),this._trimBuffer(),t.prototype.next.call(this,e)},e.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var e=this._innerSubscribe(t),r=this._infiniteTimeWindow,n=this._buffer.slice(),i=0;i<n.length&&!t.closed;i+=r?1:2)t.next(n[i]);return this._checkFinalizedStatuses(t),e},e.prototype._trimBuffer=function(){var t=this,e=t._bufferSize,r=t._timestampProvider,n=t._buffer,i=t._infiniteTimeWindow,o=(i?1:2)*e;if(e<1/0&&o<n.length&&n.splice(0,n.length-o),!i){for(var s=r.now(),a=0,u=1;u<n.length&&n[u]<=s;u+=2)a=u;a&&n.splice(0,a+1)}},e}(W),V=function(t){function e(e,r){return t.call(this)||this}return r(e,t),e.prototype.schedule=function(t,e){return this},e}(b),X={setInterval:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=X.delegate;return(null==i?void 0:i.setInterval)?i.setInterval.apply(i,u([t,e],a(r))):setInterval.apply(void 0,u([t,e],a(r)))},clearInterval:function(t){var e=X.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},q=function(t){function e(e,r){var n=t.call(this,e,r)||this;return n.scheduler=e,n.work=r,n.pending=!1,n}return r(e,t),e.prototype.schedule=function(t,e){if(void 0===e&&(e=0),this.closed)return this;this.state=t;var r=this.id,n=this.scheduler;return null!=r&&(this.id=this.recycleAsyncId(n,r,e)),this.pending=!0,this.delay=e,this.id=this.id||this.requestAsyncId(n,this.id,e),this},e.prototype.requestAsyncId=function(t,e,r){return void 0===r&&(r=0),X.setInterval(t.flush.bind(t,this),r)},e.prototype.recycleAsyncId=function(t,e,r){if(void 0===r&&(r=0),null!=r&&this.delay===r&&!1===this.pending)return e;X.clearInterval(e)},e.prototype.execute=function(t,e){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var r=this._execute(t,e);if(r)return r;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,e){var r,n=!1;try{this.work(t)}catch(t){n=!0,r=t||new Error("Scheduled action threw falsy error")}if(n)return this.unsubscribe(),r},e.prototype.unsubscribe=function(){if(!this.closed){var e=this.id,r=this.scheduler,n=r.actions;this.work=this.state=this.scheduler=null,this.pending=!1,v(n,this),null!=e&&(this.id=this.recycleAsyncId(r,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(V),Z=function(){function t(e,r){void 0===r&&(r=t.now),this.schedulerActionCtor=e,this.now=r}return t.prototype.schedule=function(t,e,r){return void 0===e&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},t.now=G.now,t}(),Q=new(function(t){function e(e,r){void 0===r&&(r=Z.now);var n=t.call(this,e,r)||this;return n.actions=[],n._active=!1,n._scheduled=void 0,n}return r(e,t),e.prototype.flush=function(t){var e=this.actions;if(this._active)e.push(t);else{var r;this._active=!0;do{if(r=t.execute(t.state,t.delay))break}while(t=e.shift());if(this._active=!1,r){for(;t=e.shift();)t.unsubscribe();throw r}}},e}(Z))(q),tt=new N((function(t){return t.complete()}));function et(t){return t&&d(t.schedule)}function rt(t){return t[t.length-1]}function nt(t){return d(rt(t))?t.pop():void 0}function it(t){return et(rt(t))?t.pop():void 0}function ot(t,e){return"number"==typeof rt(t)?t.pop():e}var st=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function at(t){return d(null==t?void 0:t.then)}function ut(t){return d(t[L])}function ct(t){return Symbol.asyncIterator&&d(null==t?void 0:t[Symbol.asyncIterator])}function lt(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var ht="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function dt(t){return d(null==t?void 0:t[ht])}function ft(t){return l(this,arguments,(function(){var e,r,n;return o(this,(function(i){switch(i.label){case 0:e=t.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,c(e.read())];case 3:return r=i.sent(),n=r.value,r.done?[4,c(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,c(n)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}function pt(t){return d(null==t?void 0:t.getReader)}function vt(t){if(t instanceof N)return t;if(null!=t){if(ut(t))return i=t,new N((function(t){var e=i[L]();if(d(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(st(t))return n=t,new N((function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()}));if(at(t))return r=t,new N((function(t){r.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,w)}));if(ct(t))return bt(t);if(dt(t))return e=t,new N((function(t){var r,n;try{for(var i=s(e),o=i.next();!o.done;o=i.next()){var a=o.value;if(t.next(a),t.closed)return}}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}t.complete()}));if(pt(t))return bt(ft(t))}var e,r,n,i;throw lt(t)}function bt(t){return new N((function(e){(function(t,e){var r,n,s,a;return i(this,void 0,void 0,(function(){var i,u;return o(this,(function(o){switch(o.label){case 0:o.trys.push([0,5,6,11]),r=h(t),o.label=1;case 1:return[4,r.next()];case 2:if((n=o.sent()).done)return[3,4];if(i=n.value,e.next(i),e.closed)return[2];o.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=o.sent(),s={error:u},[3,11];case 6:return o.trys.push([6,,9,10]),n&&!n.done&&(a=r.return)?[4,a.call(r)]:[3,8];case 7:o.sent(),o.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))}))})(t,e).catch((function(t){return e.error(t)}))}))}function gt(t,e,r,n,i){void 0===n&&(n=0),void 0===i&&(i=!1);var o=e.schedule((function(){r(),i?t.add(this.schedule(null,n)):this.unsubscribe()}),n);if(t.add(o),!i)return o}function yt(t,e){return void 0===e&&(e=0),H((function(r,n){r.subscribe(z(n,(function(r){return gt(n,t,(function(){return n.next(r)}),e)}),(function(){return gt(n,t,(function(){return n.complete()}),e)}),(function(r){return gt(n,t,(function(){return n.error(r)}),e)})))}))}function mt(t,e){return void 0===e&&(e=0),H((function(r,n){n.add(t.schedule((function(){return r.subscribe(n)}),e))}))}function Et(t,e){if(!t)throw new Error("Iterable cannot be null");return new N((function(r){gt(r,e,(function(){var n=t[Symbol.asyncIterator]();gt(r,e,(function(){n.next().then((function(t){t.done?r.complete():r.next(t.value)}))}),0,!0)}))}))}function Tt(t,e){if(null!=t){if(ut(t))return function(t,e){return vt(t).pipe(mt(e),yt(e))}(t,e);if(st(t))return function(t,e){return new N((function(r){var n=0;return e.schedule((function(){n===t.length?r.complete():(r.next(t[n++]),r.closed||this.schedule())}))}))}(t,e);if(at(t))return function(t,e){return vt(t).pipe(mt(e),yt(e))}(t,e);if(ct(t))return Et(t,e);if(dt(t))return function(t,e){return new N((function(r){var n;return gt(r,e,(function(){n=t[ht](),gt(r,e,(function(){var t,e,i;try{e=(t=n.next()).value,i=t.done}catch(t){return void r.error(t)}i?r.complete():r.next(e)}),0,!0)})),function(){return d(null==n?void 0:n.return)&&n.return()}}))}(t,e);if(pt(t))return function(t,e){return Et(ft(t),e)}(t,e)}throw lt(t)}function wt(t,e){return e?Tt(t,e):vt(t)}function St(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=it(t);return wt(t,r)}function _t(t,e){var r=d(t)?t:function(){return t},n=function(t){return t.error(r())};return new N(e?function(t){return e.schedule(n,0,t)}:n)}var xt=f((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function kt(t,e){return H((function(r,n){var i=0;r.subscribe(z(n,(function(r){n.next(t.call(e,r,i++))})))}))}var At=Array.isArray;function $t(t){return kt((function(e){return function(t,e){return At(e)?t.apply(void 0,u([],a(e))):t(e)}(t,e)}))}var Ot=Array.isArray,Rt=Object.getPrototypeOf,It=Object.prototype,Pt=Object.keys;function Dt(t){if(1===t.length){var e=t[0];if(Ot(e))return{args:e,keys:null};if((n=e)&&"object"==typeof n&&Rt(n)===It){var r=Pt(e);return{args:r.map((function(t){return e[t]})),keys:r}}}var n;return{args:t,keys:null}}function jt(t,e){return t.reduce((function(t,r,n){return t[r]=e[n],t}),{})}function Ft(t,e,r){return void 0===r&&(r=1/0),d(e)?Ft((function(r,n){return kt((function(t,i){return e(r,t,n,i)}))(vt(t(r,n)))}),r):("number"==typeof e&&(r=e),H((function(e,n){return function(t,e,r,n,i,o,s,a){var u=[],c=0,l=0,h=!1,d=function(){!h||u.length||c||e.complete()},f=function(t){return c<n?p(t):u.push(t)},p=function(t){o&&e.next(t),c++;var a=!1;vt(r(t,l++)).subscribe(z(e,(function(t){null==i||i(t),o?f(t):e.next(t)}),(function(){a=!0}),void 0,(function(){if(a)try{c--;for(var t=function(){var t=u.shift();s?gt(e,s,(function(){return p(t)})):p(t)};u.length&&c<n;)t();d()}catch(t){e.error(t)}})))};return t.subscribe(z(e,f,(function(){h=!0,d()}))),function(){null==a||a()}}(e,n,t,r)})))}function Lt(t){return void 0===t&&(t=1/0),Ft(U,t)}function Ut(){return Lt(1)}function Ct(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ut()(wt(t,it(t)))}function Nt(t,e,r){void 0===t&&(t=0),void 0===r&&(r=Q);var n=-1;return null!=e&&(et(e)?r=e:n=e),new N((function(e){var i,o=(i=t)instanceof Date&&!isNaN(i)?+t-r.now():t;o<0&&(o=0);var s=0;return r.schedule((function(){e.closed||(e.next(s++),0<=n?this.schedule(void 0,n):e.complete())}),o)}))}function Bt(t,e){return H((function(r,n){var i=0;r.subscribe(z(n,(function(r){return t.call(e,r,i++)&&n.next(r)})))}))}function Ht(t){return H((function(e,r){var n,i=null,o=!1;i=e.subscribe(z(r,void 0,void 0,(function(s){n=vt(t(s,Ht(t)(e))),i?(i.unsubscribe(),i=null,n.subscribe(r)):o=!0}))),o&&(i.unsubscribe(),i=null,n.subscribe(r))}))}function zt(t,e){return d(e)?Ft(t,e,1):Ft(t,1)}function Yt(t){return t<=0?function(){return tt}:H((function(e,r){var n=0;e.subscribe(z(r,(function(e){++n<=t&&(r.next(e),t<=n&&r.complete())})))}))}function Kt(t){var e,r,n=1/0;return null!=t&&("object"==typeof t?(e=t.count,n=void 0===e?1/0:e,r=t.delay):n=t),n<=0?function(){return tt}:H((function(t,e){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=r){var t="number"==typeof r?Nt(r):vt(r(o)),n=z(e,(function(){n.unsubscribe(),a()}));t.subscribe(n)}else a()},a=function(){var r=!1;i=t.subscribe(z(e,void 0,(function(){++o<n?i?s():r=!0:e.complete()}))),r&&s()};a()}))}function Wt(t,e){return H((function(r,n){var i=null,o=0,s=!1,a=function(){return s&&!i&&n.complete()};r.subscribe(z(n,(function(r){null==i||i.unsubscribe();var s=0,u=o++;vt(t(r,u)).subscribe(i=z(n,(function(t){return n.next(e?e(r,t,u,s++):t)}),(function(){i=null,a()})))}),(function(){s=!0,a()})))}))}function Mt(t,e,r){var n=d(t)||e||r?{next:t,error:e,complete:r}:t;return n?H((function(t,e){var r;null===(r=n.subscribe)||void 0===r||r.call(n);var i=!0;t.subscribe(z(e,(function(t){var r;null===(r=n.next)||void 0===r||r.call(n,t),e.next(t)}),(function(){var t;i=!1,null===(t=n.complete)||void 0===t||t.call(n),e.complete()}),(function(t){var r;i=!1,null===(r=n.error)||void 0===r||r.call(n,t),e.error(t)}),(function(){var t,e;i&&(null===(t=n.unsubscribe)||void 0===t||t.call(n)),null===(e=n.finalize)||void 0===e||e.call(n)})))})):U}const Gt="NUCLIA_NUA_KEY",Jt="NUCLIA_NUA_CLIENT";var Vt,Xt,qt,Zt,Qt,te,ee;t.StatsPeriod=void 0,(Vt=t.StatsPeriod||(t.StatsPeriod={})).DAY="day",Vt.WEEK="week",Vt.MONTH="month",Vt.YEAR="year",t.StatsRange=void 0,(Xt=t.StatsRange||(t.StatsRange={})).anHour="1h",Xt.twoHours="2h",Xt.threeHours="3h",Xt.sixHours="6h",Xt.twelveHours="12h",Xt.twentyFourHours="24h",Xt.fortyHeightHours="48h",t.StatsType=void 0,(qt=t.StatsType||(t.StatsType={})).PROCESSING_TIME="processing_time",qt.SEARCHES="searches",qt.CHARS="chars",qt.MEDIA_SECONDS="media_seconds",qt.BYTES="bytes",qt.RESOURCES="resources",qt.PAGES="pages",qt.TRAIN_SECONDS="train_seconds",qt.SUGGESTIONS="suggestions",qt.DOCS_NO_MEDIA="docs_no_media",t.ResourceProperties=void 0,(Zt=t.ResourceProperties||(t.ResourceProperties={})).BASIC="basic",Zt.ORIGIN="origin",Zt.RELATIONS="relations",Zt.VALUES="values",Zt.EXTRACTED="extracted",Zt.ERRORS="errors",t.ExtractedDataTypes=void 0,(Qt=t.ExtractedDataTypes||(t.ExtractedDataTypes={})).TEXT="text",Qt.METADATA="metadata",Qt.LARGE_METADATA="large_metadata",Qt.VECTOR="vectors",Qt.LINK="link",Qt.FILE="file",t.LabelSetKind=void 0,(te=t.LabelSetKind||(t.LabelSetKind={})).RESOURCES="RESOURCES",te.PARAGRAPHS="PARAGRAPHS",t.EventType=void 0,(ee=t.EventType||(t.EventType={})).VISITED="VISITED",ee.MODIFIED="MODIFIED",ee.DELETED="DELETED",ee.NEW="NEW",ee.STARTED="STARTED",ee.STOPPED="STOPPED",ee.SEARCH="SEARCH",ee.PROCESSED="PROCESSED";const re=524288,ne=new RegExp(/[^a-z0-9_-]/g),ie=(t,e,r,n,i={})=>(i.contentType||r instanceof ArrayBuffer||(i.contentType=null==r?void 0:r.type),i.filename||r instanceof ArrayBuffer||(i.filename=null==r?void 0:r.name),i.lang||r instanceof ArrayBuffer||(i.lang=r.lang),i.md5||r instanceof ArrayBuffer||(i.md5=r.md5),(r instanceof ArrayBuffer?St(r):wt(r.arrayBuffer())).pipe(Wt((o=>n?se(t,e,o,i,r.payload):oe(t,e,o,i))))),oe=(t,e,r,n)=>{const i=Object.assign({"content-type":(null==n?void 0:n.contentType)||"application/octet-stream"},ce(n));let o=1;return t.rest.post(`${e}/upload`,r,i).pipe(Kt(),Bt((t=>0==o--||503!==t.status)),Yt(1),Wt((t=>{switch(t.status){case 201:return wt(t.json()).pipe(kt((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return St({conflict:!0});default:return St({failed:!0})}})))},se=(t,e,r,n,i)=>{let o=0,s=!1;const a=r.byteLength,u=Math.ceil(a/re),c={"upload-length":`${a}`,"tus-resumable":"1.0.0"},l=[];(null==n?void 0:n.filename)&&l.push(`filename ${btoa(encodeURIComponent(n.filename))}`),(null==n?void 0:n.lang)&&l.push(`language ${btoa(n.lang)}`),(null==n?void 0:n.md5)&&l.push(`md5 ${btoa(n.md5)}`),l.push(`content_type ${btoa((null==n?void 0:n.contentType)||"application/octet-stream")}`),l.length>0&&(c["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,c,!0).pipe(Kt(),Bt((t=>0==h--||503!==t.status)),Ht((t=>St(t))),Yt(1),zt((e=>function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=it(t),n=ot(t,1/0),i=t;return i.length?1===i.length?vt(i[0]):Lt(n)(wt(i,r)):tt}(St(e).pipe(Bt((t=>201!==t.status||!t.headers.get("location"))),kt((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),St(e).pipe(Bt((t=>201===t.status&&!!t.headers.get("location"))),kt((t=>t.headers.get("location"))),zt((e=>function(t,e,r){if(null==e&&(e=t,t=0),e<=0)return tt;var n=e+t;return new N(r?function(e){var i=t;return r.schedule((function(){i<n?(e.next(i++),this.schedule()):e.complete()}))}:function(e){for(var r=t;r<n&&!e.closed;)e.next(r++);e.complete()})}(0,u).pipe(zt((()=>{const i=r.slice(o,o+re);return s?St({failed:s}):t.rest.patch(e,i,{"content-type":(null==n?void 0:n.contentType)||"application/octet-stream","upload-offset":`${o}`,"content-length":`${i.byteLength}`},!0).pipe(kt((t=>200!==t.status?(s=!0,{failed:s}):(o+=re,{completed:o>=a,progress:o>=a?100:Math.min(Math.floor(o/a*100),100)}))),Ht((()=>St({failed:!0}))))}))))))))))},ae=(t,e,r,n=!1)=>{const i=Array.from(r),o=i.reduce(((t,e)=>t+(e.size||0)),0),s=[],a=i.map((t=>({file:t,progress:0,uploaded:!1,failed:!1}))),u=i.map((r=>{let i=e;if(n){let t=r.name.toLowerCase().replace(ne,"_");s.includes(t)&&(t+="_"+s.filter((e=>e.startsWith(t))).length),s.push(t),i=`${i}/file/${t}`}const o=r.lang;if(o){const t=r.payload||{};r.payload=Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},null==t?void 0:t.metadata),{language:o})})}return ie(t,i,r,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=it(t);return H((function(e,n){(r?Ct(t,e,r):Ct(t,e)).subscribe(n)}))}({progress:0,completed:!1}),kt((t=>({status:t,file:r}))))}));return wt(u).pipe(Ft((t=>t),6),kt((t=>{const e=a.find((e=>e.file===t.file));t.status.failed&&(e.failed=!0),t.status.conflict&&(e.conflicts=!0),t.status.completed&&(e.uploaded=!0),t.status.failed||t.status.conflict||t.status.completed?e.progress=100:e.progress=t.status.progress||0;const r=a.filter((t=>t.failed)).length,n=a.filter((t=>t.conflicts)).length,i=a.filter((t=>t.uploaded)).length,s=i+r===a.length,u=Math.round(a.reduce(((t,e)=>t+e.file.size*e.progress/100),0)/o*100);return{files:a,progress:u,completed:s,uploaded:i,failed:r,conflicts:n}})))},ue=(t,e,r)=>{const n=Object.assign({"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`,"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},ce(r));return t.rest.post("/processing/upload",e,n)},ce=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=encodeURIComponent(t.filename)),(null==t?void 0:t.md5)&&(e["x-md5"]=t.md5),(null==t?void 0:t.lang)&&(e["x-language"]=t.lang),e};var le,he,de,fe;t.SHORT_FIELD_TYPE=void 0,(le=t.SHORT_FIELD_TYPE||(t.SHORT_FIELD_TYPE={})).layout="l",le.text="t",le.file="f",le.link="u",le.datetime="d",le.keywordset="k",le.generic="a",le.conversation="c",t.Search=void 0,he=t.Search||(t.Search={}),(de=he.Features||(he.Features={})).PARAGRAPH="paragraph",de.DOCUMENT="document",de.RELATIONS="relations",de.VECTOR="vector",(fe=he.ResourceFeatures||(he.ResourceFeatures={})).PARAGRAPH="paragraph",fe.RELATIONS="relations",fe.VECTOR="vector";const pe=(t,e,r,n,i=[],o,s)=>{var a;const u={};u.query=n||"",u.features=i;const c=o||{},{inTitleOnly:l}=c,h=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(c,["inTitleOnly"]);l&&(u.fields=["a/title"]),u.shards=(null===(a=t.currentShards)||void 0===a?void 0:a[e])||[];return(s?t.rest.get(`${r}/search?${be(u,h)}`):t.rest.post(`${r}/search`,Object.assign(Object.assign({},u),h))).pipe(Ht((()=>St({error:!0}))),kt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((r=>{r.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:r.shards}))})))},ve=(t,e,r,n)=>{var i;const o={};o.query=r||"",o.shards=(null===(i=t.currentShards)||void 0===i?void 0:i[e])||[];return t.rest.get(`/kb/${e}/catalog?${n?be(o,n):""}`).pipe(Ht((()=>St({error:!0}))),kt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((r=>{r.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:r.shards}))})))},be=(t,e)=>{Object.entries(e||{}).forEach((([e,r])=>{null!=r&&(Array.isArray(r)?t[e]=r.map((t=>`${t}`)):"object"==typeof r?Object.entries(r).forEach((([r,n])=>t[`${e}_${r}`]=`${n}`)):t[e]=`${r}`)}));const r=new URLSearchParams;return Object.entries(t).forEach((([t,e])=>Array.isArray(e)?e.forEach((e=>r.append(t,e))):r.append(t,e))),r.toString()},ge=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ye=(t,e,r,n,i)=>{const o=ge(i.filter((r=>Ee(r,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=ge(i.filter((r=>Te(r,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])).filter((t=>t.key!==r)),a=i.filter((r=>r.field.field!==t||r.field.field_type!==e)),u=n.length>0?[...s,{key:r,classifications:n}]:s;return o.length>0||u.length>0?[...a,{field:{field:t,field_type:e},token:o.length>0?o:void 0,paragraphs:u.length>0?u:void 0}]:a},me=(t,e,r,n)=>{const i=ge(n.filter((r=>Te(r,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])),o=n.filter((r=>r.field.field!==t||r.field.field_type!==e));return r.length>0||i.length>0?[...o,{field:{field:t,field_type:e},token:r.length>0?r:void 0,paragraphs:i.length>0?i:void 0}]:o},Ee=(t,e,r)=>t.field.field===e&&t.field.field_type===r&&t.token&&t.token.length>0,Te=(t,e,r)=>t.field.field===e&&t.field.field_type===r&&t.paragraphs&&t.paragraphs.length>0,we=(t,e,r)=>t?(Array.isArray(t)||(t=Array.from(t)),t.slice(e,r).join("")):"";class Se{constructor(t){this.data={},this.fieldTextsCache={},t.data||(t.data={}),Object.assign(this,Object.assign(Object.assign({},t),{title:this.formatTitle(t.title)}))}getFields(t=["files","links","texts","keywordsets"]){return Object.entries(this.data).filter((([e])=>t.includes(e))).map((([,t])=>t)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}getFieldData(t,e){var r;const n=null===(r=this.data[t])||void 0===r?void 0:r[e];return n||void 0}getExtractedSummaries(){return this.getFields().filter((t=>{var e,r,n;return null===(n=null===(r=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===r?void 0:r.metadata)||void 0===n?void 0:n.summary})).map((t=>t.extracted.metadata.metadata.summary))}getExtractedTexts(){return this.getFields().filter((t=>{var e;return null===(e=t.extracted)||void 0===e?void 0:e.text})).map((t=>t.extracted.text))}getFiles(){return this.getFields(["files"]).filter((t=>!!t&&!!t.value&&!!t.value.file)).map((t=>t.value.file))}getThumbnails(){return this.getFields(["files"]).map((t=>{var e,r;return null===(r=null===(e=t.extracted)||void 0===e?void 0:e.file)||void 0===r?void 0:r.file_thumbnail})).concat(this.getFields(["links"]).map((t=>{var e,r;return null===(r=null===(e=t.extracted)||void 0===e?void 0:e.link)||void 0===r?void 0:r.link_thumbnail}))).filter((t=>!!t))}getAnnotatedEntities(){return(this.fieldmetadata||[]).filter((t=>t.token&&t.token.length>0)).map((t=>t.token)).reduce(((t,e)=>(e.filter((t=>!t.cancelled_by_user)).forEach((e=>{t[e.klass]||(t[e.klass]=[]),t[e.klass].push(e.token)})),t)),{})}getNamedEntities(){return this.getFields().filter((t=>{var e,r,n;return null===(n=null===(r=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===r?void 0:r.metadata)||void 0===n?void 0:n.ner})).map((t=>Object.entries(t.extracted.metadata.metadata.ner).reduce(((t,[e,r])=>(t[r]=(t[r]||[]).concat([e]),t)),{}))).reduce(((t,e)=>(Object.entries(e).forEach((([e,r])=>{t[e]=(t[e]||[]).concat(r)})),t)),{})}getClassifications(){var t,e,r;const n=((null===(t=this.usermetadata)||void 0===t?void 0:t.classifications)||[]).filter((t=>!t.cancelled_by_user)),i=((null===(e=this.usermetadata)||void 0===e?void 0:e.classifications)||[]).filter((t=>t.cancelled_by_user));return((null===(r=this.computedmetadata)||void 0===r?void 0:r.field_classifications)||[]).reduce(((t,e)=>(e.classifications.forEach((e=>{const r=t.find((t=>t.label===e.label&&t.labelset===e.labelset)),n=i.find((t=>t.label===e.label&&t.labelset===e.labelset));r||n||t.push(Object.assign(Object.assign({},e),{immutable:!0}))})),t)),n)}getPositionedNamedEntities(t,e){var r,n,i,o;const s=null===(o=null===(i=null===(n=null===(r=this.data[t])||void 0===r?void 0:r[e])||void 0===n?void 0:n.extracted)||void 0===i?void 0:i.metadata)||void 0===o?void 0:o.metadata.positions;return s?Object.entries(s).reduce(((t,[e,r])=>{const n=e.split("/")[0];return r.position.forEach((e=>{t.push(Object.assign({entity:r.entity,family:n},e))})),t}),[]):[]}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}getParagraphText(t,e,r){return we(this.getFieldText(t,e),r.start,r.end)}getSentenceText(t,e,r){return we(this.getFieldText(t,e),r.start,r.end)}getFieldText(t,e){var r,n;const i=`${t}-${e}`;if(!this.fieldTextsCache[i]){const o=this.getFieldData(`${t}s`,e);this.fieldTextsCache[i]=Array.from((null===(n=null===(r=null==o?void 0:o.extracted)||void 0===r?void 0:r.text)||void 0===n?void 0:n.text)||"")}return this.fieldTextsCache[i]}}class _e extends Se{constructor(t,e,r){super(r),this.nuclia=t,this.kb=e,this.uuid=r.id}get path(){if(!this.uuid&&!this.slug)throw new Error("Resource must have either uuid or slug");return this.uuid?`/kb/${this.kb}/resource/${this.uuid}`:`/kb/${this.kb}/slug/${this.slug}`}modify(t,e=!0){return this.nuclia.rest.patch(this.path,t,void 0,void 0,e)}delete(t=!0){return this.nuclia.rest.delete(this.path,void 0,t)}reprocess(){return this.nuclia.rest.post(`${this.path}/reprocess`,{},void 0,void 0,!0)}getField(t,e){return this.nuclia.rest.get(`${this.path}/${t}/${e}`)}getThumbnailsUrl(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=nt(t),n=Dt(t),i=n.args,o=n.keys,s=new N((function(t){var e=i.length;if(e)for(var r=new Array(e),n=e,s=e,a=function(e){var a=!1;vt(i[e]).subscribe(z(t,(function(t){a||(a=!0,s--),r[e]=t}),(function(){return n--}),void 0,(function(){n&&a||(s||t.next(o?jt(o,r):r),t.complete())})))},u=0;u<e;u++)a(u);else t.complete()}));return r?s.pipe($t(r)):s}(this.getThumbnails().filter((t=>t.uri)).map((t=>this.nuclia.rest.getObjectURL(t.uri))))}deleteField(t,e){return this.nuclia.rest.delete(`${this.path}/${t}/${e}`)}addField(t,e,r){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,r)}updateField(t,e,r){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,r)}upload(t,e,r,n){return ie(this.nuclia,`${this.path}/file/${t}`,e,!!r,n)}batchUpload(t){return ae(this.nuclia,this.path,t,!0)}search(t,e=[],r){return pe(this.nuclia,this.kb,this.path,t,e,r,!0)}setLabels(t,e,r,n){const i=ye(t,e,r,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Mt((()=>this.fieldmetadata=i)))}setEntities(t,e,r){const n=me(t,e,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:n}).pipe(Mt((()=>this.fieldmetadata=n)))}}var xe,ke;t.FIELD_TYPE=void 0,(xe=t.FIELD_TYPE||(t.FIELD_TYPE={})).text="text",xe.file="file",xe.link="link",xe.layout="layout",xe.conversation="conversation",xe.keywordset="keywordset",xe.datetime="datetime",t.RESOURCE_STATUS=void 0,(ke=t.RESOURCE_STATUS||(t.RESOURCE_STATUS={})).PENDING="PENDING",ke.PROCESSED="PROCESSED",ke.ERROR="ERROR";var Ae,$e,Oe;t.TrainingType=void 0,(Ae=t.TrainingType||(t.TrainingType={})).classifier="classifier",Ae.resource_labeler="resource-labeler",Ae.paragraph_labeler="paragraph-labeler",Ae.ner="ner",t.TrainingStatus=void 0,($e=t.TrainingStatus||(t.TrainingStatus={})).finished="finished",$e.not_running="not_running",$e.running="running",$e.started="started",$e.stopped="stopped",t.TrainingExecutionStatus=void 0,(Oe=t.TrainingExecutionStatus||(t.TrainingExecutionStatus={})).succeeded="succeeded",Oe.failed="failed",Oe.stopped="stopped";class Re{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e||{})}stop(t){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/stop`,{})}getStatus(e){return this.nuclia.rest.get(`${this.kb.path}/train/${e}/inspect`).pipe(Ht((()=>St({task:"",status:t.TrainingStatus.not_running}))))}getExecutions(t=0){return this.nuclia.rest.get(`${this.kb.path}/train/executions?page=${t}`)}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/json_models/nuclia.json`).pipe(kt((()=>!0)),Ht((()=>St(!1))))}}class Ie{constructor(t,e,r){this.nuclia=t,this.account=e,Object.assign(this,r)}get path(){return`/kb/${this.id}`}get fullpath(){return`${this.nuclia.regionalBackend}/v1/kb/${this.id}`}getEntities(t=!1){return this.nuclia.rest.get(`${this.path}/entitiesgroups?show_entities=${t}`).pipe(kt((t=>t.groups)))}getEntitiesGroup(t){return this.nuclia.rest.get(`${this.path}/entitiesgroup/${t}`)}getLabels(){return this.nuclia.rest.get(`${this.path}/labelsets`).pipe(kt((t=>(null==t?void 0:t.labelsets)||{})))}getResource(e,r=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],n=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){return this._getResource(e,void 0,r,n)}getResourceBySlug(e,r=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],n=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){return this._getResource(void 0,e,r,n)}_getResource(e,r,n=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],i=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){const o=[...n.map((t=>`show=${t}`)),...i.map((t=>`extracted=${t}`))],s=e?`${this.path}/resource/${e}`:`${this.path}/slug/${r}`;return this.nuclia.rest.get(`${s}?${o.join("&")}`).pipe(kt((t=>new _e(this.nuclia,this.id,t))))}getResourceFromData(t){return new _e(this.nuclia,this.id,t)}search(t,e=[],r){return pe(this.nuclia,this.id,this.path,t,e,r)}catalog(t,e){return ve(this.nuclia,this.id,t,e)}suggest(t,e=!1){const r=`query=${encodeURIComponent(t)}${e?"&fields=a/title":""}`;return this.nuclia.rest.get(`${this.path}/suggest?${r}`).pipe(Ht((()=>St({error:!0}))),kt((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}counters(){return this.nuclia.rest.get(`/kb/${this.id}/counters`)}listResources(t,e){const r=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${r?"?"+r:""}`).pipe(kt((t=>({resources:t.resources.map((t=>new _e(this.nuclia,this.id,t))),pagination:t.pagination}))))}getTempToken(){if(!this.nuclia.options.account||!this.nuclia.options.kbSlug)throw new Error("Account and KB slug are required to get a temp token");return this.nuclia.rest.post(`/account/${this.nuclia.options.account}/kb/${this.nuclia.options.kbSlug}/ephemeral_tokens`,{}).pipe(kt((t=>t.token)))}listActivity(t,e,r){const n=[t?`type=${t}`:"",e?`page=${e}`:"",r?`size=${r}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/activity${n?"?"+n:""}`)}}class Pe extends Ie{get training(){return this._training||(this._training=new Re(this,this.nuclia)),this._training}modify(t){return this.nuclia.rest.patch(`/account/${this.account}/kb/${this.slug}`,t)}publish(t){return this.modify({state:t?"PUBLISHED":"PRIVATE"})}delete(){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}`)}setEntitiesGroup(t,e){return this.nuclia.rest.post(`${this.path}/entitiesgroup/${t}`,e)}deleteEntitiesGroup(t){return this.nuclia.rest.delete(`${this.path}/entitiesgroup/${t}`)}setLabelSet(t,e){return this.nuclia.rest.post(`${this.path}/labelset/${t}`,e)}deleteLabelSet(t){return this.nuclia.rest.delete(`${this.path}/labelset/${t}`)}createResource(t,e=!0){return this.nuclia.rest.post(`${this.path}/resources`,t,void 0,void 0,e)}createLinkResource(t,e,r=!0){return this.createResource({links:{link:t},usermetadata:e,title:t.uri,icon:"application/stf-link"},r)}hasResource(t){return this.nuclia.rest.get(`${this.path}/slug/${t}`).pipe(kt((()=>!0)),Ht((()=>St(!1))))}createOrUpdateResource(t,e=!0){return(t.slug?this.hasResource(t.slug):St(!1)).pipe(Wt((r=>r?this.getResourceFromData({id:"",slug:t.slug}).modify(t,e):this.createResource(t,e))))}upload(t,e,r){return ie(this.nuclia,`/kb/${this.id}`,t,!!e,r)}batchUpload(t){return ae(this.nuclia,`/kb/${this.id}`,t,!1)}getServiceAccounts(){return this.nuclia.rest.get(`/account/${this.account}/kb/${this.slug}/service_accounts`)}createServiceAccount(t){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_accounts`,t)}deleteServiceAccount(t){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}`)}createKey(t,e){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_account/${t}/keys`,{expires:e})}deleteKey(t,e){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}/key/${e}`)}}class De{constructor(t){this.nuclia=t}getAccounts(){return this.nuclia.rest.get("/accounts")}createAccount(t){return this.nuclia.rest.post("/accounts",t)}modifyAccount(t,e){return this.nuclia.rest.patch(`/account/${t}`,e)}deleteAccount(t){return this.nuclia.rest.delete(`/account/${t}`)}getAccountStatus(t){return this.nuclia.rest.get(`/account/${t}/status`)}getWelcome(){return this.nuclia.rest.get("/user/welcome")}getAccount(t){if(!(t=t||this.nuclia.options.account))throw new Error("Account is not set");return this.nuclia.rest.get(`/account/${t}`)}getKnowledgeBoxes(t){return this.nuclia.rest.get(`/account/${t}/kbs`)}getKnowledgeBox(t,e){if(t=t||this.nuclia.options.account){const r=e||this.nuclia.options.knowledgeBox||this.nuclia.options.kbSlug;if(!r)throw new Error("account and knowledgeBox must be defined in the Nuclia options");return this.nuclia.rest.get(`/account/${t}/kb/${r}`).pipe(Wt((t=>this.nuclia.options.zone?St(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Mt((t=>this.nuclia.options.zone=t)),kt((()=>t))))),kt((e=>new Pe(this.nuclia,t,e))))}if(!this.nuclia.options.knowledgeBox||!this.nuclia.options.zone)throw new Error("zone must be defined in the Nuclia options");return St(new Pe(this.nuclia,"",{id:this.nuclia.options.knowledgeBox,zone:this.nuclia.options.zone}))}createKnowledgeBox(t,e){return this.nuclia.rest.post(`/account/${t}/kbs`,e).pipe(Mt((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Wt((()=>this.getKnowledgeBox(t,e.slug))))}getStats(e,r,n,i=t.StatsPeriod.DAY,o){const s=[`period=${i}`,`stats=${r}`];return o&&s.push(`utctime=${o}`),n&&s.push(`knowledgebox=${n}`),this.nuclia.rest.get(`/account/${e}/stats?${s.join("&")}`).pipe(kt((t=>t.data)),Bt((t=>!!t)))}upload(t){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return ue(this.nuclia,t,{md5:t.md5}).pipe(Wt((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},this.getNUAHeader()))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /processing");return this.nuclia.rest.get("/processing/pull",this.getNUAHeader())}getProcessingStatus(t){if(!t){if(!this.hasNUAClient())throw new Error("NUA key or account id is needed to be able to call /processing/status")}const e=t?`/processing/status?account_id=${t}`:"/processing/status",r=t?void 0:this.getNUAHeader();return this.nuclia.rest.get(e,r)}getProcessingStats(t,e){const r=this.hasNUAClient();if(!e&&!r)throw new Error("NUA key or account id is needed to be able to call /processing/stats");const n=r?"/processing/stats"+(t?"?period="+t:""):`/processing/stats?account_id=${e}${t?"&period="+t:""}`,i=r?this.getNUAHeader():void 0;return this.nuclia.rest.get(n,i).pipe(kt((t=>t.data)))}getNUAActivity(t,e,r=0){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}/activity?page=${r}`)}getNUAClients(t){return this.nuclia.rest.get(`/account/${t}/nua_clients`).pipe(kt((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(Jt)&&!!localStorage.getItem(Gt)}getNUAHeader(){return{"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`}}createNUAClient(t,e){const r=Object.assign({},e);return r.webhook&&(r.processing_webhook={uri:r.webhook},delete r.webhook),this.nuclia.rest.post(`/account/${t}/nua_clients`,r).pipe(Ht((r=>{if(409===r.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw r})),Mt((t=>{"desktop"===this.nuclia.options.client&&(localStorage.setItem(Gt,t.token),localStorage.setItem(Jt,t.client_id))})))}renewNUAClient(t,e){return this.nuclia.rest.put(`/account/${t}/nua_client/${e}/key`,{})}deleteNUAClient(t,e){return this.nuclia.rest.delete(`/account/${t}/nua_client/${e}`)}}function je(t,e){void 0===e&&(e={});var r=e.selector,i=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(e,["selector"]);return new N((function(e){var o=new AbortController,s=o.signal,a=!0,u=i.signal;if(u)if(u.aborted)o.abort();else{var c=function(){s.aborted||o.abort()};u.addEventListener("abort",c),e.add((function(){return u.removeEventListener("abort",c)}))}var l=n(n({},i),{signal:s}),h=function(t){a=!1,e.error(t)};return fetch(t,l).then((function(t){r?vt(r(t)).subscribe(z(e,void 0,(function(){a=!1,e.complete()}),h)):(a=!1,e.next(t),e.complete())})).catch(h),function(){a&&o.abort()}}))}class Fe{constructor(t){this.token=t}urlBase64Decode(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("Illegal base64url string!")}return this.b64DecodeUnicode(e)}b64decode(t){let e="";if((t=String(t).replace(/=+$/,"")).length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let r,n,i=0,o=0;n=t.charAt(o++);~n&&(r=i%4?64*r+n:n,i++%4)?e+=String.fromCharCode(255&r>>(-2*i&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return e}b64DecodeUnicode(t){return decodeURIComponent(Array.prototype.map.call(this.b64decode(t),(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2))).join(""))}decodeToken(t=this.token){if(null===t)return null;const e=t.split(".");if(3!==e.length)throw new Error("The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.");const r=this.urlBase64Decode(e[1]);if(!r)throw new Error("Cannot decode the token.");return JSON.parse(r)}getJWTUser(t=this.token){let e;try{e=this.decodeToken(t)}catch(t){return null}return e}getTokenExpirationDate(t=this.token){const e=this.getJWTUser(t);if(!e)return null;const r=new Date(0);return r.setUTCSeconds(e.exp),r}isTokenExpired(t=this.token,e){if(null===t||""===t)return!0;const r=this.getTokenExpirationDate(t);return e=e||0,null===r||r.valueOf()<=(new Date).valueOf()+1e3*e}}const Le="JWT_KEY",Ue="JWT_REFRESH_KEY",Ce=216e5;class Ne{constructor(t){this._isAuthenticated=new J(1),this.nuclia=t,this.nuclia.options.knowledgeBox?this._isAuthenticated.next(!0):this.checkTokenExpiration()}getAuthHeaders(){return this.nuclia.options.standalone?{"X-NUCLIADB-ROLES":"READER"}:this.nuclia.options.apiKey?{"X-STF-Serviceaccount":`Bearer ${this.nuclia.options.apiKey}`}:this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{}}isAuthenticated(){return this._isAuthenticated.asObservable()}hasLoggedOut(){return this.isAuthenticated().pipe((t=1,Bt((function(e,r){return t<=r}))),Bt((t=>!t)));var t}login(t,e,r){return this.fetch("/auth/login",{username:t,password:e},!1,r?{"X-STF-VALIDATION":r}:{}).pipe(kt((t=>this.authenticate(t))))}authenticate(t){return t.access_token?(this.storeTokens(t),this._isAuthenticated.next(!0),!0):(this._isAuthenticated.next(!1),!1)}logout(){this.fetch("/auth/logout",{},!0,{}).subscribe(),localStorage.removeItem(Le),localStorage.removeItem(Ue),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Ht((t=>(this.logout(),_t(t)))),kt((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return this.nuclia.options.public?"":localStorage.getItem(Le)||""}setPassword(t){return this.fetch("/auth/setpassword",{password:t},!0,{}).pipe(kt((t=>this.authenticate(t))))}deleteAuthenticatedUser(){return this.nuclia.rest.delete("/user").pipe(Mt((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new Fe(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(Ue)||""}storeTokens(t){localStorage.setItem(Le,t.access_token),localStorage.setItem(Ue,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const r=this.getToken();if(r){const n=null===(t=new Fe(r).getTokenExpirationDate())||void 0===t?void 0:t.getTime();if(n){const t=(new Date).getTime();if(n<t)this.logout();else{this._isAuthenticated.next(!0);const r=n-t<Ce?0:Ce;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Nt(r).pipe(Wt((()=>this.refresh()))).subscribe()}}else this._isAuthenticated.next(!1)}else this._isAuthenticated.next(!1)}fetch(t,e,r,n){const i=Object.assign({"content-type":"application/json"},n);return r&&(i.Authorization=`Bearer ${this.getToken()}`),je(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Wt((t=>t.ok?wt(t.clone().json()):_t(t))))}}class Be{constructor(t){this.nuclia=t}get(t,e,r){return this.fetch("GET",t,void 0,e,r)}post(t,e,r,n,i){return this.fetch("POST",t,e,r,n,i)}put(t,e,r,n,i){return this.fetch("PUT",t,e,r,n,i)}patch(t,e,r,n,i){return this.fetch("PATCH",t,e,r,n,i)}delete(t,e,r){return this.fetch("DELETE",t,void 0,e,!0,r)}head(t,e){return this.fetch("HEAD",t,void 0,e,!0)}getHeaders(t,e=!1){const r=t&&t["x-stf-nuakey"]?{}:this.nuclia.auth.getAuthHeaders(),n=Object.assign({"content-type":"application/json","x-ndb-client":this.nuclia.options.client||"web"},r);return e&&(n["x-synchronous"]=`${e}`),Object.assign(Object.assign({},n),t)}fetch(t,e,r,n,i,o=!1){const s=n&&n["content-type"];return je(this.getFullUrl(e),{selector:t=>Promise.resolve(t),headers:this.getHeaders(n,o),method:t,body:s?r:JSON.stringify(r)}).pipe(Wt((t=>t.ok?i?St(t):wt(t.clone().json().catch((()=>t.text()))):_t((()=>t)))))}getFullUrl(t){return`${t.startsWith("/account")||t.startsWith("/user")||t.startsWith("/auth")||t.startsWith("/zones")||t.includes("/activity")||this.nuclia.options.standalone?this.nuclia.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")||t.startsWith("/export")?"":"/v1"}${t}`}getZones(){return this.zones?St(this.zones):this.get("/zones").pipe(kt((t=>{const e=t.reduce(((t,e)=>(t[e.id]=e.slug,t)),{});return this.zones=e,e})))}getZoneSlug(t){return this.getZones().pipe(kt((e=>e[t])))}getObjectURL(t){return this.get(t,void 0,!0).pipe(Wt((t=>wt(t.blob()))),kt((t=>URL.createObjectURL(t))))}}t.Authentication=Ne,t.Db=De,t.FileFieldData=class{},t.JwtHelper=Fe,t.KeywordSetFieldData=class{},t.KnowledgeBox=Ie,t.LinkFieldData=class{},t.NUA_CLIENT=Jt,t.NUA_KEY=Gt,t.Nuclia=class{constructor(t){this.currentShards={},this.options=t,this.auth=new Ne(this),this.rest=new Be(this),this.db=new De(this)}get backend(){return this.options.backend}get regionalBackend(){return this.options.backend.replace("//",`//${this.options.zone}.`)}get knowledgeBox(){if(!this.options.knowledgeBox||!this.options.zone)throw new Error("zone and knowledge box id must be defined in the Nuclia options");return this.readKb||(this.readKb=new Ie(this,"",{id:this.options.knowledgeBox,zone:this.options.zone})),this.readKb}get asyncKnowledgeBox(){return new Proxy(this.knowledgeBox,{get(t,e){const r=Reflect.get(t,e);return"function"==typeof r?(...e)=>function(t,e){var r="object"==typeof e;return new Promise((function(n,i){var o=new P({next:function(t){n(t),o.unsubscribe()},error:i,complete:function(){r?n(e.defaultValue):i(new xt)}});t.subscribe(o)}))}(r.bind(t)(...e)):r}})}},t.ReadableResource=Se,t.Resource=_e,t.Rest=Be,t.TUSuploadFile=se,t.TextFieldData=class{},t.Training=Re,t.WritableKnowledgeBox=Pe,t.batchUpload=ae,t.catalog=ve,t.deDuplicateList=ge,t.getDataKeyFromFieldType=e=>{switch(e){case t.FIELD_TYPE.text:case t.FIELD_TYPE.file:case t.FIELD_TYPE.link:case t.FIELD_TYPE.keywordset:return`${e}s`;default:return null}},t.getFileMetadata=ce,t.getFilterFromLabel=function(t){return`/l/${t.labelset}/${t.label}`},t.getLabelFromFilter=function(t){const e=t.split("/");return{labelset:e[2],label:e[3]}},t.lengthUnicode=t=>t?Array.from(t).length:0,t.longToShortFieldType=function(e){return t.SHORT_FIELD_TYPE[e]},t.resourceToAlgoliaFormat=(t,e)=>{const r={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};t.getClassifications().forEach((t=>{t.labelset&&t.label&&(r[t.labelset]=t.label)}));const n=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},r),{images:n}),t.getNamedEntities())},t.search=pe,t.setEntities=me,t.setLabels=ye,t.shortToLongFieldType=function(e){switch(e){case t.SHORT_FIELD_TYPE.conversation:return t.FIELD_TYPE.conversation;case t.SHORT_FIELD_TYPE.datetime:return t.FIELD_TYPE.datetime;case t.SHORT_FIELD_TYPE.file:return t.FIELD_TYPE.file;case t.SHORT_FIELD_TYPE.layout:return t.FIELD_TYPE.layout;case t.SHORT_FIELD_TYPE.keywordset:return t.FIELD_TYPE.keywordset;case t.SHORT_FIELD_TYPE.link:return t.FIELD_TYPE.link;case t.SHORT_FIELD_TYPE.text:return t.FIELD_TYPE.text;default:return null}},t.sliceUnicode=we,t.upload=ie,t.uploadFile=oe,t.uploadToProcess=ue})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).NucliaSDK={})}(this,(function(t){"use strict";var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},e(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)};function i(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function u(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function c(t){return this instanceof c?(this.v=t,this):new c(t)}function l(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(t,e||[]),o=[];return n={},s("next"),s("throw"),s("return"),n[Symbol.asyncIterator]=function(){return this},n;function s(t){i[t]&&(n[t]=function(e){return new Promise((function(r,n){o.push([t,e,r,n])>1||a(t,e)}))})}function a(t,e){try{(r=i[t](e)).value instanceof c?Promise.resolve(r.value.v).then(u,l):h(o[0][2],r)}catch(t){h(o[0][3],t)}var r}function u(t){a("next",t)}function l(t){a("throw",t)}function h(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}function h(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=s(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise((function(n,i){(function(t,e,r,n){Promise.resolve(n).then((function(e){t({value:e,done:r})}),e)})(n,i,(e=t[r](e)).done,e.value)}))}}}function d(t){return"function"==typeof t}function p(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var f=p((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function v(t,e){if(t){var r=t.indexOf(e);0<=r&&t.splice(r,1)}}var b=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}var e;return t.prototype.unsubscribe=function(){var t,e,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var c=s(o),l=c.next();!l.done;l=c.next()){l.value.remove(this)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(d(h))try{h()}catch(t){i=t instanceof f?t.errors:[t]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var v=s(p),b=v.next();!b.done;b=v.next()){var g=b.value;try{m(g)}catch(t){i=null!=i?i:[],t instanceof f?i=u(u([],a(i)),a(t.errors)):i.push(t)}}}catch(t){r={error:t}}finally{try{b&&!b.done&&(n=v.return)&&n.call(v)}finally{if(r)throw r.error}}}if(i)throw new f(i)}},t.prototype.add=function(e){var r;if(e&&e!==this)if(this.closed)m(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&v(e,t)},t.prototype.remove=function(e){var r=this._finalizers;r&&v(r,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t}(),g=b.EMPTY;function y(t){return t instanceof b||t&&"closed"in t&&d(t.remove)&&d(t.add)&&d(t.unsubscribe)}function m(t){d(t)?t():t.unsubscribe()}var E={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},T={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=T.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,u([t,e],a(r))):setTimeout.apply(void 0,u([t,e],a(r)))},clearTimeout:function(t){var e=T.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function w(t){T.setTimeout((function(){throw t}))}function _(){}var S=x("C",void 0,void 0);function x(t,e,r){return{kind:t,value:e,error:r}}var k=null;function A(t){if(E.useDeprecatedSynchronousErrorHandling){var e=!k;if(e&&(k={errorThrown:!1,error:null}),t(),e){var r=k,n=r.errorThrown,i=r.error;if(k=null,n)throw i}}else t()}var $=function(t){function e(e){var r=t.call(this)||this;return r.isStopped=!1,e?(r.destination=e,y(e)&&e.add(r)):r.destination=L,r}return r(e,t),e.create=function(t,e,r){return new P(t,e,r)},e.prototype.next=function(t){this.isStopped?F(function(t){return x("N",t,void 0)}(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?F(x("E",void 0,t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?F(S,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(b),O=Function.prototype.bind;function R(t,e){return O.call(t,e)}var I=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){D(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){D(t)}else D(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){D(t)}},t}(),P=function(t){function e(e,r,n){var i,o,s=t.call(this)||this;d(e)||!e?i={next:null!=e?e:void 0,error:null!=r?r:void 0,complete:null!=n?n:void 0}:s&&E.useDeprecatedNextContext?((o=Object.create(e)).unsubscribe=function(){return s.unsubscribe()},i={next:e.next&&R(e.next,o),error:e.error&&R(e.error,o),complete:e.complete&&R(e.complete,o)}):i=e;return s.destination=new I(i),s}return r(e,t),e}($);function D(t){w(t)}function F(t,e){var r=E.onStoppedNotification;r&&T.setTimeout((function(){return r(t,e)}))}var L={closed:!0,next:_,error:function(t){throw t},complete:_},j="function"==typeof Symbol&&Symbol.observable||"@@observable";function U(t){return t}function C(t){return 0===t.length?U:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var N=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(t,e,r){var n,i=this,o=(n=t)&&n instanceof $||function(t){return t&&d(t.next)&&d(t.error)&&d(t.complete)}(n)&&y(n)?t:new P(t,e,r);return A((function(){var t=i,e=t.operator,r=t.source;o.add(e?e.call(o,r):r?i._subscribe(o):i._trySubscribe(o))})),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var r=this;return new(e=Y(e))((function(e,n){var i=new P({next:function(e){try{t(e)}catch(t){n(t),i.unsubscribe()}},error:n,complete:e});r.subscribe(i)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[j]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return C(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=Y(t))((function(t,r){var n;e.subscribe((function(t){return n=t}),(function(t){return r(t)}),(function(){return t(n)}))}))},t.create=function(e){return new t(e)},t}();function Y(t){var e;return null!==(e=null!=t?t:E.Promise)&&void 0!==e?e:Promise}function B(t){return function(e){if(function(t){return d(null==t?void 0:t.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function H(t,e,r,n,i){return new z(t,e,r,n,i)}var z=function(t){function e(e,r,n,i,o,s){var a=t.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=s,a._next=r?function(t){try{r(t)}catch(t){e.error(t)}}:t.prototype._next,a._error=i?function(t){try{i(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,a._complete=n?function(){try{n()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,a}return r(e,t),e.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},e}($),K=p((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),W=function(t){function e(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return r(e,t),e.prototype.lift=function(t){var e=new M(this,this);return e.operator=t,e},e.prototype._throwIfClosed=function(){if(this.closed)throw new K},e.prototype.next=function(t){var e=this;A((function(){var r,n;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var i=s(e.currentObservers),o=i.next();!o.done;o=i.next()){o.value.next(t)}}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}}}))},e.prototype.error=function(t){var e=this;A((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var r=e.observers;r.length;)r.shift().error(t)}}))},e.prototype.complete=function(){var t=this;A((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var e=this,r=this,n=r.hasError,i=r.isStopped,o=r.observers;return n||i?g:(this.currentObservers=null,o.push(t),new b((function(){e.currentObservers=null,v(o,t)})))},e.prototype._checkFinalizedStatuses=function(t){var e=this,r=e.hasError,n=e.thrownError,i=e.isStopped;r?t.error(n):i&&t.complete()},e.prototype.asObservable=function(){var t=new N;return t.source=this,t},e.create=function(t,e){return new M(t,e)},e}(N),M=function(t){function e(e,r){var n=t.call(this)||this;return n.destination=e,n.source=r,n}return r(e,t),e.prototype.next=function(t){var e,r;null===(r=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===r||r.call(e,t)},e.prototype.error=function(t){var e,r;null===(r=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===r||r.call(e,t)},e.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},e.prototype._subscribe=function(t){var e,r;return null!==(r=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==r?r:g},e}(W),G={now:function(){return(G.delegate||Date).now()},delegate:void 0},V=function(t){function e(e,r,n){void 0===e&&(e=1/0),void 0===r&&(r=1/0),void 0===n&&(n=G);var i=t.call(this)||this;return i._bufferSize=e,i._windowTime=r,i._timestampProvider=n,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=r===1/0,i._bufferSize=Math.max(1,e),i._windowTime=Math.max(1,r),i}return r(e,t),e.prototype.next=function(e){var r=this,n=r.isStopped,i=r._buffer,o=r._infiniteTimeWindow,s=r._timestampProvider,a=r._windowTime;n||(i.push(e),!o&&i.push(s.now()+a)),this._trimBuffer(),t.prototype.next.call(this,e)},e.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var e=this._innerSubscribe(t),r=this._infiniteTimeWindow,n=this._buffer.slice(),i=0;i<n.length&&!t.closed;i+=r?1:2)t.next(n[i]);return this._checkFinalizedStatuses(t),e},e.prototype._trimBuffer=function(){var t=this,e=t._bufferSize,r=t._timestampProvider,n=t._buffer,i=t._infiniteTimeWindow,o=(i?1:2)*e;if(e<1/0&&o<n.length&&n.splice(0,n.length-o),!i){for(var s=r.now(),a=0,u=1;u<n.length&&n[u]<=s;u+=2)a=u;a&&n.splice(0,a+1)}},e}(W),J=function(t){function e(e,r){return t.call(this)||this}return r(e,t),e.prototype.schedule=function(t,e){return this},e}(b),X={setInterval:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=X.delegate;return(null==i?void 0:i.setInterval)?i.setInterval.apply(i,u([t,e],a(r))):setInterval.apply(void 0,u([t,e],a(r)))},clearInterval:function(t){var e=X.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},q=function(t){function e(e,r){var n=t.call(this,e,r)||this;return n.scheduler=e,n.work=r,n.pending=!1,n}return r(e,t),e.prototype.schedule=function(t,e){if(void 0===e&&(e=0),this.closed)return this;this.state=t;var r=this.id,n=this.scheduler;return null!=r&&(this.id=this.recycleAsyncId(n,r,e)),this.pending=!0,this.delay=e,this.id=this.id||this.requestAsyncId(n,this.id,e),this},e.prototype.requestAsyncId=function(t,e,r){return void 0===r&&(r=0),X.setInterval(t.flush.bind(t,this),r)},e.prototype.recycleAsyncId=function(t,e,r){if(void 0===r&&(r=0),null!=r&&this.delay===r&&!1===this.pending)return e;X.clearInterval(e)},e.prototype.execute=function(t,e){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var r=this._execute(t,e);if(r)return r;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,e){var r,n=!1;try{this.work(t)}catch(t){n=!0,r=t||new Error("Scheduled action threw falsy error")}if(n)return this.unsubscribe(),r},e.prototype.unsubscribe=function(){if(!this.closed){var e=this.id,r=this.scheduler,n=r.actions;this.work=this.state=this.scheduler=null,this.pending=!1,v(n,this),null!=e&&(this.id=this.recycleAsyncId(r,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(J),Z=function(){function t(e,r){void 0===r&&(r=t.now),this.schedulerActionCtor=e,this.now=r}return t.prototype.schedule=function(t,e,r){return void 0===e&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},t.now=G.now,t}(),Q=new(function(t){function e(e,r){void 0===r&&(r=Z.now);var n=t.call(this,e,r)||this;return n.actions=[],n._active=!1,n._scheduled=void 0,n}return r(e,t),e.prototype.flush=function(t){var e=this.actions;if(this._active)e.push(t);else{var r;this._active=!0;do{if(r=t.execute(t.state,t.delay))break}while(t=e.shift());if(this._active=!1,r){for(;t=e.shift();)t.unsubscribe();throw r}}},e}(Z))(q),tt=new N((function(t){return t.complete()}));function et(t){return t&&d(t.schedule)}function rt(t){return t[t.length-1]}function nt(t){return d(rt(t))?t.pop():void 0}function it(t){return et(rt(t))?t.pop():void 0}function ot(t,e){return"number"==typeof rt(t)?t.pop():e}var st=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function at(t){return d(null==t?void 0:t.then)}function ut(t){return d(t[j])}function ct(t){return Symbol.asyncIterator&&d(null==t?void 0:t[Symbol.asyncIterator])}function lt(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var ht="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function dt(t){return d(null==t?void 0:t[ht])}function pt(t){return l(this,arguments,(function(){var e,r,n;return o(this,(function(i){switch(i.label){case 0:e=t.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,c(e.read())];case 3:return r=i.sent(),n=r.value,r.done?[4,c(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,c(n)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}function ft(t){return d(null==t?void 0:t.getReader)}function vt(t){if(t instanceof N)return t;if(null!=t){if(ut(t))return i=t,new N((function(t){var e=i[j]();if(d(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(st(t))return n=t,new N((function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()}));if(at(t))return r=t,new N((function(t){r.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,w)}));if(ct(t))return bt(t);if(dt(t))return e=t,new N((function(t){var r,n;try{for(var i=s(e),o=i.next();!o.done;o=i.next()){var a=o.value;if(t.next(a),t.closed)return}}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}t.complete()}));if(ft(t))return bt(pt(t))}var e,r,n,i;throw lt(t)}function bt(t){return new N((function(e){(function(t,e){var r,n,s,a;return i(this,void 0,void 0,(function(){var i,u;return o(this,(function(o){switch(o.label){case 0:o.trys.push([0,5,6,11]),r=h(t),o.label=1;case 1:return[4,r.next()];case 2:if((n=o.sent()).done)return[3,4];if(i=n.value,e.next(i),e.closed)return[2];o.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=o.sent(),s={error:u},[3,11];case 6:return o.trys.push([6,,9,10]),n&&!n.done&&(a=r.return)?[4,a.call(r)]:[3,8];case 7:o.sent(),o.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))}))})(t,e).catch((function(t){return e.error(t)}))}))}function gt(t,e,r,n,i){void 0===n&&(n=0),void 0===i&&(i=!1);var o=e.schedule((function(){r(),i?t.add(this.schedule(null,n)):this.unsubscribe()}),n);if(t.add(o),!i)return o}function yt(t,e){return void 0===e&&(e=0),B((function(r,n){r.subscribe(H(n,(function(r){return gt(n,t,(function(){return n.next(r)}),e)}),(function(){return gt(n,t,(function(){return n.complete()}),e)}),(function(r){return gt(n,t,(function(){return n.error(r)}),e)})))}))}function mt(t,e){return void 0===e&&(e=0),B((function(r,n){n.add(t.schedule((function(){return r.subscribe(n)}),e))}))}function Et(t,e){if(!t)throw new Error("Iterable cannot be null");return new N((function(r){gt(r,e,(function(){var n=t[Symbol.asyncIterator]();gt(r,e,(function(){n.next().then((function(t){t.done?r.complete():r.next(t.value)}))}),0,!0)}))}))}function Tt(t,e){if(null!=t){if(ut(t))return function(t,e){return vt(t).pipe(mt(e),yt(e))}(t,e);if(st(t))return function(t,e){return new N((function(r){var n=0;return e.schedule((function(){n===t.length?r.complete():(r.next(t[n++]),r.closed||this.schedule())}))}))}(t,e);if(at(t))return function(t,e){return vt(t).pipe(mt(e),yt(e))}(t,e);if(ct(t))return Et(t,e);if(dt(t))return function(t,e){return new N((function(r){var n;return gt(r,e,(function(){n=t[ht](),gt(r,e,(function(){var t,e,i;try{e=(t=n.next()).value,i=t.done}catch(t){return void r.error(t)}i?r.complete():r.next(e)}),0,!0)})),function(){return d(null==n?void 0:n.return)&&n.return()}}))}(t,e);if(ft(t))return function(t,e){return Et(pt(t),e)}(t,e)}throw lt(t)}function wt(t,e){return e?Tt(t,e):vt(t)}function _t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=it(t);return wt(t,r)}function St(t,e){var r=d(t)?t:function(){return t},n=function(t){return t.error(r())};return new N(e?function(t){return e.schedule(n,0,t)}:n)}var xt=p((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function kt(t,e){return B((function(r,n){var i=0;r.subscribe(H(n,(function(r){n.next(t.call(e,r,i++))})))}))}var At=Array.isArray;function $t(t){return kt((function(e){return function(t,e){return At(e)?t.apply(void 0,u([],a(e))):t(e)}(t,e)}))}var Ot=Array.isArray,Rt=Object.getPrototypeOf,It=Object.prototype,Pt=Object.keys;function Dt(t){if(1===t.length){var e=t[0];if(Ot(e))return{args:e,keys:null};if((n=e)&&"object"==typeof n&&Rt(n)===It){var r=Pt(e);return{args:r.map((function(t){return e[t]})),keys:r}}}var n;return{args:t,keys:null}}function Ft(t,e){return t.reduce((function(t,r,n){return t[r]=e[n],t}),{})}function Lt(t,e,r){return void 0===r&&(r=1/0),d(e)?Lt((function(r,n){return kt((function(t,i){return e(r,t,n,i)}))(vt(t(r,n)))}),r):("number"==typeof e&&(r=e),B((function(e,n){return function(t,e,r,n,i,o,s,a){var u=[],c=0,l=0,h=!1,d=function(){!h||u.length||c||e.complete()},p=function(t){return c<n?f(t):u.push(t)},f=function(t){o&&e.next(t),c++;var a=!1;vt(r(t,l++)).subscribe(H(e,(function(t){null==i||i(t),o?p(t):e.next(t)}),(function(){a=!0}),void 0,(function(){if(a)try{c--;for(var t=function(){var t=u.shift();s?gt(e,s,(function(){return f(t)})):f(t)};u.length&&c<n;)t();d()}catch(t){e.error(t)}})))};return t.subscribe(H(e,p,(function(){h=!0,d()}))),function(){null==a||a()}}(e,n,t,r)})))}function jt(t){return void 0===t&&(t=1/0),Lt(U,t)}function Ut(){return jt(1)}function Ct(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ut()(wt(t,it(t)))}function Nt(t,e,r){void 0===t&&(t=0),void 0===r&&(r=Q);var n=-1;return null!=e&&(et(e)?r=e:n=e),new N((function(e){var i,o=(i=t)instanceof Date&&!isNaN(i)?+t-r.now():t;o<0&&(o=0);var s=0;return r.schedule((function(){e.closed||(e.next(s++),0<=n?this.schedule(void 0,n):e.complete())}),o)}))}function Yt(t,e){return B((function(r,n){var i=0;r.subscribe(H(n,(function(r){return t.call(e,r,i++)&&n.next(r)})))}))}function Bt(t){return B((function(e,r){var n,i=null,o=!1;i=e.subscribe(H(r,void 0,void 0,(function(s){n=vt(t(s,Bt(t)(e))),i?(i.unsubscribe(),i=null,n.subscribe(r)):o=!0}))),o&&(i.unsubscribe(),i=null,n.subscribe(r))}))}function Ht(t,e){return d(e)?Lt(t,e,1):Lt(t,1)}function zt(t){return t<=0?function(){return tt}:B((function(e,r){var n=0;e.subscribe(H(r,(function(e){++n<=t&&(r.next(e),t<=n&&r.complete())})))}))}function Kt(t){var e,r,n=1/0;return null!=t&&("object"==typeof t?(e=t.count,n=void 0===e?1/0:e,r=t.delay):n=t),n<=0?function(){return tt}:B((function(t,e){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=r){var t="number"==typeof r?Nt(r):vt(r(o)),n=H(e,(function(){n.unsubscribe(),a()}));t.subscribe(n)}else a()},a=function(){var r=!1;i=t.subscribe(H(e,void 0,(function(){++o<n?i?s():r=!0:e.complete()}))),r&&s()};a()}))}function Wt(t,e){return B((function(r,n){var i=null,o=0,s=!1,a=function(){return s&&!i&&n.complete()};r.subscribe(H(n,(function(r){null==i||i.unsubscribe();var s=0,u=o++;vt(t(r,u)).subscribe(i=H(n,(function(t){return n.next(e?e(r,t,u,s++):t)}),(function(){i=null,a()})))}),(function(){s=!0,a()})))}))}function Mt(t,e,r){var n=d(t)||e||r?{next:t,error:e,complete:r}:t;return n?B((function(t,e){var r;null===(r=n.subscribe)||void 0===r||r.call(n);var i=!0;t.subscribe(H(e,(function(t){var r;null===(r=n.next)||void 0===r||r.call(n,t),e.next(t)}),(function(){var t;i=!1,null===(t=n.complete)||void 0===t||t.call(n),e.complete()}),(function(t){var r;i=!1,null===(r=n.error)||void 0===r||r.call(n,t),e.error(t)}),(function(){var t,e;i&&(null===(t=n.unsubscribe)||void 0===t||t.call(n)),null===(e=n.finalize)||void 0===e||e.call(n)})))})):U}function Gt(t,e){void 0===e&&(e={});var r=e.selector,i=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(e,["selector"]);return new N((function(e){var o=new AbortController,s=o.signal,a=!0,u=i.signal;if(u)if(u.aborted)o.abort();else{var c=function(){s.aborted||o.abort()};u.addEventListener("abort",c),e.add((function(){return u.removeEventListener("abort",c)}))}var l=n(n({},i),{signal:s}),h=function(t){a=!1,e.error(t)};return fetch(t,l).then((function(t){r?vt(r(t)).subscribe(H(e,void 0,(function(){a=!1,e.complete()}),h)):(a=!1,e.next(t),e.complete())})).catch(h),function(){a&&o.abort()}}))}class Vt{constructor(t){this.token=t}urlBase64Decode(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("Illegal base64url string!")}return this.b64DecodeUnicode(e)}b64decode(t){let e="";if((t=String(t).replace(/=+$/,"")).length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let r,n,i=0,o=0;n=t.charAt(o++);~n&&(r=i%4?64*r+n:n,i++%4)?e+=String.fromCharCode(255&r>>(-2*i&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return e}b64DecodeUnicode(t){return decodeURIComponent(Array.prototype.map.call(this.b64decode(t),(t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2))).join(""))}decodeToken(t=this.token){if(null===t)return null;const e=t.split(".");if(3!==e.length)throw new Error("The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.");const r=this.urlBase64Decode(e[1]);if(!r)throw new Error("Cannot decode the token.");return JSON.parse(r)}getJWTUser(t=this.token){let e;try{e=this.decodeToken(t)}catch(t){return null}return e}getTokenExpirationDate(t=this.token){const e=this.getJWTUser(t);if(!e)return null;const r=new Date(0);return r.setUTCSeconds(e.exp),r}isTokenExpired(t=this.token,e){if(null===t||""===t)return!0;const r=this.getTokenExpirationDate(t);return e=e||0,null===r||r.valueOf()<=(new Date).valueOf()+1e3*e}}const Jt="JWT_KEY",Xt="JWT_REFRESH_KEY",qt=216e5;class Zt{constructor(t){this._isAuthenticated=new V(1),this.nuclia=t,this.nuclia.options.knowledgeBox?this._isAuthenticated.next(!0):this.checkTokenExpiration()}getAuthHeaders(){return this.nuclia.options.standalone?{"X-NUCLIADB-ROLES":"READER"}:this.nuclia.options.apiKey?{"X-STF-Serviceaccount":`Bearer ${this.nuclia.options.apiKey}`}:this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{}}isAuthenticated(){return this._isAuthenticated.asObservable()}hasLoggedOut(){return this.isAuthenticated().pipe((t=1,Yt((function(e,r){return t<=r}))),Yt((t=>!t)));var t}login(t,e,r){return this.fetch("/auth/login",{username:t,password:e},!1,r?{"X-STF-VALIDATION":r}:{}).pipe(kt((t=>this.authenticate(t))))}authenticate(t){return t.access_token?(this.storeTokens(t),this._isAuthenticated.next(!0),!0):(this._isAuthenticated.next(!1),!1)}logout(){this.fetch("/auth/logout",{},!0,{}).subscribe(),localStorage.removeItem(Jt),localStorage.removeItem(Xt),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Bt((t=>(this.logout(),St(t)))),kt((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return this.nuclia.options.public?"":localStorage.getItem(Jt)||""}setPassword(t){return this.fetch("/auth/setpassword",{password:t},!0,{}).pipe(kt((t=>this.authenticate(t))))}deleteAuthenticatedUser(){return this.nuclia.rest.delete("/user").pipe(Mt((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new Vt(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(Xt)||""}storeTokens(t){localStorage.setItem(Jt,t.access_token),localStorage.setItem(Xt,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const r=this.getToken();if(r){const n=null===(t=new Vt(r).getTokenExpirationDate())||void 0===t?void 0:t.getTime();if(n){const t=(new Date).getTime();if(n<t)this.logout();else{this._isAuthenticated.next(!0);const r=n-t<qt?0:qt;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Nt(r).pipe(Wt((()=>this.refresh()))).subscribe()}}else this._isAuthenticated.next(!1)}else this._isAuthenticated.next(!1)}fetch(t,e,r,n){const i=Object.assign({"content-type":"application/json"},n);return r&&(i.Authorization=`Bearer ${this.getToken()}`),Gt(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Wt((t=>t.ok?wt(t.clone().json()):St(t))))}}const Qt="NUCLIA_NUA_KEY",te="NUCLIA_NUA_CLIENT";var ee,re,ne,ie,oe,se,ae,ue;t.StatsPeriod=void 0,(ee=t.StatsPeriod||(t.StatsPeriod={})).DAY="day",ee.WEEK="week",ee.MONTH="month",ee.YEAR="year",t.StatsRange=void 0,(re=t.StatsRange||(t.StatsRange={})).anHour="1h",re.twoHours="2h",re.threeHours="3h",re.sixHours="6h",re.twelveHours="12h",re.twentyFourHours="24h",re.fortyHeightHours="48h",t.StatsType=void 0,(ne=t.StatsType||(t.StatsType={})).PROCESSING_TIME="processing_time",ne.SEARCHES="searches",ne.CHARS="chars",ne.MEDIA_SECONDS="media_seconds",ne.BYTES="bytes",ne.RESOURCES="resources",ne.PAGES="pages",ne.TRAIN_SECONDS="train_seconds",ne.SUGGESTIONS="suggestions",ne.DOCS_NO_MEDIA="docs_no_media",t.ResourceProperties=void 0,(ie=t.ResourceProperties||(t.ResourceProperties={})).BASIC="basic",ie.ORIGIN="origin",ie.RELATIONS="relations",ie.VALUES="values",ie.EXTRACTED="extracted",ie.ERRORS="errors",t.ResourceFieldProperties=void 0,(oe=t.ResourceFieldProperties||(t.ResourceFieldProperties={})).VALUE="value",oe.EXTRACTED="extracted",oe.ERROR="error",t.ExtractedDataTypes=void 0,(se=t.ExtractedDataTypes||(t.ExtractedDataTypes={})).TEXT="text",se.METADATA="metadata",se.LARGE_METADATA="large_metadata",se.VECTOR="vectors",se.LINK="link",se.FILE="file",t.LabelSetKind=void 0,(ae=t.LabelSetKind||(t.LabelSetKind={})).RESOURCES="RESOURCES",ae.PARAGRAPHS="PARAGRAPHS",t.EventType=void 0,(ue=t.EventType||(t.EventType={})).VISITED="VISITED",ue.MODIFIED="MODIFIED",ue.DELETED="DELETED",ue.NEW="NEW",ue.STARTED="STARTED",ue.STOPPED="STOPPED",ue.SEARCH="SEARCH",ue.PROCESSED="PROCESSED";const ce=524288,le=new RegExp(/[^a-z0-9_-]/g),he=(t,e,r,n,i={})=>(i.contentType||r instanceof ArrayBuffer||(i.contentType=null==r?void 0:r.type),i.filename||r instanceof ArrayBuffer||(i.filename=null==r?void 0:r.name),i.lang||r instanceof ArrayBuffer||(i.lang=r.lang),i.md5||r instanceof ArrayBuffer||(i.md5=r.md5),(r instanceof ArrayBuffer?_t(r):wt(r.arrayBuffer())).pipe(Wt((o=>n?pe(t,e,o,i,r.payload):de(t,e,o,i))))),de=(t,e,r,n)=>{const i=Object.assign({"content-type":(null==n?void 0:n.contentType)||"application/octet-stream"},be(n));let o=1;const s=(null==n?void 0:n.rslug)?`?rslug=${n.rslug}`:"";return t.rest.post(`${e}/upload${s}`,r,i).pipe(Kt(),Yt((t=>0==o--||503!==t.status)),zt(1),Wt((t=>{switch(t.status){case 201:return wt(t.json()).pipe(kt((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return _t({conflict:!0});default:return _t({failed:!0})}})))},pe=(t,e,r,n,i)=>{let o=0,s=!1;const a=r.byteLength,u=Math.ceil(a/ce),c={"upload-length":`${a}`,"tus-resumable":"1.0.0"},l=[];(null==n?void 0:n.filename)&&l.push(`filename ${btoa(encodeURIComponent(n.filename))}`),(null==n?void 0:n.lang)&&l.push(`language ${btoa(n.lang)}`),(null==n?void 0:n.md5)&&l.push(`md5 ${btoa(n.md5)}`),l.push(`content_type ${btoa((null==n?void 0:n.contentType)||"application/octet-stream")}`),l.length>0&&(c["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,c,!0).pipe(Kt(),Yt((t=>0==h--||503!==t.status)),Bt((t=>_t(t))),zt(1),Ht((e=>function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=it(t),n=ot(t,1/0),i=t;return i.length?1===i.length?vt(i[0]):jt(n)(wt(i,r)):tt}(_t(e).pipe(Yt((t=>201!==t.status||!t.headers.get("location"))),kt((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),_t(e).pipe(Yt((t=>201===t.status&&!!t.headers.get("location"))),kt((t=>t.headers.get("location"))),Ht((e=>function(t,e,r){if(null==e&&(e=t,t=0),e<=0)return tt;var n=e+t;return new N(r?function(e){var i=t;return r.schedule((function(){i<n?(e.next(i++),this.schedule()):e.complete()}))}:function(e){for(var r=t;r<n&&!e.closed;)e.next(r++);e.complete()})}(0,u).pipe(Ht((()=>{const i=r.slice(o,o+ce);return s?_t({failed:s}):t.rest.patch(e,i,{"content-type":(null==n?void 0:n.contentType)||"application/octet-stream","upload-offset":`${o}`,"content-length":`${i.byteLength}`},!0).pipe(kt((t=>200!==t.status?(s=!0,{failed:s}):(o+=ce,{completed:o>=a,progress:o>=a?100:Math.min(Math.floor(o/a*100),100)}))),Bt((()=>_t({failed:!0}))))}))))))))))},fe=(t,e,r,n=!1)=>{const i=Array.from(r),o=i.reduce(((t,e)=>t+(e.size||0)),0),s=[],a=i.map((t=>({file:t,progress:0,uploaded:!1,failed:!1}))),u=i.map((r=>{let i=e;if(n){let t=r.name.toLowerCase().replace(le,"_");s.includes(t)&&(t+="_"+s.filter((e=>e.startsWith(t))).length),s.push(t),i=`${i}/file/${t}`}const o=r.lang;if(o){const t=r.payload||{};r.payload=Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},null==t?void 0:t.metadata),{language:o})})}return he(t,i,r,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=it(t);return B((function(e,n){(r?Ct(t,e,r):Ct(t,e)).subscribe(n)}))}({progress:0,completed:!1}),kt((t=>({status:t,file:r}))))}));return wt(u).pipe(Lt((t=>t),6),kt((t=>{const e=a.find((e=>e.file===t.file));t.status.failed&&(e.failed=!0),t.status.conflict&&(e.conflicts=!0),t.status.completed&&(e.uploaded=!0),t.status.failed||t.status.conflict||t.status.completed?e.progress=100:e.progress=t.status.progress||0;const r=a.filter((t=>t.failed)).length,n=a.filter((t=>t.conflicts)).length,i=a.filter((t=>t.uploaded)).length,s=i+r===a.length,u=Math.round(a.reduce(((t,e)=>t+e.file.size*e.progress/100),0)/o*100);return{files:a,progress:u,completed:s,uploaded:i,failed:r,conflicts:n}})))},ve=(t,e,r)=>{const n=Object.assign({"x-stf-nuakey":`Bearer ${localStorage.getItem(Qt)}`,"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},be(r));return t.rest.post("/processing/upload",e,n)},be=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=encodeURIComponent(t.filename)),(null==t?void 0:t.md5)&&(e["x-md5"]=t.md5),(null==t?void 0:t.lang)&&(e["x-language"]=t.lang),e};var ge,ye,me,Ee;t.SHORT_FIELD_TYPE=void 0,(ge=t.SHORT_FIELD_TYPE||(t.SHORT_FIELD_TYPE={})).layout="l",ge.text="t",ge.file="f",ge.link="u",ge.datetime="d",ge.keywordset="k",ge.generic="a",ge.conversation="c",t.Search=void 0,ye=t.Search||(t.Search={}),(me=ye.Features||(ye.Features={})).PARAGRAPH="paragraph",me.DOCUMENT="document",me.RELATIONS="relations",me.VECTOR="vector",(Ee=ye.ResourceFeatures||(ye.ResourceFeatures={})).PARAGRAPH="paragraph",Ee.RELATIONS="relations",Ee.VECTOR="vector";const Te=(t,e,r,n,i=[],o,s)=>{var a;const u={};u.query=n||"",u.features=i;const c=o||{},{inTitleOnly:l}=c,h=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(c,["inTitleOnly"]);l&&(u.fields=["a/title"]),u.shards=(null===(a=t.currentShards)||void 0===a?void 0:a[e])||[];return(s?t.rest.get(`${r}/search?${_e(u,h)}`):t.rest.post(`${r}/search`,Object.assign(Object.assign({},u),h))).pipe(Bt((()=>_t({error:!0}))),kt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((r=>{r.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:r.shards}))})))},we=(t,e,r,n)=>{var i;const o={};o.query=r||"",o.shards=(null===(i=t.currentShards)||void 0===i?void 0:i[e])||[];return t.rest.get(`/kb/${e}/catalog?${n?_e(o,n):""}`).pipe(Bt((()=>_t({error:!0}))),kt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((r=>{r.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:r.shards}))})))},_e=(t,e)=>{Object.entries(e||{}).forEach((([e,r])=>{null!=r&&(Array.isArray(r)?t[e]=r.map((t=>`${t}`)):"object"==typeof r?Object.entries(r).forEach((([r,n])=>t[`${e}_${r}`]=`${n}`)):t[e]=`${r}`)}));const r=new URLSearchParams;return Object.entries(t).forEach((([t,e])=>Array.isArray(e)?e.forEach((e=>r.append(t,e))):r.append(t,e))),r.toString()},Se=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),xe=(t,e,r,n,i)=>{const o=Se(i.filter((r=>Ae(r,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=Se(i.filter((r=>$e(r,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])).filter((t=>t.key!==r)),a=i.filter((r=>r.field.field!==t||r.field.field_type!==e)),u=n.length>0?[...s,{key:r,classifications:n}]:s;return o.length>0||u.length>0?[...a,{field:{field:t,field_type:e},token:o.length>0?o:void 0,paragraphs:u.length>0?u:void 0}]:a},ke=(t,e,r,n)=>{const i=Se(n.filter((r=>$e(r,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])),o=n.filter((r=>r.field.field!==t||r.field.field_type!==e));return r.length>0||i.length>0?[...o,{field:{field:t,field_type:e},token:r.length>0?r:void 0,paragraphs:i.length>0?i:void 0}]:o},Ae=(t,e,r)=>t.field.field===e&&t.field.field_type===r&&t.token&&t.token.length>0,$e=(t,e,r)=>t.field.field===e&&t.field.field_type===r&&t.paragraphs&&t.paragraphs.length>0,Oe=(t,e,r)=>t?(Array.isArray(t)||(t=Array.from(t)),t.slice(e,r).join("")):"";class Re{constructor(t){this.data={},this.fieldTextsCache={},t.data||(t.data={}),Object.assign(this,Object.assign(Object.assign({},t),{title:this.formatTitle(t.title)}))}getFields(t=["files","links","texts","keywordsets"]){return Object.entries(this.data).filter((([e])=>t.includes(e))).map((([,t])=>t)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}getFieldData(t,e){var r;const n=null===(r=this.data[t])||void 0===r?void 0:r[e];return n||void 0}getExtractedSummaries(){return this.getFields().filter((t=>{var e,r,n;return null===(n=null===(r=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===r?void 0:r.metadata)||void 0===n?void 0:n.summary})).map((t=>t.extracted.metadata.metadata.summary))}getExtractedTexts(){return this.getFields().filter((t=>{var e;return null===(e=t.extracted)||void 0===e?void 0:e.text})).map((t=>t.extracted.text))}getFiles(){return this.getFields(["files"]).filter((t=>!!t&&!!t.value&&!!t.value.file)).map((t=>t.value.file))}getThumbnails(){return this.getFields(["files"]).map((t=>{var e,r;return null===(r=null===(e=t.extracted)||void 0===e?void 0:e.file)||void 0===r?void 0:r.file_thumbnail})).concat(this.getFields(["links"]).map((t=>{var e,r;return null===(r=null===(e=t.extracted)||void 0===e?void 0:e.link)||void 0===r?void 0:r.link_thumbnail}))).filter((t=>!!t))}getAnnotatedEntities(){return(this.fieldmetadata||[]).filter((t=>t.token&&t.token.length>0)).map((t=>t.token)).reduce(((t,e)=>(e.filter((t=>!t.cancelled_by_user)).forEach((e=>{t[e.klass]||(t[e.klass]=[]),t[e.klass].push(e.token)})),t)),{})}getNamedEntities(){return this.getFields().filter((t=>{var e,r,n;return null===(n=null===(r=null===(e=t.extracted)||void 0===e?void 0:e.metadata)||void 0===r?void 0:r.metadata)||void 0===n?void 0:n.ner})).map((t=>Object.entries(t.extracted.metadata.metadata.ner).reduce(((t,[e,r])=>(t[r]=(t[r]||[]).concat([e]),t)),{}))).reduce(((t,e)=>(Object.entries(e).forEach((([e,r])=>{t[e]=(t[e]||[]).concat(r)})),t)),{})}getClassifications(){var t,e,r;const n=((null===(t=this.usermetadata)||void 0===t?void 0:t.classifications)||[]).filter((t=>!t.cancelled_by_user)),i=((null===(e=this.usermetadata)||void 0===e?void 0:e.classifications)||[]).filter((t=>t.cancelled_by_user));return((null===(r=this.computedmetadata)||void 0===r?void 0:r.field_classifications)||[]).reduce(((t,e)=>(e.classifications.forEach((e=>{const r=t.find((t=>t.label===e.label&&t.labelset===e.labelset)),n=i.find((t=>t.label===e.label&&t.labelset===e.labelset));r||n||t.push(Object.assign(Object.assign({},e),{immutable:!0}))})),t)),n)}getPositionedNamedEntities(t,e){var r,n,i,o;const s=null===(o=null===(i=null===(n=null===(r=this.data[t])||void 0===r?void 0:r[e])||void 0===n?void 0:n.extracted)||void 0===i?void 0:i.metadata)||void 0===o?void 0:o.metadata.positions;return s?Object.entries(s).reduce(((t,[e,r])=>{const n=e.split("/")[0];return r.position.forEach((e=>{t.push(Object.assign({entity:r.entity,family:n},e))})),t}),[]):[]}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}getParagraphText(t,e,r){return Oe(this.getFieldText(t,e),r.start,r.end)}getSentenceText(t,e,r){return Oe(this.getFieldText(t,e),r.start,r.end)}getFieldText(t,e){var r,n;const i=`${t}-${e}`;if(!this.fieldTextsCache[i]){const o=this.getFieldData(`${t}s`,e);this.fieldTextsCache[i]=Array.from((null===(n=null===(r=null==o?void 0:o.extracted)||void 0===r?void 0:r.text)||void 0===n?void 0:n.text)||"")}return this.fieldTextsCache[i]}}class Ie extends Re{constructor(t,e,r){super(r),this.nuclia=t,this.kb=e,this.uuid=r.id}get path(){if(!this.uuid&&!this.slug)throw new Error("Resource must have either uuid or slug");return this.uuid?`/kb/${this.kb}/resource/${this.uuid}`:`/kb/${this.kb}/slug/${this.slug}`}modify(t,e=!0){return this.nuclia.rest.patch(this.path,t,void 0,void 0,e)}delete(t=!0){return this.nuclia.rest.delete(this.path,void 0,t)}reprocess(){return this.nuclia.rest.post(`${this.path}/reprocess`,{},void 0,void 0,!0)}getField(e,r,n=[t.ResourceFieldProperties.VALUE],i=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){const o=[...n.map((t=>`show=${t}`)),...i.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this.path}/${e}/${r}?${o.join("&")}`)}getThumbnailsUrl(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=nt(t),n=Dt(t),i=n.args,o=n.keys,s=new N((function(t){var e=i.length;if(e)for(var r=new Array(e),n=e,s=e,a=function(e){var a=!1;vt(i[e]).subscribe(H(t,(function(t){a||(a=!0,s--),r[e]=t}),(function(){return n--}),void 0,(function(){n&&a||(s||t.next(o?Ft(o,r):r),t.complete())})))},u=0;u<e;u++)a(u);else t.complete()}));return r?s.pipe($t(r)):s}(this.getThumbnails().filter((t=>t.uri)).map((t=>this.nuclia.rest.getObjectURL(t.uri))))}deleteField(t,e){return this.nuclia.rest.delete(`${this.path}/${t}/${e}`)}addField(t,e,r){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,r)}updateField(t,e,r){return this.nuclia.rest.put(`${this.path}/${t}/${e}`,r)}upload(t,e,r,n){return he(this.nuclia,`${this.path}/file/${t}`,e,!!r,n)}batchUpload(t){return fe(this.nuclia,this.path,t,!0)}search(t,e=[],r){return Te(this.nuclia,this.kb,this.path,t,e,r,!0)}setLabels(t,e,r,n){const i=xe(t,e,r,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Mt((()=>this.fieldmetadata=i)))}setEntities(t,e,r){const n=ke(t,e,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:n}).pipe(Mt((()=>this.fieldmetadata=n)))}}var Pe,De;t.FIELD_TYPE=void 0,(Pe=t.FIELD_TYPE||(t.FIELD_TYPE={})).text="text",Pe.file="file",Pe.link="link",Pe.layout="layout",Pe.conversation="conversation",Pe.keywordset="keywordset",Pe.datetime="datetime",t.RESOURCE_STATUS=void 0,(De=t.RESOURCE_STATUS||(t.RESOURCE_STATUS={})).PENDING="PENDING",De.PROCESSED="PROCESSED",De.ERROR="ERROR";var Fe,Le,je;t.TrainingType=void 0,(Fe=t.TrainingType||(t.TrainingType={})).classifier="classifier",Fe.resource_labeler="resource-labeler",Fe.paragraph_labeler="paragraph-labeler",Fe.ner="ner",t.TrainingStatus=void 0,(Le=t.TrainingStatus||(t.TrainingStatus={})).finished="finished",Le.not_running="not_running",Le.running="running",Le.started="started",Le.stopped="stopped",t.TrainingExecutionStatus=void 0,(je=t.TrainingExecutionStatus||(t.TrainingExecutionStatus={})).succeeded="succeeded",je.failed="failed",je.stopped="stopped";class Ue{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e||{})}stop(t){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/stop`,{})}getStatus(e){return this.nuclia.rest.get(`${this.kb.path}/train/${e}/inspect`).pipe(Bt((()=>_t({task:"",status:t.TrainingStatus.not_running}))))}getExecutions(t=0){return this.nuclia.rest.get(`${this.kb.path}/train/executions?page=${t}`)}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/model/nuclia.json`).pipe(kt((()=>!0)),Bt((()=>_t(!1))))}}class Ce{constructor(t,e,r){this.nuclia=t,this.account=e,Object.assign(this,r)}get path(){return`/kb/${this.id}`}get fullpath(){return`${this.nuclia.regionalBackend}/v1/kb/${this.id}`}getEntities(t=!1){return this.nuclia.rest.get(`${this.path}/entitiesgroups?show_entities=${t}`).pipe(kt((t=>t.groups)))}getEntitiesGroup(t){return this.nuclia.rest.get(`${this.path}/entitiesgroup/${t}`)}getLabels(){return this.nuclia.rest.get(`${this.path}/labelsets`).pipe(kt((t=>(null==t?void 0:t.labelsets)||{})))}getResource(e,r=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],n=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){return this._getResource(e,void 0,r,n)}getResourceBySlug(e,r=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],n=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){return this._getResource(void 0,e,r,n)}_getResource(e,r,n=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],i=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){const o=[...n.map((t=>`show=${t}`)),...i.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this._getPath(e,r)}?${o.join("&")}`).pipe(kt((t=>new Ie(this.nuclia,this.id,t))))}_getPath(t,e){return t?`${this.path}/resource/${t}`:`${this.path}/slug/${e}`}getResourceFromData(t){return new Ie(this.nuclia,this.id,t)}search(t,e=[],r){return Te(this.nuclia,this.id,this.path,t,e,r)}catalog(t,e){return we(this.nuclia,this.id,t,e)}suggest(t,e=!1){const r=`query=${encodeURIComponent(t)}${e?"&fields=a/title":""}`;return this.nuclia.rest.get(`${this.path}/suggest?${r}`).pipe(Bt((()=>_t({error:!0}))),kt((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}counters(){return this.nuclia.rest.get(`/kb/${this.id}/counters`)}listResources(t,e){const r=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${r?"?"+r:""}`).pipe(kt((t=>({resources:t.resources.map((t=>new Ie(this.nuclia,this.id,t))),pagination:t.pagination}))))}getTempToken(){if(!this.nuclia.options.account||!this.nuclia.options.kbSlug)throw new Error("Account and KB slug are required to get a temp token");return this.nuclia.rest.post(`/account/${this.nuclia.options.account}/kb/${this.nuclia.options.kbSlug}/ephemeral_tokens`,{}).pipe(kt((t=>t.token)))}listActivity(t,e,r){const n=[t?`type=${t}`:"",e?`page=${e}`:"",r?`size=${r}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/activity${n?"?"+n:""}`)}}class Ne extends Ce{get training(){return this._training||(this._training=new Ue(this,this.nuclia)),this._training}modify(t){return this.nuclia.rest.patch(`/account/${this.account}/kb/${this.slug}`,t)}publish(t){return this.modify({state:t?"PUBLISHED":"PRIVATE"})}delete(){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}`)}setEntitiesGroup(t,e){return this.nuclia.rest.post(`${this.path}/entitiesgroup/${t}`,e)}deleteEntitiesGroup(t){return this.nuclia.rest.delete(`${this.path}/entitiesgroup/${t}`)}setLabelSet(t,e){return this.nuclia.rest.post(`${this.path}/labelset/${t}`,e)}deleteLabelSet(t){return this.nuclia.rest.delete(`${this.path}/labelset/${t}`)}createResource(t,e=!0){return this.nuclia.rest.post(`${this.path}/resources`,t,void 0,void 0,e)}createLinkResource(t,e,r=!0,n){return this.createResource(Object.assign({links:{link:t},usermetadata:e,title:t.uri,icon:"application/stf-link"},n?{origin:n}:{}),r)}hasResource(t){return this.nuclia.rest.get(`${this.path}/slug/${t}`).pipe(kt((()=>!0)),Bt((()=>_t(!1))))}createOrUpdateResource(t,e=!0){return(t.slug?this.hasResource(t.slug):_t(!1)).pipe(Wt((r=>r?this.getResourceFromData({id:"",slug:t.slug}).modify(t,e):this.createResource(t,e))))}upload(t,e,r){return he(this.nuclia,`/kb/${this.id}`,t,!!e,r)}batchUpload(t){return fe(this.nuclia,`/kb/${this.id}`,t,!1)}getServiceAccounts(){return this.nuclia.rest.get(`/account/${this.account}/kb/${this.slug}/service_accounts`)}createServiceAccount(t){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_accounts`,t)}deleteServiceAccount(t){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}`)}createKey(t,e){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_account/${t}/keys`,{expires:e})}deleteKey(t,e){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}/key/${e}`)}}class Ye{constructor(t){this.nuclia=t}getAccounts(){return this.nuclia.rest.get("/accounts")}createAccount(t){return this.nuclia.rest.post("/accounts",t)}modifyAccount(t,e){return this.nuclia.rest.patch(`/account/${t}`,e)}deleteAccount(t){return this.nuclia.rest.delete(`/account/${t}`)}getAccountStatus(t){return this.nuclia.rest.get(`/account/${t}/status`)}getWelcome(){return this.nuclia.rest.get("/user/welcome")}getAccount(t){if(!(t=t||this.nuclia.options.account))throw new Error("Account is not set");return this.nuclia.rest.get(`/account/${t}`)}getKnowledgeBoxes(t){return this.nuclia.rest.get(`/account/${t}/kbs`)}getKnowledgeBox(t,e){if(t=t||this.nuclia.options.account){const r=e||this.nuclia.options.knowledgeBox||this.nuclia.options.kbSlug;if(!r)throw new Error("account and knowledgeBox must be defined in the Nuclia options");return this.nuclia.rest.get(`/account/${t}/kb/${r}`).pipe(Wt((t=>this.nuclia.options.zone?_t(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Mt((t=>this.nuclia.options.zone=t)),kt((()=>t))))),kt((e=>new Ne(this.nuclia,t,e))))}if(!this.nuclia.options.knowledgeBox||!this.nuclia.options.zone)throw new Error("zone must be defined in the Nuclia options");return _t(new Ne(this.nuclia,"",{id:this.nuclia.options.knowledgeBox,zone:this.nuclia.options.zone}))}createKnowledgeBox(t,e){return this.nuclia.rest.post(`/account/${t}/kbs`,e).pipe(Mt((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Wt((()=>this.getKnowledgeBox(t,e.slug))))}getStats(e,r,n,i=t.StatsPeriod.DAY,o){const s=[`period=${i}`,`stats=${r}`];return o&&s.push(`utctime=${o}`),n&&s.push(`knowledgebox=${n}`),this.nuclia.rest.get(`/account/${e}/stats?${s.join("&")}`).pipe(kt((t=>t.data)),Yt((t=>!!t)))}upload(t){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return ve(this.nuclia,t,{md5:t.md5}).pipe(Wt((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},this.getNUAHeader()))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /processing");return this.nuclia.rest.get("/processing/pull",this.getNUAHeader())}getProcessingStatus(t){if(!t){if(!this.hasNUAClient())throw new Error("NUA key or account id is needed to be able to call /processing/status")}const e=t?`/processing/status?account_id=${t}`:"/processing/status",r=t?void 0:this.getNUAHeader();return this.nuclia.rest.get(e,r)}getProcessingStats(t,e){const r=this.hasNUAClient();if(!e&&!r)throw new Error("NUA key or account id is needed to be able to call /processing/stats");const n=r?"/processing/stats"+(t?"?period="+t:""):`/processing/stats?account_id=${e}${t?"&period="+t:""}`,i=r?this.getNUAHeader():void 0;return this.nuclia.rest.get(n,i).pipe(kt((t=>t.data)))}getNUAActivity(t,e,r=0){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}/activity?page=${r}`)}getNUAClients(t){return this.nuclia.rest.get(`/account/${t}/nua_clients`).pipe(kt((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(te)&&!!localStorage.getItem(Qt)}getNUAHeader(){return{"x-stf-nuakey":`Bearer ${localStorage.getItem(Qt)}`}}createNUAClient(t,e){const r=Object.assign({},e);return r.webhook&&(r.processing_webhook={uri:r.webhook},delete r.webhook),this.nuclia.rest.post(`/account/${t}/nua_clients`,r).pipe(Bt((r=>{if(409===r.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw r})),Mt((t=>{"desktop"===this.nuclia.options.client&&(localStorage.setItem(Qt,t.token),localStorage.setItem(te,t.client_id))})))}renewNUAClient(t,e){return this.nuclia.rest.put(`/account/${t}/nua_client/${e}/key`,{})}deleteNUAClient(t,e){return this.nuclia.rest.delete(`/account/${t}/nua_client/${e}`)}}class Be{constructor(t){this.nuclia=t}get(t,e,r){return this.fetch("GET",t,void 0,e,r)}post(t,e,r,n,i){return this.fetch("POST",t,e,r,n,i)}put(t,e,r,n,i){return this.fetch("PUT",t,e,r,n,i)}patch(t,e,r,n,i){return this.fetch("PATCH",t,e,r,n,i)}delete(t,e,r){return this.fetch("DELETE",t,void 0,e,!0,r)}head(t,e){return this.fetch("HEAD",t,void 0,e,!0)}getHeaders(t,e=!1){const r=t&&t["x-stf-nuakey"]?{}:this.nuclia.auth.getAuthHeaders(),n=Object.assign({"content-type":"application/json","x-ndb-client":this.nuclia.options.client||"web"},r);return e&&(n["x-synchronous"]=`${e}`),Object.assign(Object.assign({},n),t)}fetch(t,e,r,n,i,o=!1){const s=n&&n["content-type"];return Gt(this.getFullUrl(e),{selector:t=>Promise.resolve(t),headers:this.getHeaders(n,o),method:t,body:s?r:JSON.stringify(r)}).pipe(Wt((t=>t.ok?i?_t(t):wt(t.clone().json().catch((()=>t.text()))):St((()=>t)))))}getFullUrl(t){return`${t.startsWith("/account")||t.startsWith("/user")||t.startsWith("/auth")||t.startsWith("/zones")||t.includes("/activity")||this.nuclia.options.standalone?this.nuclia.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")||t.startsWith("/export")?"":"/v1"}${t}`}getZones(){return this.zones?_t(this.zones):this.get("/zones").pipe(kt((t=>{const e=t.reduce(((t,e)=>(t[e.id]=e.slug,t)),{});return this.zones=e,e})))}getZoneSlug(t){return this.getZones().pipe(kt((e=>e[t])))}getObjectURL(t){return this.get(t,void 0,!0).pipe(Wt((t=>wt(t.blob()))),kt((t=>URL.createObjectURL(t))))}}t.Authentication=Zt,t.Db=Ye,t.FileFieldData=class{},t.JwtHelper=Vt,t.KeywordSetFieldData=class{},t.KnowledgeBox=Ce,t.LinkFieldData=class{},t.NUA_CLIENT=te,t.NUA_KEY=Qt,t.Nuclia=class{constructor(t){this.currentShards={},this.options=t,this.auth=new Zt(this),this.rest=new Be(this),this.db=new Ye(this)}get backend(){return this.options.backend}get regionalBackend(){return this.options.backend.replace("//",`//${this.options.zone}.`)}get knowledgeBox(){if(!this.options.knowledgeBox||!this.options.zone)throw new Error("zone and knowledge box id must be defined in the Nuclia options");return this.readKb||(this.readKb=new Ce(this,"",{id:this.options.knowledgeBox,zone:this.options.zone})),this.readKb}get asyncKnowledgeBox(){return new Proxy(this.knowledgeBox,{get(t,e){const r=Reflect.get(t,e);return"function"==typeof r?(...e)=>function(t,e){var r="object"==typeof e;return new Promise((function(n,i){var o=new P({next:function(t){n(t),o.unsubscribe()},error:i,complete:function(){r?n(e.defaultValue):i(new xt)}});t.subscribe(o)}))}(r.bind(t)(...e)):r}})}},t.ReadableResource=Re,t.Resource=Ie,t.Rest=Be,t.TUSuploadFile=pe,t.TextFieldData=class{},t.Training=Ue,t.WritableKnowledgeBox=Ne,t.batchUpload=fe,t.catalog=we,t.deDuplicateList=Se,t.getDataKeyFromFieldType=e=>{switch(e){case t.FIELD_TYPE.text:case t.FIELD_TYPE.file:case t.FIELD_TYPE.link:case t.FIELD_TYPE.keywordset:return`${e}s`;default:return null}},t.getFieldTypeFromString=function(e){switch(e){case t.FIELD_TYPE.file:return t.FIELD_TYPE.file;case t.FIELD_TYPE.link:return t.FIELD_TYPE.link;case t.FIELD_TYPE.text:return t.FIELD_TYPE.text;case t.FIELD_TYPE.layout:return t.FIELD_TYPE.layout;case t.FIELD_TYPE.conversation:return t.FIELD_TYPE.conversation;case t.FIELD_TYPE.datetime:return t.FIELD_TYPE.datetime;default:return null}},t.getFileMetadata=be,t.getFilterFromLabel=function(t){return`/l/${t.labelset}/${t.label}`},t.getLabelFromFilter=function(t){const e=t.split("/");return{labelset:e[2],label:e[3]}},t.lengthUnicode=t=>t?Array.from(t).length:0,t.longToShortFieldType=function(e){return t.SHORT_FIELD_TYPE[e]},t.resourceToAlgoliaFormat=(t,e)=>{const r={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};t.getClassifications().forEach((t=>{t.labelset&&t.label&&(r[t.labelset]=t.label)}));const n=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},r),{images:n}),t.getNamedEntities())},t.search=Te,t.setEntities=ke,t.setLabels=xe,t.shortToLongFieldType=function(e){switch(e){case t.SHORT_FIELD_TYPE.conversation:return t.FIELD_TYPE.conversation;case t.SHORT_FIELD_TYPE.datetime:return t.FIELD_TYPE.datetime;case t.SHORT_FIELD_TYPE.file:return t.FIELD_TYPE.file;case t.SHORT_FIELD_TYPE.layout:return t.FIELD_TYPE.layout;case t.SHORT_FIELD_TYPE.keywordset:return t.FIELD_TYPE.keywordset;case t.SHORT_FIELD_TYPE.link:return t.FIELD_TYPE.link;case t.SHORT_FIELD_TYPE.text:return t.FIELD_TYPE.text;default:return null}},t.sliceUnicode=Oe,t.upload=he,t.uploadFile=de,t.uploadToProcess=ve})); |
@@ -0,5 +1,5 @@ | ||
export * from './lib/auth'; | ||
export * from './lib/core'; | ||
export * from './lib/db'; | ||
export * from './lib/models'; | ||
export * from './lib/auth'; | ||
export * from './lib/db'; | ||
export * from './lib/rest'; |
@@ -5,3 +5,3 @@ import { Observable } from 'rxjs'; | ||
import type { INuclia } from '../../models'; | ||
import type { ICreateResource, IResource, LinkField, UserMetadata } from '../resource'; | ||
import type { ICreateResource, IResource, LinkField, Origin, UserMetadata } from '../resource'; | ||
import { Resource } from '../resource'; | ||
@@ -26,2 +26,3 @@ import type { UploadResponse } from '../upload'; | ||
private _getResource; | ||
private _getPath; | ||
getResourceFromData(data: IResource): Resource; | ||
@@ -51,3 +52,3 @@ search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
}>; | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean): Observable<{ | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean, origin?: Origin): Observable<{ | ||
uuid: string; | ||
@@ -54,0 +55,0 @@ }>; |
import type { Observable } from 'rxjs'; | ||
import type { IResource, LinkField, Resource, UserMetadata } from '../resource'; | ||
import type { IResource, LinkField, Origin, Resource, UserMetadata } from '../resource'; | ||
import type { FileMetadata, FileWithMetadata, UploadResponse, UploadStatus } from '../upload'; | ||
@@ -15,2 +15,7 @@ import type { Search, SearchOptions } from '../search'; | ||
} | ||
export declare enum ResourceFieldProperties { | ||
VALUE = "value", | ||
EXTRACTED = "extracted", | ||
ERROR = "error" | ||
} | ||
export declare enum ExtractedDataTypes { | ||
@@ -55,3 +60,4 @@ TEXT = "text", | ||
getLabels(): Observable<LabelSets>; | ||
getResource(uuid: string): Observable<IResource>; | ||
getResource(uuid: string, show?: ResourceProperties[], extracted?: ExtractedDataTypes[]): Observable<IResource>; | ||
getResourceBySlug(slug: string, show?: ResourceProperties[], extracted?: ExtractedDataTypes[]): Observable<IResource>; | ||
search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
@@ -78,3 +84,3 @@ catalog(query: string, options?: SearchOptions): Observable<Search.Results>; | ||
}>; | ||
createLinkResource(link: LinkField, metadata?: UserMetadata): Observable<{ | ||
createLinkResource(link: LinkField, metadata?: UserMetadata, synchronous?: boolean, origin?: Origin): Observable<{ | ||
uuid: string; | ||
@@ -81,0 +87,0 @@ }>; |
@@ -7,2 +7,3 @@ import { Observable } from 'rxjs'; | ||
import type { Search, SearchOptions } from '../search'; | ||
import { ExtractedDataTypes, ResourceFieldProperties } from '../kb'; | ||
export interface ReadableResource extends IResource { | ||
@@ -42,3 +43,3 @@ } | ||
reprocess(): Observable<void>; | ||
getField(type: FIELD_TYPE, field: string): Observable<ResourceField>; | ||
getField(type: FIELD_TYPE, field: string, show?: ResourceFieldProperties[], extracted?: ExtractedDataTypes[]): Observable<ResourceField>; | ||
getThumbnailsUrl(): Observable<string[]>; | ||
@@ -45,0 +46,0 @@ deleteField(type: FIELD_TYPE, field: string): Observable<void>; |
@@ -16,2 +16,3 @@ import type { Resource } from './resource'; | ||
export declare function shortToLongFieldType(shortType: SHORT_FIELD_TYPE): FIELD_TYPE | null; | ||
export declare function getFieldTypeFromString(type: string): FIELD_TYPE | null; | ||
export {}; |
@@ -101,3 +101,3 @@ export interface IResource { | ||
tags?: string[]; | ||
colaborators?: string[]; | ||
collaborators?: string[]; | ||
filename?: string; | ||
@@ -104,0 +104,0 @@ related?: string[]; |
import type { ExtractedDataTypes, ResourceProperties } from '../kb'; | ||
import type { FIELD_TYPE, FieldId, IResource, RelationEntityType, RelationType } from '../resource'; | ||
import type { FIELD_TYPE, FieldId, IFieldData, IResource, RelationEntityType, RelationType } from '../resource'; | ||
export declare type ResourceStatus = 'PENDING' | 'PROCESSED' | 'ERROR'; | ||
@@ -15,2 +15,3 @@ export declare type SortOrder = 'asc' | 'desc'; | ||
filters?: string[]; | ||
fields?: string[]; | ||
sort?: SortOption; | ||
@@ -72,2 +73,3 @@ page_number?: number; | ||
field?: FieldId; | ||
fieldData?: IFieldData; | ||
} | ||
@@ -74,0 +76,0 @@ interface SmartParagraph extends Paragraph { |
@@ -37,2 +37,3 @@ import { Observable } from 'rxjs'; | ||
md5?: string; | ||
rslug?: string; | ||
} | ||
@@ -39,0 +40,0 @@ export declare const upload: (nuclia: INuclia, path: string, data: File | FileWithMetadata | ArrayBuffer, TUS: boolean, metadata?: FileMetadata) => Observable<UploadResponse>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254875
4388