@corva/ui 0.33.0-6 → 0.33.0-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/slicedToArray";import r from"@babel/runtime/helpers/classCallCheck";import n from"@babel/runtime/regenerator";import a from"@babel/runtime/helpers/asyncToGenerator";import{parse as o,stringify as s}from"query-string";import{getDCAppKey as i}from"../utils.js";import c from"@babel/runtime/helpers/createClass";import{DISPLAY_HTTP_MESSAGES as p}from"./httpMessages.js";function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function l(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?u(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var h={400:"Request Failed",403:"No Permission",404:"Not Found"},f=["POST","PUT","PATCH","DELETE"],d=function(){function e(t,n){r(this,e),this.status=t.status,this.statusText=t.statusText,this.message=n.message||"No Message"}return c(e,[{key:"isAuthenticationProblem",value:function(){return 401===this.status||"Invalid authentication token"===this.message}},{key:"isTermsProblem",value:function(){return 401===this.status&&"Please accept the latest terms of service"===this.message}}]),e}(),m=o(window.location.search).api_url||process.env.REACT_APP_API_URL||"https://api.qa.corva.ai",y={"Content-Type":"application/json",Accept:"application/json"};function v(e){var t=e.config,r=e.appKey;return l(l({},t),{},{headers:l(l({},t.headers||{}),{},{"X-Corva-App":r})})}function b(e){e.isAuthenticationProblem&&e.isAuthenticationProblem()&&!e.isTermsProblem()&&(console.error("Problem with user"),"/login"!==window.location.pathname&&(window.location.href="/login"))}var g=/^\/v1\/assets.*/;function w(){return(w=a(n.mark((function e(t){var r,a,o,s,i,c=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=c.length>1&&void 0!==c[1]?c[1]:{},a=c.length>2&&void 0!==c[2]?c[2]:{},o=a.apiUrl,s=void 0===o?m:o,i=a.appKey,g.test(t)&&(r.cache="reload"),r.credentials="include",e.abrupt("return",fetch("".concat(s).concat(t),v({config:r,appKey:i})));case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var P,x,O=(P=function(e){return w.apply(this,arguments)},x=a(n.mark((function e(t,r,a){var o,s,i,c,u,l,m;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,P(t,r,a);case 2:if(o=e.sent,s=o.status,!o.ok){e.next=6;break}return e.abrupt("return",204===s?null:o);case 6:return e.prev=6,e.next=9,o.json();case 9:i=e.sent,e.next=15;break;case 12:e.prev=12,e.t0=e.catch(6),i={};case 15:throw c=r.method,u=f.includes(c),l=p[i.message]||h[s],u&&l&&console.error("ERROR"),b(m=new d(o,i)),m;case 22:case"end":return e.stop()}}),e,null,[[6,12]])}))),function(e,t,r){return x.apply(this,arguments)});function j(e,t){return k.apply(this,arguments)}function k(){return(k=a(n.mark((function e(t,r){var a,o,s,c=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=c.length>2&&void 0!==c[2]?c[2]:{},o=a.apiUrl,e.next=4,O(t,{method:"POST",headers:y,body:JSON.stringify(r)},{apiUrl:o,appKey:i()});case 4:return s=e.sent,e.abrupt("return",s&&s.json());case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function T(e){return A.apply(this,arguments)}function A(){return(A=a(n.mark((function e(t){var r,a,o,i,c,p,u=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=u.length>1&&void 0!==u[1]?u[1]:{},a=u.length>2&&void 0!==u[2]?u[2]:{},o=a.apiUrl,i=a.appKey,c=s(r,{arrayFormat:"bracket"}),e.next=6,O("".concat(t).concat(c?"?":"").concat(c),{method:"GET"},{apiUrl:o,appKey:i});case 6:if(p=e.sent,e.t0=p,!e.t0){e.next=12;break}return e.next=11,p.json();case 11:e.t0=e.sent;case 12:return e.t1=e.t0,e.t2=p&&p.headers,e.abrupt("return",{data:e.t1,headers:e.t2});case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function U(e){return E.apply(this,arguments)}function E(){return(E=a(n.mark((function e(t){var r,a,o,s=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>1&&void 0!==s[1]?s[1]:{},a=s.length>2&&void 0!==s[2]?s[2]:{},e.next=4,T(t,r,l(l({},a),{},{appKey:a.appKey||i()}));case 4:return o=e.sent,e.abrupt("return",o.data);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function K(e,t){return C.apply(this,arguments)}function C(){return(C=a(n.mark((function e(t,r){var a,o,c,p,u,l=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=l.length>2&&void 0!==l[2]?l[2]:{},o=l.length>3&&void 0!==l[3]?l[3]:{},c=o.apiUrl,p=s(a),e.next=6,O("".concat(t).concat(p?"?":"").concat(p),{method:"PUT",headers:y,body:JSON.stringify(r)},{apiUrl:c,appKey:i()});case 6:return u=e.sent,e.abrupt("return",u&&u.json());case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function S(e,t){return D.apply(this,arguments)}function D(){return(D=a(n.mark((function e(t,r){var a,o,c,p,u,l=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=l.length>2&&void 0!==l[2]?l[2]:{},o=l.length>3&&void 0!==l[3]?l[3]:{},c=o.apiUrl,p=s(a),e.next=6,O("".concat(t).concat(p?"?":"").concat(p),{method:"PATCH",headers:y,body:JSON.stringify(r)},{apiUrl:c,appKey:i()});case 6:return u=e.sent,e.abrupt("return",u&&u.json());case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function N(e){return R.apply(this,arguments)}function R(){return(R=a(n.mark((function e(t){var r,a,o,c,p,u=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=u.length>1&&void 0!==u[1]?u[1]:{},a=u.length>2&&void 0!==u[2]?u[2]:{},o=a.apiUrl,c=s(r),e.next=6,O(c?"".concat(t,"?").concat(c):t,{method:"DELETE",headers:y},{apiUrl:o,appKey:i()});case 6:return p=e.sent,e.abrupt("return",p&&p.json());case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function F(e,t){return _.apply(this,arguments)}function _(){return(_=a(n.mark((function e(r,a){var o,c,p,u,l,h,f,d=arguments;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=d.length>2&&void 0!==d[2]?d[2]:{},c=d.length>3&&void 0!==d[3]?d[3]:{},p=s(o),u=c.method,l=void 0===u?"POST":u,h=new FormData,Object.entries(a).forEach((function(e){var r=t(e,2),n=r[0],a=r[1];Array.isArray(a)?a.forEach((function(e){h.append(n,e)})):h.append(n,a)})),e.next=8,O(p?"".concat(r,"?").concat(p):r,{method:l,headers:{Accept:"application/json"},body:h},{appKey:i()});case 8:return f=e.sent,e.abrupt("return",f&&f.json());case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}export{m as baseUrl,N as del,U as get,T as getWithHeaders,b as handleAuthenticationProblem,S as patch,j as post,K as put,F as sendFormData};
1
+ import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/slicedToArray";import r from"@babel/runtime/helpers/classCallCheck";import n from"@babel/runtime/regenerator";import a from"@babel/runtime/helpers/asyncToGenerator";import{parse as o,stringify as s}from"query-string";import{getAppKeyFromStackTrace as i,attachHTTPHeaders as c}from"../utils.js";import u from"@babel/runtime/helpers/createClass";import{DISPLAY_HTTP_MESSAGES as p}from"./httpMessages.js";function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function h(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?l(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var f={400:"Request Failed",403:"No Permission",404:"Not Found"},d=["POST","PUT","PATCH","DELETE"],m=function(){function t(e,n){r(this,t),this.status=e.status,this.statusText=e.statusText,this.message=n.message||"No Message"}return u(t,[{key:"isAuthenticationProblem",value:function(){return 401===this.status||"Invalid authentication token"===this.message}},{key:"isTermsProblem",value:function(){return 401===this.status&&"Please accept the latest terms of service"===this.message}}]),t}(),y=o(window.location.search).api_url||process.env.REACT_APP_API_URL||"https://api.qa.corva.ai",v={"Content-Type":"application/json",Accept:"application/json"};function b(t){t.isAuthenticationProblem&&t.isAuthenticationProblem()&&!t.isTermsProblem()&&(console.error("Problem with user"),"/login"!==window.location.pathname&&(window.location.href="/login"))}var g=/^\/v1\/assets.*/;function w(){return(w=a(n.mark((function t(e){var r,a,o,s,i,u=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=u.length>1&&void 0!==u[1]?u[1]:{},a=u.length>2&&void 0!==u[2]?u[2]:{},o=a.apiUrl,s=void 0===o?y:o,i=a.appKey,g.test(e)&&(r.cache="reload"),r.credentials="include",t.abrupt("return",fetch("".concat(s).concat(e),c({config:r,appKey:i})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var P,x,O=(P=function(t){return w.apply(this,arguments)},x=a(n.mark((function t(e,r,a){var o,s,i,c,u,l,h;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,P(e,r,a);case 2:if(o=t.sent,s=o.status,!o.ok){t.next=6;break}return t.abrupt("return",204===s?null:o);case 6:return t.prev=6,t.next=9,o.json();case 9:i=t.sent,t.next=15;break;case 12:t.prev=12,t.t0=t.catch(6),i={};case 15:throw c=r.method,u=d.includes(c),l=p[i.message]||f[s],u&&l&&console.error("ERROR"),b(h=new m(o,i)),h;case 22:case"end":return t.stop()}}),t,null,[[6,12]])}))),function(t,e,r){return x.apply(this,arguments)});function j(t,e){return k.apply(this,arguments)}function k(){return(k=a(n.mark((function t(e,r){var a,o,s,c=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=c.length>2&&void 0!==c[2]?c[2]:{},o=a.apiUrl,t.next=4,O(e,{method:"POST",headers:v,body:JSON.stringify(r)},{apiUrl:o,appKey:i()});case 4:return s=t.sent,t.abrupt("return",s&&s.json());case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function T(t){return U.apply(this,arguments)}function U(){return(U=a(n.mark((function t(e){var r,a,o,c,u,p,l=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=l.length>1&&void 0!==l[1]?l[1]:{},a=l.length>2&&void 0!==l[2]?l[2]:{},o=a.apiUrl,c=a.appKey,u=s(r,{arrayFormat:"bracket"}),t.next=6,O("".concat(e).concat(u?"?":"").concat(u),{method:"GET"},{apiUrl:o,appKey:c||i()});case 6:if(p=t.sent,t.t0=p,!t.t0){t.next=12;break}return t.next=11,p.json();case 11:t.t0=t.sent;case 12:return t.t1=t.t0,t.t2=p&&p.headers,t.abrupt("return",{data:t.t1,headers:t.t2});case 15:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function A(t){return E.apply(this,arguments)}function E(){return(E=a(n.mark((function t(e){var r,a,o,s=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=s.length>1&&void 0!==s[1]?s[1]:{},a=s.length>2&&void 0!==s[2]?s[2]:{},t.next=4,T(e,r,h(h({},a),{},{appKey:a.appKey||i()}));case 4:return o=t.sent,t.abrupt("return",o.data);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function K(t,e){return S.apply(this,arguments)}function S(){return(S=a(n.mark((function t(e,r){var a,o,c,u,p,l=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=l.length>2&&void 0!==l[2]?l[2]:{},o=l.length>3&&void 0!==l[3]?l[3]:{},c=o.apiUrl,u=s(a),t.next=6,O("".concat(e).concat(u?"?":"").concat(u),{method:"PUT",headers:v,body:JSON.stringify(r)},{apiUrl:c,appKey:i()});case 6:return p=t.sent,t.abrupt("return",p&&p.json());case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function C(t,e){return D.apply(this,arguments)}function D(){return(D=a(n.mark((function t(e,r){var a,o,c,u,p,l=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=l.length>2&&void 0!==l[2]?l[2]:{},o=l.length>3&&void 0!==l[3]?l[3]:{},c=o.apiUrl,u=s(a),t.next=6,O("".concat(e).concat(u?"?":"").concat(u),{method:"PATCH",headers:v,body:JSON.stringify(r)},{apiUrl:c,appKey:i()});case 6:return p=t.sent,t.abrupt("return",p&&p.json());case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function N(t){return R.apply(this,arguments)}function R(){return(R=a(n.mark((function t(e){var r,a,o,c,u,p=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=p.length>1&&void 0!==p[1]?p[1]:{},a=p.length>2&&void 0!==p[2]?p[2]:{},o=a.apiUrl,c=s(r),t.next=6,O(c?"".concat(e,"?").concat(c):e,{method:"DELETE",headers:v},{apiUrl:o,appKey:i()});case 6:return u=t.sent,t.abrupt("return",u&&u.json());case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function F(t,e){return _.apply(this,arguments)}function _(){return(_=a(n.mark((function t(r,a){var o,c,u,p,l,h,f,d=arguments;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=d.length>2&&void 0!==d[2]?d[2]:{},c=d.length>3&&void 0!==d[3]?d[3]:{},u=s(o),p=c.method,l=void 0===p?"POST":p,h=new FormData,Object.entries(a).forEach((function(t){var r=e(t,2),n=r[0],a=r[1];Array.isArray(a)?a.forEach((function(t){h.append(n,t)})):h.append(n,a)})),t.next=8,O(u?"".concat(r,"?").concat(u):r,{method:l,headers:{Accept:"application/json"},body:h},{appKey:i()});case 8:return f=t.sent,t.abrupt("return",f&&f.json());case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}export{y as baseUrl,N as del,A as get,T as getWithHeaders,b as handleAuthenticationProblem,C as patch,j as post,K as put,F as sendFormData};
package/clients/utils.js CHANGED
@@ -1 +1 @@
1
- var r=/corva\.ai\/(.+?)\/packages/;function a(){var a=Error.stackTraceLimit;Error.stackTraceLimit=30;var c=(new Error).stack.match(r);return Error.stackTraceLimit=a,c?c[1].replace("/app/","."):null}export{a as getDCAppKey};
1
+ import r from"@babel/runtime/helpers/defineProperty";function e(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(r);e&&(c=c.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,c)}return t}function t(t){for(var c=1;c<arguments.length;c++){var n=null!=arguments[c]?arguments[c]:{};c%2?e(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}var c=/corva\.ai\/(.+?)\/packages/,n=/app\/(.+?)\.chunk\.js/;function a(){var r=Error.stackTraceLimit;Error.stackTraceLimit=300;var e=new Error,t=e.stack.match(c)||e.stack.match(n);return Error.stackTraceLimit=r,t?t[1].replace("/app/","."):null}function o(r){var e=r.config,c=r.appKey,n=t({},e.headers||{});return c&&(n["x-corva-app"]=c),t(t({},e),{},{headers:n})}export{o as attachHTTPHeaders,a as getAppKeyFromStackTrace};
@@ -1 +1 @@
1
- import r from"@babel/runtime/helpers/defineProperty";import{castArray as t,differenceBy as e,omit as n,merge as u,concat as a,mapValues as i}from"lodash";import o from"@babel/runtime/helpers/slicedToArray";import c from"@babel/runtime/regenerator";import s from"@babel/runtime/helpers/asyncToGenerator";import{useState as p,useRef as f,useMemo as l,useEffect as m}from"react";import{parse as b}from"querystring";import d from"uuid/v1";import{getDCAppKey as y}from"../clients/utils.js";import{getAppStorage as v,getDataAppStorage as h,getDataAppStorageAggregate as O}from"../clients/jsonApi/index.js";import{getSubscriptionId as w}from"../clients/subscriptions.js";function g(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function j(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}function I(r,t,e){var n=w(r,t);return j(j({},r),{},{hookId:t,subId:n,appInstanceId:n,app_key:e})}function k(r,t){return x.apply(this,arguments)}function x(){return(x=s(c.mark((function r(t,e){var n,u,a;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.timeQuery,u=e.appKey,a=t.map(function(){var r=s(c.mark((function r(t){var e,a,i,o,s,p,f,l,m;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e=t.provider,a=t.collection,i=t.assetId,o=t.subscribeOnly,s=t.params,!o){r.next=3;break}return r.abrupt("return",null);case 3:return p=s.query,f=n?"{timestamp#lte#".concat(n.timestamp.$lte):"",l=p&&f?"AND":"",m="".concat(p).concat(l).concat(f),r.prev=7,r.next=10,v(e,a,i,j(j(j({},s),m?{query:m}:{}),{},{appKey:u}));case 10:return r.abrupt("return",r.sent);case 13:return r.prev=13,r.t0=r.catch(7),r.abrupt("return",[]);case 16:case"end":return r.stop()}}),r,null,[[7,13]])})));return function(t){return r.apply(this,arguments)}}()),r.abrupt("return",Promise.all(a));case 3:case"end":return r.stop()}}),r)})))).apply(this,arguments)}function P(r,t){return E.apply(this,arguments)}function E(){return(E=s(c.mark((function r(t,e){var n,a,o;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.timeQuery,a=e.appKey,o=t.map(function(){var r=s(c.mark((function r(t){var e,o,s,p,f,l,m,b,d,y,v,w;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e=t.provider,o=t.collection,s=t.assetId,p=t.subscribeOnly,f=t.params,l=void 0===f?{}:f,!p){r.next=3;break}return r.abrupt("return",null);case 3:if(!l.aggregate){r.next=5;break}return r.abrupt("return",O(e,o,j({},i(l.aggregate,JSON.stringify))));case 5:return m=JSON.stringify(u({asset_id:s},l.query,n)),b=l.limit,d=void 0===b?1:b,y=l.sort,v=void 0===y?'{"timestamp": 1}':y,r.prev=7,w=j(j({},l),{},{limit:d,sort:v,query:m,appKey:a}),r.next=11,h(e,o,w);case 11:return r.abrupt("return",r.sent);case 14:return r.prev=14,r.t0=r.catch(7),r.abrupt("return",[]);case 17:case"end":return r.stop()}}),r,null,[[7,14]])})));return function(t){return r.apply(this,arguments)}}()),r.abrupt("return",Promise.all(o));case 3:case"end":return r.stop()}}),r)})))).apply(this,arguments)}function D(u){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=i.timestamp,s=i.isOldApiUsed,v=p({}),h=o(v,2),O=h[0],w=h[1],g=f();g.current||(g.current=d());var x=window[Symbol.for("socket")],E=x.subscribe,D=x.unsubscribe,S=x.socket,q=l((function(){return y()}),[]),A=f([]),K=t(u).map((function(r){return I(r,g.current,q)})),N=K.map((function(r){return r.subId})).join(),Q=l((function(){if(c)return{timestamp:{$lte:c}};var r=b(window.location.search).time;return r?{timestamp:{$lte:new Date(r)/1e3}}:null}),[window.location.search,c]);return m((function(){var t=function(t){t.hookId===g.current&&w((function(e){var n=t.data;return t.subId in e&&!t.subscribeOnly&&(n=a(e[t.subId],t.data)),t.params&&t.params.limit&&(n=n.slice(-t.params.limit)),j(j({},e),{},r({},t.subId,n))}))};return S&&S.on("data",t),function(){return S&&S.off("data",t)}}),[]),m((function(){A.current.forEach(D),A.current=[]}),[Q]),m((function(){var r=A.current,t=e(K,r,"subId"),u=e(r,K,"subId");t.forEach((function(r){Q&&!r.alwaysSubscribe||E(r)})),u.forEach(D),A.current=K,(s?k:P)(t,{timeQuery:Q,appKey:q,isOldApiUsed:s}).then((function(r){return w((function(e){var a=n(e,u.map((function(r){return r.subId})));return t.forEach((function(t,e){null!==r[e]&&(a[t.subId]=r[e])})),a}))}))}),[N,Q]),m((function(){return function(){return A.current.forEach(D)}}),[]),l((function(){return K.map((function(r){var t=r.subId;return{loading:!(t in O),data:O[t]}}))}),[O,N])}export default D;
1
+ import r from"@babel/runtime/helpers/defineProperty";import{castArray as t,differenceBy as e,omit as n,merge as u,concat as a,mapValues as i}from"lodash";import o from"@babel/runtime/helpers/slicedToArray";import c from"@babel/runtime/regenerator";import s from"@babel/runtime/helpers/asyncToGenerator";import{useState as p,useRef as f,useMemo as l,useEffect as m}from"react";import{parse as b}from"querystring";import d from"uuid/v1";import{getAppKeyFromStackTrace as y}from"../clients/utils.js";import{getAppStorage as v,getDataAppStorage as h,getDataAppStorageAggregate as O}from"../clients/jsonApi/index.js";import{getSubscriptionId as w}from"../clients/subscriptions.js";function g(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function j(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}function I(r,t,e){var n=w(r,t);return j(j({},r),{},{hookId:t,subId:n,appInstanceId:n,app_key:e})}function k(r,t){return x.apply(this,arguments)}function x(){return(x=s(c.mark((function r(t,e){var n,u,a;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.timeQuery,u=e.appKey,a=t.map(function(){var r=s(c.mark((function r(t){var e,a,i,o,s,p,f,l,m;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e=t.provider,a=t.collection,i=t.assetId,o=t.subscribeOnly,s=t.params,!o){r.next=3;break}return r.abrupt("return",null);case 3:return p=s.query,f=n?"{timestamp#lte#".concat(n.timestamp.$lte):"",l=p&&f?"AND":"",m="".concat(p).concat(l).concat(f),r.prev=7,r.next=10,v(e,a,i,j(j(j({},s),m?{query:m}:{}),{},{appKey:u}));case 10:return r.abrupt("return",r.sent);case 13:return r.prev=13,r.t0=r.catch(7),r.abrupt("return",[]);case 16:case"end":return r.stop()}}),r,null,[[7,13]])})));return function(t){return r.apply(this,arguments)}}()),r.abrupt("return",Promise.all(a));case 3:case"end":return r.stop()}}),r)})))).apply(this,arguments)}function P(r,t){return E.apply(this,arguments)}function E(){return(E=s(c.mark((function r(t,e){var n,a,o;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.timeQuery,a=e.appKey,o=t.map(function(){var r=s(c.mark((function r(t){var e,o,s,p,f,l,m,b,d,y,v,w;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e=t.provider,o=t.collection,s=t.assetId,p=t.subscribeOnly,f=t.params,l=void 0===f?{}:f,!p){r.next=3;break}return r.abrupt("return",null);case 3:if(!l.aggregate){r.next=5;break}return r.abrupt("return",O(e,o,j({},i(l.aggregate,JSON.stringify))));case 5:return m=JSON.stringify(u({asset_id:s},l.query,n)),b=l.limit,d=void 0===b?1:b,y=l.sort,v=void 0===y?'{"timestamp": 1}':y,r.prev=7,w=j(j({},l),{},{limit:d,sort:v,query:m,appKey:a}),r.next=11,h(e,o,w);case 11:return r.abrupt("return",r.sent);case 14:return r.prev=14,r.t0=r.catch(7),r.abrupt("return",[]);case 17:case"end":return r.stop()}}),r,null,[[7,14]])})));return function(t){return r.apply(this,arguments)}}()),r.abrupt("return",Promise.all(o));case 3:case"end":return r.stop()}}),r)})))).apply(this,arguments)}function D(u){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=i.timestamp,s=i.isOldApiUsed,v=p({}),h=o(v,2),O=h[0],w=h[1],g=f();g.current||(g.current=d());var x=window[Symbol.for("socket")],E=x.subscribe,D=x.unsubscribe,S=x.socket,q=l((function(){return y()}),[]),A=f([]),K=t(u).map((function(r){return I(r,g.current,q)})),N=K.map((function(r){return r.subId})).join(),Q=l((function(){if(c)return{timestamp:{$lte:c}};var r=b(window.location.search).time;return r?{timestamp:{$lte:new Date(r)/1e3}}:null}),[window.location.search,c]);return m((function(){var t=function(t){t.hookId===g.current&&w((function(e){var n=t.data;return t.subId in e&&!t.subscribeOnly&&(n=a(e[t.subId],t.data)),t.params&&t.params.limit&&(n=n.slice(-t.params.limit)),j(j({},e),{},r({},t.subId,n))}))};return S&&S.on("data",t),function(){return S&&S.off("data",t)}}),[]),m((function(){A.current.forEach(D),A.current=[]}),[Q]),m((function(){var r=A.current,t=e(K,r,"subId"),u=e(r,K,"subId");t.forEach((function(r){Q&&!r.alwaysSubscribe||E(r)})),u.forEach(D),A.current=K,(s?k:P)(t,{timeQuery:Q,appKey:q,isOldApiUsed:s}).then((function(r){return w((function(e){var a=n(e,u.map((function(r){return r.subId})));return t.forEach((function(t,e){null!==r[e]&&(a[t.subId]=r[e])})),a}))}))}),[N,Q]),m((function(){return function(){return A.current.forEach(D)}}),[]),l((function(){return K.map((function(r){var t=r.subId;return{loading:!(t in O),data:O[t]}}))}),[O,N])}export default D;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/ui",
3
- "version": "0.33.0-6",
3
+ "version": "0.33.0-7",
4
4
  "description": "Shared components/utils for Corva ui projects",
5
5
  "keywords": [
6
6
  "corva-ui"