Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nuclia/core

Package Overview
Dependencies
Maintainers
3
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuclia/core - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

esm/index.js

@@ -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 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 d(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 p?t.errors:[t]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var v=o(d),b=v.next();!b.done;b=v.next()){var g=b.value;try{y(g)}catch(t){i=null!=i?i:[],t instanceof p?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 p(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)&&d(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&d(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 _(t){w.setTimeout((function(){throw t}))}function E(){}var k=S("C",void 0,void 0);function S(t,e,n){return{kind:t,value:e,error:n}}function x(t){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=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?j(function(t){return S("N",t,void 0)}(t),this):this._next(t)},n.prototype.error=function(t){this.isStopped?j(S("E",void 0,t),this):(this.isStopped=!0,this._error(t))},n.prototype.complete=function(){this.isStopped?j(k,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 A(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&&A(e.next,o),error:e.error&&A(e.error,o),complete:e.complete&&A(e.complete,o)}):i=e;return s.destination=new O(i),s}return e(n,t),n}($);function R(t){_(t)}function j(t,e){var n=m.onStoppedNotification;n&&w.setTimeout((function(){return n(t,e)}))}var C={closed:!0,next:E,error:function(t){throw t},complete:E},N="function"==typeof Symbol&&Symbol.observable||"@@observable";function P(t){return t}function U(t){return 0===t.length?P: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 $||function(t){return t&&h(t.next)&&h(t.error)&&h(t.complete)}(r)&&g(r)?t:new I(t,e,n);return x((function(){var t=i,e=t.operator,n=t.source;o.add(e?e.call(o,n):n?i._subscribe(o):i._trySubscribe(o))})),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var n=this;return new(e=B(e))((function(e,r){var i=new I({next:function(e){try{t(e)}catch(t){r(t),i.unsubscribe()}},error:r,complete:e});n.subscribe(i)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[N]=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=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 L(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 F(t,e,n,r,i)}var F=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 H(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;x((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;x((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;x((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,d(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 H(t,e)},n}(D),H=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),M={now:function(){return(M.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=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}(K),G=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,d(r,this),null!=e&&(this.id=this.recycleAsyncId(n,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},n}(G),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=M.now,t}(),X=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))(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[N])}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 pt(t){if(t instanceof D)return t;if(null!=t){if(st(t))return i=t,new D((function(t){var e=i[N]();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,_)}));if(ut(t))return dt(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 dt(ht(t))}var e,n,r,i;throw ct(t)}function dt(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),L((function(n,r){n.subscribe(z(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),L((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 pt(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 pt(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):pt(t)}function _t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t);return wt(t,n)}function Et(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 kt=f((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function St(t,e){return L((function(n,r){var i=0;n.subscribe(z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var xt=Array.isArray;function $t(t){return St((function(e){return function(t,e){return xt(e)?t.apply(void 0,u([],s(e))):t(e)}(t,e)}))}var Tt=Array.isArray,At=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&&At(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 jt(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 St((function(t,i){return e(n,t,r,i)}))(pt(t(n,r)))}),n):("number"==typeof e&&(n=e),L((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()},p=function(t){return a<r?d(t):c.push(t)},d=function(t){o&&e.next(t),a++;var u=!1;pt(n(t,l++)).subscribe(z(e,(function(t){null==i||i(t),o?p(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 d(t)})):d(t)};c.length&&a<r;)t();f()}catch(t){e.error(t)}})))};return t.subscribe(z(e,p,(function(){h=!0,f()}))),function(){null==u||u()}}(e,r,t,n)})))}function Nt(t){return void 0===t&&(t=1/0),Ct(P,t)}function Pt(){return Nt(1)}function Ut(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Pt()(wt(t,nt(t)))}function Dt(t,e,n){void 0===t&&(t=0),void 0===n&&(n=X);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 Bt(t,e){return L((function(n,r){var i=0;n.subscribe(z(r,(function(n){return t.call(e,n,i++)&&r.next(n)})))}))}function Lt(t){return L((function(e,n){var r,i=null,o=!1;i=e.subscribe(z(n,void 0,void 0,(function(s){r=pt(t(s,Lt(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)?Ct(t,e,1):Ct(t,1)}function Ft(t){return t<=0?function(){return Z}:L((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 Z}:L((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):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 L((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,c=o++;pt(t(n,c)).subscribe(i=z(r,(function(t){return r.next(e?e(n,t,c,s++):t)}),(function(){i=null,u()})))}),(function(){s=!0,u()})))}))}function Ht(t,e,n){var r=h(t)||e||n?{next:t,error:e,complete:n}:t;return r?L((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)})))})):P}const Mt="NUCLIA_NUA_KEY",Jt="NUCLIA_NUA_CLIENT";var Gt,Yt,Vt,qt,Xt,Zt;!function(t){t.DAY="day",t.WEEK="week",t.MONTH="month",t.YEAR="year"}(Gt||(Gt={})),function(t){t.PROCESSING_TIME="processing_time",t.SEARCHES="searches",t.CHARS="chars",t.MEDIA_SECONDS="media_seconds",t.BYTES="bytes",t.FILES="files"}(Yt||(Yt={})),function(t){t.BASIC="basic",t.ORIGIN="origin",t.RELATIONS="relations",t.VALUES="values",t.EXTRACTED="extracted",t.ERRORS="errors"}(Vt||(Vt={})),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"}(Xt||(Xt={})),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"}(Zt||(Zt={}));const Qt=new RegExp(/[^a-z0-9_-]/g),te=(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?_t(n):wt(n.arrayBuffer())).pipe(Kt((o=>r?ne(t,e,o,i,n.payload):ee(t,e,o,i))))),ee=(t,e,n,r)=>{const i=Object.assign({"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},oe(r));let o=1;return t.rest.post(`${e}/upload`,n,i).pipe(Wt(),Bt((t=>0==o--||503!==t.status)),Ft(1),Kt((t=>{switch(t.status){case 201:return wt(t.json()).pipe(St((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return _t({conflict:!0});default:return _t({failed:!0})}})))},ne=(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)}`),(null==r?void 0:r.contentType)&&l.push(`content_type ${btoa(r.contentType)}`),l.length>0&&(a["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,a,!0).pipe(Wt(),Bt((t=>0==h--||503!==t.status)),Lt((t=>_t(t))),Ft(1),zt((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?pt(i[0]):Nt(r)(wt(i,n)):Z}(_t(e).pipe(Bt((t=>201!==t.status||!t.headers.get("location"))),St((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),_t(e).pipe(Bt((t=>201===t.status&&!!t.headers.get("location"))),St((t=>t.headers.get("location"))),zt((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(zt((()=>{const i=n.slice(o,o+524288);return s?_t({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(St((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)}))),Lt((()=>_t({failed:!0}))))}))))))))))},re=(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(Qt,"_");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 te(t,i,n,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t);return L((function(e,r){(n?Ut(t,e,n):Ut(t,e)).subscribe(r)}))}({progress:0,completed:!1}),St((t=>({status:t,file:n}))))}))).pipe(Ct((t=>t),6),St((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}})))},ie=(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"},oe(n));return t.rest.post("/processing/upload",e,r)},oe=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=btoa(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},se=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ue=(t,e,n,r,i)=>{const o=se(i.filter((n=>ae(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=se(i.filter((n=>le(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},ce=(t,e,n,r)=>{const i=se(r.filter((n=>le(n,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])),o=r.filter((n=>n.field.field!==t||n.field.field_type!==e));return n.length>0||i.length>0?[...o,{field:{field:t,field_type:e},token:n.length>0?n:void 0,paragraphs:i.length>0?i:void 0}]:o},ae=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,le=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0;class he{constructor(t,e,n,r){this.data={},this.nuclia=t,this.kb=e,this.uuid=n,Object.assign(this,Object.assign(Object.assign({},r),{title:this.formatTitle(r.title)}))}get path(){return`/kb/${this.kb}/resource/${this.uuid}`}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`,{})}getField(t,e){return this.nuclia.rest.get(`${this.path}/${t}/${e}`)}getFields(t=["files","links","texts","keywordsets"]){return Object.entries(this.data).filter((([e,n])=>t.includes(e))).map((([t,e])=>e)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}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))}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;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?jt(o,n):n),t.complete())})))},c=0;c<e;c++)u(c);else t.complete()}));return n?s.pipe($t(n)):s}(this.getThumbnails().filter((t=>t.uri)).map((t=>this.nuclia.rest.getObjectURL(t.uri))))}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)),{})}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 te(this.nuclia,`${this.path}/file/${t}`,e,!!n,r)}batchUpload(t){return re(this.nuclia,this.path,t,!0)}search(t,e=[],n=!1){const r=[`query=${encodeURIComponent(t)}`,...e.map((t=>`features=${t}`))];return n&&r.push("highlight=true&split=true"),this.nuclia.rest.get(`${this.path}/search?${r.join("&")}`).pipe(Lt((()=>_t({error:!0}))),St((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}setLabels(t,e,n,r){return this.modify({fieldmetadata:ue(t,e,n,r,this.fieldmetadata||[])})}setEntities(t,e,n){return this.modify({fieldmetadata:ce(t,e,n,this.fieldmetadata||[])})}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}}class fe{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e?{valid_labelsets: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`)}}class pe{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(St((t=>t.groups)))}getEntitiesGroup(t){return this.nuclia.rest.get(`${this.path}/entitiesgroup/${t}`)}getLabels(){return this.nuclia.rest.get(`${this.path}/labelsets`).pipe(St((t=>(null==t?void 0:t.labelsets)||{})))}getResource(t,e=[Vt.BASIC,Vt.ORIGIN,Vt.RELATIONS,Vt.VALUES,Vt.EXTRACTED,Vt.ERRORS],n=[qt.TEXT,qt.METADATA,qt.LINK,qt.FILE]){const r=[...e.map((t=>`show=${t}`)),...n.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this.path}/resource/${t}?${r.join("&")}`).pipe(St((e=>new he(this.nuclia,this.id,t,e))))}search(t,e=[],n){const r=[`query=${encodeURIComponent(t)}`,...e.map((t=>`features=${t}`))];return(null==n?void 0:n.highlight)&&r.push("highlight=true&split=true"),(null==n?void 0:n.inTitleOnly)&&r.push("fields=a/title"),this.nuclia.rest.get(`${this.path}/search?${r.join("&")}`).pipe(Lt((()=>_t({error:!0}))),St((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}suggest(t){const e=`query=${encodeURIComponent(t)}`;return this.nuclia.rest.get(`${this.path}/suggest?${e}`).pipe(Lt((()=>_t({error:!0}))),St((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}getWidgets(){return this.nuclia.rest.get(`${this.path}/widgets`).pipe(St((t=>t.widgets)))}getWidget(t){return this.nuclia.rest.get(`${this.path}/widget/${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(St((t=>({resources:t.resources.map((t=>new he(this.nuclia,this.id,t.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(St((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 de extends pe{get training(){return this._training||(this._training=new fe(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)}saveWidget(t,e){return this.nuclia.rest.post(`${this.path}/widget/${t}`,e)}deleteWidget(t){return this.nuclia.rest.delete(`${this.path}/widget/${t}`)}upload(t,e,n){return te(this.nuclia,`/kb/${this.id}`,t,!!e,n)}batchUpload(t){return re(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 ve{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?_t(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Ht((t=>this.nuclia.options.zone=t)),St((()=>t))))),St((e=>new de(this.nuclia,t,e))))}if(!this.nuclia.options.knowledgeBox||!this.nuclia.options.zone)throw new Error("zone must be defined in the Nuclia options");return _t(new de(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(Ht((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Kt((()=>this.getKnowledgeBox(t,e.slug))))}getStats(t,e,n,r=Gt.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(St((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 ie(this.nuclia,t,{md5:t.md5}).pipe(Kt((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},{"x-stf-nuakey":`Bearer ${localStorage.getItem(Mt)}`}))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return this.nuclia.rest.get("/processing/pull",{"x-stf-nuakey":`Bearer ${localStorage.getItem(Mt)}`})}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(St((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)}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(Lt((n=>{if(409===n.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw n})),Ht((t=>{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}`)}}const be=(t,e)=>{var n,r;const i={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};null===(r=null===(n=t.usermetadata)||void 0===n?void 0:n.classifications)||void 0===r||r.forEach((t=>{t.labelset&&t.label&&(i[t.labelset]=t.label)}));const o=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},i),{images:o}),t.getNamedEntities())};var ge,ye,me,we,_e;!function(t){t.text="text",t.file="file",t.link="link",t.layout="layout",t.conversation="conversation",t.keywordset="keywordset",t.datetime="datetime"}(ge||(ge={})),function(t){t.PENDING="PENDING",t.PROCESSED="PROCESSED",t.ERROR="ERROR"}(ye||(ye={}));class Ee{}class ke{}class Se{}class xe{}function $e(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?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()}}))}!function(t){var e,n;(e=t.Features||(t.Features={})).PARAGRAPH="paragraph",e.DOCUMENT="document",e.RELATIONS="relations",e.VECTOR="vector",(n=t.ResourceFeatures||(t.ResourceFeatures={})).PARAGRAPH="paragraph",n.RELATIONS="relations",n.VECTOR="vector"}(me||(me={})),function(t){t.classifier="classifier",t.labeller="labeller"}(we||(we={})),function(t){t.finished="finished",t.not_running="not_running",t.running="running",t.started="started",t.stopped="stopped"}(_e||(_e={}));class Te{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 Ae{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.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(St((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(Lt((t=>(this.logout(),Et(t)))),St((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return localStorage.getItem("JWT_KEY")||""}setPassword(t){return this.fetch("/auth/setpassword",{password:t},!0,{}).pipe(St((t=>this.authenticate(t))))}deleteAuthenticatedUser(){return this.nuclia.rest.delete("/user").pipe(Ht((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new Te(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 Te(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(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()}`),$e(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Kt((t=>t.ok?wt(t.clone().json()):Et(t))))}}class Oe{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"]&&"application/json"!==r["content-type"];return $e(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?_t(t):wt(t.clone().json().catch((()=>t.text()))):Et(t))))}getFullUrl(t){return`${t.startsWith("/account")||t.startsWith("/user")||t.startsWith("/auth")||t.startsWith("/zones")||t.includes("/activity")?this.nuclia.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")?"":"/v1"}${t}`}getZones(){return this.zones?_t(this.zones):this.get("/zones").pipe(St((t=>{const e=t.reduce(((t,e)=>(t[e.id]=e.slug,t)),{});return this.zones=e,e})))}getZoneSlug(t){return this.getZones().pipe(St((e=>e[t])))}getObjectURL(t){return this.get(t,void 0,!0).pipe(Kt((t=>wt(t.blob()))),St((t=>URL.createObjectURL(t))))}}class Ie{constructor(t){this.options=t,this.auth=new Ae(this),this.rest=new Oe(this),this.db=new ve(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 pe(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 kt)}});t.subscribe(o)}))}(n.bind(t)(...e)):n}})}}export{Ae as Authentication,ve as Db,Zt as EventType,qt as ExtractedDataTypes,ge as FIELD_TYPE,Ee as FileFieldData,Te as JwtHelper,Se as KeywordSetFieldData,pe as KnowledgeBox,Xt as LabelSetKind,xe as LinkFieldData,Jt as NUA_CLIENT,Mt as NUA_KEY,Ie as Nuclia,ye as RESOURCE_STATUS,he as Resource,Vt as ResourceProperties,Oe as Rest,me as Search,Gt as StatsPeriod,Yt as StatsType,ne as TUSuploadFile,ke as TextFieldData,fe as Training,_e as TrainingStatus,we as TrainingType,de as WritableKnowledgeBox,re as batchUpload,oe as getFileMetadata,be as resourceToAlgoliaFormat,te as upload,ee as uploadFile,ie 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{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 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 d(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 p?t.errors:[t]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var v=o(d),b=v.next();!b.done;b=v.next()){var g=b.value;try{y(g)}catch(t){i=null!=i?i:[],t instanceof p?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 p(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)&&d(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&d(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 k(t){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=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?j(function(t){return x("N",t,void 0)}(t),this):this._next(t)},n.prototype.error=function(t){this.isStopped?j(x("E",void 0,t),this):(this.isStopped=!0,this._error(t))},n.prototype.complete=function(){this.isStopped?j(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 A(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&&A(e.next,o),error:e.error&&A(e.error,o),complete:e.complete&&A(e.complete,o)}):i=e;return s.destination=new O(i),s}return e(n,t),n}($);function R(t){E(t)}function j(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:_},P="function"==typeof Symbol&&Symbol.observable||"@@observable";function N(t){return t}function U(t){return 0===t.length?N: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 $||function(t){return t&&h(t.next)&&h(t.error)&&h(t.complete)}(r)&&g(r)?t:new I(t,e,n);return k((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[P]=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=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 z(t,e,n,r,i){return new F(t,e,n,r,i)}var F=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 H(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;k((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;k((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;k((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,d(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 H(t,e)},n}(D),H=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),M={now:function(){return(M.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=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}(K),G=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,d(r,this),null!=e&&(this.id=this.recycleAsyncId(n,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},n}(G),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=M.now,t}(),X=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))(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[P])}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 pt(t){if(t instanceof D)return t;if(null!=t){if(st(t))return i=t,new D((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(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 dt(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 dt(ht(t))}var e,n,r,i;throw ct(t)}function dt(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(z(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 pt(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 pt(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):pt(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(z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var kt=Array.isArray;function $t(t){return xt((function(e){return function(t,e){return kt(e)?t.apply(void 0,u([],s(e))):t(e)}(t,e)}))}var Tt=Array.isArray,At=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&&At(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 jt(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)}))(pt(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()},p=function(t){return a<r?d(t):c.push(t)},d=function(t){o&&e.next(t),a++;var u=!1;pt(n(t,l++)).subscribe(z(e,(function(t){null==i||i(t),o?p(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 d(t)})):d(t)};c.length&&a<r;)t();f()}catch(t){e.error(t)}})))};return t.subscribe(z(e,p,(function(){h=!0,f()}))),function(){null==u||u()}}(e,r,t,n)})))}function Pt(t){return void 0===t&&(t=1/0),Ct(N,t)}function Nt(){return Pt(1)}function Ut(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Nt()(wt(t,nt(t)))}function Dt(t,e,n){void 0===t&&(t=0),void 0===n&&(n=X);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(z(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(z(n,void 0,void 0,(function(s){r=pt(t(s,Bt(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)?Ct(t,e,1):Ct(t,1)}function Ft(t){return t<=0?function(){return Z}:B((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 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):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 B((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,c=o++;pt(t(n,c)).subscribe(i=z(r,(function(t){return r.next(e?e(n,t,c,s++):t)}),(function(){i=null,u()})))}),(function(){s=!0,u()})))}))}function Ht(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(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)})))})):N}const Mt="NUCLIA_NUA_KEY",Jt="NUCLIA_NUA_CLIENT";var Gt,Yt,Vt,qt,Xt,Zt;!function(t){t.DAY="day",t.WEEK="week",t.MONTH="month",t.YEAR="year"}(Gt||(Gt={})),function(t){t.PROCESSING_TIME="processing_time",t.SEARCHES="searches",t.CHARS="chars",t.MEDIA_SECONDS="media_seconds",t.BYTES="bytes",t.FILES="files"}(Yt||(Yt={})),function(t){t.BASIC="basic",t.ORIGIN="origin",t.RELATIONS="relations",t.VALUES="values",t.EXTRACTED="extracted",t.ERRORS="errors"}(Vt||(Vt={})),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"}(Xt||(Xt={})),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"}(Zt||(Zt={}));const Qt=new RegExp(/[^a-z0-9_-]/g),te=(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(Kt((o=>r?ne(t,e,o,i,n.payload):ee(t,e,o,i))))),ee=(t,e,n,r)=>{const i=Object.assign({"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},oe(r));let o=1;return t.rest.post(`${e}/upload`,n,i).pipe(Wt(),Lt((t=>0==o--||503!==t.status)),Ft(1),Kt((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})}})))},ne=(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)}`),(null==r?void 0:r.contentType)&&l.push(`content_type ${btoa(r.contentType)}`),l.length>0&&(a["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,a,!0).pipe(Wt(),Lt((t=>0==h--||503!==t.status)),Bt((t=>Et(t))),Ft(1),zt((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?pt(i[0]):Pt(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"))),zt((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(zt((()=>{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}))))}))))))))))},re=(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(Qt,"_");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 te(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?Ut(t,e,n):Ut(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}})))},ie=(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"},oe(n));return t.rest.post("/processing/upload",e,r)},oe=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=btoa(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},se=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ue=(t,e,n,r,i)=>{const o=se(i.filter((n=>ae(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=se(i.filter((n=>le(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},ce=(t,e,n,r)=>{const i=se(r.filter((n=>le(n,t,e))).map((t=>t.paragraphs)).reduce(((t,e)=>t.concat(e)),[])),o=r.filter((n=>n.field.field!==t||n.field.field_type!==e));return n.length>0||i.length>0?[...o,{field:{field:t,field_type:e},token:n.length>0?n:void 0,paragraphs:i.length>0?i:void 0}]:o},ae=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,le=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0;class he{constructor(t){this.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,n])=>t.includes(e))).map((([t,e])=>e)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}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))}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)),{})}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}}class fe extends he{constructor(t,e,n,r){super(r),this.nuclia=t,this.kb=e,this.uuid=n}get path(){return`/kb/${this.kb}/resource/${this.uuid}`}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`,{})}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;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?jt(o,n):n),t.complete())})))},c=0;c<e;c++)u(c);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)}upload(t,e,n,r){return te(this.nuclia,`${this.path}/file/${t}`,e,!!n,r)}batchUpload(t){return re(this.nuclia,this.path,t,!0)}search(t,e=[],n=!1){const r=[`query=${encodeURIComponent(t)}`,...e.map((t=>`features=${t}`))];return n&&r.push("highlight=true&split=true"),this.nuclia.rest.get(`${this.path}/search?${r.join("&")}`).pipe(Bt((()=>Et({error:!0}))),xt((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}setLabels(t,e,n,r){return this.modify({fieldmetadata:ue(t,e,n,r,this.fieldmetadata||[])})}setEntities(t,e,n){return this.modify({fieldmetadata:ce(t,e,n,this.fieldmetadata||[])})}}class pe{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e?{valid_labelsets: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`)}}class de{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=[Vt.BASIC,Vt.ORIGIN,Vt.RELATIONS,Vt.VALUES,Vt.EXTRACTED,Vt.ERRORS],n=[qt.TEXT,qt.METADATA,qt.LINK,qt.FILE]){const r=[...e.map((t=>`show=${t}`)),...n.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this.path}/resource/${t}?${r.join("&")}`).pipe(xt((e=>new fe(this.nuclia,this.id,t,e))))}search(t,e=[],n){const r=new URLSearchParams;r.append("query",t),e.forEach((t=>r.append("features",t)));const i=n||{},{inTitleOnly:o}=i,s=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}(i,["inTitleOnly"]);return o&&r.append("fields","a/title"),Object.entries(s||{}).forEach((([t,e])=>Array.isArray(e)?e.forEach((e=>r.append(t,`${e}`))):r.append(t,`${e}`))),this.nuclia.rest.get(`${this.path}/search?${r.toString()}`).pipe(Bt((()=>Et({error:!0}))),xt((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}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)))}getWidgets(){return this.nuclia.rest.get(`${this.path}/widgets`).pipe(xt((t=>t.widgets)))}getWidget(t){return this.nuclia.rest.get(`${this.path}/widget/${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 fe(this.nuclia,this.id,t.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 ve extends de{get training(){return this._training||(this._training=new pe(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)}saveWidget(t,e){return this.nuclia.rest.post(`${this.path}/widget/${t}`,e)}deleteWidget(t){return this.nuclia.rest.delete(`${this.path}/widget/${t}`)}upload(t,e,n){return te(this.nuclia,`/kb/${this.id}`,t,!!e,n)}batchUpload(t){return re(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 be{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?Et(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Ht((t=>this.nuclia.options.zone=t)),xt((()=>t))))),xt((e=>new ve(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 ve(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(Ht((t=>{if(!t.id)throw"KnowledgeBox creation failed"})),Kt((()=>this.getKnowledgeBox(t,e.slug))))}getStats(t,e,n,r=Gt.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 ie(this.nuclia,t,{md5:t.md5}).pipe(Kt((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},{"x-stf-nuakey":`Bearer ${localStorage.getItem(Mt)}`}))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return this.nuclia.rest.get("/processing/pull",{"x-stf-nuakey":`Bearer ${localStorage.getItem(Mt)}`})}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)}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})),Ht((t=>{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}`)}}const ge=(t,e)=>{var n,r;const i={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};null===(r=null===(n=t.usermetadata)||void 0===n?void 0:n.classifications)||void 0===r||r.forEach((t=>{t.labelset&&t.label&&(i[t.labelset]=t.label)}));const o=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},i),{images:o}),t.getNamedEntities())};var ye,me,we,Ee,_e;!function(t){t.text="text",t.file="file",t.link="link",t.layout="layout",t.conversation="conversation",t.keywordset="keywordset",t.datetime="datetime"}(ye||(ye={})),function(t){t.PENDING="PENDING",t.PROCESSED="PROCESSED",t.ERROR="ERROR"}(me||(me={}));class Se{}class xe{}class ke{}class $e{}function Te(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?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()}}))}!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"}(we||(we={})),function(t){t.classifier="classifier",t.labeller="labeller"}(Ee||(Ee={})),function(t){t.finished="finished",t.not_running="not_running",t.running="running",t.started="started",t.stopped="stopped"}(_e||(_e={}));class Ae{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 Oe{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.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 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(Ht((()=>this.storeTokens({access_token:"",refresh_token:""}))))}getJWTUser(){const t=this.getToken();if(t){return new Ae(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 Ae(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(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()}`),Te(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Kt((t=>t.ok?wt(t.clone().json()):_t(t))))}}class Ie{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"]&&"application/json"!==r["content-type"];return Te(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?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.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")?"":"/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(Kt((t=>wt(t.blob()))),xt((t=>URL.createObjectURL(t))))}}class Re{constructor(t){this.options=t,this.auth=new Oe(this),this.rest=new Ie(this),this.db=new be(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 de(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{Oe as Authentication,be as Db,Zt as EventType,qt as ExtractedDataTypes,ye as FIELD_TYPE,Se as FileFieldData,Ae as JwtHelper,ke as KeywordSetFieldData,de as KnowledgeBox,Xt as LabelSetKind,$e as LinkFieldData,Jt as NUA_CLIENT,Mt as NUA_KEY,Re as Nuclia,me as RESOURCE_STATUS,he as ReadableResource,fe as Resource,Vt as ResourceProperties,Ie as Rest,we as Search,Gt as StatsPeriod,Yt as StatsType,ne as TUSuploadFile,xe as TextFieldData,pe as Training,_e as TrainingStatus,Ee as TrainingType,ve as WritableKnowledgeBox,re as batchUpload,oe as getFileMetadata,ge as resourceToAlgoliaFormat,te as upload,ee as uploadFile,ie as uploadToProcess};
import type { Observable } from 'rxjs';
import type { IResource, LinkField, UserMetadata } from './resource.models';
import type { FIELD_TYPE, IResource, LinkField, UserMetadata } from './resource.models';
import type { FileMetadata, FileWithMetadata, UploadResponse, UploadStatus } from './upload';

@@ -196,4 +196,18 @@ import type { Search } from './search.models';

export interface SearchOptions {
inTitleOnly?: boolean;
highlight?: boolean;
inTitleOnly?: boolean;
faceted?: string[];
filters?: string[];
sort?: 'created' | 'modified';
page_number?: number;
page_size?: number;
max_score?: number;
range_creation_start?: string;
range_creation_end?: string;
range_modification_start?: string;
range_modification_end?: string;
show?: ResourceProperties[];
extracted?: ExtractedDataTypes[];
field_type?: FIELD_TYPE[];
shards?: string[];
}

@@ -7,9 +7,21 @@ import type { Observable } from 'rxjs';

import type { Search } from './search.models';
export interface Resource extends IResource {
export interface ReadableResource extends IResource {
}
export declare class Resource implements IResource {
export declare class ReadableResource implements IResource {
data: ResourceData;
constructor(data: IResource);
getFields<T = IFieldData>(types?: (keyof ResourceData)[]): T[];
getExtractedSummaries(): string[];
getExtractedTexts(): ExtractedText[];
getFiles(): CloudLink[];
getThumbnails(): CloudLink[];
getNamedEntities(): {
[key: string]: string[];
};
private formatTitle;
}
export declare class Resource extends ReadableResource implements IResource {
kb: string;
uuid: string;
private nuclia;
data: ResourceData;
get path(): string;

@@ -21,11 +33,3 @@ constructor(nuclia: INuclia, kb: string, uuid: string, data: IResource);

getField(type: FIELD_TYPE, field: string): Observable<ResourceField>;
getFields<T = IFieldData>(types?: (keyof ResourceData)[]): T[];
getExtractedSummaries(): string[];
getExtractedTexts(): ExtractedText[];
getFiles(): CloudLink[];
getThumbnails(): CloudLink[];
getThumbnailsUrl(): Observable<string[]>;
getNamedEntities(): {
[key: string]: string[];
};
deleteField(type: FIELD_TYPE, field: string): Observable<void>;

@@ -39,3 +43,2 @@ addField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<void>;

setEntities(fieldId: string, fieldType: string, entities: TokenAnnotation[]): Observable<void>;
private formatTitle;
}
{
"name": "@nuclia/core",
"version": "0.0.3",
"version": "0.0.4",
"description": "SDK allowing to integrate Nuclia services in your frontend application",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -661,9 +661,21 @@ import { Observable } from 'rxjs';

interface Resource extends IResource {
interface ReadableResource extends IResource {
}
declare class Resource implements IResource {
declare class ReadableResource implements IResource {
data: ResourceData;
constructor(data: IResource);
getFields<T = IFieldData>(types?: (keyof ResourceData)[]): T[];
getExtractedSummaries(): string[];
getExtractedTexts(): ExtractedText[];
getFiles(): CloudLink[];
getThumbnails(): CloudLink[];
getNamedEntities(): {
[key: string]: string[];
};
private formatTitle;
}
declare class Resource extends ReadableResource implements IResource {
kb: string;
uuid: string;
private nuclia;
data: ResourceData;
get path(): string;

@@ -675,11 +687,3 @@ constructor(nuclia: INuclia, kb: string, uuid: string, data: IResource);

getField(type: FIELD_TYPE, field: string): Observable<ResourceField>;
getFields<T = IFieldData>(types?: (keyof ResourceData)[]): T[];
getExtractedSummaries(): string[];
getExtractedTexts(): ExtractedText[];
getFiles(): CloudLink[];
getThumbnails(): CloudLink[];
getThumbnailsUrl(): Observable<string[]>;
getNamedEntities(): {
[key: string]: string[];
};
deleteField(type: FIELD_TYPE, field: string): Observable<void>;

@@ -693,3 +697,2 @@ addField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<void>;

setEntities(fieldId: string, fieldType: string, entities: TokenAnnotation[]): Observable<void>;
private formatTitle;
}

@@ -887,4 +890,18 @@

interface SearchOptions {
inTitleOnly?: boolean;
highlight?: boolean;
inTitleOnly?: boolean;
faceted?: string[];
filters?: string[];
sort?: 'created' | 'modified';
page_number?: number;
page_size?: number;
max_score?: number;
range_creation_start?: string;
range_creation_end?: string;
range_modification_start?: string;
range_modification_end?: string;
show?: ResourceProperties[];
extracted?: ExtractedDataTypes[];
field_type?: FIELD_TYPE[];
shards?: string[];
}

@@ -1060,2 +1077,2 @@

export { Account, AccountConfig, AccountCreation, AccountLimits, AccountStatus, AccountTypes, AuthTokens, Authentication, Classification, CloudLink, Counters, Db, Entities, EntitiesGroup, Entity, Event, EventList, EventType, ExtractedData, ExtractedDataTypes, ExtractedText, FIELD_TYPE, FieldComputedMetadata, 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, LabelValue, Labels, Language, LinkExtractedData, LinkField, LinkFieldData, LinkFieldExtractedData, Metadata, NUAClient, NUAClientPayload, NUA_CLIENT, NUA_KEY, NestedPosition, Nuclia, NucliaOptions, Origin, PagePositions, Paragraph, ParagraphAnnotation, ProcessingPullResponse, ProcessingPushResponse, ProcessingStat, PromiseMapper, RESOURCE_STATUS, Relation, Resource, ResourceData, ResourceField, ResourceList, ResourcePagination, ResourceProperties, Rest, Row, RowsPreview, Search, SearchOptions, Sentence, ServiceAccount, ServiceAccountCreation, ServiceAccountKey, Sheet, StatsPeriod, StatsType, TUSuploadFile, TextField, TextFieldData, TokenAnnotation, Training, TrainingExecution, TrainingStatus, TrainingTask, TrainingType, TypeParagraph, UploadResponse, UploadStatus, UserFieldMetadata, UserMetadata, UserType, Welcome, WelcomeUser, Widget, Widgets, WritableKnowledgeBox, WriteFileField, batchUpload, getFileMetadata, resourceToAlgoliaFormat, upload, uploadFile, uploadToProcess };
export { Account, AccountConfig, AccountCreation, AccountLimits, AccountStatus, AccountTypes, AuthTokens, Authentication, Classification, CloudLink, Counters, Db, Entities, EntitiesGroup, Entity, Event, EventList, EventType, ExtractedData, ExtractedDataTypes, ExtractedText, FIELD_TYPE, FieldComputedMetadata, 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, LabelValue, Labels, Language, LinkExtractedData, LinkField, LinkFieldData, LinkFieldExtractedData, Metadata, NUAClient, NUAClientPayload, NUA_CLIENT, NUA_KEY, NestedPosition, Nuclia, NucliaOptions, Origin, PagePositions, Paragraph, ParagraphAnnotation, ProcessingPullResponse, ProcessingPushResponse, ProcessingStat, PromiseMapper, RESOURCE_STATUS, ReadableResource, Relation, Resource, ResourceData, ResourceField, ResourceList, ResourcePagination, ResourceProperties, Rest, Row, RowsPreview, Search, SearchOptions, Sentence, ServiceAccount, ServiceAccountCreation, ServiceAccountKey, Sheet, StatsPeriod, StatsType, TUSuploadFile, TextField, TextFieldData, TokenAnnotation, Training, TrainingExecution, TrainingStatus, TrainingTask, TrainingType, TypeParagraph, UploadResponse, UploadStatus, UserFieldMetadata, UserMetadata, UserType, Welcome, WelcomeUser, Widget, Widgets, WritableKnowledgeBox, WriteFileField, batchUpload, getFileMetadata, resourceToAlgoliaFormat, 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,n){return e=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])},e(t,n)};function n(t,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=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=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},r.apply(this,arguments)};function i(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 o(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 s(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 u(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 c(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 l(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 h(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=s(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 f(t){return"function"==typeof t}function d(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var p=d((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function v(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,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,n,r,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=s(o),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 o.remove(this);var h=this.initialTeardown;if(f(h))try{h()}catch(t){i=t instanceof p?t.errors:[t]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var v=s(d),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=c(c([],u(i)),u(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 p(i)}},t.prototype.add=function(e){var n;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!==(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)&&v(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&v(n,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&&f(t.remove)&&f(t.add)&&f(t.unsubscribe)}function m(t){f(t)?t():t.unsubscribe()}var w={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},S={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=S.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,c([t,e],u(n))):setTimeout.apply(void 0,c([t,e],u(n)))},clearTimeout:function(t){var e=S.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function E(t){S.setTimeout((function(){throw t}))}function T(){}var x=_("C",void 0,void 0);function _(t,e,n){return{kind:t,value:e,error:n}}function k(t){t()}var $=function(t){function e(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,y(e)&&e.add(n)):n.destination=C,n}return n(e,t),e.create=function(t,e,n){return new R(t,e,n)},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),A=Function.prototype.bind;function O(t,e){return A.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){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}(),R=function(t){function e(e,n,r){var i,o,s=t.call(this)||this;f(e)||!e?i={next:null!=e?e:void 0,error:null!=n?n:void 0,complete:null!=r?r: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 I(i),s}return n(e,t),e}($);function P(t){E(t)}function j(t,e){var n=w.onStoppedNotification;n&&S.setTimeout((function(){return n(t,e)}))}var C={closed:!0,next:T,error:function(t){throw t},complete:T},D="function"==typeof Symbol&&Symbol.observable||"@@observable";function U(t){return t}function N(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&&f(t.next)&&f(t.error)&&f(t.complete)}(r)&&y(r)?t:new R(t,e,n);return k((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=F(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[D]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return N(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=F(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 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 f(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 K(t,e,n,r,i)}var K=function(t){function e(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 n(e,t),e.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))}},e}($),W=d((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),H=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 n(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 W},e.prototype.next=function(t){var e=this;k((function(){var n,r;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){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.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 n=e.observers;n.length;)n.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,n=this,r=n.hasError,i=n.isStopped,o=n.observers;return r||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,n=e.hasError,r=e.thrownError,i=e.isStopped;n?t.error(r):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,n){var r=t.call(this)||this;return r.destination=e,r.source=n,r}return n(e,t),e.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)},e.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)},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,n;return null!==(n=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==n?n:g},e}(H),G={now:function(){return(G.delegate||Date).now()},delegate:void 0},Y=function(t){function e(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 n(e,t),e.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)},e.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},e.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)}},e}(H),J=function(t){function e(e,n){return t.call(this)||this}return n(e,t),e.prototype.schedule=function(t,e){return this},e}(b),V={setInterval:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=V.delegate;return(null==i?void 0:i.setInterval)?i.setInterval.apply(i,c([t,e],u(n))):setInterval.apply(void 0,c([t,e],u(n)))},clearInterval:function(t){var e=V.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},q=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.scheduler=e,r.work=n,r.pending=!1,r}return n(e,t),e.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},e.prototype.requestAsyncId=function(t,e,n){return void 0===n&&(n=0),V.setInterval(t.flush.bind(t,this),n)},e.prototype.recycleAsyncId=function(t,e,n){if(void 0===n&&(n=0),null!=n&&this.delay===n&&!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 n=this._execute(t,e);if(n)return n;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.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},e.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,v(r,this),null!=e&&(this.id=this.recycleAsyncId(n,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(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=G.now,t}(),Z=new(function(t){function e(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 n(e,t),e.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}}},e}(X))(q),Q=new L((function(t){return t.complete()}));function tt(t){return t&&f(t.schedule)}function et(t){return t[t.length-1]}function nt(t){return f(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 f(null==t?void 0:t.then)}function ut(t){return f(t[D])}function ct(t){return Symbol.asyncIterator&&f(null==t?void 0:t[Symbol.asyncIterator])}function at(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 f(null==t?void 0:t[lt])}function ft(t){return l(this,arguments,(function(){var e,n,r;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,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 f(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[D]();if(f(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(ct(t))return vt(t);if(ht(t))return e=t,new L((function(t){var n,r;try{for(var i=s(e),o=i.next();!o.done;o=i.next()){var u=o.value;if(t.next(u),t.closed)return}}catch(t){n={error:t}}finally{try{o&&!o.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 at(t)}function vt(t){return new L((function(e){(function(t,e){var n,r,s,u;return i(this,void 0,void 0,(function(){var i,c;return o(this,(function(o){switch(o.label){case 0:o.trys.push([0,5,6,11]),n=h(t),o.label=1;case 1:return[4,n.next()];case 2:if((r=o.sent()).done)return[3,4];if(i=r.value,e.next(i),e.closed)return[2];o.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=o.sent(),s={error:c},[3,11];case 6:return o.trys.push([6,,9,10]),r&&!r.done&&(u=n.return)?[4,u.call(n)]:[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,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),B((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),B((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(ct(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 f(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 at(t)}function St(t,e){return e?wt(t,e):pt(t)}function Et(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return St(t,n)}function Tt(t,e){var n=f(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=d((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function _t(t,e){return B((function(n,r){var i=0;n.subscribe(z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var kt=Array.isArray;function $t(t){return _t((function(e){return function(t,e){return kt(e)?t.apply(void 0,c([],u(e))):t(e)}(t,e)}))}var At=Array.isArray,Ot=Object.getPrototypeOf,It=Object.prototype,Rt=Object.keys;function Pt(t){if(1===t.length){var e=t[0];if(At(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 jt(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),f(e)?Ct((function(n,r){return _t((function(t,i){return e(n,t,r,i)}))(pt(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;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{a--;for(var t=function(){var t=c.shift();s?bt(e,s,(function(){return p(t)})):p(t)};c.length&&a<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 Dt(t){return void 0===t&&(t=1/0),Ct(U,t)}function Ut(){return Dt(1)}function Nt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ut()(St(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 Ft(t,e){return B((function(n,r){var i=0;n.subscribe(z(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(z(n,void 0,void 0,(function(s){r=pt(t(s,Bt(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 f(e)?Ct(t,e,1):Ct(t,1)}function Kt(t){return t<=0?function(){return Q}:B((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}:B((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 Ht(t,e){return B((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,c=o++;pt(t(n,c)).subscribe(i=z(r,(function(t){return r.next(e?e(n,t,c,s++):t)}),(function(){i=null,u()})))}),(function(){s=!0,u()})))}))}function Mt(t,e,n){var r=f(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(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",Yt="NUCLIA_NUA_CLIENT";var Jt,Vt,qt,Xt,Zt,Qt;t.StatsPeriod=void 0,(Jt=t.StatsPeriod||(t.StatsPeriod={})).DAY="day",Jt.WEEK="week",Jt.MONTH="month",Jt.YEAR="year",t.StatsType=void 0,(Vt=t.StatsType||(t.StatsType={})).PROCESSING_TIME="processing_time",Vt.SEARCHES="searches",Vt.CHARS="chars",Vt.MEDIA_SECONDS="media_seconds",Vt.BYTES="bytes",Vt.FILES="files",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,(Xt=t.ExtractedDataTypes||(t.ExtractedDataTypes={})).TEXT="text",Xt.METADATA="metadata",Xt.LARGE_METADATA="large_metadata",Xt.VECTOR="vectors",Xt.LINK="link",Xt.FILE="file",t.LabelSetKind=void 0,(Zt=t.LabelSetKind||(t.LabelSetKind={})).RESOURCES="RESOURCES",Zt.PARAGRAPHS="PARAGRAPHS",Zt.SENTENCES="SENTENCES",t.EventType=void 0,(Qt=t.EventType||(t.EventType={})).VISITED="VISITED",Qt.MODIFIED="MODIFIED",Qt.DELETED="DELETED",Qt.NEW="NEW",Qt.STARTED="STARTED",Qt.STOPPED="STOPPED",Qt.SEARCH="SEARCH",Qt.PROCESSED="PROCESSED";const te=524288,ee=new RegExp(/[^a-z0-9_-]/g),ne=(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):St(n.arrayBuffer())).pipe(Ht((o=>r?ie(t,e,o,i,n.payload):re(t,e,o,i))))),re=(t,e,n,r)=>{const i=Object.assign({"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},ue(r));let o=1;return t.rest.post(`${e}/upload`,n,i).pipe(Wt(),Ft((t=>0==o--||503!==t.status)),Kt(1),Ht((t=>{switch(t.status){case 201:return St(t.json()).pipe(_t((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return Et({conflict:!0});default:return Et({failed:!0})}})))},ie=(t,e,n,r,i)=>{let o=0,s=!1;const u=n.byteLength,c=Math.ceil(u/te),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)}`),(null==r?void 0:r.contentType)&&l.push(`content_type ${btoa(r.contentType)}`),l.length>0&&(a["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,a,!0).pipe(Wt(),Ft((t=>0==h--||503!==t.status)),Bt((t=>Et(t))),Kt(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]):Dt(r)(St(i,n)):Q}(Et(e).pipe(Ft((t=>201!==t.status||!t.headers.get("location"))),_t((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),Et(e).pipe(Ft((t=>201===t.status&&!!t.headers.get("location"))),_t((t=>t.headers.get("location"))),zt((e=>function(t,e,n){if(null==e&&(e=t,t=0),e<=0)return Q;var r=e+t;return new L(n?function(e){var i=t;return n.schedule((function(){i<r?(e.next(i++),this.schedule()):e.complete()}))}:function(e){for(var n=t;n<r&&!e.closed;)e.next(n++);e.complete()})}(0,c).pipe(zt((()=>{const i=n.slice(o,o+te);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(_t((t=>200!==t.status?(s=!0,{failed:s}):(o+=te,{completed:o>=u,progress:o>=u?100:Math.min(Math.floor(o/u*100),100)}))),Bt((()=>Et({failed:!0}))))}))))))))))},oe=(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}))),c=i.map((n=>{let i=e;if(r){let t=n.name.toLowerCase().replace(ee,"_");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 ne(t,i,n,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return B((function(e,r){(n?Nt(t,e,n):Nt(t,e)).subscribe(r)}))}({progress:0,completed:!1}),_t((t=>({status:t,file:n}))))}));return St(c).pipe(Ct((t=>t),6),_t((t=>{const e=u.find((e=>e.file===t.file));t.status.failed&&(e.failed=!0),t.status.conflict&&(e.conflicts=!0),t.status.completed&&(e.uploaded=!0),t.status.failed||t.status.conflict||t.status.completed?e.progress=100:e.progress=t.status.progress||0;const n=u.filter((t=>t.failed)).length,r=u.filter((t=>t.conflicts)).length,i=u.filter((t=>t.uploaded)).length,s=i+n===u.length,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}})))},se=(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"},ue(n));return t.rest.post("/processing/upload",e,r)},ue=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=btoa(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},ce=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ae=(t,e,n,r,i)=>{const o=ce(i.filter((n=>he(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=ce(i.filter((n=>fe(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},le=(t,e,n,r)=>{const i=ce(r.filter((n=>fe(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},he=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,fe=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0;class de{constructor(t,e,n,r){this.data={},this.nuclia=t,this.kb=e,this.uuid=n,Object.assign(this,Object.assign(Object.assign({},r),{title:this.formatTitle(r.title)}))}get path(){return`/kb/${this.kb}/resource/${this.uuid}`}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`,{})}getField(t,e){return this.nuclia.rest.get(`${this.path}/${t}/${e}`)}getFields(t=["files","links","texts","keywordsets"]){return Object.entries(this.data).filter((([e,n])=>t.includes(e))).map((([t,e])=>e)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}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))}getThumbnailsUrl(){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=nt(t),r=Pt(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?jt(o,n):n),t.complete())})))},c=0;c<e;c++)u(c);else t.complete()}));return n?s.pipe($t(n)):s}(this.getThumbnails().filter((t=>t.uri)).map((t=>this.nuclia.rest.getObjectURL(t.uri))))}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)),{})}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 ne(this.nuclia,`${this.path}/file/${t}`,e,!!n,r)}batchUpload(t){return oe(this.nuclia,this.path,t,!0)}search(t,e=[],n=!1){const r=[`query=${encodeURIComponent(t)}`,...e.map((t=>`features=${t}`))];return n&&r.push("highlight=true&split=true"),this.nuclia.rest.get(`${this.path}/search?${r.join("&")}`).pipe(Bt((()=>Et({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}setLabels(t,e,n,r){return this.modify({fieldmetadata:ae(t,e,n,r,this.fieldmetadata||[])})}setEntities(t,e,n){return this.modify({fieldmetadata:le(t,e,n,this.fieldmetadata||[])})}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}}class pe{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e?{valid_labelsets: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`)}}class ve{constructor(t,e,n){this.nuclia=t,this.account=e,Object.assign(this,n)}get path(){return`/kb/${this.id}`}get fullpath(){return`${this.nuclia.regionalBackend}/v1/kb/${this.id}`}getEntities(){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,n=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],r=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){const i=[...n.map((t=>`show=${t}`)),...r.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this.path}/resource/${e}?${i.join("&")}`).pipe(_t((t=>new de(this.nuclia,this.id,e,t))))}search(t,e=[],n){const r=[`query=${encodeURIComponent(t)}`,...e.map((t=>`features=${t}`))];return(null==n?void 0:n.highlight)&&r.push("highlight=true&split=true"),(null==n?void 0:n.inTitleOnly)&&r.push("fields=a/title"),this.nuclia.rest.get(`${this.path}/search?${r.join("&")}`).pipe(Bt((()=>Et({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}suggest(t){const e=`query=${encodeURIComponent(t)}`;return this.nuclia.rest.get(`${this.path}/suggest?${e}`).pipe(Bt((()=>Et({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}getWidgets(){return this.nuclia.rest.get(`${this.path}/widgets`).pipe(_t((t=>t.widgets)))}getWidget(t){return this.nuclia.rest.get(`${this.path}/widget/${t}`)}counters(){return this.nuclia.rest.get(`/kb/${this.id}/counters`)}listResources(t,e){const n=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${n?"?"+n:""}`).pipe(_t((t=>({resources:t.resources.map((t=>new de(this.nuclia,this.id,t.id,t))),pagination:t.pagination}))))}getTempToken(){if(!this.nuclia.options.account||!this.nuclia.options.kbSlug)throw new Error("Account and KB slug are required to get a temp token");return this.nuclia.rest.post(`/account/${this.nuclia.options.account}/kb/${this.nuclia.options.kbSlug}/ephemeral_tokens`,{}).pipe(_t((t=>t.token)))}listActivity(t,e,n){const r=[t?`type=${t}`:"",e?`page=${e}`:"",n?`size=${n}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/activity${r?"?"+r:""}`)}}class be extends ve{get training(){return this._training||(this._training=new pe(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)}saveWidget(t,e){return this.nuclia.rest.post(`${this.path}/widget/${t}`,e)}deleteWidget(t){return this.nuclia.rest.delete(`${this.path}/widget/${t}`)}upload(t,e,n){return ne(this.nuclia,`/kb/${this.id}`,t,!!e,n)}batchUpload(t){return oe(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 ge{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(Ht((t=>this.nuclia.options.zone?Et(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Mt((t=>this.nuclia.options.zone=t)),_t((()=>t))))),_t((e=>new be(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 be(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"})),Ht((()=>this.getKnowledgeBox(t,e.slug))))}getStats(e,n,r,i=t.StatsPeriod.DAY,o){const s=[`period=${i}`,`stats=${n}`];return o&&s.push(`utctime=${o}`),r&&s.push(`knowledgebox=${r}`),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 se(this.nuclia,t,{md5:t.md5}).pipe(Ht((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},{"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`}))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return this.nuclia.rest.get("/processing/pull",{"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`})}getNUAActivity(t,e,n=0){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}/activity?page=${n}`)}getNUAClients(t){return this.nuclia.rest.get(`/account/${t}/nua_clients`).pipe(_t((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(Yt)&&!!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(Bt((n=>{if(409===n.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw n})),Mt((t=>{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}`)}}var ye,me,we,Se,Ee,Te,xe;t.FIELD_TYPE=void 0,(ye=t.FIELD_TYPE||(t.FIELD_TYPE={})).text="text",ye.file="file",ye.link="link",ye.layout="layout",ye.conversation="conversation",ye.keywordset="keywordset",ye.datetime="datetime",t.RESOURCE_STATUS=void 0,(me=t.RESOURCE_STATUS||(t.RESOURCE_STATUS={})).PENDING="PENDING",me.PROCESSED="PROCESSED",me.ERROR="ERROR";function _e(t,e){void 0===e&&(e={});var n=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,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=r(r({},i),{signal:s}),h=function(t){u=!1,e.error(t)};return fetch(t,l).then((function(t){n?pt(n(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()}}))}t.Search=void 0,we=t.Search||(t.Search={}),(Se=we.Features||(we.Features={})).PARAGRAPH="paragraph",Se.DOCUMENT="document",Se.RELATIONS="relations",Se.VECTOR="vector",(Ee=we.ResourceFeatures||(we.ResourceFeatures={})).PARAGRAPH="paragraph",Ee.RELATIONS="relations",Ee.VECTOR="vector",t.TrainingType=void 0,(Te=t.TrainingType||(t.TrainingType={})).classifier="classifier",Te.labeller="labeller",t.TrainingStatus=void 0,(xe=t.TrainingStatus||(t.TrainingStatus={})).finished="finished",xe.not_running="not_running",xe.running="running",xe.started="started",xe.stopped="stopped";class ke{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 $e="JWT_KEY",Ae="JWT_REFRESH_KEY",Oe=216e5;class Ie{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.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,n){return t<=n}))),Ft((t=>!t)));var t}login(t,e,n){return this.fetch("/auth/login",{username:t,password:e},!1,n?{"X-STF-VALIDATION":n}:{}).pipe(_t((t=>this.authenticate(t))))}authenticate(t){return t.access_token?(this.storeTokens(t),this._isAuthenticated.next(!0),!0):(this._isAuthenticated.next(!1),!1)}logout(){this.fetch("/auth/logout",{},!0,{}).subscribe(),localStorage.removeItem($e),localStorage.removeItem(Ae),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 localStorage.getItem($e)||""}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 ke(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(Ae)||""}storeTokens(t){localStorage.setItem($e,t.access_token),localStorage.setItem(Ae,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const n=this.getToken();if(n){const r=null===(t=new ke(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<Oe?0:Oe;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Lt(n).pipe(Ht((()=>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()}`),_e(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Ht((t=>t.ok?St(t.clone().json()):Tt(t))))}}class Re{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"]&&"application/json"!==r["content-type"];return _e(this.getFullUrl(e),{selector:t=>Promise.resolve(t),headers:this.getHeaders(r,o),method:t,body:s?n:JSON.stringify(n)}).pipe(Ht((t=>t.ok?i?Et(t):St(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.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")?"":"/v1"}${t}`}getZones(){return this.zones?Et(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(Ht((t=>St(t.blob()))),_t((t=>URL.createObjectURL(t))))}}t.Authentication=Ie,t.Db=ge,t.FileFieldData=class{},t.JwtHelper=ke,t.KeywordSetFieldData=class{},t.KnowledgeBox=ve,t.LinkFieldData=class{},t.NUA_CLIENT=Yt,t.NUA_KEY=Gt,t.Nuclia=class{constructor(t){this.options=t,this.auth=new Ie(this),this.rest=new Re(this),this.db=new ge(this)}get backend(){return this.options.backend}get regionalBackend(){return this.options.backend.replace("//",`//${this.options.zone}.`)}get knowledgeBox(){if(!this.options.knowledgeBox||!this.options.zone)throw new Error("zone and knowledge box id must be defined in the Nuclia options");return this.readKb||(this.readKb=new ve(this,"",{id:this.options.knowledgeBox,zone:this.options.zone})),this.readKb}get asyncKnowledgeBox(){return new Proxy(this.knowledgeBox,{get(t,e){const n=Reflect.get(t,e);return"function"==typeof n?(...e)=>function(t,e){var n="object"==typeof e;return new Promise((function(r,i){var o=new 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}})}},t.Resource=de,t.Rest=Re,t.TUSuploadFile=ie,t.TextFieldData=class{},t.Training=pe,t.WritableKnowledgeBox=be,t.batchUpload=oe,t.getFileMetadata=ue,t.resourceToAlgoliaFormat=(t,e)=>{var n,r;const i={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};null===(r=null===(n=t.usermetadata)||void 0===n?void 0:n.classifications)||void 0===r||r.forEach((t=>{t.labelset&&t.label&&(i[t.labelset]=t.label)}));const o=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},i),{images:o}),t.getNamedEntities())},t.upload=ne,t.uploadFile=re,t.uploadToProcess=se,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,n){return e=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])},e(t,n)};function n(t,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=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=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},r.apply(this,arguments)};function i(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 o(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 s(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 u(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 c(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 l(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 h(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t=s(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 f(t){return"function"==typeof t}function p(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var d=p((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function v(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,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,n,r,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=s(o),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 o.remove(this);var h=this.initialTeardown;if(f(h))try{h()}catch(t){i=t instanceof d?t.errors:[t]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var v=s(p),b=v.next();!b.done;b=v.next()){var g=b.value;try{m(g)}catch(t){i=null!=i?i:[],t instanceof d?i=c(c([],u(i)),u(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)m(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)&&v(e,t)},t.prototype.remove=function(e){var n=this._finalizers;n&&v(n,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&&f(t.remove)&&f(t.add)&&f(t.unsubscribe)}function m(t){f(t)?t():t.unsubscribe()}var w={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},S={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=S.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,c([t,e],u(n))):setTimeout.apply(void 0,c([t,e],u(n)))},clearTimeout:function(t){var e=S.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function E(t){S.setTimeout((function(){throw t}))}function x(){}var T=_("C",void 0,void 0);function _(t,e,n){return{kind:t,value:e,error:n}}function k(t){t()}var $=function(t){function e(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,y(e)&&e.add(n)):n.destination=C,n}return n(e,t),e.create=function(t,e,n){return new R(t,e,n)},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(T,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),A=Function.prototype.bind;function O(t,e){return A.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){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}(),R=function(t){function e(e,n,r){var i,o,s=t.call(this)||this;f(e)||!e?i={next:null!=e?e:void 0,error:null!=n?n:void 0,complete:null!=r?r: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 I(i),s}return n(e,t),e}($);function P(t){E(t)}function j(t,e){var n=w.onStoppedNotification;n&&S.setTimeout((function(){return n(t,e)}))}var C={closed:!0,next:x,error:function(t){throw t},complete:x},D="function"==typeof Symbol&&Symbol.observable||"@@observable";function U(t){return t}function N(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&&f(t.next)&&f(t.error)&&f(t.complete)}(r)&&y(r)?t:new R(t,e,n);return k((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=F(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[D]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return N(t)(this)},t.prototype.toPromise=function(t){var e=this;return new(t=F(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 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 f(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 K(t,e,n,r,i)}var K=function(t){function e(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 n(e,t),e.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))}},e}($),W=p((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),H=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 n(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 W},e.prototype.next=function(t){var e=this;k((function(){var n,r;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){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.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 n=e.observers;n.length;)n.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,n=this,r=n.hasError,i=n.isStopped,o=n.observers;return r||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,n=e.hasError,r=e.thrownError,i=e.isStopped;n?t.error(r):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,n){var r=t.call(this)||this;return r.destination=e,r.source=n,r}return n(e,t),e.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)},e.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)},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,n;return null!==(n=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==n?n:g},e}(H),G={now:function(){return(G.delegate||Date).now()},delegate:void 0},Y=function(t){function e(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 n(e,t),e.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)},e.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},e.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)}},e}(H),J=function(t){function e(e,n){return t.call(this)||this}return n(e,t),e.prototype.schedule=function(t,e){return this},e}(b),V={setInterval:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=V.delegate;return(null==i?void 0:i.setInterval)?i.setInterval.apply(i,c([t,e],u(n))):setInterval.apply(void 0,c([t,e],u(n)))},clearInterval:function(t){var e=V.delegate;return((null==e?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0},q=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.scheduler=e,r.work=n,r.pending=!1,r}return n(e,t),e.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},e.prototype.requestAsyncId=function(t,e,n){return void 0===n&&(n=0),V.setInterval(t.flush.bind(t,this),n)},e.prototype.recycleAsyncId=function(t,e,n){if(void 0===n&&(n=0),null!=n&&this.delay===n&&!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 n=this._execute(t,e);if(n)return n;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.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},e.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,v(r,this),null!=e&&(this.id=this.recycleAsyncId(n,e,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(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=G.now,t}(),Z=new(function(t){function e(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 n(e,t),e.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}}},e}(X))(q),Q=new L((function(t){return t.complete()}));function tt(t){return t&&f(t.schedule)}function et(t){return t[t.length-1]}function nt(t){return f(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 f(null==t?void 0:t.then)}function ut(t){return f(t[D])}function ct(t){return Symbol.asyncIterator&&f(null==t?void 0:t[Symbol.asyncIterator])}function at(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 f(null==t?void 0:t[lt])}function ft(t){return l(this,arguments,(function(){var e,n,r;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,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 pt(t){return f(null==t?void 0:t.getReader)}function dt(t){if(t instanceof L)return t;if(null!=t){if(ut(t))return i=t,new L((function(t){var e=i[D]();if(f(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(ct(t))return vt(t);if(ht(t))return e=t,new L((function(t){var n,r;try{for(var i=s(e),o=i.next();!o.done;o=i.next()){var u=o.value;if(t.next(u),t.closed)return}}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}t.complete()}));if(pt(t))return vt(ft(t))}var e,n,r,i;throw at(t)}function vt(t){return new L((function(e){(function(t,e){var n,r,s,u;return i(this,void 0,void 0,(function(){var i,c;return o(this,(function(o){switch(o.label){case 0:o.trys.push([0,5,6,11]),n=h(t),o.label=1;case 1:return[4,n.next()];case 2:if((r=o.sent()).done)return[3,4];if(i=r.value,e.next(i),e.closed)return[2];o.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=o.sent(),s={error:c},[3,11];case 6:return o.trys.push([6,,9,10]),r&&!r.done&&(u=n.return)?[4,u.call(n)]:[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,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),B((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),B((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 dt(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 dt(t).pipe(yt(e),gt(e))}(t,e);if(ct(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 f(null==r?void 0:r.return)&&r.return()}}))}(t,e);if(pt(t))return function(t,e){return mt(ft(t),e)}(t,e)}throw at(t)}function St(t,e){return e?wt(t,e):dt(t)}function Et(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return St(t,n)}function xt(t,e){var n=f(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 Tt=p((function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}}));function _t(t,e){return B((function(n,r){var i=0;n.subscribe(z(r,(function(n){r.next(t.call(e,n,i++))})))}))}var kt=Array.isArray;function $t(t){return _t((function(e){return function(t,e){return kt(e)?t.apply(void 0,c([],u(e))):t(e)}(t,e)}))}var At=Array.isArray,Ot=Object.getPrototypeOf,It=Object.prototype,Rt=Object.keys;function Pt(t){if(1===t.length){var e=t[0];if(At(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 jt(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),f(e)?Ct((function(n,r){return _t((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()},p=function(t){return a<r?d(t):c.push(t)},d=function(t){o&&e.next(t),a++;var u=!1;dt(n(t,l++)).subscribe(z(e,(function(t){null==i||i(t),o?p(t):e.next(t)}),(function(){u=!0}),void 0,(function(){if(u)try{a--;for(var t=function(){var t=c.shift();s?bt(e,s,(function(){return d(t)})):d(t)};c.length&&a<r;)t();f()}catch(t){e.error(t)}})))};return t.subscribe(z(e,p,(function(){h=!0,f()}))),function(){null==u||u()}}(e,r,t,n)})))}function Dt(t){return void 0===t&&(t=1/0),Ct(U,t)}function Ut(){return Dt(1)}function Nt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ut()(St(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 Ft(t,e){return B((function(n,r){var i=0;n.subscribe(z(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(z(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 zt(t,e){return f(e)?Ct(t,e,1):Ct(t,1)}function Kt(t){return t<=0?function(){return Q}:B((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}:B((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):dt(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 Ht(t,e){return B((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,c=o++;dt(t(n,c)).subscribe(i=z(r,(function(t){return r.next(e?e(n,t,c,s++):t)}),(function(){i=null,u()})))}),(function(){s=!0,u()})))}))}function Mt(t,e,n){var r=f(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(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",Yt="NUCLIA_NUA_CLIENT";var Jt,Vt,qt,Xt,Zt,Qt;t.StatsPeriod=void 0,(Jt=t.StatsPeriod||(t.StatsPeriod={})).DAY="day",Jt.WEEK="week",Jt.MONTH="month",Jt.YEAR="year",t.StatsType=void 0,(Vt=t.StatsType||(t.StatsType={})).PROCESSING_TIME="processing_time",Vt.SEARCHES="searches",Vt.CHARS="chars",Vt.MEDIA_SECONDS="media_seconds",Vt.BYTES="bytes",Vt.FILES="files",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,(Xt=t.ExtractedDataTypes||(t.ExtractedDataTypes={})).TEXT="text",Xt.METADATA="metadata",Xt.LARGE_METADATA="large_metadata",Xt.VECTOR="vectors",Xt.LINK="link",Xt.FILE="file",t.LabelSetKind=void 0,(Zt=t.LabelSetKind||(t.LabelSetKind={})).RESOURCES="RESOURCES",Zt.PARAGRAPHS="PARAGRAPHS",Zt.SENTENCES="SENTENCES",t.EventType=void 0,(Qt=t.EventType||(t.EventType={})).VISITED="VISITED",Qt.MODIFIED="MODIFIED",Qt.DELETED="DELETED",Qt.NEW="NEW",Qt.STARTED="STARTED",Qt.STOPPED="STOPPED",Qt.SEARCH="SEARCH",Qt.PROCESSED="PROCESSED";const te=524288,ee=new RegExp(/[^a-z0-9_-]/g),ne=(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):St(n.arrayBuffer())).pipe(Ht((o=>r?ie(t,e,o,i,n.payload):re(t,e,o,i))))),re=(t,e,n,r)=>{const i=Object.assign({"content-type":(null==r?void 0:r.contentType)||"application/octet-stream"},ue(r));let o=1;return t.rest.post(`${e}/upload`,n,i).pipe(Wt(),Ft((t=>0==o--||503!==t.status)),Kt(1),Ht((t=>{switch(t.status){case 201:return St(t.json()).pipe(_t((t=>({resource:t.uuid||"",field:t.field_id||"",completed:!0}))));case 409:return Et({conflict:!0});default:return Et({failed:!0})}})))},ie=(t,e,n,r,i)=>{let o=0,s=!1;const u=n.byteLength,c=Math.ceil(u/te),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)}`),(null==r?void 0:r.contentType)&&l.push(`content_type ${btoa(r.contentType)}`),l.length>0&&(a["upload-metadata"]=l.join(","));let h=1;return t.rest.post(`${e}/tusupload`,i,a,!0).pipe(Wt(),Ft((t=>0==h--||503!==t.status)),Bt((t=>Et(t))),Kt(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?dt(i[0]):Dt(r)(St(i,n)):Q}(Et(e).pipe(Ft((t=>201!==t.status||!t.headers.get("location"))),_t((t=>409===t.status?{conflict:!0,failed:!0}:{failed:!0}))),Et(e).pipe(Ft((t=>201===t.status&&!!t.headers.get("location"))),_t((t=>t.headers.get("location"))),zt((e=>function(t,e,n){if(null==e&&(e=t,t=0),e<=0)return Q;var r=e+t;return new L(n?function(e){var i=t;return n.schedule((function(){i<r?(e.next(i++),this.schedule()):e.complete()}))}:function(e){for(var n=t;n<r&&!e.closed;)e.next(n++);e.complete()})}(0,c).pipe(zt((()=>{const i=n.slice(o,o+te);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(_t((t=>200!==t.status?(s=!0,{failed:s}):(o+=te,{completed:o>=u,progress:o>=u?100:Math.min(Math.floor(o/u*100),100)}))),Bt((()=>Et({failed:!0}))))}))))))))))},oe=(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}))),c=i.map((n=>{let i=e;if(r){let t=n.name.toLowerCase().replace(ee,"_");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 ne(t,i,n,!0,{}).pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=rt(t);return B((function(e,r){(n?Nt(t,e,n):Nt(t,e)).subscribe(r)}))}({progress:0,completed:!1}),_t((t=>({status:t,file:n}))))}));return St(c).pipe(Ct((t=>t),6),_t((t=>{const e=u.find((e=>e.file===t.file));t.status.failed&&(e.failed=!0),t.status.conflict&&(e.conflicts=!0),t.status.completed&&(e.uploaded=!0),t.status.failed||t.status.conflict||t.status.completed?e.progress=100:e.progress=t.status.progress||0;const n=u.filter((t=>t.failed)).length,r=u.filter((t=>t.conflicts)).length,i=u.filter((t=>t.uploaded)).length,s=i+n===u.length,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}})))},se=(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"},ue(n));return t.rest.post("/processing/upload",e,r)},ue=t=>{const e={};return(null==t?void 0:t.filename)&&(e["x-filename"]=btoa(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},ce=t=>[...new Set([...t].map((t=>JSON.stringify(t))))].map((t=>JSON.parse(t))),ae=(t,e,n,r,i)=>{const o=ce(i.filter((n=>he(n,t,e))).map((t=>t.token)).reduce(((t,e)=>t.concat(e)),[])),s=ce(i.filter((n=>fe(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},le=(t,e,n,r)=>{const i=ce(r.filter((n=>fe(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},he=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.token&&t.token.length>0,fe=(t,e,n)=>t.field.field===e&&t.field.field_type===n&&t.paragraphs&&t.paragraphs.length>0;class pe{constructor(t){this.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,n])=>t.includes(e))).map((([t,e])=>e)).filter((t=>!!t)).map((t=>Object.values(t))).reduce(((t,e)=>t.concat(e)),[])}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))}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)),{})}formatTitle(t){t=t||"–";try{return decodeURIComponent(t)}catch(e){return t}}}class de extends pe{constructor(t,e,n,r){super(r),this.nuclia=t,this.kb=e,this.uuid=n}get path(){return`/kb/${this.kb}/resource/${this.uuid}`}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`,{})}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=Pt(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;dt(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?jt(o,n):n),t.complete())})))},c=0;c<e;c++)u(c);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)}upload(t,e,n,r){return ne(this.nuclia,`${this.path}/file/${t}`,e,!!n,r)}batchUpload(t){return oe(this.nuclia,this.path,t,!0)}search(t,e=[],n=!1){const r=[`query=${encodeURIComponent(t)}`,...e.map((t=>`features=${t}`))];return n&&r.push("highlight=true&split=true"),this.nuclia.rest.get(`${this.path}/search?${r.join("&")}`).pipe(Bt((()=>Et({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}setLabels(t,e,n,r){return this.modify({fieldmetadata:ae(t,e,n,r,this.fieldmetadata||[])})}setEntities(t,e,n){return this.modify({fieldmetadata:le(t,e,n,this.fieldmetadata||[])})}}class ve{constructor(t,e){this.kb=t,this.nuclia=e}start(t,e){return this.nuclia.rest.post(`${this.kb.path}/train/${t}/start`,e?{valid_labelsets: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`)}}class be{constructor(t,e,n){this.nuclia=t,this.account=e,Object.assign(this,n)}get path(){return`/kb/${this.id}`}get fullpath(){return`${this.nuclia.regionalBackend}/v1/kb/${this.id}`}getEntities(){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,n=[t.ResourceProperties.BASIC,t.ResourceProperties.ORIGIN,t.ResourceProperties.RELATIONS,t.ResourceProperties.VALUES,t.ResourceProperties.EXTRACTED,t.ResourceProperties.ERRORS],r=[t.ExtractedDataTypes.TEXT,t.ExtractedDataTypes.METADATA,t.ExtractedDataTypes.LINK,t.ExtractedDataTypes.FILE]){const i=[...n.map((t=>`show=${t}`)),...r.map((t=>`extracted=${t}`))];return this.nuclia.rest.get(`${this.path}/resource/${e}?${i.join("&")}`).pipe(_t((t=>new de(this.nuclia,this.id,e,t))))}search(t,e=[],n){const r=new URLSearchParams;r.append("query",t),e.forEach((t=>r.append("features",t)));const i=n||{},{inTitleOnly:o}=i,s=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}(i,["inTitleOnly"]);return o&&r.append("fields","a/title"),Object.entries(s||{}).forEach((([t,e])=>Array.isArray(e)?e.forEach((e=>r.append(t,`${e}`))):r.append(t,`${e}`))),this.nuclia.rest.get(`${this.path}/search?${r.toString()}`).pipe(Bt((()=>Et({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}suggest(t){const e=`query=${encodeURIComponent(t)}`;return this.nuclia.rest.get(`${this.path}/suggest?${e}`).pipe(Bt((()=>Et({error:!0}))),_t((t=>Object.keys(t).includes("detail")?{error:!0}:t)))}getWidgets(){return this.nuclia.rest.get(`${this.path}/widgets`).pipe(_t((t=>t.widgets)))}getWidget(t){return this.nuclia.rest.get(`${this.path}/widget/${t}`)}counters(){return this.nuclia.rest.get(`/kb/${this.id}/counters`)}listResources(t,e){const n=[t?`page=${t}`:"",e?`size=${e}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/resources${n?"?"+n:""}`).pipe(_t((t=>({resources:t.resources.map((t=>new de(this.nuclia,this.id,t.id,t))),pagination:t.pagination}))))}getTempToken(){if(!this.nuclia.options.account||!this.nuclia.options.kbSlug)throw new Error("Account and KB slug are required to get a temp token");return this.nuclia.rest.post(`/account/${this.nuclia.options.account}/kb/${this.nuclia.options.kbSlug}/ephemeral_tokens`,{}).pipe(_t((t=>t.token)))}listActivity(t,e,n){const r=[t?`type=${t}`:"",e?`page=${e}`:"",n?`size=${n}`:""].filter((t=>t)).join("&");return this.nuclia.rest.get(`/kb/${this.id}/activity${r?"?"+r:""}`)}}class ge extends be{get training(){return this._training||(this._training=new ve(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)}saveWidget(t,e){return this.nuclia.rest.post(`${this.path}/widget/${t}`,e)}deleteWidget(t){return this.nuclia.rest.delete(`${this.path}/widget/${t}`)}upload(t,e,n){return ne(this.nuclia,`/kb/${this.id}`,t,!!e,n)}batchUpload(t){return oe(this.nuclia,`/kb/${this.id}`,t,!1)}getServiceAccounts(){return this.nuclia.rest.get(`/account/${this.account}/kb/${this.slug}/service_accounts`)}createServiceAccount(t){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_accounts`,t)}deleteServiceAccount(t){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}`)}createKey(t,e){return this.nuclia.rest.post(`/account/${this.account}/kb/${this.slug}/service_account/${t}/keys`,{expires:e})}deleteKey(t,e){return this.nuclia.rest.delete(`/account/${this.account}/kb/${this.slug}/service_account/${t}/key/${e}`)}}class ye{constructor(t){this.nuclia=t}getAccounts(){return this.nuclia.rest.get("/accounts")}createAccount(t){return this.nuclia.rest.post("/accounts",t)}modifyAccount(t,e){return this.nuclia.rest.patch(`/account/${t}`,e)}deleteAccount(t){return this.nuclia.rest.delete(`/account/${t}`)}getAccountStatus(t){return this.nuclia.rest.get(`/account/${t}/status`)}getWelcome(){return this.nuclia.rest.get("/user/welcome")}getAccount(t){if(!(t=t||this.nuclia.options.account))throw new Error("Account is not set");return this.nuclia.rest.get(`/account/${t}`)}getKnowledgeBoxes(t){return this.nuclia.rest.get(`/account/${t}/kbs`)}getKnowledgeBox(t,e){if(t=t||this.nuclia.options.account){const 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(Ht((t=>this.nuclia.options.zone?Et(t):this.nuclia.rest.getZoneSlug(t.zone).pipe(Mt((t=>this.nuclia.options.zone=t)),_t((()=>t))))),_t((e=>new ge(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 ge(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"})),Ht((()=>this.getKnowledgeBox(t,e.slug))))}getStats(e,n,r,i=t.StatsPeriod.DAY,o){const s=[`period=${i}`,`stats=${n}`];return o&&s.push(`utctime=${o}`),r&&s.push(`knowledgebox=${r}`),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 se(this.nuclia,t,{md5:t.md5}).pipe(Ht((t=>this.nuclia.rest.post("/processing/push",{filefield:{file:t}},{"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`}))))}pull(){if(!this.hasNUAClient())throw new Error("NUA key is needed to be able to call /process");return this.nuclia.rest.get("/processing/pull",{"x-stf-nuakey":`Bearer ${localStorage.getItem(Gt)}`})}getNUAActivity(t,e,n=0){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}/activity?page=${n}`)}getNUAClients(t){return this.nuclia.rest.get(`/account/${t}/nua_clients`).pipe(_t((t=>t.clients)))}getNUAClient(t,e){return this.nuclia.rest.get(`/account/${t}/nua_client/${e}`)}hasNUAClient(){return!!localStorage.getItem(Yt)&&!!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(Bt((n=>{if(409===n.status&&e.client_id)return this.renewNUAClient(t,e.client_id);throw n})),Mt((t=>{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}`)}}var me,we,Se,Ee,xe,Te,_e;t.FIELD_TYPE=void 0,(me=t.FIELD_TYPE||(t.FIELD_TYPE={})).text="text",me.file="file",me.link="link",me.layout="layout",me.conversation="conversation",me.keywordset="keywordset",me.datetime="datetime",t.RESOURCE_STATUS=void 0,(we=t.RESOURCE_STATUS||(t.RESOURCE_STATUS={})).PENDING="PENDING",we.PROCESSED="PROCESSED",we.ERROR="ERROR";function ke(t,e){void 0===e&&(e={});var n=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,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=r(r({},i),{signal:s}),h=function(t){u=!1,e.error(t)};return fetch(t,l).then((function(t){n?dt(n(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()}}))}t.Search=void 0,Se=t.Search||(t.Search={}),(Ee=Se.Features||(Se.Features={})).PARAGRAPH="paragraph",Ee.DOCUMENT="document",Ee.RELATIONS="relations",Ee.VECTOR="vector",(xe=Se.ResourceFeatures||(Se.ResourceFeatures={})).PARAGRAPH="paragraph",xe.RELATIONS="relations",xe.VECTOR="vector",t.TrainingType=void 0,(Te=t.TrainingType||(t.TrainingType={})).classifier="classifier",Te.labeller="labeller",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 $e{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 Ae="JWT_KEY",Oe="JWT_REFRESH_KEY",Ie=216e5;class Re{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.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,n){return t<=n}))),Ft((t=>!t)));var t}login(t,e,n){return this.fetch("/auth/login",{username:t,password:e},!1,n?{"X-STF-VALIDATION":n}:{}).pipe(_t((t=>this.authenticate(t))))}authenticate(t){return t.access_token?(this.storeTokens(t),this._isAuthenticated.next(!0),!0):(this._isAuthenticated.next(!1),!1)}logout(){this.fetch("/auth/logout",{},!0,{}).subscribe(),localStorage.removeItem(Ae),localStorage.removeItem(Oe),this._isAuthenticated.next(!1)}refresh(){return this.fetch("/auth/refresh",{refresh_token:this.getRefreshToken()},!0,{}).pipe(Bt((t=>(this.logout(),xt(t)))),_t((t=>t.access_token?(this.storeTokens(t),!0):(this.logout(),!1))))}getToken(){return localStorage.getItem(Ae)||""}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 $e(t).getJWTUser()}return null}getRefreshToken(){return localStorage.getItem(Oe)||""}storeTokens(t){localStorage.setItem(Ae,t.access_token),localStorage.setItem(Oe,t.refresh_token),this.checkTokenExpiration()}checkTokenExpiration(){var t,e;const n=this.getToken();if(n){const r=null===(t=new $e(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<Ie?0:Ie;null===(e=this.timerSubscription)||void 0===e||e.unsubscribe(),this.timerSubscription=Lt(n).pipe(Ht((()=>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()}`),ke(`${this.nuclia.backend}${t}`,{method:"POST",selector:t=>Promise.resolve(t),headers:i,body:JSON.stringify(e)}).pipe(Ht((t=>t.ok?St(t.clone().json()):xt(t))))}}class Pe{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"]&&"application/json"!==r["content-type"];return ke(this.getFullUrl(e),{selector:t=>Promise.resolve(t),headers:this.getHeaders(r,o),method:t,body:s?n:JSON.stringify(n)}).pipe(Ht((t=>t.ok?i?Et(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.backend:this.nuclia.regionalBackend}${t.startsWith("/auth")?"":"/v1"}${t}`}getZones(){return this.zones?Et(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(Ht((t=>St(t.blob()))),_t((t=>URL.createObjectURL(t))))}}t.Authentication=Re,t.Db=ye,t.FileFieldData=class{},t.JwtHelper=$e,t.KeywordSetFieldData=class{},t.KnowledgeBox=be,t.LinkFieldData=class{},t.NUA_CLIENT=Yt,t.NUA_KEY=Gt,t.Nuclia=class{constructor(t){this.options=t,this.auth=new Re(this),this.rest=new Pe(this),this.db=new ye(this)}get backend(){return this.options.backend}get regionalBackend(){return this.options.backend.replace("//",`//${this.options.zone}.`)}get knowledgeBox(){if(!this.options.knowledgeBox||!this.options.zone)throw new Error("zone and knowledge box id must be defined in the Nuclia options");return this.readKb||(this.readKb=new be(this,"",{id:this.options.knowledgeBox,zone:this.options.zone})),this.readKb}get asyncKnowledgeBox(){return new Proxy(this.knowledgeBox,{get(t,e){const n=Reflect.get(t,e);return"function"==typeof n?(...e)=>function(t,e){var n="object"==typeof e;return new Promise((function(r,i){var o=new R({next:function(t){r(t),o.unsubscribe()},error:i,complete:function(){n?r(e.defaultValue):i(new Tt)}});t.subscribe(o)}))}(n.bind(t)(...e)):n}})}},t.ReadableResource=pe,t.Resource=de,t.Rest=Pe,t.TUSuploadFile=ie,t.TextFieldData=class{},t.Training=ve,t.WritableKnowledgeBox=ge,t.batchUpload=oe,t.getFileMetadata=ue,t.resourceToAlgoliaFormat=(t,e)=>{var n,r;const i={title:t.title,fullText:t.getExtractedTexts().filter((t=>t)).map((t=>t.text))};null===(r=null===(n=t.usermetadata)||void 0===n?void 0:n.classifications)||void 0===r||r.forEach((t=>{t.labelset&&t.label&&(i[t.labelset]=t.label)}));const o=t.getThumbnails().filter((t=>!!t.uri)).map((t=>`${e}/v1${t.uri}`));return Object.assign(Object.assign(Object.assign({},i),{images:o}),t.getNamedEntities())},t.upload=ne,t.uploadFile=re,t.uploadToProcess=se,Object.defineProperty(t,"__esModule",{value:!0})}));
import type { Observable } from 'rxjs';
import type { IResource, LinkField, UserMetadata } from './resource.models';
import type { FIELD_TYPE, IResource, LinkField, UserMetadata } from './resource.models';
import type { FileMetadata, FileWithMetadata, UploadResponse, UploadStatus } from './upload';

@@ -196,4 +196,18 @@ import type { Search } from './search.models';

export interface SearchOptions {
inTitleOnly?: boolean;
highlight?: boolean;
inTitleOnly?: boolean;
faceted?: string[];
filters?: string[];
sort?: 'created' | 'modified';
page_number?: number;
page_size?: number;
max_score?: number;
range_creation_start?: string;
range_creation_end?: string;
range_modification_start?: string;
range_modification_end?: string;
show?: ResourceProperties[];
extracted?: ExtractedDataTypes[];
field_type?: FIELD_TYPE[];
shards?: string[];
}

@@ -7,9 +7,21 @@ import type { Observable } from 'rxjs';

import type { Search } from './search.models';
export interface Resource extends IResource {
export interface ReadableResource extends IResource {
}
export declare class Resource implements IResource {
export declare class ReadableResource implements IResource {
data: ResourceData;
constructor(data: IResource);
getFields<T = IFieldData>(types?: (keyof ResourceData)[]): T[];
getExtractedSummaries(): string[];
getExtractedTexts(): ExtractedText[];
getFiles(): CloudLink[];
getThumbnails(): CloudLink[];
getNamedEntities(): {
[key: string]: string[];
};
private formatTitle;
}
export declare class Resource extends ReadableResource implements IResource {
kb: string;
uuid: string;
private nuclia;
data: ResourceData;
get path(): string;

@@ -21,11 +33,3 @@ constructor(nuclia: INuclia, kb: string, uuid: string, data: IResource);

getField(type: FIELD_TYPE, field: string): Observable<ResourceField>;
getFields<T = IFieldData>(types?: (keyof ResourceData)[]): T[];
getExtractedSummaries(): string[];
getExtractedTexts(): ExtractedText[];
getFiles(): CloudLink[];
getThumbnails(): CloudLink[];
getThumbnailsUrl(): Observable<string[]>;
getNamedEntities(): {
[key: string]: string[];
};
deleteField(type: FIELD_TYPE, field: string): Observable<void>;

@@ -39,3 +43,2 @@ addField(type: FIELD_TYPE, field: string, data: TextField | LinkField | FileField | KeywordSetField): Observable<void>;

setEntities(fieldId: string, fieldType: string, entities: TokenAnnotation[]): Observable<void>;
private formatTitle;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc