@nuclia/core
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,3 +0,14 @@ | ||
# 1.1.2 (unreleased) | ||
# 1.1.2 (2023-01-20) | ||
### Bugfix | ||
- Remove the sentence labelset type | ||
### Improvements | ||
- Add `filename` and `md5` in `CloudLink` model | ||
- Add `updateField` method on resource | ||
- Allow to get suggestions based on title only | ||
- Sort option on search is now an object. Add corresponding `SortOption` interface and `SortOrder` type in our model. | ||
# 1.1.1 (2023-01-03) | ||
@@ -4,0 +15,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{c(r.next(t))}catch(t){o(t)}}function u(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}c((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 c(t){return this instanceof c?(this.v=t,this):new c(t)}function a(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 c?Promise.resolve(n.value.v).then(a,l):h(o[0][2],n)}catch(t){h(o[0][3],t)}var n}function a(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 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 d=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 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 c=this._parentage;if(c)if(this._parentage=null,Array.isArray(c))try{for(var a=o(c),l=a.next();!l.done;l=a.next()){l.value.remove(this)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else c.remove(this);var f=this.initialTeardown;if(h(f))try{f()}catch(t){i=t instanceof d?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 d?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 d(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 _(){}var S=x("C",void 0,void 0);function x(t,e,n){return{kind:t,value:e,error:n}}function A(t){t()}var k=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=C,n}return e(n,t),n.create=function(t,e,n){return new I(t,e,n)},n.prototype.next=function(t){this.isStopped?N(function(t){return x("N",t,void 0)}(t),this):this._next(t)},n.prototype.error=function(t){this.isStopped?N(x("E",void 0,t),this):(this.isStopped=!0,this._error(t))},n.prototype.complete=function(){this.isStopped?N(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 $(t,e){return T.call(t,e)}var O=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){R(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){R(t)}else R(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){R(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&&$(e.next,o),error:e.error&&$(e.error,o),complete:e.complete&&$(e.complete,o)}):i=e;return s.destination=new O(i),s}return e(n,t),n}(k);function R(t){E(t)}function N(t,e){var n=m.onStoppedNotification;n&&w.setTimeout((function(){return n(t,e)}))}var C={closed:!0,next:_,error:function(t){throw t},complete:_},j="function"==typeof Symbol&&Symbol.observable||"@@observable";function U(t){return t}function P(t){return 0===t.length?U:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var D=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 k||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=L(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[j]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return P(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=L(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 L(t){var e;return null!==(e=null!=t?t:m.Promise)&&void 0!==e?e:Promise}function B(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 F(t,e,n,r,i){return new z(t,e,n,r,i)}var z=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),H=f((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 K(this,this);return e.operator=t,e},n.prototype._throwIfClosed=function(){if(this.closed)throw new H},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 D;return t.source=this,t},n.create=function(t,e){return new K(t,e)},n}(D),K=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),M={now:function(){return(M.delegate||Date).now()},delegate:void 0},G=function(t){function n(e,n,r){void 0===e&&(e=1/0),void 0===n&&(n=1/0),void 0===r&&(r=M);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,c=1;c<r.length&&r[c]<=s;c+=2)u=c;u&&r.splice(0,u+1)}},n}(W),J=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),Y={setInterval:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=Y.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=Y.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},V=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),Y.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;Y.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}(J),X=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=M.now,t}(),q=new(function(t){function n(e,n){void 0===n&&(n=X.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}(X))(V),Z=new D((function(t){return t.complete()}));function Q(t){return t&&h(t.schedule)}function tt(t){return t[t.length-1]}function et(t){return h(tt(t))?t.pop():void 0}function nt(t){return Q(tt(t))?t.pop():void 0}function rt(t,e){return"number"==typeof tt(t)?t.pop():e}var it=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function ot(t){return h(null==t?void 0:t.then)}function st(t){return h(t[j])}function ut(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 at="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function lt(t){return h(null==t?void 0:t[at])}function ht(t){return a(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,c(e.read())];case 3:return n=i.sent(),r=n.value,n.done?[4,c(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,c(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 dt(t){if(t instanceof D)return t;if(null!=t){if(st(t))return i=t,new D((function(t){var e=i[j]();if(h(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(it(t))return r=t,new D((function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()}));if(ot(t))return n=t,new D((function(t){n.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,E)}));if(ut(t))return pt(t);if(lt(t))return e=t,new D((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 pt(ht(t))}var e,n,r,i;throw ct(t)}function pt(t){return new D((function(e){(function(t,e){var n,o,s,u;return r(this,void 0,void 0,(function(){var r,c;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 c=i.sent(),s={error:c},[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 vt(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 bt(t,e){return void 0===e&&(e=0),B((function(n,r){n.subscribe(F(r,(function(n){return vt(r,t,(function(){return r.next(n)}),e)}),(function(){return vt(r,t,(function(){return r.complete()}),e)}),(function(n){return vt(r,t,(function(){return r.error(n)}),e)})))}))}function gt(t,e){return void 0===e&&(e=0),B((function(n,r){r.add(t.schedule((function(){return n.subscribe(r)}),e))}))}function yt(t,e){if(!t)throw new Error("Iterable cannot be null");return new D((function(n){vt(n,e,(function(){var r=t[Symbol.asyncIterator]();vt(n,e,(function(){r.next().then((function(t){t.done?n.complete():n.next(t.value)}))}),0,!0)}))}))}function mt(t,e){if(null!=t){if(st(t))return function(t,e){return dt(t).pipe(gt(e),bt(e))}(t,e);if(it(t))return function(t,e){return new D((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(ot(t))return function(t,e){return dt(t).pipe(gt(e),bt(e))}(t,e);if(ut(t))return yt(t,e);if(lt(t))return function(t,e){return new D((function(n){var r;return vt(n,e,(function(){r=t[at](),vt(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 yt(ht(t),e)}(t,e)}throw ct(t)}function wt(t,e){return e?mt(t,e):dt(t)}function Et(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t);return wt(t,n)}function _t(t,e){var n=h(t)?t:function(){return t},r=function(t){return t.error(n())};return new D(e?function(t){return e.schedule(r,0,t)}:r)}var St=f((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function xt(t,e){return B((function(n,r){var i=0;n.subscribe(F(r,(function(n){r.next(t.call(e,n,i++))})))}))}var At=Array.isArray;function kt(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,$t=Object.getPrototypeOf,Ot=Object.prototype,It=Object.keys;function Rt(t){if(1===t.length){var e=t[0];if(Tt(e))return{args:e,keys:null};if((r=e)&&"object"==typeof r&&$t(r)===Ot){var n=It(e);return{args:n.map((function(t){return e[t]})),keys:n}}}var r;return{args:t,keys:null}}function Nt(t,e){return t.reduce((function(t,n,r){return t[n]=e[r],t}),{})}function Ct(t,e,n){return void 0===n&&(n=1/0),h(e)?Ct((function(n,r){return xt((function(t,i){return e(n,t,r,i)}))(dt(t(n,r)))}),n):("number"==typeof e&&(n=e),B((function(e,r){return function(t,e,n,r,i,o,s,u){var c=[],a=0,l=0,h=!1,f=function(){!h||c.length||a||e.complete()},d=function(t){return a<r?p(t):c.push(t)},p=function(t){o&&e.next(t),a++;var u=!1;dt(n(t,l++)).subscribe(F(e,(function(t){null==i||i(t),o?d(t):e.next(t)}),(function(){u=!0}),void 0,(function(){if(u)try{a--;for(var t=function(){var t=c.shift();s?vt(e,s,(function(){return p(t)})):p(t)};c.length&&a<r;)t();f()}catch(t){e.error(t)}})))};return t.subscribe(F(e,d,(function(){h=!0,f()}))),function(){null==u||u()}}(e,r,t,n)})))}function jt(t){return void 0===t&&(t=1/0),Ct(U,t)}function Ut(){return jt(1)}function Pt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ut()(wt(t,nt(t)))}function Dt(t,e,n){void 0===t&&(t=0),void 0===n&&(n=q);var r=-1;return null!=e&&(Q(e)?n=e:r=e),new D((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 Lt(t,e){return B((function(n,r){var i=0;n.subscribe(F(r,(function(n){return t.call(e,n,i++)&&r.next(n)})))}))}function Bt(t){return B((function(e,n){var r,i=null,o=!1;i=e.subscribe(F(n,void 0,void 0,(function(s){r=dt(t(s,Bt(t)(e))),i?(i.unsubscribe(),i=null,r.subscribe(n)):o=!0}))),o&&(i.unsubscribe(),i=null,r.subscribe(n))}))}function Ft(t,e){return h(e)?Ct(t,e,1):Ct(t,1)}function zt(t){return t<=0?function(){return Z}:B((function(e,n){var r=0;e.subscribe(F(n,(function(e){++r<=t&&(n.next(e),t<=r&&n.complete())})))}))}function Ht(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 Z}:B((function(t,e){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=n){var t="number"==typeof n?Dt(n):dt(n(o)),r=F(e,(function(){r.unsubscribe(),u()}));t.subscribe(r)}else u()},u=function(){var n=!1;i=t.subscribe(F(e,void 0,(function(){++o<r?i?s():n=!0:e.complete()}))),n&&s()};u()}))}function Wt(t,e){return B((function(n,r){var i=null,o=0,s=!1,u=function(){return s&&!i&&r.complete()};n.subscribe(F(r,(function(n){null==i||i.unsubscribe();var s=0,c=o++;dt(t(n,c)).subscribe(i=F(r,(function(t){return r.next(e?e(n,t,c,s++):t)}),(function(){i=null,u()})))}),(function(){s=!0,u()})))}))}function Kt(t,e,n){var r=h(t)||e||n?{next:t,error:e,complete:n}:t;return r?B((function(t,e){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var i=!0;t.subscribe(F(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 Mt="NUCLIA_NUA_KEY",Gt="NUCLIA_NUA_CLIENT";var Jt,Yt,Vt,Xt,qt,Zt,Qt;!function(t){t.DAY="day",t.WEEK="week",t.MONTH="month",t.YEAR="year"}(Jt||(Jt={})),function(t){t.anHour="1h",t.twoHours="2h",t.threeHours="3h",t.sixHours="6h",t.twelveHours="12h",t.twentyFourHours="24h",t.fortyHeightHours="48h"}(Yt||(Yt={})),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"}(Vt||(Vt={})),function(t){t.BASIC="basic",t.ORIGIN="origin",t.RELATIONS="relations",t.VALUES="values",t.EXTRACTED="extracted",t.ERRORS="errors"}(Xt||(Xt={})),function(t){t.TEXT="text",t.METADATA="metadata",t.LARGE_METADATA="large_metadata",t.VECTOR="vectors",t.LINK="link",t.FILE="file"}(qt||(qt={})),function(t){t.RESOURCES="RESOURCES",t.PARAGRAPHS="PARAGRAPHS",t.SENTENCES="SENTENCES"}(Zt||(Zt={})),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"}(Qt||(Qt={}));const te=new RegExp(/[^a-z0-9_-]/g),ee=(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?Et(n):wt(n.arrayBuffer())).pipe(Wt((o=>r?re(t,e,o,i,n.payload):ne(t,e,o,i))))),ne=(t,e,n,r)=>{const i=Object.assign({"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},se(r));let o=1;return t.rest.post(`${e}/upload`,n,i).pipe(Ht(),Lt((t=>0==o--||503!==t.status)),zt(1),Wt((t=>{switch(t.status){case 201:return wt(t.json()).pipe(xt((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return Et({conflict:!0});default:return Et({failed:!0})}})))},re=(t,e,n,r,i)=>{let o=0,s=!1;const u=n.byteLength,c=Math.ceil(u/524288),a={"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&&(a["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,a,!0).pipe(Ht(),Lt((t=>0==h--||503!==t.status)),Bt((t=>Et(t))),zt(1),Ft((e=>function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t),r=rt(t,1/0),i=t;return i.length?1===i.length?dt(i[0]):jt(r)(wt(i,n)):Z}(Et(e).pipe(Lt((t=>201!==t.status||!t.headers.get("location"))),xt((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),Et(e).pipe(Lt((t=>201===t.status&&!!t.headers.get("location"))),xt((t=>t.headers.get("location"))),Ft((e=>function(t,e,n){if(null==e&&(e=t,t=0),e<=0)return Z;var r=e+t;return new D(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,c).pipe(Ft((()=>{const i=n.slice(o,o+524288);return s?Et({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+=524288,{completed:o>=u,progress:o>=u?100:Math.min(Math.floor(o/u*100),100)}))),Bt((()=>Et({failed:!0}))))}))))))))))},ie=(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 wt(i.map((n=>{let i=e;if(r){let t=n.name.toLowerCase().replace(te,"_");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 ee(t,i,n,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t);return B((function(e,r){(n?Pt(t,e,n):Pt(t,e)).subscribe(r)}))}({progress:0,completed:!1}),xt((t=>({status:t,file:n}))))}))).pipe(Ct((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,c=Math.round(u.reduce(((t,e)=>t+e.file.size*e.progress/100),0)/o*100);return{files:u,progress:c,completed:s,uploaded:i,failed:n,conflicts:r}})))},oe=(t,e,n)=>{const r=Object.assign({"x-stf-nuakey":`Bearer ${localStorage.getItem(Mt)}`,"content-type":(null==n?void 0:n.contentType)||"application/octet-stream"},se(n));return t.rest.post("/processing/upload",e,r)},se=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 ue(t){return`/l/${t.labelset}/${t.label}`}function ce(t){const e=t.split("/");return{labelset:e[2],label:e[3]}}var ae;!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"}(ae||(ae={}));const le=(t,e,n,r,i=[],o,s)=>{var u;const c={};c.query=r||"",c.features=i;const a=o||{},{inTitleOnly:l}=a,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}(a,["inTitleOnly"]);l&&(c.fields=["a/title"]),Object.entries(h||{}).forEach((([t,e])=>c[t]=Array.isArray(e)?e.map((t=>`${t}`)):`${e}`));const f=(null===(u=t.currentShards)||void 0===u?void 0:u[e])||[];c.shards=f;return(s?t.rest.get(`${n}/search?${he(c)}`):t.rest.post(`${n}/search`,c)).pipe(Bt((()=>Et({error:!0}))),xt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Kt((n=>{n.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:n.shards}))})))},he=t=>{const e=new URLSearchParams;return Object.entries(t).forEach((([t,n])=>Array.isArray(n)?n.forEach((n=>e.append(t,n))):e.append(t,n))),e.toString()},fe=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),de=(t,e,n,r,i)=>{const o=fe(i.filter((n=>ve(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=fe(i.filter((n=>be(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)),c=r.length>0?[...s,{key:n,classifications:r}]:s;return o.length>0||c.length>0?[...u,{field:{field:t,field_type:e},token:o.length>0?o:void 0,paragraphs:c.length>0?c:void 0}]:u},pe=(t,e,n,r)=>{const i=fe(r.filter((n=>be(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},ve=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,be=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0,ge=(t,e,n)=>t?(Array.isArray(t)||(t=Array.from(t)),t.slice(e,n).join("")):"",ye=t=>t?Array.from(t).length:0;class me{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.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 ge(this.getFieldText(t,e),n.start,n.end)}getSentenceText(t,e,n){return ge(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 we extends me{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=et(t),r=Rt(t),i=r.args,o=r.keys,s=new D((function(t){var e=i.length;if(e)for(var n=new Array(e),r=e,s=e,u=function(e){var u=!1;dt(i[e]).subscribe(F(t,(function(t){u||(u=!0,s--),n[e]=t}),(function(){return r--}),void 0,(function(){r&&u||(s||t.next(o?Nt(o,n):n),t.complete())})))},c=0;c<e;c++)u(c);else t.complete()}));return n?s.pipe(kt(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)}upload(t,e,n,r){return ee(this.nuclia,`${this.path}/file/${t}`,e,!!n,r)}batchUpload(t){return ie(this.nuclia,this.path,t,!0)}search(t,e=[],n){return le(this.nuclia,this.kb,this.path,t,e,n,!0)}setLabels(t,e,n,r){const i=de(t,e,n,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Kt((()=>this.fieldmetadata=i)))}setEntities(t,e,n){const r=pe(t,e,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:r}).pipe(Kt((()=>this.fieldmetadata=r)))}}const Ee=(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())};var _e,Se,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"}(_e||(_e={})),function(t){t.PENDING="PENDING",t.PROCESSED="PROCESSED",t.ERROR="ERROR"}(Se||(Se={}));class ke{}class Te{}class $e{}class Oe{}!function(t){t.classifier="classifier",t.labeler="labeler",t.ner="ner"}(xe||(xe={})),function(t){t.finished="finished",t.not_running="not_running",t.running="running",t.started="started",t.stopped="stopped"}(Ae||(Ae={}));class Ie{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(Bt((()=>Et({task:"",status:Ae.not_running}))))}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/json_models/nuclia.json`).pipe(xt((()=>!0)),Bt((()=>Et(!1))))}}class Re{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(){return this.nuclia.rest.get(`${this.path}/entitiesgroups`).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=[Xt.BASIC,Xt.ORIGIN,Xt.RELATIONS,Xt.VALUES,Xt.EXTRACTED,Xt.ERRORS],n=[qt.TEXT,qt.METADATA,qt.LINK,qt.FILE]){return this._getResource(t,void 0,e,n)}getResourceBySlug(t,e=[Xt.BASIC,Xt.ORIGIN,Xt.RELATIONS,Xt.VALUES,Xt.EXTRACTED,Xt.ERRORS],n=[qt.TEXT,qt.METADATA,qt.LINK,qt.FILE]){return this._getResource(void 0,t,e,n)}_getResource(t,e,n=[Xt.BASIC,Xt.ORIGIN,Xt.RELATIONS,Xt.VALUES,Xt.EXTRACTED,Xt.ERRORS],r=[qt.TEXT,qt.METADATA,qt.LINK,qt.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 we(this.nuclia,this.id,t))))}getResourceFromData(t){return new we(this.nuclia,this.id,t)}search(t,e=[],n){return le(this.nuclia,this.id,this.path,t,e,n)}suggest(t){const e=`query=${encodeURIComponent(t)}`;return this.nuclia.rest.get(`${this.path}/suggest?${e}`).pipe(Bt((()=>Et({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 we(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 Ne extends Re{get training(){return this._training||(this._training=new Ie(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)),Bt((()=>Et(!1))))}createOrUpdateResource(t,e=!0){return(t.slug?this.hasResource(t.slug):Et(!1)).pipe(Wt((n=>n?this.getResourceFromData({id:"",slug:t.slug}).modify(t,e):this.createResource(t,e))))}importDataset(t){return this.nuclia.rest.post(`/import/${this.id}`,{export_id:t})}upload(t,e,n){return ee(this.nuclia,`/kb/${this.id}`,t,!!e,n)}batchUpload(t){return ie(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 Ce{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?Et(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Kt((t=>this.nuclia.options.zone=t)),xt((()=>t))))),xt((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 Et(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(Kt((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Wt((()=>this.getKnowledgeBox(t,e.slug))))}getStats(t,e,n,r=Jt.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)),Lt((t=>!!t)))}upload(t){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return oe(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(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("NUCLIA_NUA_CLIENT")&&!!localStorage.getItem(Mt)}getNUAHeader(){return{"x-stf-nuakey":`Bearer ${localStorage.getItem(Mt)}`}}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(Bt((n=>{if(409===n.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw n})),Kt((t=>{"desktop"===this.nuclia.options.client&&(localStorage.setItem(Mt,t.token),localStorage.setItem("NUCLIA_NUA_CLIENT",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 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 D((function(e){var o=new AbortController,s=o.signal,u=!0,c=i.signal;if(c)if(c.aborted)o.abort();else{var a=function(){s.aborted||o.abort()};c.addEventListener("abort",a),e.add((function(){return c.removeEventListener("abort",a)}))}var l=n(n({},i),{signal:s}),h=function(t){u=!1,e.error(t)};return fetch(t,l).then((function(t){r?dt(r(t)).subscribe(F(e,void 0,(function(){u=!1,e.complete()}),h)):(u=!1,e.next(t),e.complete())})).catch(h),function(){u&&o.abort()}}))}class Ue{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}}class Pe{constructor(t){this._isAuthenticated=new G(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,Lt((function(e,n){return t<=n}))),Lt((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("JWT_KEY"),localStorage.removeItem("JWT_REFRESH_KEY"),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Bt((t=>(this.logout(),_t(t)))),xt((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return this.nuclia.options.public?"":localStorage.getItem("JWT_KEY")||""}setPassword(t){return this.fetch("/auth/setpassword",{password:t},!0,{}).pipe(xt((t=>this.authenticate(t))))}deleteAuthenticatedUser(){return this.nuclia.rest.delete("/user").pipe(Kt((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new Ue(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem("JWT_REFRESH_KEY")||""}storeTokens(t){localStorage.setItem("JWT_KEY",t.access_token),localStorage.setItem("JWT_REFRESH_KEY",t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const n=this.getToken();if(n){const r=null===(t=new Ue(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<216e5?0:216e5;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Dt(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()}`),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 De{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 je(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?Et(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("/import")?"":"/v1"}${t}`}getZones(){return this.zones?Et(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(Wt((t=>wt(t.blob()))),xt((t=>URL.createObjectURL(t))))}}class Le{constructor(t){this.currentShards={},this.options=t,this.auth=new Pe(this),this.rest=new De(this),this.db=new Ce(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 Re(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{Pe as Authentication,Ce as Db,Qt as EventType,qt as ExtractedDataTypes,_e as FIELD_TYPE,ke as FileFieldData,Ue as JwtHelper,$e as KeywordSetFieldData,Re as KnowledgeBox,Zt as LabelSetKind,Oe as LinkFieldData,Gt as NUA_CLIENT,Mt as NUA_KEY,Le as Nuclia,Se as RESOURCE_STATUS,me as ReadableResource,we as Resource,Xt as ResourceProperties,De as Rest,ae as Search,Jt as StatsPeriod,Yt as StatsRange,Vt as StatsType,re as TUSuploadFile,Te as TextFieldData,Ie as Training,Ae as TrainingStatus,xe as TrainingType,Ne as WritableKnowledgeBox,ie as batchUpload,fe as deDuplicateList,se as getFileMetadata,ue as getFilterFromLabel,ce as getLabelFromFilter,ye as lengthUnicode,Ee as resourceToAlgoliaFormat,le as search,pe as setEntities,de as setLabels,ge as sliceUnicode,ee as upload,ne as uploadFile,oe 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 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 d=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 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 f=this.initialTeardown;if(h(f))try{f()}catch(t){i=t instanceof d?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 d?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 d(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 S(){}var _=x("C",void 0,void 0);function x(t,e,n){return{kind:t,value:e,error:n}}var k=null;function A(t){if(m.useDeprecatedSynchronousErrorHandling){var e=!k;if(e&&(k={errorThrown:!1,error:null}),t(),e){var n=k,r=n.errorThrown,i=n.error;if(k=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 x("N",t,void 0)}(t),this):this._next(t)},n.prototype.error=function(t){this.isStopped?C(x("E",void 0,t),this):(this.isStopped=!0,this._error(t))},n.prototype.complete=function(){this.isStopped?C(_,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:S,error:function(t){throw t},complete:S},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=f((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 ft(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 dt(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(dt(t))return vt(ft(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(dt(t))return function(t,e){return mt(ft(t),e)}(t,e)}throw ct(t)}function Et(t,e){return e?wt(t,e):pt(t)}function St(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return Et(t,n)}function _t(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 xt=f((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function kt(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 kt((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 kt((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,f=function(){!h||a.length||c||e.complete()},d=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?d(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();f()}catch(t){e.error(t)}})))};return t.subscribe(z(e,d,(function(){h=!0,f()}))),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?St(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(kt((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return St({conflict:!0});default:return St({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=>St(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}(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,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?St({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(kt((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((()=>St({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}),kt((t=>({status:t,file:n}))))}))).pipe(Nt((t=>t),6),kt((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;!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"}(he||(he={}));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?${de(a,h)}`):t.rest.post(`${n}/search`,a)).pipe(Ft((()=>St({error:!0}))),kt((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((n=>{n.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:n.shards}))})))},de=(t,e)=>{Object.entries(e||{}).forEach((([e,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()},pe=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ve=(t,e,n,r,i)=>{const o=pe(i.filter((n=>ge(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=pe(i.filter((n=>ye(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},be=(t,e,n,r)=>{const i=pe(r.filter((n=>ye(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},ge=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,ye=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0,me=(t,e,n)=>t?(Array.isArray(t)||(t=Array.from(t)),t.slice(e,n).join("")):"",we=t=>t?Array.from(t).length:0;class Ee{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.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 me(this.getFieldText(t,e),n.start,n.end)}getSentenceText(t,e,n){return me(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 Se extends Ee{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=ve(t,e,n,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Mt((()=>this.fieldmetadata=i)))}setEntities(t,e,n){const r=be(t,e,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:r}).pipe(Mt((()=>this.fieldmetadata=r)))}}const _e=(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())};var xe,ke,Ae,$e;!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"}(ke||(ke={}));class Te{}class Oe{}class Ie{}class Re{}!function(t){t.classifier="classifier",t.labeler="labeler",t.ner="ner"}(Ae||(Ae={})),function(t){t.finished="finished",t.not_running="not_running",t.running="running",t.started="started",t.stopped="stopped"}($e||($e={}));class je{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((()=>St({task:"",status:$e.not_running}))))}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/json_models/nuclia.json`).pipe(kt((()=>!0)),Ft((()=>St(!1))))}}class Ce{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(){return this.nuclia.rest.get(`${this.path}/entitiesgroups`).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(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(kt((t=>new Se(this.nuclia,this.id,t))))}getResourceFromData(t){return new Se(this.nuclia,this.id,t)}search(t,e=[],n){return fe(this.nuclia,this.id,this.path,t,e,n)}suggest(t,e=!1){const n=`query=${encodeURIComponent(t)}${e?"&fields=a/title":""}`;return this.nuclia.rest.get(`${this.path}/suggest?${n}`).pipe(Ft((()=>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 n=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${n?"?"+n:""}`).pipe(kt((t=>({resources:t.resources.map((t=>new Se(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,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 Ne extends Ce{get training(){return this._training||(this._training=new je(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(kt((()=>!0)),Ft((()=>St(!1))))}createOrUpdateResource(t,e=!0){return(t.slug?this.hasResource(t.slug):St(!1)).pipe(Kt((n=>n?this.getResourceFromData({id:"",slug:t.slug}).modify(t,e):this.createResource(t,e))))}importDataset(t){return this.nuclia.rest.post(`/import/${this.id}`,{export_id:t})}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 Pe{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?St(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 St(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"})),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(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(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(kt((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(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 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 Ue(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 De{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 Le="JWT_KEY",Be="JWT_REFRESH_KEY",Fe=216e5;class ze{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(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(Be),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Ft((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 De(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(Be)||""}storeTokens(t){localStorage.setItem(Le,t.access_token),localStorage.setItem(Be,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const n=this.getToken();if(n){const r=null===(t=new De(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<Fe?0:Fe;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()}`),Ue(`${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()):_t(t))))}}class He{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 Ue(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?St(t):Et(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("/import")?"":"/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(Kt((t=>Et(t.blob()))),kt((t=>URL.createObjectURL(t))))}}class We{constructor(t){this.currentShards={},this.options=t,this.auth=new ze(this),this.rest=new He(this),this.db=new Pe(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 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 xt)}});t.subscribe(o)}))}(n.bind(t)(...e)):n}})}}export{ze as Authentication,Pe as Db,te as EventType,Zt as ExtractedDataTypes,xe as FIELD_TYPE,Te as FileFieldData,De as JwtHelper,Ie as KeywordSetFieldData,Ce as KnowledgeBox,Qt as LabelSetKind,Re as LinkFieldData,Jt as NUA_CLIENT,Gt as NUA_KEY,We as Nuclia,ke as RESOURCE_STATUS,Ee as ReadableResource,Se as Resource,qt as ResourceProperties,He as Rest,he as Search,Vt as StatsPeriod,Xt as StatsRange,Yt as StatsType,oe as TUSuploadFile,Oe as TextFieldData,je as Training,$e as TrainingStatus,Ae as TrainingType,Ne as WritableKnowledgeBox,se as batchUpload,pe as deDuplicateList,ae as getFileMetadata,ce as getFilterFromLabel,le as getLabelFromFilter,we as lengthUnicode,_e as resourceToAlgoliaFormat,fe as search,be as setEntities,ve as setLabels,me as sliceUnicode,re as upload,ie as uploadFile,ue as uploadToProcess}; |
@@ -27,3 +27,3 @@ import { Observable } from 'rxjs'; | ||
search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
suggest(query: string): Observable<Search.Suggestions>; | ||
suggest(query: string, inTitleOnly?: boolean): Observable<Search.Suggestions>; | ||
counters(): Observable<Counters>; | ||
@@ -30,0 +30,0 @@ listResources(page?: number, size?: number): Observable<ResourceList>; |
@@ -25,4 +25,3 @@ import type { Observable } from 'rxjs'; | ||
RESOURCES = "RESOURCES", | ||
PARAGRAPHS = "PARAGRAPHS", | ||
SENTENCES = "SENTENCES" | ||
PARAGRAPHS = "PARAGRAPHS" | ||
} | ||
@@ -29,0 +28,0 @@ export declare enum EventType { |
@@ -45,2 +45,5 @@ import { Observable } from 'rxjs'; | ||
addField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<void>; | ||
updateField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<{ | ||
seqid: number; | ||
}>; | ||
upload(field: string, file: File, TUS?: boolean, metadata?: FileMetadata): Observable<UploadResponse>; | ||
@@ -47,0 +50,0 @@ upload(field: string, buffer: ArrayBuffer, TUS?: boolean, metadata?: FileMetadata): Observable<UploadResponse>; |
@@ -302,2 +302,4 @@ export interface IResource { | ||
export interface CloudLink { | ||
filename?: string; | ||
md5?: string; | ||
uri?: string; | ||
@@ -304,0 +306,0 @@ size?: number; |
import type { ExtractedDataTypes, ResourceProperties } from '../kb'; | ||
import type { FIELD_TYPE, IResource } from '../resource'; | ||
export declare type ResourceStatus = 'PENDING' | 'PROCESSED' | 'ERROR'; | ||
export declare type SortOrder = 'asc' | 'desc'; | ||
export interface SortOption { | ||
field: 'created' | 'modified' | 'title'; | ||
limit?: number; | ||
order?: SortOrder; | ||
} | ||
export interface SearchOptions { | ||
@@ -9,3 +15,3 @@ inTitleOnly?: boolean; | ||
filters?: string[]; | ||
sort?: 'created' | 'modified'; | ||
sort?: SortOption; | ||
page_number?: number; | ||
@@ -12,0 +18,0 @@ page_size?: number; |
{ | ||
"name": "@nuclia/core", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "SDK allowing to integrate Nuclia services in your frontend application", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -627,2 +627,4 @@ import * as rxjs from 'rxjs'; | ||
interface CloudLink { | ||
filename?: string; | ||
md5?: string; | ||
uri?: string; | ||
@@ -675,2 +677,8 @@ size?: number; | ||
declare type ResourceStatus = 'PENDING' | 'PROCESSED' | 'ERROR'; | ||
declare type SortOrder = 'asc' | 'desc'; | ||
interface SortOption { | ||
field: 'created' | 'modified' | 'title'; | ||
limit?: number; | ||
order?: SortOrder; | ||
} | ||
interface SearchOptions { | ||
@@ -681,3 +689,3 @@ inTitleOnly?: boolean; | ||
filters?: string[]; | ||
sort?: 'created' | 'modified'; | ||
sort?: SortOption; | ||
page_number?: number; | ||
@@ -820,2 +828,5 @@ page_size?: number; | ||
addField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<void>; | ||
updateField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<{ | ||
seqid: number; | ||
}>; | ||
upload(field: string, file: File, TUS?: boolean, metadata?: FileMetadata): Observable<UploadResponse>; | ||
@@ -862,4 +873,3 @@ upload(field: string, buffer: ArrayBuffer, TUS?: boolean, metadata?: FileMetadata): Observable<UploadResponse>; | ||
RESOURCES = "RESOURCES", | ||
PARAGRAPHS = "PARAGRAPHS", | ||
SENTENCES = "SENTENCES" | ||
PARAGRAPHS = "PARAGRAPHS" | ||
} | ||
@@ -1070,3 +1080,3 @@ declare enum EventType { | ||
search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
suggest(query: string): Observable<Search.Suggestions>; | ||
suggest(query: string, inTitleOnly?: boolean): Observable<Search.Suggestions>; | ||
counters(): Observable<Counters>; | ||
@@ -1197,2 +1207,2 @@ listResources(page?: number, size?: number): Observable<ResourceList>; | ||
export { Account, AccountConfig, AccountCreation, AccountLimits, AccountStatus, AccountTypes, AuthTokens, Authentication, Classification, CloudLink, ComputedMetadata, Counters, Db, Entities, EntitiesGroup, Entity, 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, ParagraphAnnotation, PositionedNER, ProcessingPullResponse, ProcessingPushResponse, ProcessingStat, ProcessingStatusResponse, PromiseMapper, RESOURCE_STATUS, ReadableResource, Relation, Resource, ResourceData, ResourceField, ResourceList, ResourcePagination, ResourceProperties, ResourceStatus, Rest, Row, RowsPreview, Search, SearchOptions, Sentence, ServiceAccount, ServiceAccountCreation, ServiceAccountKey, Sheet, StatsPeriod, StatsRange, StatsType, TUSuploadFile, TextField, TextFieldData, TextFieldFormat, TokenAnnotation, Training, TrainingExecution, TrainingStatus, TrainingTask, TrainingType, TypeParagraph, UploadResponse, UploadStatus, UserClassification, UserFieldMetadata, UserMetadata, UserType, Welcome, WelcomeUser, WidgetFeatures, WritableKnowledgeBox, WriteFileField, batchUpload, deDuplicateList, getFileMetadata, getFilterFromLabel, getLabelFromFilter, lengthUnicode, resourceToAlgoliaFormat, search, setEntities, setLabels, sliceUnicode, upload, uploadFile, uploadToProcess }; | ||
export { Account, AccountConfig, AccountCreation, AccountLimits, AccountStatus, AccountTypes, AuthTokens, Authentication, Classification, CloudLink, ComputedMetadata, Counters, Db, Entities, EntitiesGroup, Entity, 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, ParagraphAnnotation, PositionedNER, ProcessingPullResponse, ProcessingPushResponse, ProcessingStat, ProcessingStatusResponse, PromiseMapper, RESOURCE_STATUS, ReadableResource, Relation, Resource, ResourceData, ResourceField, ResourceList, ResourcePagination, ResourceProperties, ResourceStatus, Rest, Row, RowsPreview, Search, SearchOptions, Sentence, ServiceAccount, ServiceAccountCreation, ServiceAccountKey, Sheet, SortOption, SortOrder, StatsPeriod, StatsRange, StatsType, TUSuploadFile, TextField, TextFieldData, TextFieldFormat, TokenAnnotation, Training, TrainingExecution, TrainingStatus, TrainingTask, TrainingType, TypeParagraph, UploadResponse, UploadStatus, UserClassification, UserFieldMetadata, UserMetadata, UserType, Welcome, WelcomeUser, WidgetFeatures, WritableKnowledgeBox, WriteFileField, batchUpload, deDuplicateList, getFileMetadata, getFilterFromLabel, getLabelFromFilter, lengthUnicode, resourceToAlgoliaFormat, search, setEntities, setLabels, 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 w={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},E={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=E.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=E.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function S(t){E.setTimeout((function(){throw t}))}function T(){}var x=_("C",void 0,void 0);function _(t,e,r){return{kind:t,value:e,error:r}}function A(t){t()}var k=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=N,r}return r(e,t),e.create=function(t,e,r){return new I(t,e,r)},e.prototype.next=function(t){this.isStopped?D(function(t){return _("N",t,void 0)}(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?D(_("E",void 0,t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?D(x,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),$=Function.prototype.bind;function O(t,e){return $.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){P(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){P(t)}else P(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){P(t)}},t}(),I=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&&w.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 r(e,t),e}(k);function P(t){S(t)}function D(t,e){var r=w.onStoppedNotification;r&&E.setTimeout((function(){return r(t,e)}))}var N={closed:!0,next:T,error:function(t){throw t},complete:T},j="function"==typeof Symbol&&Symbol.observable||"@@observable";function C(t){return t}function U(t){return 0===t.length?C: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 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 k||function(t){return t&&d(t.next)&&d(t.error)&&d(t.complete)}(n)&&y(n)?t:new I(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=F(e))((function(e,n){var i=new I({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 U(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=F(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 F(t){var e;return null!==(e=null!=t?t:w.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 z(t,e,r,n,i){return new H(t,e,r,n,i)}var H=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),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 L;return t.source=this,t},e.create=function(t,e){return new M(t,e)},e}(L),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},Y=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),V={setInterval:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=V.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=V.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},X=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),V.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;V.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),q=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}(),Z=new(function(t){function e(e,r){void 0===r&&(r=q.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}(q))(X),Q=new L((function(t){return t.complete()}));function tt(t){return t&&d(t.schedule)}function et(t){return t[t.length-1]}function rt(t){return d(et(t))?t.pop():void 0}function nt(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 d(null==t?void 0:t.then)}function at(t){return d(t[j])}function ut(t){return Symbol.asyncIterator&&d(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 d(null==t?void 0:t[lt])}function dt(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 pt(t){if(t instanceof L)return t;if(null!=t){if(at(t))return i=t,new L((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(ot(t))return n=t,new L((function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()}));if(st(t))return r=t,new L((function(t){r.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,S)}));if(ut(t))return vt(t);if(ht(t))return e=t,new L((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 vt(dt(t))}var e,r,n,i;throw ct(t)}function vt(t){return new L((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 bt(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 gt(t,e){return void 0===e&&(e=0),B((function(r,n){r.subscribe(z(n,(function(r){return bt(n,t,(function(){return n.next(r)}),e)}),(function(){return bt(n,t,(function(){return n.complete()}),e)}),(function(r){return bt(n,t,(function(){return n.error(r)}),e)})))}))}function yt(t,e){return void 0===e&&(e=0),B((function(r,n){n.add(t.schedule((function(){return r.subscribe(n)}),e))}))}function mt(t,e){if(!t)throw new Error("Iterable cannot be null");return new L((function(r){bt(r,e,(function(){var n=t[Symbol.asyncIterator]();bt(r,e,(function(){n.next().then((function(t){t.done?r.complete():r.next(t.value)}))}),0,!0)}))}))}function wt(t,e){if(null!=t){if(at(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(r){var n=0;return e.schedule((function(){n===t.length?r.complete():(r.next(t[n++]),r.closed||this.schedule())}))}))}(t,e);if(st(t))return function(t,e){return pt(t).pipe(yt(e),gt(e))}(t,e);if(ut(t))return mt(t,e);if(ht(t))return function(t,e){return new L((function(r){var n;return bt(r,e,(function(){n=t[lt](),bt(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 mt(dt(t),e)}(t,e)}throw ct(t)}function Et(t,e){return e?wt(t,e):pt(t)}function St(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=nt(t);return Et(t,r)}function Tt(t,e){var r=d(t)?t:function(){return t},n=function(t){return t.error(r())};return new L(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 _t(t,e){return B((function(r,n){var i=0;r.subscribe(z(n,(function(r){n.next(t.call(e,r,i++))})))}))}var At=Array.isArray;function kt(t){return _t((function(e){return function(t,e){return At(e)?t.apply(void 0,u([],a(e))):t(e)}(t,e)}))}var $t=Array.isArray,Ot=Object.getPrototypeOf,Rt=Object.prototype,It=Object.keys;function Pt(t){if(1===t.length){var e=t[0];if($t(e))return{args:e,keys:null};if((n=e)&&"object"==typeof n&&Ot(n)===Rt){var r=It(e);return{args:r.map((function(t){return e[t]})),keys:r}}}var n;return{args:t,keys:null}}function Dt(t,e){return t.reduce((function(t,r,n){return t[r]=e[n],t}),{})}function Nt(t,e,r){return void 0===r&&(r=1/0),d(e)?Nt((function(r,n){return _t((function(t,i){return e(r,t,n,i)}))(pt(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()},f=function(t){return c<n?p(t):u.push(t)},p=function(t){o&&e.next(t),c++;var a=!1;pt(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?bt(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 jt(t){return void 0===t&&(t=1/0),Nt(C,t)}function Ct(){return jt(1)}function Ut(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ct()(Et(t,nt(t)))}function Lt(t,e,r){void 0===t&&(t=0),void 0===r&&(r=Z);var n=-1;return null!=e&&(tt(e)?r=e:n=e),new L((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 Ft(t,e){return B((function(r,n){var i=0;r.subscribe(z(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(z(r,void 0,void 0,(function(s){n=pt(t(s,Bt(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)?Nt(t,e,1):Nt(t,1)}function Ht(t){return t<=0?function(){return Q}:B((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 Q}:B((function(t,e){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=r){var t="number"==typeof r?Lt(r):pt(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 B((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++;pt(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?B((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)})))})):C}const Gt="NUCLIA_NUA_KEY",Yt="NUCLIA_NUA_CLIENT";var Jt,Vt,Xt,qt,Zt,Qt,te;t.StatsPeriod=void 0,(Jt=t.StatsPeriod||(t.StatsPeriod={})).DAY="day",Jt.WEEK="week",Jt.MONTH="month",Jt.YEAR="year",t.StatsRange=void 0,(Vt=t.StatsRange||(t.StatsRange={})).anHour="1h",Vt.twoHours="2h",Vt.threeHours="3h",Vt.sixHours="6h",Vt.twelveHours="12h",Vt.twentyFourHours="24h",Vt.fortyHeightHours="48h",t.StatsType=void 0,(Xt=t.StatsType||(t.StatsType={})).PROCESSING_TIME="processing_time",Xt.SEARCHES="searches",Xt.CHARS="chars",Xt.MEDIA_SECONDS="media_seconds",Xt.BYTES="bytes",Xt.RESOURCES="resources",Xt.PAGES="pages",Xt.TRAIN_SECONDS="train_seconds",Xt.SUGGESTIONS="suggestions",Xt.DOCS_NO_MEDIA="docs_no_media",t.ResourceProperties=void 0,(qt=t.ResourceProperties||(t.ResourceProperties={})).BASIC="basic",qt.ORIGIN="origin",qt.RELATIONS="relations",qt.VALUES="values",qt.EXTRACTED="extracted",qt.ERRORS="errors",t.ExtractedDataTypes=void 0,(Zt=t.ExtractedDataTypes||(t.ExtractedDataTypes={})).TEXT="text",Zt.METADATA="metadata",Zt.LARGE_METADATA="large_metadata",Zt.VECTOR="vectors",Zt.LINK="link",Zt.FILE="file",t.LabelSetKind=void 0,(Qt=t.LabelSetKind||(t.LabelSetKind={})).RESOURCES="RESOURCES",Qt.PARAGRAPHS="PARAGRAPHS",Qt.SENTENCES="SENTENCES",t.EventType=void 0,(te=t.EventType||(t.EventType={})).VISITED="VISITED",te.MODIFIED="MODIFIED",te.DELETED="DELETED",te.NEW="NEW",te.STARTED="STARTED",te.STOPPED="STOPPED",te.SEARCH="SEARCH",te.PROCESSED="PROCESSED";const ee=524288,re=new RegExp(/[^a-z0-9_-]/g),ne=(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):Et(r.arrayBuffer())).pipe(Wt((o=>n?oe(t,e,o,i,r.payload):ie(t,e,o,i))))),ie=(t,e,r,n)=>{const i=Object.assign({"content-type":(null==n?void 0:n.contentType)||"application/octet-stream"},ue(n));let o=1;return t.rest.post(`${e}/upload`,r,i).pipe(Kt(),Ft((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 St({conflict:!0});default:return St({failed:!0})}})))},oe=(t,e,r,n,i)=>{let o=0,s=!1;const a=r.byteLength,u=Math.ceil(a/ee),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(),Ft((t=>0==h--||503!==t.status)),Bt((t=>St(t))),Ht(1),zt((e=>function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=nt(t),n=it(t,1/0),i=t;return i.length?1===i.length?pt(i[0]):jt(n)(Et(i,r)):Q}(St(e).pipe(Ft((t=>201!==t.status||!t.headers.get("location"))),_t((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),St(e).pipe(Ft((t=>201===t.status&&!!t.headers.get("location"))),_t((t=>t.headers.get("location"))),zt((e=>function(t,e,r){if(null==e&&(e=t,t=0),e<=0)return Q;var n=e+t;return new L(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+ee);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(_t((t=>200!==t.status?(s=!0,{failed:s}):(o+=ee,{completed:o>=a,progress:o>=a?100:Math.min(Math.floor(o/a*100),100)}))),Bt((()=>St({failed:!0}))))}))))))))))},se=(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(re,"_");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 ne(t,i,r,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=nt(t);return B((function(e,n){(r?Ut(t,e,r):Ut(t,e)).subscribe(n)}))}({progress:0,completed:!1}),_t((t=>({status:t,file:r}))))}));return Et(u).pipe(Nt((t=>t),6),_t((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}})))},ae=(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"},ue(r));return t.rest.post("/processing/upload",e,n)},ue=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 ce,le,he;t.Search=void 0,ce=t.Search||(t.Search={}),(le=ce.Features||(ce.Features={})).PARAGRAPH="paragraph",le.DOCUMENT="document",le.RELATIONS="relations",le.VECTOR="vector",(he=ce.ResourceFeatures||(ce.ResourceFeatures={})).PARAGRAPH="paragraph",he.RELATIONS="relations",he.VECTOR="vector";const de=(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"]),Object.entries(h||{}).forEach((([t,e])=>u[t]=Array.isArray(e)?e.map((t=>`${t}`)):`${e}`));const d=(null===(a=t.currentShards)||void 0===a?void 0:a[e])||[];u.shards=d;return(s?t.rest.get(`${r}/search?${fe(u)}`):t.rest.post(`${r}/search`,u)).pipe(Bt((()=>St({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Mt((r=>{r.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:r.shards}))})))},fe=t=>{const e=new URLSearchParams;return Object.entries(t).forEach((([t,r])=>Array.isArray(r)?r.forEach((r=>e.append(t,r))):e.append(t,r))),e.toString()},pe=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ve=(t,e,r,n,i)=>{const o=pe(i.filter((r=>ge(r,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=pe(i.filter((r=>ye(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},be=(t,e,r,n)=>{const i=pe(n.filter((r=>ye(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},ge=(t,e,r)=>t.field.field===e&&t.field.field_type===r&&t.token&&t.token.length>0,ye=(t,e,r)=>t.field.field===e&&t.field.field_type===r&&t.paragraphs&&t.paragraphs.length>0,me=(t,e,r)=>t?(Array.isArray(t)||(t=Array.from(t)),t.slice(e,r).join("")):"";class we{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.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 me(this.getFieldText(t,e),r.start,r.end)}getSentenceText(t,e,r){return me(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 Ee extends we{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=rt(t),n=Pt(t),i=n.args,o=n.keys,s=new L((function(t){var e=i.length;if(e)for(var r=new Array(e),n=e,s=e,a=function(e){var a=!1;pt(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?Dt(o,r):r),t.complete())})))},u=0;u<e;u++)a(u);else t.complete()}));return r?s.pipe(kt(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)}upload(t,e,r,n){return ne(this.nuclia,`${this.path}/file/${t}`,e,!!r,n)}batchUpload(t){return se(this.nuclia,this.path,t,!0)}search(t,e=[],r){return de(this.nuclia,this.kb,this.path,t,e,r,!0)}setLabels(t,e,r,n){const i=ve(t,e,r,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Mt((()=>this.fieldmetadata=i)))}setEntities(t,e,r){const n=be(t,e,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:n}).pipe(Mt((()=>this.fieldmetadata=n)))}}var Se,Te,xe,_e;t.FIELD_TYPE=void 0,(Se=t.FIELD_TYPE||(t.FIELD_TYPE={})).text="text",Se.file="file",Se.link="link",Se.layout="layout",Se.conversation="conversation",Se.keywordset="keywordset",Se.datetime="datetime",t.RESOURCE_STATUS=void 0,(Te=t.RESOURCE_STATUS||(t.RESOURCE_STATUS={})).PENDING="PENDING",Te.PROCESSED="PROCESSED",Te.ERROR="ERROR";t.TrainingType=void 0,(xe=t.TrainingType||(t.TrainingType={})).classifier="classifier",xe.labeler="labeler",xe.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";class Ae{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((()=>St({task:"",status:t.TrainingStatus.not_running}))))}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/json_models/nuclia.json`).pipe(_t((()=>!0)),Bt((()=>St(!1))))}}class ke{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(){return this.nuclia.rest.get(`${this.path}/entitiesgroups`).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(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(_t((t=>new Ee(this.nuclia,this.id,t))))}getResourceFromData(t){return new Ee(this.nuclia,this.id,t)}search(t,e=[],r){return de(this.nuclia,this.id,this.path,t,e,r)}suggest(t){const e=`query=${encodeURIComponent(t)}`;return this.nuclia.rest.get(`${this.path}/suggest?${e}`).pipe(Bt((()=>St({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 r=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${r?"?"+r:""}`).pipe(_t((t=>({resources:t.resources.map((t=>new Ee(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,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 $e extends ke{get training(){return this._training||(this._training=new Ae(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(_t((()=>!0)),Bt((()=>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))))}importDataset(t){return this.nuclia.rest.post(`/import/${this.id}`,{export_id:t})}upload(t,e,r){return ne(this.nuclia,`/kb/${this.id}`,t,!!e,r)}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 Oe{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)),_t((()=>t))))),_t((e=>new $e(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 $e(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(_t((t=>t.data)),Ft((t=>!!t)))}upload(t){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return ae(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(_t((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(_t((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(Yt)&&!!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(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(Gt,t.token),localStorage.setItem(Yt,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 Re(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 L((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?pt(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 Ie{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 Pe="JWT_KEY",De="JWT_REFRESH_KEY",Ne=216e5;class je{constructor(t){this._isAuthenticated=new Y(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,Ft((function(e,r){return t<=r}))),Ft((t=>!t)));var t}login(t,e,r){return this.fetch("/auth/login",{username:t,password:e},!1,r?{"X-STF-VALIDATION":r}:{}).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(Pe),localStorage.removeItem(De),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Bt((t=>(this.logout(),Tt(t)))),_t((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return this.nuclia.options.public?"":localStorage.getItem(Pe)||""}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 Ie(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(De)||""}storeTokens(t){localStorage.setItem(Pe,t.access_token),localStorage.setItem(De,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const r=this.getToken();if(r){const n=null===(t=new Ie(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<Ne?0:Ne;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Lt(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()}`),Re(`${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()):Tt(t))))}}class Ce{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 Re(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):Et(t.clone().json().catch((()=>t.text()))):Tt((()=>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("/import")?"":"/v1"}${t}`}getZones(){return this.zones?St(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))))}}t.Authentication=je,t.Db=Oe,t.FileFieldData=class{},t.JwtHelper=Ie,t.KeywordSetFieldData=class{},t.KnowledgeBox=ke,t.LinkFieldData=class{},t.NUA_CLIENT=Yt,t.NUA_KEY=Gt,t.Nuclia=class{constructor(t){this.currentShards={},this.options=t,this.auth=new je(this),this.rest=new Ce(this),this.db=new Oe(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 ke(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 I({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=we,t.Resource=Ee,t.Rest=Ce,t.TUSuploadFile=oe,t.TextFieldData=class{},t.Training=Ae,t.WritableKnowledgeBox=$e,t.batchUpload=se,t.deDuplicateList=pe,t.getFileMetadata=ue,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.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=de,t.setEntities=be,t.setLabels=ve,t.sliceUnicode=me,t.upload=ne,t.uploadFile=ie,t.uploadToProcess=ae,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!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 w={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},E={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=E.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=E.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function S(t){E.setTimeout((function(){throw t}))}function T(){}var x=_("C",void 0,void 0);function _(t,e,r){return{kind:t,value:e,error:r}}var A=null;function k(t){if(w.useDeprecatedSynchronousErrorHandling){var e=!A;if(e&&(A={errorThrown:!1,error:null}),t(),e){var r=A,n=r.errorThrown,i=r.error;if(A=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=U,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 _("N",t,void 0)}(t),this):this._next(t)},e.prototype.error=function(t){this.isStopped?j(_("E",void 0,t),this):(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped?j(x,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&&w.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){S(t)}function j(t,e){var r=w.onStoppedNotification;r&&E.setTimeout((function(){return r(t,e)}))}var U={closed:!0,next:T,error:function(t){throw t},complete:T},C="function"==typeof Symbol&&Symbol.observable||"@@observable";function N(t){return t}function L(t){return 0===t.length?N:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)}}var F=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 k((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[C]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return L(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:w.Promise)&&void 0!==e?e:Promise}function z(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 K(t,e,r,n,i)}var K=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}($),W=f((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),M=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 G(this,this);return e.operator=t,e},e.prototype._throwIfClosed=function(){if(this.closed)throw new W},e.prototype.next=function(t){var e=this;k((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;k((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;k((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 F;return t.source=this,t},e.create=function(t,e){return new G(t,e)},e}(F),G=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}(M),Y={now:function(){return(Y.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=Y);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}(M),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=Y.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 F((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[C])}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 F)return t;if(null!=t){if(ut(t))return i=t,new F((function(t){var e=i[C]();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 F((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 F((function(t){r.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,S)}));if(ct(t))return bt(t);if(dt(t))return e=t,new F((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 F((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),z((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),z((function(r,n){n.add(t.schedule((function(){return r.subscribe(n)}),e))}))}function wt(t,e){if(!t)throw new Error("Iterable cannot be null");return new F((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 Et(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 F((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 wt(t,e);if(dt(t))return function(t,e){return new F((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 wt(ft(t),e)}(t,e)}throw lt(t)}function St(t,e){return e?Et(t,e):vt(t)}function Tt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=it(t);return St(t,r)}function xt(t,e){var r=d(t)?t:function(){return t},n=function(t){return t.error(r())};return new F(e?function(t){return e.schedule(n,0,t)}:n)}var _t=f((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function At(t,e){return z((function(r,n){var i=0;r.subscribe(H(n,(function(r){n.next(t.call(e,r,i++))})))}))}var kt=Array.isArray;function $t(t){return At((function(e){return function(t,e){return kt(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 Ut(t,e,r){return void 0===r&&(r=1/0),d(e)?Ut((function(r,n){return At((function(t,i){return e(r,t,n,i)}))(vt(t(r,n)))}),r):("number"==typeof e&&(r=e),z((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(H(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(H(e,f,(function(){h=!0,d()}))),function(){null==a||a()}}(e,n,t,r)})))}function Ct(t){return void 0===t&&(t=1/0),Ut(N,t)}function Nt(){return Ct(1)}function Lt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Nt()(St(t,it(t)))}function Ft(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 F((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 z((function(r,n){var i=0;r.subscribe(H(n,(function(r){return t.call(e,r,i++)&&n.next(r)})))}))}function zt(t){return z((function(e,r){var n,i=null,o=!1;i=e.subscribe(H(r,void 0,void 0,(function(s){n=vt(t(s,zt(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)?Ut(t,e,1):Ut(t,1)}function Kt(t){return t<=0?function(){return tt}:z((function(e,r){var n=0;e.subscribe(H(r,(function(e){++n<=t&&(r.next(e),t<=n&&r.complete())})))}))}function Wt(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}:z((function(t,e){var i,o=0,s=function(){if(null==i||i.unsubscribe(),i=null,null!=r){var t="number"==typeof r?Ft(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 Mt(t,e){return z((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 Gt(t,e,r){var n=d(t)||e||r?{next:t,error:e,complete:r}:t;return n?z((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)})))})):N}const Yt="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?Tt(r):St(r.arrayBuffer())).pipe(Mt((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(Wt(),Bt((t=>0==o--||503!==t.status)),Kt(1),Mt((t=>{switch(t.status){case 201:return St(t.json()).pipe(At((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return Tt({conflict:!0});default:return Tt({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(Wt(),Bt((t=>0==h--||503!==t.status)),zt((t=>Tt(t))),Kt(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]):Ct(n)(St(i,r)):tt}(Tt(e).pipe(Bt((t=>201!==t.status||!t.headers.get("location"))),At((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),Tt(e).pipe(Bt((t=>201===t.status&&!!t.headers.get("location"))),At((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 F(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+re);return s?Tt({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(At((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)}))),zt((()=>Tt({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 z((function(e,n){(r?Lt(t,e,r):Lt(t,e)).subscribe(n)}))}({progress:0,completed:!1}),At((t=>({status:t,file:r}))))}));return St(u).pipe(Ut((t=>t),6),At((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(Yt)}`,"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;t.Search=void 0,le=t.Search||(t.Search={}),(he=le.Features||(le.Features={})).PARAGRAPH="paragraph",he.DOCUMENT="document",he.RELATIONS="relations",he.VECTOR="vector",(de=le.ResourceFeatures||(le.ResourceFeatures={})).PARAGRAPH="paragraph",de.RELATIONS="relations",de.VECTOR="vector";const fe=(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?${pe(u,h)}`):t.rest.post(`${r}/search`,u)).pipe(zt((()=>Tt({error:!0}))),At((t=>Object.keys(t).includes("detail")?{error:!0}:t)),Gt((r=>{r.shards&&(t.currentShards=Object.assign(Object.assign({},t.currentShards),{[e]:r.shards}))})))},pe=(t,e)=>{Object.entries(e||{}).forEach((([e,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()},ve=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),be=(t,e,r,n,i)=>{const o=ve(i.filter((r=>ye(r,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=ve(i.filter((r=>me(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},ge=(t,e,r,n)=>{const i=ve(n.filter((r=>me(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},ye=(t,e,r)=>t.field.field===e&&t.field.field_type===r&&t.token&&t.token.length>0,me=(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 Ee{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.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 Se extends Ee{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 F((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?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 fe(this.nuclia,this.kb,this.path,t,e,r,!0)}setLabels(t,e,r,n){const i=be(t,e,r,n,this.fieldmetadata||[]);return this.modify({fieldmetadata:i}).pipe(Gt((()=>this.fieldmetadata=i)))}setEntities(t,e,r){const n=ge(t,e,r,this.fieldmetadata||[]);return this.modify({fieldmetadata:n}).pipe(Gt((()=>this.fieldmetadata=n)))}}var Te,xe,_e,Ae;t.FIELD_TYPE=void 0,(Te=t.FIELD_TYPE||(t.FIELD_TYPE={})).text="text",Te.file="file",Te.link="link",Te.layout="layout",Te.conversation="conversation",Te.keywordset="keywordset",Te.datetime="datetime",t.RESOURCE_STATUS=void 0,(xe=t.RESOURCE_STATUS||(t.RESOURCE_STATUS={})).PENDING="PENDING",xe.PROCESSED="PROCESSED",xe.ERROR="ERROR";t.TrainingType=void 0,(_e=t.TrainingType||(t.TrainingType={})).classifier="classifier",_e.labeler="labeler",_e.ner="ner",t.TrainingStatus=void 0,(Ae=t.TrainingStatus||(t.TrainingStatus={})).finished="finished",Ae.not_running="not_running",Ae.running="running",Ae.started="started",Ae.stopped="stopped";class ke{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(zt((()=>Tt({task:"",status:t.TrainingStatus.not_running}))))}hasModel(t){return this.nuclia.rest.get(`${this.kb.path}/train/${t}/model/json_models/nuclia.json`).pipe(At((()=>!0)),zt((()=>Tt(!1))))}}class $e{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(){return this.nuclia.rest.get(`${this.path}/entitiesgroups`).pipe(At((t=>t.groups)))}getEntitiesGroup(t){return this.nuclia.rest.get(`${this.path}/entitiesgroup/${t}`)}getLabels(){return this.nuclia.rest.get(`${this.path}/labelsets`).pipe(At((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(At((t=>new Se(this.nuclia,this.id,t))))}getResourceFromData(t){return new Se(this.nuclia,this.id,t)}search(t,e=[],r){return fe(this.nuclia,this.id,this.path,t,e,r)}suggest(t,e=!1){const r=`query=${encodeURIComponent(t)}${e?"&fields=a/title":""}`;return this.nuclia.rest.get(`${this.path}/suggest?${r}`).pipe(zt((()=>Tt({error:!0}))),At((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(At((t=>({resources:t.resources.map((t=>new Se(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(At((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 Oe extends $e{get training(){return this._training||(this._training=new ke(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(At((()=>!0)),zt((()=>Tt(!1))))}createOrUpdateResource(t,e=!0){return(t.slug?this.hasResource(t.slug):Tt(!1)).pipe(Mt((r=>r?this.getResourceFromData({id:"",slug:t.slug}).modify(t,e):this.createResource(t,e))))}importDataset(t){return this.nuclia.rest.post(`/import/${this.id}`,{export_id:t})}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 Re{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(Mt((t=>this.nuclia.options.zone?Tt(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Gt((t=>this.nuclia.options.zone=t)),At((()=>t))))),At((e=>new Oe(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 Tt(new Oe(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(Gt((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Mt((()=>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(At((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(Mt((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(At((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(At((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(Jt)&&!!localStorage.getItem(Yt)}getNUAHeader(){return{"x-stf-nuakey":`Bearer ${localStorage.getItem(Yt)}`}}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(zt((r=>{if(409===r.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw r})),Gt((t=>{"desktop"===this.nuclia.options.client&&(localStorage.setItem(Yt,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 Ie(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 F((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 Pe{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 De="JWT_KEY",je="JWT_REFRESH_KEY",Ue=216e5;class Ce{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(At((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(De),localStorage.removeItem(je),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(zt((t=>(this.logout(),xt(t)))),At((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return this.nuclia.options.public?"":localStorage.getItem(De)||""}setPassword(t){return this.fetch("/auth/setpassword",{password:t},!0,{}).pipe(At((t=>this.authenticate(t))))}deleteAuthenticatedUser(){return this.nuclia.rest.delete("/user").pipe(Gt((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new Pe(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(je)||""}storeTokens(t){localStorage.setItem(De,t.access_token),localStorage.setItem(je,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const r=this.getToken();if(r){const n=null===(t=new Pe(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<Ue?0:Ue;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Ft(r).pipe(Mt((()=>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()}`),Ie(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Mt((t=>t.ok?St(t.clone().json()):xt(t))))}}class Ne{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 Ie(this.getFullUrl(e),{selector:t=>Promise.resolve(t),headers:this.getHeaders(n,o),method:t,body:s?r:JSON.stringify(r)}).pipe(Mt((t=>t.ok?i?Tt(t):St(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("/import")?"":"/v1"}${t}`}getZones(){return this.zones?Tt(this.zones):this.get("/zones").pipe(At((t=>{const e=t.reduce(((t,e)=>(t[e.id]=e.slug,t)),{});return this.zones=e,e})))}getZoneSlug(t){return this.getZones().pipe(At((e=>e[t])))}getObjectURL(t){return this.get(t,void 0,!0).pipe(Mt((t=>St(t.blob()))),At((t=>URL.createObjectURL(t))))}}t.Authentication=Ce,t.Db=Re,t.FileFieldData=class{},t.JwtHelper=Pe,t.KeywordSetFieldData=class{},t.KnowledgeBox=$e,t.LinkFieldData=class{},t.NUA_CLIENT=Jt,t.NUA_KEY=Yt,t.Nuclia=class{constructor(t){this.currentShards={},this.options=t,this.auth=new Ce(this),this.rest=new Ne(this),this.db=new Re(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 $e(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 _t)}});t.subscribe(o)}))}(r.bind(t)(...e)):r}})}},t.ReadableResource=Ee,t.Resource=Se,t.Rest=Ne,t.TUSuploadFile=se,t.TextFieldData=class{},t.Training=ke,t.WritableKnowledgeBox=Oe,t.batchUpload=ae,t.deDuplicateList=ve,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.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=fe,t.setEntities=ge,t.setLabels=be,t.sliceUnicode=we,t.upload=ie,t.uploadFile=oe,t.uploadToProcess=ue})); |
@@ -27,3 +27,3 @@ import { Observable } from 'rxjs'; | ||
search(query: string, features?: Search.Features[], options?: SearchOptions): Observable<Search.Results>; | ||
suggest(query: string): Observable<Search.Suggestions>; | ||
suggest(query: string, inTitleOnly?: boolean): Observable<Search.Suggestions>; | ||
counters(): Observable<Counters>; | ||
@@ -30,0 +30,0 @@ listResources(page?: number, size?: number): Observable<ResourceList>; |
@@ -25,4 +25,3 @@ import type { Observable } from 'rxjs'; | ||
RESOURCES = "RESOURCES", | ||
PARAGRAPHS = "PARAGRAPHS", | ||
SENTENCES = "SENTENCES" | ||
PARAGRAPHS = "PARAGRAPHS" | ||
} | ||
@@ -29,0 +28,0 @@ export declare enum EventType { |
@@ -45,2 +45,5 @@ import { Observable } from 'rxjs'; | ||
addField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<void>; | ||
updateField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<{ | ||
seqid: number; | ||
}>; | ||
upload(field: string, file: File, TUS?: boolean, metadata?: FileMetadata): Observable<UploadResponse>; | ||
@@ -47,0 +50,0 @@ upload(field: string, buffer: ArrayBuffer, TUS?: boolean, metadata?: FileMetadata): Observable<UploadResponse>; |
@@ -302,2 +302,4 @@ export interface IResource { | ||
export interface CloudLink { | ||
filename?: string; | ||
md5?: string; | ||
uri?: string; | ||
@@ -304,0 +306,0 @@ size?: number; |
import type { ExtractedDataTypes, ResourceProperties } from '../kb'; | ||
import type { FIELD_TYPE, IResource } from '../resource'; | ||
export declare type ResourceStatus = 'PENDING' | 'PROCESSED' | 'ERROR'; | ||
export declare type SortOrder = 'asc' | 'desc'; | ||
export interface SortOption { | ||
field: 'created' | 'modified' | 'title'; | ||
limit?: number; | ||
order?: SortOrder; | ||
} | ||
export interface SearchOptions { | ||
@@ -9,3 +15,3 @@ inTitleOnly?: boolean; | ||
filters?: string[]; | ||
sort?: 'created' | 'modified'; | ||
sort?: SortOption; | ||
page_number?: number; | ||
@@ -12,0 +18,0 @@ page_size?: number; |
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
239556
4135