@machinemetrics/mm-react-tools 4.0.5 → 4.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.
@@ -23079,7 +23079,7 @@ const TF = () => {
23079
23079
  loginUrl: "https://login.development.machinemetrics.com",
23080
23080
  appUrl: "https://app.development.machinemetrics.com",
23081
23081
  apiUrl: "https://api.development.machinemetrics.com",
23082
- graphQLUrl: "https://development.graphql.machinemetrics.com/v1/graphql",
23082
+ graphQLUrl: "https://hasura.tsdb.perlman.m12s.com/v1/graphql",
23083
23083
  natsUrl: "https://stream.data.dev.m12s.com"
23084
23084
  }
23085
23085
  }, AF = fI([
@@ -135,7 +135,7 @@ function print() { __p += __j.call(arguments, '') }
135
135
  font-size: 20px;
136
136
  text-align: center;
137
137
  margin-top: 300px;
138
- `;const bI=()=>{const{isAuthenticated:r}=ti(),{authorize:e,authError:t,setAuthError:n}=he.useContext(rc);return bo(async i=>{try{await e(i)}catch(a){console.log(a),n("Login Failed. Try again.")}},[]),t?nr.jsx(Fb,{loadError:t}):r?nr.jsx(Fb,{}):nr.jsx(nr.Fragment,{})},xo={production:{loginUrl:"https://login.machinemetrics.com",appUrl:"https://app.machinemetrics.com",apiUrl:"https://api.machinemetrics.com",graphQLUrl:"https://graphql.machinemetrics.com/v1/graphql",natsUrl:"https://stream.machinemetrics.com"},staging:{loginUrl:"https://login-staging.machinemetrics.com",appUrl:"https://staging.machinemetrics.com",apiUrl:"https://api-staging.machinemetrics.com",graphQLUrl:"https://development.graphql.machinemetrics.com/v1/graphql",natsUrl:"https://stream.data.dev.m12s.com"},development:{loginUrl:"https://login.development.machinemetrics.com",appUrl:"https://app.development.machinemetrics.com",apiUrl:"https://api.development.machinemetrics.com",graphQLUrl:"https://development.graphql.machinemetrics.com/v1/graphql",natsUrl:"https://stream.data.dev.m12s.com"}},wI=pn.createBrowserRouter([{path:"/authorize/mm/callback",element:nr.jsx(bI,{})},{path:"/*",element:nr.jsx(gI,{})}]),_I=({domain:r,children:e,scope:t,clientId:n,clientSecret:i,releaseStage:a,graphQLRoleOverride:u,urls:c})=>{r&&console.warn("MMProvider domain is no longer used. It is inferred from the url.");const[f,h]=he.useState(),[d,y]=he.useState(!1);let g;if(xo[a])g=xo[a];else if(!g){const oe=ci.keys(xo).join(", "),Ie=ci.keys(xo[Object.keys(xo)[0]]);throw Error(`MMProvider releaseStage must be one of the following: ${oe}, or the following urls need to be provided: ${Ie}.`)}g=ci.merge(g,c);const[m,b]=he.useState(xk());he.useEffect(()=>{Sk(m)},[m]);const I=oe=>{const Ie=A0();I0(Ie),k0(window.location.pathname+window.location.search);const Ne=(ge=>ci.map(ge,(ve,pe)=>`${pe}=${ve}`).join("&"))({response_type:"code",state:Ie,scope:t,ttl:1209600,client_id:n,redirect_uri:`${window.location.origin}/authorize/mm/callback`,...oe}),Ce=`${g.loginUrl}/oauth/authorize?${Ne}`;window.location=Ce},x=async oe=>{const Ie=vk.parse(window.location.search),ye=Ie.code;if(Ie.error)throw Error(Ie.error_description);if(Ie.state!==Ok())throw Error("Oops");const Ne={grant_type:"authorization_code",client_id:n,client_secret:i,code:ye,redirect_uri:`${window.location.origin}/authorize/mm/callback`},Ce=await C0(`${g.loginUrl}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:new URLSearchParams(Ne),signal:oe});b(Ce.access_token),I0()},_=()=>{b()},A=async(oe,Ie={})=>{Ie.headers={...Ie.headers,"Content-Type":"application/json",Authorization:`Bearer ${m}`};const ye=await C0(oe,Ie);if(ye.error&&ye.error.status===401)throw await P(),Error("UNAUTHORIZED");return ye},P=async()=>{await A(`${g.loginUrl}/logout`,{method:"DELETE"}),_()},[M,U]=he.useState(),W=he.useRef(),K=he.useRef();wo(async()=>{if(!m){W.current=null,U(!1);return}try{const oe=await A(`${g.apiUrl}/user-token?graphql=1`);W.current=oe,U(!0)}catch{}},1e3*60*4.5,[m]),wo(async()=>{if(!m){K.current=null;return}try{const oe=await A(`${g.apiUrl}/nats-token`);K.current=oe}catch{}},1e3*60*9.5,[m]);const X=he.useMemo(()=>({clientId:n,accessToken:m,jwtRef:W,natsCredsRef:K,isAuthenticated:M,login:I,logout:P,request:A,urls:g}),[m,n,M,W,I,P,K,A,g]),fe=he.useMemo(()=>({children:e,graphQLRoleOverride:u,authorize:x,isEmbedded:d,setIsEmbedded:y,authError:f,setAuthError:h}),[e,u,x,d,y,f,h]);return nr.jsx(c0.Provider,{value:X,children:nr.jsx(rc.Provider,{value:fe,children:nr.jsx(pn.RouterProvider,{router:wI})})})},bn=new Uint8Array(0),xi=new TextEncoder,cn=new TextDecoder;function xI(...r){let e=0;for(let i=0;i<r.length;i++)e+=r[i].length;const t=new Uint8Array(e);let n=0;for(let i=0;i<r.length;i++)t.set(r[i],n),n+=r[i].length;return t}function So(...r){const e=[];for(let t=0;t<r.length;t++)e.push(xi.encode(r[t]));return e.length===0?bn:e.length===1?e[0]:xI(...e)}function Lb(r){return!r||r.length===0?"":cn.decode(r)}const qb="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",jb=36,SI=0xcfd41b9100000,Ub=33,EI=333,$b=22;function OI(r){for(let e=0;e<r.length;e++)r[e]=Math.floor(Math.random()*255)}function TI(r){var e;(e=globalThis==null?void 0:globalThis.crypto)!=null&&e.getRandomValues?globalThis.crypto.getRandomValues(r):OI(r)}class AI{constructor(){E(this,"buf");E(this,"seq");E(this,"inc");E(this,"inited");this.buf=new Uint8Array($b),this.inited=!1}init(){this.inited=!0,this.setPre(),this.initSeqAndInc(),this.fillSeq()}initSeqAndInc(){this.seq=Math.floor(Math.random()*SI),this.inc=Math.floor(Math.random()*(EI-Ub)+Ub)}setPre(){const e=new Uint8Array(12);TI(e);for(let t=0;t<12;t++){const n=e[t]%36;this.buf[t]=qb.charCodeAt(n)}}fillSeq(){let e=this.seq;for(let t=$b-1;t>=12;t--)this.buf[t]=qb.charCodeAt(e%jb),e=Math.floor(e/jb)}next(){return this.inited||this.init(),this.seq+=this.inc,this.seq>0xcfd41b9100000&&(this.setPre(),this.initSeqAndInc()),this.fillSeq(),String.fromCharCode.apply(String,this.buf)}reset(){this.init()}}const Cs=new AI;var Si;(function(r){r.Disconnect="disconnect",r.Reconnect="reconnect",r.Update="update",r.LDM="ldm",r.Error="error"})(Si||(Si={}));var pa;(function(r){r.Reconnecting="reconnecting",r.PingTimer="pingTimer",r.StaleConnection="staleConnection",r.ClientInitiatedReconnect="client initiated reconnect"})(pa||(pa={}));var we;(function(r){r.ApiError="BAD API",r.BadAuthentication="BAD_AUTHENTICATION",r.BadCreds="BAD_CREDS",r.BadHeader="BAD_HEADER",r.BadJson="BAD_JSON",r.BadPayload="BAD_PAYLOAD",r.BadSubject="BAD_SUBJECT",r.Cancelled="CANCELLED",r.ConnectionClosed="CONNECTION_CLOSED",r.ConnectionDraining="CONNECTION_DRAINING",r.ConnectionRefused="CONNECTION_REFUSED",r.ConnectionTimeout="CONNECTION_TIMEOUT",r.Disconnect="DISCONNECT",r.InvalidOption="INVALID_OPTION",r.InvalidPayload="INVALID_PAYLOAD",r.MaxPayloadExceeded="MAX_PAYLOAD_EXCEEDED",r.NoResponders="503",r.NotFunction="NOT_FUNC",r.RequestError="REQUEST_ERROR",r.ServerOptionNotAvailable="SERVER_OPT_NA",r.SubClosed="SUB_CLOSED",r.SubDraining="SUB_DRAINING",r.Timeout="TIMEOUT",r.Tls="TLS",r.Unknown="UNKNOWN_ERROR",r.WssRequired="WSS_REQUIRED",r.JetStreamInvalidAck="JESTREAM_INVALID_ACK",r.JetStream404NoMessages="404",r.JetStream408RequestTimeout="408",r.JetStream409MaxAckPendingExceeded="409",r.JetStream409="409",r.JetStreamNotEnabled="503",r.JetStreamIdleHeartBeat="IDLE_HEARTBEAT",r.AuthorizationViolation="AUTHORIZATION_VIOLATION",r.AuthenticationExpired="AUTHENTICATION_EXPIRED",r.ProtocolError="NATS_PROTOCOL_ERR",r.PermissionsViolation="PERMISSIONS_VIOLATION",r.AuthenticationTimeout="AUTHENTICATION_TIMEOUT",r.AccountExpired="ACCOUNT_EXPIRED"})(we||(we={}));function kI(r){return typeof r.code=="string"}class Bb{constructor(){E(this,"messages");this.messages=new Map,this.messages.set(we.InvalidPayload,"Invalid payload type - payloads can be 'binary', 'string', or 'json'"),this.messages.set(we.BadJson,"Bad JSON"),this.messages.set(we.WssRequired,"TLS is required, therefore a secure websocket connection is also required")}static getMessage(e){return II.getMessage(e)}getMessage(e){return this.messages.get(e)||e}}const II=new Bb;class Re extends Error{constructor(t,n,i){super(t);E(this,"name");E(this,"message");E(this,"code");E(this,"permissionContext");E(this,"chainedError");E(this,"api_error");this.name="NatsError",this.message=t,this.code=n,this.chainedError=i}static errorForCode(t,n){const i=Bb.getMessage(t);return new Re(i,t,n)}isAuthError(){return this.code===we.AuthenticationExpired||this.code===we.AuthorizationViolation||this.code===we.AccountExpired}isAuthTimeout(){return this.code===we.AuthenticationTimeout}isPermissionError(){return this.code===we.PermissionsViolation}isProtocolError(){return this.code===we.ProtocolError}isJetStreamError(){return this.api_error!==void 0}jsError(){return this.api_error?this.api_error:null}}var wn;(function(r){r[r.Exact=0]="Exact",r[r.CanonicalMIME=1]="CanonicalMIME",r[r.IgnoreCase=2]="IgnoreCase"})(wn||(wn={}));var ri;(function(r){r.Timer="timer",r.Count="count",r.JitterTimer="jitterTimer",r.SentinelMsg="sentinelMsg"})(ri||(ri={}));var Eo;(function(r){r.STATS="io.nats.micro.v1.stats_response",r.INFO="io.nats.micro.v1.info_response",r.PING="io.nats.micro.v1.ping_response"})(Eo||(Eo={}));const nc="Nats-Service-Error",ic="Nats-Service-Error-Code";class sc extends Error{constructor(t,n){super(n);E(this,"code");this.code=t}static isServiceError(t){return sc.toServiceError(t)!==null}static toServiceError(t){var i,a;const n=((i=t==null?void 0:t.headers)==null?void 0:i.get(ic))||"";if(n!==""){const u=parseInt(n)||400,c=((a=t==null?void 0:t.headers)==null?void 0:a.get(nc))||"";return new sc(u,c.length?c:n)}return null}}function Ei(r=""){if(r=r||"_INBOX",typeof r!="string")throw new Error("prefix must be a string");return r.split(".").forEach(e=>{if(e==="*"||e===">")throw new Error(`inbox prefixes cannot have wildcards '${r}'`)}),`${r}.${Cs.next()}`}const ld="127.0.0.1";var ts;(function(r){r.PING="PING",r.STATS="STATS",r.INFO="INFO"})(ts||(ts={}));function ac(r,...e){for(let t=0;t<e.length;t++){const n=e[t];Object.keys(n).forEach(function(i){r[i]=n[i]})}return r}function oc(r){return cn.decode(r).replace(/\n/g,"␊").replace(/\r/g,"␍")}function ma(r,e=!0){const t=e?Re.errorForCode(we.Timeout):null;let n,i;const a=new Promise((u,c)=>{n={cancel:()=>{i&&clearTimeout(i)}},i=setTimeout(()=>{c(t===null?Re.errorForCode(we.Timeout):t)},r)});return Object.assign(a,n)}function ya(r=0){let e;const t=new Promise(n=>{const i=setTimeout(()=>{n()},r);e={cancel:()=>{i&&clearTimeout(i)}}});return Object.assign(t,e)}function ir(){let r={};const e=new Promise((t,n)=>{r={resolve:t,reject:n}});return Object.assign(e,r)}function Vb(r){for(let e=r.length-1;e>0;e--){const t=Math.floor(Math.random()*(e+1));[r[e],r[t]]=[r[t],r[e]]}return r}function CI(r){return r===0?0:Math.floor(r/2+Math.random()*r)}function fd(r=[0,250,250,500,500,3e3,5e3]){Array.isArray(r)||(r=[0,250,250,500,500,3e3,5e3]);const e=r.length-1;return{backoff(t){return CI(t>e?r[e]:r[t])}}}function cr(r){return r*1e6}function hd(r){return Math.floor(r/1e6)}function Wb(r){let n=!0;const i=new Array(r.length);for(let a=0;a<r.length;a++){let u=r.charCodeAt(a);if(u===58||u<33||u>126)throw new Re(`'${r[a]}' is not a valid character for a header key`,we.BadHeader);n&&97<=u&&u<=122?u-=32:!n&&65<=u&&u<=90&&(u+=32),i[a]=u,n=u==45}return String.fromCharCode(...i)}function Oi(r=0,e=""){if(r===0&&e!==""||r>0&&e==="")throw new Error("setting status requires both code and description");return new rs(r,e)}const dd="NATS/1.0";class rs{constructor(e=0,t=""){E(this,"_code");E(this,"headers");E(this,"_description");this._code=e,this._description=t,this.headers=new Map}[Symbol.iterator](){return this.headers.entries()}size(){return this.headers.size}equals(e){if(e&&this.headers.size===e.headers.size&&this._code===e._code){for(const[t,n]of this.headers){const i=e.values(t);if(n.length!==i.length)return!1;const a=[...n].sort(),u=[...i].sort();for(let c=0;c<a.length;c++)if(a[c]!==u[c])return!1}return!0}return!1}static decode(e){const t=new rs,i=cn.decode(e).split(`\r
138
+ `;const bI=()=>{const{isAuthenticated:r}=ti(),{authorize:e,authError:t,setAuthError:n}=he.useContext(rc);return bo(async i=>{try{await e(i)}catch(a){console.log(a),n("Login Failed. Try again.")}},[]),t?nr.jsx(Fb,{loadError:t}):r?nr.jsx(Fb,{}):nr.jsx(nr.Fragment,{})},xo={production:{loginUrl:"https://login.machinemetrics.com",appUrl:"https://app.machinemetrics.com",apiUrl:"https://api.machinemetrics.com",graphQLUrl:"https://graphql.machinemetrics.com/v1/graphql",natsUrl:"https://stream.machinemetrics.com"},staging:{loginUrl:"https://login-staging.machinemetrics.com",appUrl:"https://staging.machinemetrics.com",apiUrl:"https://api-staging.machinemetrics.com",graphQLUrl:"https://development.graphql.machinemetrics.com/v1/graphql",natsUrl:"https://stream.data.dev.m12s.com"},development:{loginUrl:"https://login.development.machinemetrics.com",appUrl:"https://app.development.machinemetrics.com",apiUrl:"https://api.development.machinemetrics.com",graphQLUrl:"https://hasura.tsdb.perlman.m12s.com/v1/graphql",natsUrl:"https://stream.data.dev.m12s.com"}},wI=pn.createBrowserRouter([{path:"/authorize/mm/callback",element:nr.jsx(bI,{})},{path:"/*",element:nr.jsx(gI,{})}]),_I=({domain:r,children:e,scope:t,clientId:n,clientSecret:i,releaseStage:a,graphQLRoleOverride:u,urls:c})=>{r&&console.warn("MMProvider domain is no longer used. It is inferred from the url.");const[f,h]=he.useState(),[d,y]=he.useState(!1);let g;if(xo[a])g=xo[a];else if(!g){const oe=ci.keys(xo).join(", "),Ie=ci.keys(xo[Object.keys(xo)[0]]);throw Error(`MMProvider releaseStage must be one of the following: ${oe}, or the following urls need to be provided: ${Ie}.`)}g=ci.merge(g,c);const[m,b]=he.useState(xk());he.useEffect(()=>{Sk(m)},[m]);const I=oe=>{const Ie=A0();I0(Ie),k0(window.location.pathname+window.location.search);const Ne=(ge=>ci.map(ge,(ve,pe)=>`${pe}=${ve}`).join("&"))({response_type:"code",state:Ie,scope:t,ttl:1209600,client_id:n,redirect_uri:`${window.location.origin}/authorize/mm/callback`,...oe}),Ce=`${g.loginUrl}/oauth/authorize?${Ne}`;window.location=Ce},x=async oe=>{const Ie=vk.parse(window.location.search),ye=Ie.code;if(Ie.error)throw Error(Ie.error_description);if(Ie.state!==Ok())throw Error("Oops");const Ne={grant_type:"authorization_code",client_id:n,client_secret:i,code:ye,redirect_uri:`${window.location.origin}/authorize/mm/callback`},Ce=await C0(`${g.loginUrl}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:new URLSearchParams(Ne),signal:oe});b(Ce.access_token),I0()},_=()=>{b()},A=async(oe,Ie={})=>{Ie.headers={...Ie.headers,"Content-Type":"application/json",Authorization:`Bearer ${m}`};const ye=await C0(oe,Ie);if(ye.error&&ye.error.status===401)throw await P(),Error("UNAUTHORIZED");return ye},P=async()=>{await A(`${g.loginUrl}/logout`,{method:"DELETE"}),_()},[M,U]=he.useState(),W=he.useRef(),K=he.useRef();wo(async()=>{if(!m){W.current=null,U(!1);return}try{const oe=await A(`${g.apiUrl}/user-token?graphql=1`);W.current=oe,U(!0)}catch{}},1e3*60*4.5,[m]),wo(async()=>{if(!m){K.current=null;return}try{const oe=await A(`${g.apiUrl}/nats-token`);K.current=oe}catch{}},1e3*60*9.5,[m]);const X=he.useMemo(()=>({clientId:n,accessToken:m,jwtRef:W,natsCredsRef:K,isAuthenticated:M,login:I,logout:P,request:A,urls:g}),[m,n,M,W,I,P,K,A,g]),fe=he.useMemo(()=>({children:e,graphQLRoleOverride:u,authorize:x,isEmbedded:d,setIsEmbedded:y,authError:f,setAuthError:h}),[e,u,x,d,y,f,h]);return nr.jsx(c0.Provider,{value:X,children:nr.jsx(rc.Provider,{value:fe,children:nr.jsx(pn.RouterProvider,{router:wI})})})},bn=new Uint8Array(0),xi=new TextEncoder,cn=new TextDecoder;function xI(...r){let e=0;for(let i=0;i<r.length;i++)e+=r[i].length;const t=new Uint8Array(e);let n=0;for(let i=0;i<r.length;i++)t.set(r[i],n),n+=r[i].length;return t}function So(...r){const e=[];for(let t=0;t<r.length;t++)e.push(xi.encode(r[t]));return e.length===0?bn:e.length===1?e[0]:xI(...e)}function Lb(r){return!r||r.length===0?"":cn.decode(r)}const qb="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",jb=36,SI=0xcfd41b9100000,Ub=33,EI=333,$b=22;function OI(r){for(let e=0;e<r.length;e++)r[e]=Math.floor(Math.random()*255)}function TI(r){var e;(e=globalThis==null?void 0:globalThis.crypto)!=null&&e.getRandomValues?globalThis.crypto.getRandomValues(r):OI(r)}class AI{constructor(){E(this,"buf");E(this,"seq");E(this,"inc");E(this,"inited");this.buf=new Uint8Array($b),this.inited=!1}init(){this.inited=!0,this.setPre(),this.initSeqAndInc(),this.fillSeq()}initSeqAndInc(){this.seq=Math.floor(Math.random()*SI),this.inc=Math.floor(Math.random()*(EI-Ub)+Ub)}setPre(){const e=new Uint8Array(12);TI(e);for(let t=0;t<12;t++){const n=e[t]%36;this.buf[t]=qb.charCodeAt(n)}}fillSeq(){let e=this.seq;for(let t=$b-1;t>=12;t--)this.buf[t]=qb.charCodeAt(e%jb),e=Math.floor(e/jb)}next(){return this.inited||this.init(),this.seq+=this.inc,this.seq>0xcfd41b9100000&&(this.setPre(),this.initSeqAndInc()),this.fillSeq(),String.fromCharCode.apply(String,this.buf)}reset(){this.init()}}const Cs=new AI;var Si;(function(r){r.Disconnect="disconnect",r.Reconnect="reconnect",r.Update="update",r.LDM="ldm",r.Error="error"})(Si||(Si={}));var pa;(function(r){r.Reconnecting="reconnecting",r.PingTimer="pingTimer",r.StaleConnection="staleConnection",r.ClientInitiatedReconnect="client initiated reconnect"})(pa||(pa={}));var we;(function(r){r.ApiError="BAD API",r.BadAuthentication="BAD_AUTHENTICATION",r.BadCreds="BAD_CREDS",r.BadHeader="BAD_HEADER",r.BadJson="BAD_JSON",r.BadPayload="BAD_PAYLOAD",r.BadSubject="BAD_SUBJECT",r.Cancelled="CANCELLED",r.ConnectionClosed="CONNECTION_CLOSED",r.ConnectionDraining="CONNECTION_DRAINING",r.ConnectionRefused="CONNECTION_REFUSED",r.ConnectionTimeout="CONNECTION_TIMEOUT",r.Disconnect="DISCONNECT",r.InvalidOption="INVALID_OPTION",r.InvalidPayload="INVALID_PAYLOAD",r.MaxPayloadExceeded="MAX_PAYLOAD_EXCEEDED",r.NoResponders="503",r.NotFunction="NOT_FUNC",r.RequestError="REQUEST_ERROR",r.ServerOptionNotAvailable="SERVER_OPT_NA",r.SubClosed="SUB_CLOSED",r.SubDraining="SUB_DRAINING",r.Timeout="TIMEOUT",r.Tls="TLS",r.Unknown="UNKNOWN_ERROR",r.WssRequired="WSS_REQUIRED",r.JetStreamInvalidAck="JESTREAM_INVALID_ACK",r.JetStream404NoMessages="404",r.JetStream408RequestTimeout="408",r.JetStream409MaxAckPendingExceeded="409",r.JetStream409="409",r.JetStreamNotEnabled="503",r.JetStreamIdleHeartBeat="IDLE_HEARTBEAT",r.AuthorizationViolation="AUTHORIZATION_VIOLATION",r.AuthenticationExpired="AUTHENTICATION_EXPIRED",r.ProtocolError="NATS_PROTOCOL_ERR",r.PermissionsViolation="PERMISSIONS_VIOLATION",r.AuthenticationTimeout="AUTHENTICATION_TIMEOUT",r.AccountExpired="ACCOUNT_EXPIRED"})(we||(we={}));function kI(r){return typeof r.code=="string"}class Bb{constructor(){E(this,"messages");this.messages=new Map,this.messages.set(we.InvalidPayload,"Invalid payload type - payloads can be 'binary', 'string', or 'json'"),this.messages.set(we.BadJson,"Bad JSON"),this.messages.set(we.WssRequired,"TLS is required, therefore a secure websocket connection is also required")}static getMessage(e){return II.getMessage(e)}getMessage(e){return this.messages.get(e)||e}}const II=new Bb;class Re extends Error{constructor(t,n,i){super(t);E(this,"name");E(this,"message");E(this,"code");E(this,"permissionContext");E(this,"chainedError");E(this,"api_error");this.name="NatsError",this.message=t,this.code=n,this.chainedError=i}static errorForCode(t,n){const i=Bb.getMessage(t);return new Re(i,t,n)}isAuthError(){return this.code===we.AuthenticationExpired||this.code===we.AuthorizationViolation||this.code===we.AccountExpired}isAuthTimeout(){return this.code===we.AuthenticationTimeout}isPermissionError(){return this.code===we.PermissionsViolation}isProtocolError(){return this.code===we.ProtocolError}isJetStreamError(){return this.api_error!==void 0}jsError(){return this.api_error?this.api_error:null}}var wn;(function(r){r[r.Exact=0]="Exact",r[r.CanonicalMIME=1]="CanonicalMIME",r[r.IgnoreCase=2]="IgnoreCase"})(wn||(wn={}));var ri;(function(r){r.Timer="timer",r.Count="count",r.JitterTimer="jitterTimer",r.SentinelMsg="sentinelMsg"})(ri||(ri={}));var Eo;(function(r){r.STATS="io.nats.micro.v1.stats_response",r.INFO="io.nats.micro.v1.info_response",r.PING="io.nats.micro.v1.ping_response"})(Eo||(Eo={}));const nc="Nats-Service-Error",ic="Nats-Service-Error-Code";class sc extends Error{constructor(t,n){super(n);E(this,"code");this.code=t}static isServiceError(t){return sc.toServiceError(t)!==null}static toServiceError(t){var i,a;const n=((i=t==null?void 0:t.headers)==null?void 0:i.get(ic))||"";if(n!==""){const u=parseInt(n)||400,c=((a=t==null?void 0:t.headers)==null?void 0:a.get(nc))||"";return new sc(u,c.length?c:n)}return null}}function Ei(r=""){if(r=r||"_INBOX",typeof r!="string")throw new Error("prefix must be a string");return r.split(".").forEach(e=>{if(e==="*"||e===">")throw new Error(`inbox prefixes cannot have wildcards '${r}'`)}),`${r}.${Cs.next()}`}const ld="127.0.0.1";var ts;(function(r){r.PING="PING",r.STATS="STATS",r.INFO="INFO"})(ts||(ts={}));function ac(r,...e){for(let t=0;t<e.length;t++){const n=e[t];Object.keys(n).forEach(function(i){r[i]=n[i]})}return r}function oc(r){return cn.decode(r).replace(/\n/g,"␊").replace(/\r/g,"␍")}function ma(r,e=!0){const t=e?Re.errorForCode(we.Timeout):null;let n,i;const a=new Promise((u,c)=>{n={cancel:()=>{i&&clearTimeout(i)}},i=setTimeout(()=>{c(t===null?Re.errorForCode(we.Timeout):t)},r)});return Object.assign(a,n)}function ya(r=0){let e;const t=new Promise(n=>{const i=setTimeout(()=>{n()},r);e={cancel:()=>{i&&clearTimeout(i)}}});return Object.assign(t,e)}function ir(){let r={};const e=new Promise((t,n)=>{r={resolve:t,reject:n}});return Object.assign(e,r)}function Vb(r){for(let e=r.length-1;e>0;e--){const t=Math.floor(Math.random()*(e+1));[r[e],r[t]]=[r[t],r[e]]}return r}function CI(r){return r===0?0:Math.floor(r/2+Math.random()*r)}function fd(r=[0,250,250,500,500,3e3,5e3]){Array.isArray(r)||(r=[0,250,250,500,500,3e3,5e3]);const e=r.length-1;return{backoff(t){return CI(t>e?r[e]:r[t])}}}function cr(r){return r*1e6}function hd(r){return Math.floor(r/1e6)}function Wb(r){let n=!0;const i=new Array(r.length);for(let a=0;a<r.length;a++){let u=r.charCodeAt(a);if(u===58||u<33||u>126)throw new Re(`'${r[a]}' is not a valid character for a header key`,we.BadHeader);n&&97<=u&&u<=122?u-=32:!n&&65<=u&&u<=90&&(u+=32),i[a]=u,n=u==45}return String.fromCharCode(...i)}function Oi(r=0,e=""){if(r===0&&e!==""||r>0&&e==="")throw new Error("setting status requires both code and description");return new rs(r,e)}const dd="NATS/1.0";class rs{constructor(e=0,t=""){E(this,"_code");E(this,"headers");E(this,"_description");this._code=e,this._description=t,this.headers=new Map}[Symbol.iterator](){return this.headers.entries()}size(){return this.headers.size}equals(e){if(e&&this.headers.size===e.headers.size&&this._code===e._code){for(const[t,n]of this.headers){const i=e.values(t);if(n.length!==i.length)return!1;const a=[...n].sort(),u=[...i].sort();for(let c=0;c<a.length;c++)if(a[c]!==u[c])return!1}return!0}return!1}static decode(e){const t=new rs,i=cn.decode(e).split(`\r
139
139
  `),a=i[0];if(a!==dd){let u=a.replace(dd,"").trim();if(u.length>0){t._code=parseInt(u,10),isNaN(t._code)&&(t._code=0);const c=t._code.toString();u=u.replace(c,""),t._description=u.trim()}}return i.length>=1&&i.slice(1).map(u=>{if(u){const c=u.indexOf(":");if(c>-1){const f=u.slice(0,c),h=u.slice(c+1).trim();t.append(f,h)}}}),t}toString(){if(this.headers.size===0&&this._code===0)return"";let e=dd;this._code>0&&this._description!==""&&(e+=` ${this._code} ${this._description}`);for(const[t,n]of this.headers)for(let i=0;i<n.length;i++)e=`${e}\r
140
140
  ${t}: ${n[i]}`;return`${e}\r
141
141
  \r
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-react-tools",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "Components, hooks, and helper functions for writing React apps using MachineMetrics APIs.",
5
5
  "author": "machinemetrics",
6
6
  "license": "MIT",