@iotopen/react-lynx 1.0.0 → 1.0.2-rc.0

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.
Files changed (104) hide show
  1. package/README.md +1 -1
  2. package/dist/{cjs/Contexts → Contexts}/LynxClientProvider.d.ts +6 -5
  3. package/dist/Contexts/LynxProvider.d.ts +9 -0
  4. package/dist/{esm/Contexts → Contexts}/UserProvider.d.ts +3 -3
  5. package/dist/{esm/Contexts → Contexts}/index.d.ts +2 -2
  6. package/dist/{cjs/Hooks → Hooks}/index.d.ts +42 -26
  7. package/dist/Hooks/useCheckPermissions.d.ts +4 -0
  8. package/dist/{cjs/Hooks → Hooks}/useDevice.d.ts +4 -4
  9. package/dist/{esm/Hooks → Hooks}/useDevices.d.ts +1 -1
  10. package/dist/{esm/Hooks → Hooks}/useEdgeApp.d.ts +1 -1
  11. package/dist/{esm/Hooks → Hooks}/useFunction.d.ts +1 -1
  12. package/dist/{cjs/Hooks → Hooks}/useFunctions.d.ts +1 -1
  13. package/dist/{cjs/Hooks → Hooks}/useInstallation.d.ts +1 -1
  14. package/dist/Hooks/useLiveInstallation.d.ts +10 -0
  15. package/dist/Hooks/useMQTT.d.ts +1 -0
  16. package/dist/Hooks/useMultiLiveInstallation.d.ts +11 -0
  17. package/dist/{esm/Hooks → Hooks}/useNewDevice.d.ts +4 -4
  18. package/dist/{esm/Hooks → Hooks}/useNewFunction.d.ts +4 -4
  19. package/dist/{esm/Hooks → Hooks}/useNewInstallation.d.ts +4 -4
  20. package/dist/{esm/Hooks → Hooks}/useNewNotificationMessage.d.ts +4 -4
  21. package/dist/{cjs/Hooks → Hooks}/useNewNotificationOutput.d.ts +4 -4
  22. package/dist/{esm/Hooks → Hooks}/useNewOAuth2Client.d.ts +4 -4
  23. package/dist/{esm/Hooks → Hooks}/useNewOrganization.d.ts +4 -4
  24. package/dist/{cjs/Hooks → Hooks}/useNewUser.d.ts +7 -8
  25. package/dist/{cjs/Hooks → Hooks}/useNotificationMessage.d.ts +1 -1
  26. package/dist/{esm/Hooks → Hooks}/useNotificationOutput.d.ts +1 -1
  27. package/dist/{cjs/Hooks → Hooks}/useNotificationOutputExecutor.d.ts +1 -1
  28. package/dist/{cjs/Hooks → Hooks}/useOAuth2Client.d.ts +2 -2
  29. package/dist/Hooks/useOAuth2Consent.d.ts +5 -0
  30. package/dist/{cjs/Hooks → Hooks}/useOrganization.d.ts +2 -2
  31. package/dist/{cjs/Hooks → Hooks}/useOrganizations.d.ts +3 -3
  32. package/dist/{esm/Hooks → Hooks}/usePahoMQTTClient.d.ts +4 -4
  33. package/dist/Hooks/useSimpleMQTT.d.ts +18 -0
  34. package/dist/{cjs/Hooks → Hooks}/useTokens.d.ts +1 -1
  35. package/dist/{esm/Hooks → Hooks}/useUser.d.ts +2 -2
  36. package/dist/{esm/Hooks → Hooks}/useUsers.d.ts +1 -1
  37. package/dist/cjs/index.js +1 -16
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/esm/index.js +1423 -16
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/index.d.ts +2 -439
  42. package/package.json +87 -49
  43. package/dist/cjs/Contexts/LynxProvider.d.ts +0 -8
  44. package/dist/cjs/Contexts/UserProvider.d.ts +0 -19
  45. package/dist/cjs/Contexts/index.d.ts +0 -3
  46. package/dist/cjs/Hooks/useDevices.d.ts +0 -10
  47. package/dist/cjs/Hooks/useEdgeApp.d.ts +0 -8
  48. package/dist/cjs/Hooks/useFunction.d.ts +0 -15
  49. package/dist/cjs/Hooks/useMeta.d.ts +0 -15
  50. package/dist/cjs/Hooks/useNewDevice.d.ts +0 -12
  51. package/dist/cjs/Hooks/useNewFunction.d.ts +0 -12
  52. package/dist/cjs/Hooks/useNewInstallation.d.ts +0 -12
  53. package/dist/cjs/Hooks/useNewNotificationMessage.d.ts +0 -11
  54. package/dist/cjs/Hooks/useNewOAuth2Client.d.ts +0 -22
  55. package/dist/cjs/Hooks/useNewOrganization.d.ts +0 -18
  56. package/dist/cjs/Hooks/useNotificationOutput.d.ts +0 -10
  57. package/dist/cjs/Hooks/useOAuth2Consent.d.ts +0 -5
  58. package/dist/cjs/Hooks/usePahoMQTTClient.d.ts +0 -16
  59. package/dist/cjs/Hooks/useSimpleMQTT.d.ts +0 -12
  60. package/dist/cjs/Hooks/useUser.d.ts +0 -10
  61. package/dist/cjs/Hooks/useUsers.d.ts +0 -8
  62. package/dist/cjs/index.d.ts +0 -2
  63. package/dist/esm/Contexts/LynxClientProvider.d.ts +0 -14
  64. package/dist/esm/Contexts/LynxProvider.d.ts +0 -8
  65. package/dist/esm/Hooks/index.d.ts +0 -38
  66. package/dist/esm/Hooks/useConfiguredEdgeApps.d.ts +0 -7
  67. package/dist/esm/Hooks/useDevice.d.ts +0 -15
  68. package/dist/esm/Hooks/useEdgeAppVersions.d.ts +0 -8
  69. package/dist/esm/Hooks/useEdgeApps.d.ts +0 -7
  70. package/dist/esm/Hooks/useFunctions.d.ts +0 -10
  71. package/dist/esm/Hooks/useIDTokenAlgorithms.d.ts +0 -7
  72. package/dist/esm/Hooks/useInstallation.d.ts +0 -9
  73. package/dist/esm/Hooks/useInstallationInfo.d.ts +0 -7
  74. package/dist/esm/Hooks/useInstallations.d.ts +0 -7
  75. package/dist/esm/Hooks/useNewNotificationOutput.d.ts +0 -15
  76. package/dist/esm/Hooks/useNewUser.d.ts +0 -27
  77. package/dist/esm/Hooks/useNotificationMessage.d.ts +0 -10
  78. package/dist/esm/Hooks/useNotificationMessages.d.ts +0 -7
  79. package/dist/esm/Hooks/useNotificationOutputExecutor.d.ts +0 -8
  80. package/dist/esm/Hooks/useNotificationOutputExecutors.d.ts +0 -7
  81. package/dist/esm/Hooks/useNotificationOutputs.d.ts +0 -7
  82. package/dist/esm/Hooks/useOAuth2Client.d.ts +0 -10
  83. package/dist/esm/Hooks/useOAuth2Clients.d.ts +0 -7
  84. package/dist/esm/Hooks/useOAuth2Consent.d.ts +0 -5
  85. package/dist/esm/Hooks/useOrganization.d.ts +0 -10
  86. package/dist/esm/Hooks/useOrganizations.d.ts +0 -9
  87. package/dist/esm/Hooks/useRoles.d.ts +0 -7
  88. package/dist/esm/Hooks/useSimpleMQTT.d.ts +0 -12
  89. package/dist/esm/Hooks/useTokens.d.ts +0 -9
  90. package/dist/esm/index.d.ts +0 -2
  91. package/dist/esm/types.d.ts +0 -1
  92. package/dist/{cjs/Hooks → Hooks}/useConfiguredEdgeApps.d.ts +0 -0
  93. package/dist/{cjs/Hooks → Hooks}/useEdgeAppVersions.d.ts +0 -0
  94. package/dist/{cjs/Hooks → Hooks}/useEdgeApps.d.ts +0 -0
  95. package/dist/{cjs/Hooks → Hooks}/useIDTokenAlgorithms.d.ts +0 -0
  96. package/dist/{cjs/Hooks → Hooks}/useInstallationInfo.d.ts +0 -0
  97. package/dist/{cjs/Hooks → Hooks}/useInstallations.d.ts +0 -0
  98. package/dist/{esm/Hooks → Hooks}/useMeta.d.ts +1 -1
  99. /package/dist/{cjs/Hooks → Hooks}/useNotificationMessages.d.ts +0 -0
  100. /package/dist/{cjs/Hooks → Hooks}/useNotificationOutputExecutors.d.ts +0 -0
  101. /package/dist/{cjs/Hooks → Hooks}/useNotificationOutputs.d.ts +0 -0
  102. /package/dist/{cjs/Hooks → Hooks}/useOAuth2Clients.d.ts +0 -0
  103. /package/dist/{cjs/Hooks → Hooks}/useRoles.d.ts +0 -0
  104. /package/dist/{cjs/types.d.ts → types.d.ts} +0 -0
package/dist/esm/index.js CHANGED
@@ -1,17 +1,1424 @@
1
- import{useState as e,useLayoutEffect as t,useCallback as n,createContext as r,useContext as i,useMemo as o,useRef as s,useEffect as a}from"react";import{jsx as c}from"react/jsx-runtime";import{LynxClient as l,zero as d}from"@iotopen/node-lynx";import u from"paho-mqtt";const p=(r,i)=>{const[o,s]=e([]);t((()=>{if(r){const e=[];for(const t in r.meta){const n=r.meta[t];e.push({key:t,value:n,protected:!1})}for(const t in r.protected_meta){const n=r.protected_meta[t];e.push({key:t,value:n,protected:!0})}e.sort(((e,t)=>e.key.localeCompare(t.key))),s(e)}}),i||(r?[r]:[]));const a=n((()=>{const e={meta:{},protected_meta:{}};return o.forEach((t=>{t.protected?e.protected_meta[t.key]=t.value:e.meta[t.key]=t.value})),e}),[o]),c=n((e=>{s([...o,e||{key:"",value:"",protected:!1}])}),[o,s]),l=n((e=>{s(o.filter(((t,n)=>n!==e)))}),[o,s]),d=n(((e,t)=>{s(o.map(((n,r)=>r===e?t:n)))}),[o,s]),u=n(((e,t)=>{s(o.map(((n,r)=>r==e?Object.assign(Object.assign({},n),{key:t}):n)))}),[o,s]),p=n(((e,t)=>{s(o.map(((n,r)=>r==e?Object.assign(Object.assign({},n),{value:t}):n)))}),[o,s]),g=n(((e,t)=>{s(o.map(((n,r)=>r==e?Object.assign(Object.assign({},n),{protected:t}):n)))}),[o,s]);return{metaList:o,compile:a,addMeta:c,removeMeta:l,setMeta:d,setMetaKey:u,setMetaValue:p,setMetaProtected:g}},g=r({lynxClient:new l(""),newLynxClient:(e,t)=>{}}),f=({children:t,url:r,apiKey:i})=>{const[s,a]=e(new l(r,i)),d=n(((e,t)=>a(new l(e,t))),[a]),u=o((()=>({lynxClient:s,newLynxClient:d})),[s,d]);return c(g.Provider,Object.assign({value:u},{children:t}))},h=()=>i(g),v=r({user:null,permissions:null}),y=({children:n})=>{const[r,i]=e(null),[s,a]=e(null),[l,d]=e(!0),[u,p]=e(),{lynxClient:g}=h();t((()=>{const e=g.getMe(),t=g.getPermissions();d(!0),Promise.all([e,t]).then((([e,t])=>{i(e),a(t)})).catch((e=>{p(e),i(null),a(null)})).finally((()=>{d(!1)}))}),[g]);const f=o((()=>({user:r,permissions:s,loading:l,error:u})),[r,s,l,u]);return c(v.Provider,Object.assign({value:f},{children:n}))},m=()=>i(v),w=()=>{const{permissions:e}=m();return[e]},b=({children:e,apiURL:t,apiKey:n})=>c(f,Object.assign({url:t,apiKey:n},{children:c(y,{children:e})})),N=r=>{const{lynxClient:i}=h(),[o,s]=e([]),[a,c]=e(!0),[l,d]=e(void 0),u=n((()=>{c(!0),i.getInstallations(r).then((e=>{void 0!==l&&d(void 0),s(e)})).catch((e=>{d(e)})).finally((()=>{c(!1)}))}),[i]);return t((()=>{u()}),[u]),{installations:o,refresh:u,loading:a,error:l}},O=(r,i,o,a)=>{var c;if(void 0===a){let e;e=(null===(c=null===window||void 0===window?void 0:window.crypto)||void 0===c?void 0:c.randomUUID)?window.crypto.randomUUID():"undefined"!=typeof crypto&&(null===crypto||void 0===crypto?void 0:crypto.randomUUID)?crypto.randomUUID():Math.random().toString(36).substring(2,15),a=`paho-ws-mqtt-${e}`}const l=s(new u.Client(r,a)),d=s(o),p=s(i),g=s(void 0),[f,h]=e(!1),[v,y]=e(void 0);t((()=>{const e=l,t=g,n=Object.assign(Object.assign({timeout:5},d.current),{onFailure:r=>{y(r),h(l.current.isConnected()),void 0===t.current&&(t.current=window.setInterval((()=>{e.current.isConnected()?clearInterval(t.current):e.current.connect(n)}),1e3))},onSuccess:()=>{y(void 0),h(l.current.isConnected()),void 0!==t.current&&(window.clearInterval(t.current),t.current=void 0)}}),r=p.current;e.current.onConnectionLost=e=>{var t;y(e),h(l.current.isConnected()),null===(t=null==r?void 0:r.onDisconnect)||void 0===t||t.call(r,e)},e.current.onConnected=(e,t)=>{var n;h(l.current.isConnected()),y(void 0),null===(n=null==r?void 0:r.onConnected)||void 0===n||n.call(r,e,t)},r&&(r.onMessage&&(e.current.onMessageArrived=r.onMessage),r.onDelivery&&(e.current.onMessageDelivered=r.onDelivery));try{e.current.connect(n)}catch(t){window.setTimeout((()=>{e.current.connect(n)}),1e3)}return()=>{try{e.current.disconnect(),void 0!==t.current&&window.clearInterval(t.current)}catch(e){console.log(e)}}}),[]);const m=n(((e,t)=>new Promise((n=>{l.current.subscribe(e,{qos:t||0,timeout:1,onFailure:e=>{throw e},onSuccess:e=>{n(e.grantedQos)}})}))),[l]),w=n(((e,t,n,r)=>{l.current.send(e,t,n,r)}),[l]),b=n((e=>new Promise((t=>{l.current.unsubscribe(e,{timeout:1,onSuccess:()=>{t()},onFailure:e=>{throw e}})}))),[l]);return{client:l,connected:f,error:v,sub:m,pub:w,unsub:b}};
2
- /*! *****************************************************************************
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
- PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */
16
- function I(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}const j=(e,t,r)=>{void 0===e&&(e="http:"===location.protocol?`ws://${location.host}/mqtt`:`wss://${location.host}/mqtt`);const i=s([]),o=s(new Map([])),a=s(new Map([])),c=n((e=>{const t=a.current.get(e.destinationName);t&&t.forEach((t=>{t(e.destinationName,e.payloadString,e.qos,e.retained)})),o.current.forEach(((t,n)=>{new RegExp(n).test(e.destinationName)&&t.forEach((t=>{t(e.destinationName,e.payloadString,e.qos,e.retained)}))}))}),[]),l={cleanSession:!0,reconnect:!0,keepAliveInterval:5};t&&(l.userName=t),r&&(l.password=r);const{error:d,connected:u,sub:p,unsub:g,pub:f}=O(e,{onMessage:c,onConnected:()=>{i.current.forEach((e=>{p(e).then().catch()}))}},l),h=n(((e,t)=>{let n;n="string"==typeof e?new RegExp(`^${e}$`):e;const r=n.toString().slice(1,-1);let i=o.current.get(r);if(void 0===i)return i=[t],void o.current.set(r,i);i.includes(t)||i.push(t)}),[]),v=n((e=>{o.current.forEach(((t,n)=>{const r=t.filter((t=>t!==e));o.current.set(n,r)}))}),[]),y=n(((e,t)=>{let n=a.current.get(e);void 0===n&&(n=[t]),n.includes(t)||n.push(t)}),[]),m=n(((e,t)=>{const n=a.current.get(e);void 0!==n&&a.current.set(e,n.filter((e=>e!==t)))}),[]),w=n((e=>{(function(e,t){if(e.length===t.length){for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}return!1})(i.current,e)||(u&&function(e,t){return new Promise((n=>{t.forEach((t=>I(this,void 0,void 0,(function*(){try{yield e(t)}catch(e){console.log(e)}})))),n()}))}(g,i.current).then((()=>{(function(e,t){return new Promise((n=>{t.forEach((t=>I(this,void 0,void 0,(function*(){try{yield e(t)}catch(e){console.log(e)}})))),n()}))})(p,e).then().catch()})).catch(),i.current=e)}),[p,g]);return{setSubs:w,error:d,connected:u,bind:h,unbind:v,bindExact:y,unbindExact:m,pub:f}},C=()=>{const{lynxClient:r}=h(),[i,o]=e(!0),[s,a]=e(),[c,l]=e([]),d=n((()=>{o(!0),r.getTokens().then((e=>{void 0!==s&&a(void 0),l(e)})).catch((e=>{a(e)})).finally((()=>{o(!1)}))}),[r]),u=n((e=>r.deleteToken(e)),[r]),p=n((e=>r.createToken(e)),[r]);return t((()=>{d()}),[d]),{tokens:c,remove:u,create:p,refresh:d,loading:i,error:s}},_=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t;if(isNaN(i))throw new Error("invalid installationId");const{lynxClient:o}=h(),[s,a]=e(Object.assign(Object.assign({meta:{},protected_meta:{},type:""},r),{installation_id:i})),c=n((e=>{a(Object.assign(Object.assign({},s),{type:e}))}),[s,a]),l=n((()=>o.createFunction(s)),[o,s]);return{newFunction:s,setNewFunction:a,create:l,setType:c}},x=(r,i)=>{const o="string"==typeof r?Number.parseInt(r):r;if(isNaN(o)&&void 0!==o)throw new Error("invalid installationId");const{lynxClient:s}=h(),[a,c]=e(!0),[l,d]=e([]),[u,p]=e(),g=n((()=>{if(void 0===o)return c(!1),void d([]);c(!0),s.getFunctions(o,i).then((e=>(void 0!==u&&p(void 0),d(e),e))).catch((e=>{p(e)})).finally((()=>{c(!1)}))}),[s,o,i]);const f=n((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>s.createFunction(e,!0)));return Promise.allSettled(n).then((e=>I(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield s.createFunction(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return s.createFunction(e)}),[s]),v=n((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>s.deleteFunction(e,!0)));return Promise.allSettled(n).then((e=>I(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield s.deleteFunction(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return s.deleteFunction(e)}),[s]);return t((()=>{g()}),[g]),{loading:a,error:u,create:f,remove:v,functions:l,refresh:g}},E={id:0,installation_id:0,type:"",updated:0,created:0,meta:{},protected_meta:{}},M=(r,i)=>{const o="string"==typeof r?Number.parseInt(r):r,s="string"==typeof i?Number.parseInt(i):i;if(isNaN(o)||isNaN(s))throw new Error("invalid installationId or functionId");const{lynxClient:a}=h(),[c,l]=e(!0),[d,u]=e(Object.assign({},E)),[p,g]=e();t((()=>{a.getFunction(o,s).then((e=>{void 0!==p&&g(void 0),u(e)})).catch((e=>{g(e)})).finally((()=>{l(!1)}))}),[a,o,s]);const f=n((()=>new Promise((()=>{if(!d)throw new Error("update on undefined function");return a.updateFunction(d)}))),[a,d]),v=n((e=>{d&&u(Object.assign(Object.assign({},d),{type:e}))}),[d,u]),y=n((()=>new Promise((()=>{if(!d)throw new Error("delete on undefined function");return a.deleteFunction(d)}))),[d,a]);return{loading:c,error:p,Function:d,setFunction:u,update:f,remove:y,setType:v}},D=(e,t)=>{const r="string"==typeof e?Number.parseInt(e):e,i="string"==typeof t?Number.parseInt(t):t,{lynxClient:o}=h();return{createMeta:n(((e,t,n,s)=>{const a=n||(null!=i?i:0);return o.createFunctionMeta(r,a,e,t,s)}),[o,r,i]),updateMeta:n(((e,t,n,s,a)=>{const c=s||(null!=i?i:0);return o.updateFunctionMeta(r,c,e,t,a,n)}),[o,r,i]),removeMeta:n(((e,t,n)=>{const s=t||(null!=i?i:0);return o.deleteFunctionMeta(r,s,e,n)}),[o,r,i])}},P={client_id:0,notes:"",organization_id:0,id:0,name:"",created:0,meta:{},users:[],protected_meta:{}},A=r=>{const i="string"==typeof r?Number.parseInt(r):r;if(isNaN(i))throw new Error("invalid installationId");const{lynxClient:o}=h(),[s,a]=e(!0),[c,l]=e(void 0),[d,u]=e(Object.assign({},P));t((()=>{o.getInstallationRow(i).then((e=>{void 0!==c&&l(void 0),u(e)})).catch((e=>{l(e)})).finally((()=>{a(!1)}))}),[o,i]);const p=n((()=>new Promise((()=>{if(!d)throw new Error("update on undefined installation");return o.updateInstallation(d)}))),[o,d]),g=n((()=>new Promise((()=>{if(!d)throw new Error("update on undefined installation");return o.deleteInstallation(d)}))),[o,d]);return{installation:d,setInstallation:u,update:p,remove:g,error:c,loading:s}},U=t=>{const{lynxClient:r}=h(),[i,o]=e(!0),[s,a]=e([]),[c,l]=e(),d=n((()=>{o(!0),r.listInstallations(t).then((e=>{void 0!==c&&l(void 0),a(e)})).catch((e=>{l(e)})).finally((()=>{o(!1)}))}),[r,t]);return{loading:i,error:c,installations:s,refresh:d}},z=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t;if(isNaN(i))throw new Error("invalid organizationId");const[o,s]=e(Object.assign(Object.assign({name:"",notes:"",users:[],meta:{},protected_meta:{}},r),{organization_id:i})),{lynxClient:a}=h(),c=n((()=>a.createInstallation(o)),[a,o]);return{newInstallation:o,setNewInstallation:s,create:c}},F=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t;if(isNaN(i))throw new Error("invalid installationId");const{lynxClient:o}=h(),[s,a]=e(Object.assign(Object.assign({meta:{},protected_meta:{},type:""},r),{installation_id:i})),c=n((e=>{a(Object.assign(Object.assign({},s),{type:e}))}),[s,a]),l=n((()=>o.createDevice(s)),[o,s]);return{newDevice:s,setNewDevice:a,create:l,setType:c}},S=(r,i)=>{const o="string"==typeof r?Number.parseInt(r):r;if(isNaN(o)&&void 0!==o)throw new Error("invalid installationId");const{lynxClient:s}=h(),[a,c]=e(!0),[l,d]=e([]),[u,p]=e(),g=n((()=>{if(void 0===o)return c(!1),void d([]);c(!0),s.getDevices(o,i).then((e=>{void 0!==u&&p(void 0),d(e)})).catch((e=>{p(e)})).finally((()=>{c(!1)}))}),[s,o,i]);const f=n((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>s.createDevice(e,!0)));return Promise.allSettled(n).then((e=>I(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield s.createDevice(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return s.createDevice(e)}),[s]),v=n((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>s.deleteDevice(e,!0)));return Promise.allSettled(n).then((e=>I(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield s.deleteDevice(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return s.deleteDevice(e)}),[s]);return t((()=>{g()}),[g]),{loading:a,error:u,create:f,remove:v,devices:l,refresh:g}},k={updated:0,created:0,id:0,installation_id:0,type:"",meta:{},protected_meta:{}},R=(r,i)=>{const o="string"==typeof r?Number.parseInt(r):r,s="string"==typeof i?Number.parseInt(i):i;if(isNaN(o)||isNaN(s))throw new Error("invalid installationId or deviceId");const{lynxClient:a}=h(),[c,l]=e(!0),[d,u]=e(Object.assign({},k)),[p,g]=e();t((()=>{a.getDevice(o,s).then((e=>{void 0!==p&&g(void 0),u(e)})).catch((e=>{g(e)})).finally((()=>{l(!1)}))}),[a,o,s]);const f=n((()=>new Promise((()=>{if(!d)throw new Error("update on undefined function");return a.updateDevice(d)}))),[a,d]),v=n((e=>{d&&u(Object.assign(Object.assign({},d),{type:e}))}),[d,u]),y=n((()=>new Promise((()=>{if(!d)throw new Error("delete on undefined function");return a.deleteDevice(d)}))),[d,a]);return{loading:c,error:p,Device:d,setDevice:u,update:f,remove:y,setType:v}},T=(e,t)=>{const r="string"==typeof e?Number.parseInt(e):e,i="string"==typeof t?Number.parseInt(t):t,{lynxClient:o}=h();return{createMeta:n(((e,t,n,i)=>{const s=n||(null!=n?n:0);return o.createDeviceMeta(r,s,e,t,i)}),[o,r,i]),updateMeta:n(((e,t,n,i,s)=>{const a=i||(null!=i?i:0);return o.updateDeviceMeta(r,a,e,t,s,n)}),[o,r,i]),removeMeta:n(((e,t,n)=>{const i=t||(null!=t?t:0);return o.deleteDeviceMeta(r,i,e,n)}),[o,r,i])}},q=r=>{const i="string"==typeof r?Number.parseInt(r):r;if(isNaN(i))throw new Error("invalid installationId");const{lynxClient:o}=h(),[s,a]=e(!0),[c,l]=e(),[d,u]=e([]),p=n((()=>{a(!0),o.getConfiguredEdgeApps(i).then((e=>{void 0!==c&&l(void 0),u(e)})).catch((e=>{l(e)})).finally((()=>{a(!1)}))}),[i,o]);return t((()=>{p()}),[p]),{refresh:p,loading:s,error:c,apps:d}},L=()=>{const{lynxClient:r}=h(),[i,o]=e(!0),[s,a]=e(),[c,l]=e([]),d=n((()=>{o(!0),r.getEdgeApps().then((e=>{void 0!==s&&a(void 0),l(e)})).catch((e=>{a(e)})).finally((()=>{o(!1)}))}),[s,r]);return t((()=>{d()}),[]),{apps:c,error:s,loading:i,refresh:d}},$={id:0,created:0,updated:0,name:"",category:"",short_description:"",description:"",source_url:"",tags:[],publisher:{id:0},public:!1,official:!1},K=r=>{const i="string"==typeof r?Number.parseInt(r):r;if(isNaN(i))throw new Error("invalid appId");const{lynxClient:o}=h(),[s,a]=e(!1),[c,l]=e(),[d,u]=e(Object.assign({},$)),p=n((()=>{a(!0),o.getEdgeApp(i).then((e=>{void 0!==c&&l(void 0),u(e)})).catch((e=>{l(e)})).finally((()=>{a(!1)}))}),[i,o]);return t((()=>{p()}),[i]),{loading:s,error:c,app:d,setApp:u,refresh:p}},V=(r,i)=>{const o="string"==typeof r?Number.parseInt(r):r;if(isNaN(o))throw new Error("invalid appId");const{lynxClient:s}=h(),[a,c]=e(!1),[l,d]=e(),[u,p]=e([]),g=n((()=>{c(!0),s.getEdgeAppVersions(o,i).then((e=>{void 0!==l&&d(void 0),p(e)})).catch((e=>{d(e)})).finally((()=>{c(!1)}))}),[s,i]),f=n(((e,t)=>s.nameEdgeAppVersion(o,e,t)),[s,o]);return t((()=>{g()}),[o,i]),{loading:a,error:l,versions:u,nameVersion:f,refresh:g}},Q=t=>{const{lynxClient:r}=h(),[i,o]=e(Object.assign(Object.assign({},d.getEmptyOAuth2Client()),t)),s=n((e=>{o(Object.assign(Object.assign({},i),{name:e}))}),[i]),a=n((e=>{o(Object.assign(Object.assign({},i),{allowed_scopes:e}))}),[i]),c=n((e=>{o(Object.assign(Object.assign({},i),{icon_uri:e}))}),[i]),l=n((e=>{o(Object.assign(Object.assign({},i),{tos_uri:e}))}),[i]),u=n((e=>{o(Object.assign(Object.assign({},i),{policy_uri:e}))}),[i]),p=n((e=>{o(Object.assign(Object.assign({},i),{redirect_uris:e}))}),[i]),g=n((()=>r.createOAuth2Client(i)),[r,i]);return{newClient:i,create:g,setName:s,setScope:a,setIconURI:c,setTosURI:l,setPolicyURI:u,setRedirectURIs:p,setClient:o}},B=t=>{const{lynxClient:r}=h(),[i,o]=e(!0),[s,c]=e(),[l,u]=e(Object.assign({},d.getOAuth2Client())),p=n((()=>{i||o(!0),r.getOAuth2Client(t).then((e=>{void 0!==s&&c(void 0),u(e)})).catch((e=>{c(e)})).finally((()=>{o(!1)}))}),[i,r,t,s]);a((()=>{p()}),[t]);const g=n((()=>r.deleteOAuth2Client(l)),[l,r]),f=n((()=>r.updateOAuth2Client(l)),[l,r]);return{refresh:p,client:l,setClient:u,error:s,loading:i,remove:g,update:f}},G=()=>{const{lynxClient:t}=h(),[r,i]=e(!0),[o,s]=e(),[c,l]=e([]),d=n((()=>{t.getOAuth2Clients().then((e=>{void 0!==o&&s(void 0),l(e)})).catch((e=>{s(e)})).finally((()=>{i(!1)}))}),[t,o]);return a((()=>{d()}),[]),{refresh:d,clients:c,error:o,loading:r}},H=()=>{var t;const{lynxClient:r}=h(),[i,o]=e([]),[s]=e(new URLSearchParams(window.location.search)),{client:c}=B(null!==(t=s.get("client_id"))&&void 0!==t?t:""),l=n((e=>{const t=Object.fromEntries(s);return t.scope=e.join(" "),r.consentOAuth2Authorization(t)}),[r,s]);return a((()=>{var e,t;o(null!==(t=null===(e=s.get("scope"))||void 0===e?void 0:e.split(" "))&&void 0!==t?t:[])}),[s]),{consent:l,client:c,requestedScopes:i}},J=()=>{const{lynxClient:t}=h(),[r,i]=e(!0),[o,s]=e(),[c,l]=e([]),d=n((()=>{i(!0),t.getIDTokenAlgorithms().then((e=>{void 0!==o&&s(void 0),l(e)})).catch((e=>{s(e)})).finally((()=>{i(!1)}))}),[o,t]);return a((()=>{d()}),[]),{loading:r,refresh:d,algs:c,error:o}},W={address:{address:"",city:"",country:"",zip:""},children:[],email:"",force_sms_login:!1,meta:{},name:"",notes:"",parent:0,password_valid_days:0,phone:"",protected_meta:{},id:0},X=t=>{const r="string"==typeof t?Number.parseInt(t):t;if(isNaN(r))throw new Error("invalid organizationId");const[i,o]=e(Object.assign({},W)),[s,c]=e(!0),[l,d]=e(),{lynxClient:u}=h(),p=n((()=>{c(!0),u.getOrganization(r).then((e=>{void 0!==l&&d(void 0),o(e)})).catch((e=>{d(e)})).finally((()=>{c(!1)}))}),[l,u,r]);a((()=>{p()}),[]);const g=n((()=>u.updateOrganization(i)),[u,i]),f=n((()=>u.deleteOrganization(i)),[u,i]);return{loading:s,organization:i,setOrganization:o,error:l,update:g,remove:f,refresh:p}},Y=t=>{const{lynxClient:r}=h(),[i,o]=e(!0),[s,c]=e(),[l,d]=e([]),u=n((()=>{o(!0),r.getOrganizations(!0===t).then((e=>{void 0!==s&&c(void 0),d(e)})).catch((e=>{c(e)})).finally((()=>{o(!1)}))}),[r,t]);a((()=>{u()}),[]);const p=n((e=>r.createOrganization(e)),[r]),g=n((e=>r.deleteOrganization(e)),[r]);return{loading:i,organizations:l,setOrganizations:d,error:s,create:p,remove:g}},Z={address:{address:"",city:"",country:"",zip:""},children:[],email:"",force_sms_login:!1,meta:{},name:"",notes:"",parent:0,password_valid_days:0,phone:"",protected_meta:{}},ee=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t;if(isNaN(i))throw new Error("invalid parentId");const{lynxClient:o}=h(),[s,a]=e(Object.assign(Object.assign(Object.assign({},Z),r),{parent:i})),c=n((()=>o.createOrganization(s)),[o,s]);return{newOrganization:s,setNewOrganization:a,create:c}},te={address:{address:"",zip:"",city:"",country:""},assigned_installations:[],email:"",expire_at:0,first_name:"",last_name:"",mobile:"",note:"",organisations:[],password:"",role:0,sms_login:!1,protected_meta:{},meta:{}},ne=t=>{const[r,i]=e(Object.assign(Object.assign({},te),t)),{lynxClient:o}=h(),s=n((()=>o.createUser(r)),[o,r]);return{newUser:r,setNewUser:i,create:s}},re=t=>{const[r,i]=e([]),[o,s]=e(!0),[a,c]=e(),{lynxClient:l}=h();new URLSearchParams;const d=n((()=>{s(!0),l.getUsers(t).then((e=>{void 0!==a&&c(void 0),i(e)})).catch((e=>{c(e)})).finally((()=>{s(!1)}))}),[l,t,a]);return{users:r,setUsers:i,refresh:d,loading:o,error:a}},ie={id:0,address:{address:"",zip:"",city:"",country:""},assigned_installations:[],email:"",expire_at:0,first_name:"",last_name:"",mobile:"",note:"",organisations:[],password:"",role:0,sms_login:!1,protected_meta:{},meta:{}},oe=t=>{const r="string"==typeof t?Number.parseInt(t):t;if(isNaN(r))throw new Error("invalid userId");const[i,o]=e(Object.assign({},ie)),[s,a]=e(!0),{lynxClient:c}=h(),[l,d]=e(),u=n((()=>{a(!0),c.getUser(r).then((e=>{void 0!==l&&d(void 0),o(e)})).catch((e=>{d(e)})).finally((()=>{a(!1)}))}),[c,r]),p=n((()=>c.updateUser(i)),[c,i]),g=n((()=>c.deleteUser(i)),[c,i]);return{loading:s,error:l,user:i,setUser:o,update:p,refresh:u,remove:g}},se=()=>{const{lynxClient:t}=h(),[r,i]=e([]),[o,s]=e(),[c,l]=e(!0),d=n((()=>{l(!0),t.getRoles().then((e=>{i(e)})).catch((e=>{s(e)})).finally((()=>{l(!1)}))}),[t]);return a((()=>{d()}),[]),{loading:c,error:o,roles:r,refresh:d}},ae={installation_id:0,name:"",text:""},ce=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t,{lynxClient:o}=h(),[s,a]=e(Object.assign(Object.assign(Object.assign({},ae),r),{installation_id:i})),c=n((()=>o.createNotificationMessage(s)),[o,s]);return{newNotificationMessage:s,setNewNotificationMessage:a,create:c}},le={id:0,installation_id:0,name:"",text:""},de=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t,o="string"==typeof r?Number.parseInt(r):r;if(isNaN(i))throw new Error("invalid installationId");if(isNaN(o))throw new Error("invalid messageId");const{lynxClient:s}=h(),[c,l]=e(!0),[d,u]=e(Object.assign({},le)),[p,g]=e(),f=n((()=>{0!==i&&0!==o&&(l(!0),s.getNotificationMessage(i,o).then((e=>{void 0!==p&&g(void 0),u(e)})).catch((e=>{g(e)})).finally((()=>{l(!1)})))}),[p,o,i,s]),v=n((()=>{void 0!==p&&g(void 0),s.updateNotificationMessage(d).then((e=>{u(e)})).catch((e=>{g(e)}))}),[p,s,d]),y=n((()=>{s.deleteNotificationMessage(d).then((()=>{u(Object.assign({},le))})).catch((e=>{g(e)}))}),[s,d]);return a((()=>{f()}),[]),{refresh:f,message:d,setMessage:u,error:p,loading:c,remove:y,update:v}},ue=t=>{const r="string"==typeof t?Number.parseInt(t):t;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:i}=h(),[o,s]=e([]),[c,l]=e(!0),[d,u]=e(),p=n((()=>{i.getNotificationMessages(r).then((e=>{void 0!==d&&u(void 0),s(e)})).catch((e=>{u(e)})).finally((()=>{l(!1)}))}),[d,r,i]);return a((()=>{p()}),[]),{refresh:p,notificationMessages:o,error:d,loading:c}},pe={installation_id:0,name:"",notification_message_id:0,notification_output_executor_id:0,config:{}},ge=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t,{lynxClient:o}=h(),[s,a]=e(Object.assign(Object.assign(Object.assign({},pe),r),{installation_id:i})),c=n((()=>o.createNotificationOutput(s)),[o,s]);return{newNotificationOutput:s,setNewNotificationOutput:a,create:c}},fe={id:0,installation_id:0,name:"",notification_message_id:0,notification_output_executor_id:0,config:{}},he=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t,o="string"==typeof r?Number.parseInt(r):r;if(isNaN(i))throw new Error("invalid installationId");if(isNaN(o))throw new Error("invalid notificationId");const{lynxClient:s}=h(),[c,l]=e(!0),[d,u]=e(Object.assign(Object.assign({},fe),{config:Object.assign({},fe.config)})),[p,g]=e(),f=n((()=>{0!==i&&0!==o&&(l(!0),s.getNotificationOutput(i,o).then((e=>{void 0!==p&&g(void 0),u(e)})).catch((e=>{g(e)})).finally((()=>{l(!1)})))}),[p,o,i,s]),v=n((()=>{void 0!==p&&g(void 0),s.updateNotificationOutput(d).then((e=>{u(e)})).catch((e=>{g(e)}))}),[p,s,d]),y=n((()=>{s.deleteNotificationOutput(d).then((()=>{u(Object.assign({},fe))})).catch((e=>{g(e)}))}),[s,d]);return a((()=>{f()}),[]),{refresh:f,output:d,setOutput:u,error:p,loading:c,remove:y,update:v}},ve=t=>{const r="string"==typeof t?Number.parseInt(t):t;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:i}=h(),[o,s]=e([]),[c,l]=e(!0),[d,u]=e(),p=n((()=>{i.getNotificationOutputs(r).then((e=>{void 0!==d&&u(void 0),s(e)})).catch((e=>{u(e)})).finally((()=>{l(!1)}))}),[d,r,i]);return a((()=>{p()}),[]),{refresh:p,notificationOutputs:o,error:d,loading:c}},ye={id:0,type:"",name:"",organization_id:0,config:{},secret:""},me=(t,r)=>{const i="string"==typeof t?Number.parseInt(t):t,o="string"==typeof r?Number.parseInt(r):r;if(isNaN(i))throw new Error("invalid installationId");if(isNaN(o))throw new Error("invalid messageId");const{lynxClient:s}=h(),[c,l]=e(!0),[d,u]=e(Object.assign({},ye)),[p,g]=e(),f=n((()=>{0!==i&&0!==o&&(l(!0),s.getNotificationOutputExecutor(i,o).then((e=>{void 0!==p&&g(void 0),u(e)})).catch((e=>{g(e)})).finally((()=>{l(!1)})))}),[p,o,i,s]);return a((()=>{f()}),[]),{refresh:f,outputExecutor:d,setOutputExecutor:u,error:p,loading:c}},we=t=>{const r="string"==typeof t?Number.parseInt(t):t;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:i}=h(),[o,s]=e([]),[c,l]=e(!0),[d,u]=e(),p=n((()=>{i.getNotificationOutputExecutors(r).then((e=>{void 0!==d&&u(void 0),s(e)})).catch((e=>{u(e)})).finally((()=>{l(!1)}))}),[d,r,i]);return a((()=>{p()}),[]),{refresh:p,notificationExecutors:o,error:d,loading:c}};export{b as LynxProvider,q as useConfiguredEdgeApps,R as useDevice,T as useDeviceMeta,S as useDevices,K as useEdgeApp,V as useEdgeAppVersions,L as useEdgeApps,M as useFunction,D as useFunctionMeta,x as useFunctions,h as useGlobalLynxClient,w as useGlobalPermissions,m as useGlobalUser,J as useIDTokenAlgorithms,A as useInstallation,N as useInstallationInfo,U as useInstallations,p as useMeta,F as useNewDevice,_ as useNewFunction,z as useNewInstallation,ce as useNewNotificationMessage,ge as useNewNotificationOutput,Q as useNewOAuth2Client,ee as useNewOrganization,ne as useNewUser,de as useNotificationMessage,ue as useNotificationMessages,he as useNotificationOutput,me as useNotificationOutputExecutor,we as useNotificationOutputExecutors,ve as useNotificationOutputs,B as useOAuth2Client,G as useOAuth2Clients,H as useOAuth2Consent,X as useOrganization,Y as useOrganizations,O as usePahoMQTTClient,se as useRoles,j as useSimpleMQTT,C as useTokens,oe as useUser,re as useUsers};
1
+ import { jsx as S } from "react/jsx-runtime";
2
+ import { createContext as K, useContext as Q, useState as f, useCallback as p, useMemo as j, useLayoutEffect as O, useEffect as M, useRef as I } from "react";
3
+ import { LynxClient as R, zero as G } from "@iotopen/node-lynx";
4
+ import ee from "paho-mqtt";
5
+ const te = {
6
+ lynxClient: new R(""),
7
+ newLynxClient: (t, r, e) => {
8
+ }
9
+ }, H = K(te), ne = ({ children: t, url: r, apiKey: e, bearer: n }) => {
10
+ const [o, a] = f(new R(r, e, n)), u = p((i, l, d) => {
11
+ a(new R(i, l, d));
12
+ }, [a]), s = j(() => ({ lynxClient: o, newLynxClient: u }), [o, u]);
13
+ return /* @__PURE__ */ S(H.Provider, { value: s, children: t });
14
+ }, E = () => Q(H), oe = {
15
+ user: null,
16
+ permissions: null
17
+ }, J = K(oe), re = ({ children: t }) => {
18
+ const [r, e] = f(null), [n, o] = f(null), [a, u] = f(!0), [s, i] = f(), { lynxClient: l } = E();
19
+ O(() => {
20
+ const c = l.getMe(), h = l.getPermissions();
21
+ u(!0), Promise.all([c, h]).then(([g, m]) => {
22
+ i((v) => v !== void 0 ? void 0 : v), e(g), o(m);
23
+ }).catch((g) => {
24
+ i(g), e(null), o(null);
25
+ }).finally(() => {
26
+ u(!1);
27
+ });
28
+ }, [l]);
29
+ const d = j(() => ({ user: r, permissions: n, loading: a, error: s }), [r, n, a, s]);
30
+ return /* @__PURE__ */ S(J.Provider, { value: d, children: t });
31
+ }, W = () => Q(J), X = () => {
32
+ const { permissions: t } = W();
33
+ return t;
34
+ }, Oe = ({ children: t, apiURL: r, apiKey: e, bearer: n }) => /* @__PURE__ */ S(ne, { url: r, apiKey: e, bearer: n, children: /* @__PURE__ */ S(re, { children: t }) }), Le = (...t) => {
35
+ const r = X();
36
+ return r == null ? !1 : t.every((e) => r[e] !== void 0 && r[e]);
37
+ }, Ae = (...t) => {
38
+ const r = X();
39
+ return r == null ? !1 : t.some((e) => r[e] !== void 0 && r[e]);
40
+ }, De = (t) => {
41
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
42
+ if (isNaN(r))
43
+ throw new Error("invalid installationId");
44
+ const { lynxClient: e } = E(), [n, o] = f(!0), [a, u] = f(), [s, i] = f([]), l = p(() => {
45
+ o(!0), e.getConfiguredEdgeApps(r).then((d) => {
46
+ u((c) => c !== void 0 ? void 0 : c), i(d);
47
+ }).catch((d) => {
48
+ u(d);
49
+ }).finally(() => {
50
+ o(!1);
51
+ });
52
+ }, [r, e]);
53
+ return O(() => {
54
+ l();
55
+ }, [l]), {
56
+ refresh: l,
57
+ loading: n,
58
+ error: a,
59
+ apps: s
60
+ };
61
+ }, se = {
62
+ updated: 0,
63
+ created: 0,
64
+ id: 0,
65
+ installation_id: 0,
66
+ type: "",
67
+ meta: {},
68
+ protected_meta: {}
69
+ }, Pe = (t, r) => {
70
+ const e = typeof t == "string" ? Number.parseInt(t) : t, n = typeof r == "string" ? Number.parseInt(r) : r;
71
+ if (isNaN(e) || isNaN(n))
72
+ throw new Error("invalid installationId or deviceId");
73
+ const { lynxClient: o } = E(), [a, u] = f(!0), [s, i] = f({ ...se }), [l, d] = f();
74
+ O(() => {
75
+ o.getDevice(e, n).then((m) => {
76
+ d((v) => v !== void 0 ? void 0 : v), i(m);
77
+ }).catch((m) => {
78
+ d(m);
79
+ }).finally(() => {
80
+ u(!1);
81
+ });
82
+ }, [o, e, n]);
83
+ const c = p(() => new Promise(() => {
84
+ if (!s)
85
+ throw new Error("update on undefined function");
86
+ return o.updateDevice(s);
87
+ }), [o, s]), h = p((m) => {
88
+ s && i({ ...s, type: m });
89
+ }, [s, i]), g = p(() => new Promise(() => {
90
+ if (!s)
91
+ throw new Error("delete on undefined function");
92
+ return o.deleteDevice(s);
93
+ }), [s, o]);
94
+ return {
95
+ loading: a,
96
+ error: l,
97
+ Device: s,
98
+ setDevice: i,
99
+ update: c,
100
+ remove: g,
101
+ setType: h
102
+ };
103
+ }, Fe = (t, r) => {
104
+ const e = typeof t == "string" ? Number.parseInt(t) : t, n = typeof r == "string" ? Number.parseInt(r) : r, { lynxClient: o } = E(), a = p((i, l, d, c) => {
105
+ const h = d ?? n ?? 0;
106
+ return o.createDeviceMeta(e, h, i, l, c);
107
+ }, [o, e, n]), u = p((i, l, d, c, h) => {
108
+ const g = c ?? n ?? 0;
109
+ return o.updateDeviceMeta(e, g, i, l, h, d);
110
+ }, [o, e, n]), s = p((i, l, d) => {
111
+ const c = l ?? n ?? 0;
112
+ return o.deleteDeviceMeta(e, c, i, d);
113
+ }, [o, e, n]);
114
+ return {
115
+ createMeta: a,
116
+ updateMeta: u,
117
+ removeMeta: s
118
+ };
119
+ }, Y = (t, r) => {
120
+ const e = typeof t == "string" ? Number.parseInt(t) : t;
121
+ if (isNaN(e) && e !== void 0)
122
+ throw new Error("invalid installationId");
123
+ const { lynxClient: n } = E(), [o, a] = f(!0), [u, s] = f([]), [i, l] = f(), d = p(() => {
124
+ if (e === void 0) {
125
+ a(!1), s([]);
126
+ return;
127
+ }
128
+ a(!0), n.getDevices(e, r).then((v) => {
129
+ l((w) => w !== void 0 ? void 0 : w), s(v);
130
+ }).catch((v) => {
131
+ l(v);
132
+ }).finally(() => {
133
+ a(!1);
134
+ });
135
+ }, [n, e, r]);
136
+ function c(v) {
137
+ if (Array.isArray(v)) {
138
+ const w = v.pop();
139
+ if (!w)
140
+ return Promise.allSettled([]);
141
+ const C = v.map(((N) => n.deleteDevice(N, !0)));
142
+ return Promise.allSettled(C).then(async (N) => {
143
+ try {
144
+ N.push({ status: "fulfilled", value: await n.deleteDevice(w) });
145
+ } catch (y) {
146
+ N.push({ status: "rejected", reason: y });
147
+ }
148
+ return N;
149
+ });
150
+ }
151
+ return n.deleteDevice(v);
152
+ }
153
+ function h(v) {
154
+ if (Array.isArray(v)) {
155
+ const w = v.pop();
156
+ if (!w)
157
+ return Promise.allSettled([]);
158
+ const C = v.map((N) => n.createDevice(N, !0));
159
+ return Promise.allSettled(C).then(async (N) => {
160
+ try {
161
+ N.push({ status: "fulfilled", value: await n.createDevice(w) });
162
+ } catch (y) {
163
+ N.push({ status: "rejected", reason: y });
164
+ }
165
+ return N;
166
+ });
167
+ }
168
+ return n.createDevice(v);
169
+ }
170
+ const g = p(h, [n, h]), m = p(c, [n, c]);
171
+ return O(() => {
172
+ d();
173
+ }, [d]), {
174
+ loading: o,
175
+ error: i,
176
+ create: g,
177
+ remove: m,
178
+ devices: u,
179
+ refresh: d
180
+ };
181
+ }, ie = {
182
+ id: 0,
183
+ created: 0,
184
+ updated: 0,
185
+ name: "",
186
+ category: "",
187
+ short_description: "",
188
+ description: "",
189
+ source_url: "",
190
+ tags: [],
191
+ publisher: { id: 0 },
192
+ public: !1,
193
+ official: !1
194
+ }, Ie = (t) => {
195
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
196
+ if (isNaN(r))
197
+ throw new Error("invalid appId");
198
+ const { lynxClient: e } = E(), [n, o] = f(!1), [a, u] = f(), [s, i] = f({ ...ie }), l = p(() => {
199
+ o(!0), e.getEdgeApp(r).then((d) => {
200
+ u((c) => c !== void 0 ? void 0 : c), i(d);
201
+ }).catch((d) => {
202
+ u(d);
203
+ }).finally(() => {
204
+ o(!1);
205
+ });
206
+ }, [r, e]);
207
+ return O(() => {
208
+ l();
209
+ }, [l]), {
210
+ loading: n,
211
+ error: a,
212
+ app: s,
213
+ setApp: i,
214
+ refresh: l
215
+ };
216
+ }, ze = () => {
217
+ const { lynxClient: t } = E(), [r, e] = f(!0), [n, o] = f(), [a, u] = f([]), s = p(() => {
218
+ e(!0), t.getEdgeApps().then((i) => {
219
+ o((l) => l !== void 0 ? void 0 : l), u(i);
220
+ }).catch((i) => {
221
+ o(i);
222
+ }).finally(() => {
223
+ e(!1);
224
+ });
225
+ }, [t]);
226
+ return O(() => {
227
+ s();
228
+ }, [s]), {
229
+ apps: a,
230
+ error: n,
231
+ loading: r,
232
+ refresh: s
233
+ };
234
+ }, Ue = (t, r) => {
235
+ const e = typeof t == "string" ? Number.parseInt(t) : t;
236
+ if (isNaN(e))
237
+ throw new Error("invalid appId");
238
+ const { lynxClient: n } = E(), [o, a] = f(!1), [u, s] = f(), [i, l] = f([]), d = p(() => {
239
+ a(!0), n.getEdgeAppVersions(e, r).then((h) => {
240
+ s((g) => g !== void 0 ? void 0 : g), l(h);
241
+ }).catch((h) => {
242
+ s(h);
243
+ }).finally(() => {
244
+ a(!1);
245
+ });
246
+ }, [n, e, r]), c = p((h, g) => n.nameEdgeAppVersion(e, h, g), [n, e]);
247
+ return O(() => {
248
+ d();
249
+ }, [d]), {
250
+ loading: o,
251
+ error: u,
252
+ versions: i,
253
+ nameVersion: c,
254
+ refresh: d
255
+ };
256
+ }, ce = {
257
+ id: 0,
258
+ installation_id: 0,
259
+ type: "",
260
+ updated: 0,
261
+ created: 0,
262
+ meta: {},
263
+ protected_meta: {}
264
+ }, Se = (t, r) => {
265
+ const e = typeof t == "string" ? Number.parseInt(t) : t, n = typeof r == "string" ? Number.parseInt(r) : r;
266
+ if (isNaN(e) || isNaN(n))
267
+ throw new Error("invalid installationId or functionId");
268
+ const { lynxClient: o } = E(), [a, u] = f(!0), [s, i] = f({ ...ce }), [l, d] = f();
269
+ O(() => {
270
+ o.getFunction(e, n).then((m) => {
271
+ d((v) => v !== void 0 ? void 0 : v), i(m);
272
+ }).catch((m) => {
273
+ d(m);
274
+ }).finally(() => {
275
+ u(!1);
276
+ });
277
+ }, [o, e, n]);
278
+ const c = p(() => new Promise(() => {
279
+ if (!s)
280
+ throw new Error("update on undefined function");
281
+ return o.updateFunction(s);
282
+ }), [o, s]), h = p((m) => {
283
+ s && i({ ...s, type: m });
284
+ }, [s, i]), g = p(() => new Promise(() => {
285
+ if (!s)
286
+ throw new Error("delete on undefined function");
287
+ return o.deleteFunction(s);
288
+ }), [s, o]);
289
+ return {
290
+ loading: a,
291
+ error: l,
292
+ Function: s,
293
+ setFunction: i,
294
+ update: c,
295
+ remove: g,
296
+ setType: h
297
+ };
298
+ }, ke = (t, r) => {
299
+ const e = typeof t == "string" ? Number.parseInt(t) : t, n = typeof r == "string" ? Number.parseInt(r) : r, { lynxClient: o } = E(), a = p((i, l, d, c) => {
300
+ const h = d ?? n ?? 0;
301
+ return o.createFunctionMeta(e, h, i, l, c);
302
+ }, [o, e, n]), u = p((i, l, d, c, h) => {
303
+ const g = c ?? n ?? 0;
304
+ return o.updateFunctionMeta(e, g, i, l, h, d);
305
+ }, [o, e, n]), s = p((i, l, d) => {
306
+ const c = l ?? n ?? 0;
307
+ return o.deleteFunctionMeta(e, c, i, d);
308
+ }, [o, e, n]);
309
+ return {
310
+ createMeta: a,
311
+ updateMeta: u,
312
+ removeMeta: s
313
+ };
314
+ }, Z = (t, r) => {
315
+ const e = typeof t == "string" ? Number.parseInt(t) : t;
316
+ if (isNaN(e) && e !== void 0)
317
+ throw new Error("invalid installationId");
318
+ const { lynxClient: n } = E(), [o, a] = f(!0), [u, s] = f([]), [i, l] = f(), d = p(() => {
319
+ if (e === void 0) {
320
+ a(!1), s([]);
321
+ return;
322
+ }
323
+ a(!0), n.getFunctions(e, r).then((v) => (l((w) => w !== void 0 ? void 0 : w), s(v), v)).catch((v) => {
324
+ l(v);
325
+ }).finally(() => {
326
+ a(!1);
327
+ });
328
+ }, [n, e, r]);
329
+ function c(v) {
330
+ if (Array.isArray(v)) {
331
+ const w = v.pop();
332
+ if (!w)
333
+ return Promise.allSettled([]);
334
+ const C = v.map(((N) => n.deleteFunction(N, !0)));
335
+ return Promise.allSettled(C).then(async (N) => {
336
+ try {
337
+ N.push({ status: "fulfilled", value: await n.deleteFunction(w) });
338
+ } catch (y) {
339
+ N.push({ status: "rejected", reason: y });
340
+ }
341
+ return N;
342
+ });
343
+ }
344
+ return n.deleteFunction(v);
345
+ }
346
+ function h(v) {
347
+ if (Array.isArray(v)) {
348
+ const w = v.pop();
349
+ if (!w)
350
+ return Promise.allSettled([]);
351
+ const C = v.map((N) => n.createFunction(N, !0));
352
+ return Promise.allSettled(C).then(async (N) => {
353
+ try {
354
+ N.push({ status: "fulfilled", value: await n.createFunction(w) });
355
+ } catch (y) {
356
+ N.push({ status: "rejected", reason: y });
357
+ }
358
+ return N;
359
+ });
360
+ }
361
+ return n.createFunction(v);
362
+ }
363
+ const g = p(h, [n, h]), m = p(c, [n, c]);
364
+ return O(() => {
365
+ d();
366
+ }, [d]), {
367
+ loading: o,
368
+ error: i,
369
+ create: g,
370
+ remove: m,
371
+ functions: u,
372
+ refresh: d
373
+ };
374
+ }, Re = () => {
375
+ const { lynxClient: t } = E(), [r, e] = f(!0), [n, o] = f(), [a, u] = f([]), s = p(() => {
376
+ e(!0), t.getIDTokenAlgorithms().then((i) => {
377
+ o((l) => l !== void 0 ? void 0 : l), u(i);
378
+ }).catch((i) => {
379
+ o(i);
380
+ }).finally(() => {
381
+ e(!1);
382
+ });
383
+ }, [t]);
384
+ return M(() => {
385
+ s();
386
+ }, []), {
387
+ loading: r,
388
+ refresh: s,
389
+ algs: a,
390
+ error: n
391
+ };
392
+ }, ae = {
393
+ client_id: 0,
394
+ notes: "",
395
+ organization_id: 0,
396
+ id: 0,
397
+ name: "",
398
+ created: 0,
399
+ meta: {},
400
+ users: [],
401
+ protected_meta: {}
402
+ }, ue = (t) => {
403
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
404
+ if (isNaN(r))
405
+ throw new Error("invalid installationId");
406
+ const { lynxClient: e } = E(), [n, o] = f(!0), [a, u] = f(void 0), [s, i] = f({ ...ae });
407
+ O(() => {
408
+ e.getInstallationRow(r).then((c) => {
409
+ u((h) => h !== void 0 ? void 0 : h), i(c);
410
+ }).catch((c) => {
411
+ u(c);
412
+ }).finally(() => {
413
+ o(!1);
414
+ });
415
+ }, [e, r]);
416
+ const l = p(() => new Promise(() => {
417
+ if (!s)
418
+ throw new Error("update on undefined installation");
419
+ return e.updateInstallation(s);
420
+ }), [e, s]), d = p(() => new Promise(() => {
421
+ if (!s)
422
+ throw new Error("update on undefined installation");
423
+ return e.deleteInstallation(s);
424
+ }), [e, s]);
425
+ return {
426
+ installation: s,
427
+ setInstallation: i,
428
+ update: l,
429
+ remove: d,
430
+ error: a,
431
+ loading: n
432
+ };
433
+ }, Te = (t) => {
434
+ const { lynxClient: r } = E(), [e, n] = f([]), [o, a] = f(!0), [u, s] = f(void 0), i = p(() => {
435
+ a(!0), r.getInstallations(t).then((l) => {
436
+ s((d) => d !== void 0 ? void 0 : d), n(l);
437
+ }).catch((l) => {
438
+ s(l);
439
+ }).finally(() => {
440
+ a(!1);
441
+ });
442
+ }, [r]);
443
+ return O(() => {
444
+ i();
445
+ }, [i]), {
446
+ installations: e,
447
+ refresh: i,
448
+ loading: o,
449
+ error: u
450
+ };
451
+ }, qe = (t) => {
452
+ const { lynxClient: r } = E(), [e, n] = f(!0), [o, a] = f([]), [u, s] = f(), i = p(() => {
453
+ n(!0), r.listInstallations(t).then((l) => {
454
+ s((d) => d !== void 0 ? void 0 : d), a(l);
455
+ }).catch((l) => {
456
+ s(() => l);
457
+ }).finally(() => {
458
+ n(!1);
459
+ });
460
+ }, [r, t]);
461
+ return O(() => {
462
+ i();
463
+ }, [i]), {
464
+ loading: e,
465
+ error: u,
466
+ installations: o,
467
+ refresh: i
468
+ };
469
+ }, le = (t, r, e, n) => {
470
+ if (n === void 0) {
471
+ let v;
472
+ window?.crypto?.randomUUID ? v = window.crypto.randomUUID() : typeof crypto < "u" && crypto?.randomUUID ? v = crypto.randomUUID() : v = Math.random().toString(36).substring(2, 15), n = `paho-ws-mqtt-${v}`;
473
+ }
474
+ const o = I(new ee.Client(t, n)), a = I(e), u = I(r), s = I(void 0), [i, l] = f(!1), [d, c] = f(void 0);
475
+ O(() => {
476
+ const v = o, w = s, C = {
477
+ timeout: 5,
478
+ ...a.current,
479
+ onFailure: (y) => {
480
+ c(y), l(o.current.isConnected()), w.current ??= window.setInterval(() => {
481
+ v.current.isConnected() ? clearInterval(w.current) : v.current.connect(C);
482
+ }, 5e3);
483
+ },
484
+ onSuccess: () => {
485
+ c(void 0), l(o.current.isConnected()), w.current !== void 0 && (window.clearInterval(w.current), w.current = void 0);
486
+ }
487
+ }, N = u.current;
488
+ v.current.onConnectionLost = (y) => {
489
+ c(y), l(o.current.isConnected()), N?.onDisconnect?.(y);
490
+ }, v.current.onConnected = (y, b) => {
491
+ l(o.current.isConnected()), c(void 0), N?.onConnected?.(y, b);
492
+ }, N && (N.onMessage && (v.current.onMessageArrived = N.onMessage), N.onDelivery && (v.current.onMessageDelivered = N.onDelivery));
493
+ try {
494
+ v.current.connect(C);
495
+ } catch {
496
+ window.setTimeout(() => {
497
+ v.current.connect(C);
498
+ }, 5e3);
499
+ }
500
+ return () => {
501
+ try {
502
+ v.current.disconnect(), w.current !== void 0 && window.clearInterval(w.current);
503
+ } catch (y) {
504
+ console.log(y);
505
+ }
506
+ };
507
+ }, []);
508
+ const h = p((v, w) => new Promise((C) => {
509
+ o.current.subscribe(v, {
510
+ qos: w ?? 0,
511
+ timeout: 1,
512
+ onFailure: (N) => {
513
+ throw N;
514
+ },
515
+ onSuccess: (N) => {
516
+ C(N.grantedQos);
517
+ }
518
+ });
519
+ }), [o]), g = p((v, w, C, N) => {
520
+ let y;
521
+ if (typeof w == "string")
522
+ y = w;
523
+ else if (ArrayBuffer.isView(w))
524
+ y = new Uint8Array(w.buffer, w.byteOffset, w.byteLength).slice().buffer;
525
+ else
526
+ throw new Error("Payload must be a string or TypedArray");
527
+ o.current.send(v, y, C, N);
528
+ }, [o]), m = p((v) => new Promise((w) => {
529
+ o.current.unsubscribe(v, {
530
+ timeout: 1,
531
+ onSuccess: () => {
532
+ w();
533
+ },
534
+ onFailure: (C) => {
535
+ throw C;
536
+ }
537
+ });
538
+ }), [o]);
539
+ return {
540
+ client: o,
541
+ connected: i,
542
+ error: d,
543
+ sub: h,
544
+ pub: g,
545
+ unsub: m
546
+ };
547
+ };
548
+ function de(t, r) {
549
+ if (t.length === r.length) {
550
+ for (let e = 0; e < t.length; e++)
551
+ if (t[e] !== r[e])
552
+ return !1;
553
+ return !0;
554
+ }
555
+ return !1;
556
+ }
557
+ function fe(t, r) {
558
+ return new Promise((e) => {
559
+ r.forEach(async (n) => {
560
+ try {
561
+ await t(n);
562
+ } catch (o) {
563
+ console.warn("failed to unsubscribe to", n, o);
564
+ }
565
+ }), e();
566
+ });
567
+ }
568
+ function pe(t, r) {
569
+ return new Promise((e) => {
570
+ r.forEach(async (n) => {
571
+ try {
572
+ await t(n);
573
+ } catch (o) {
574
+ console.warn("failed to subscribe to", n, o);
575
+ }
576
+ }), e();
577
+ });
578
+ }
579
+ const he = (t, r, e) => {
580
+ t === void 0 && (window !== void 0 ? t = window.location.protocol === "http:" ? `ws://${window.location.host}/mqtt` : `wss://${window.location.host}/mqtt` : t = location.protocol === "http:" ? `ws://${location.host}/mqtt` : `wss://${location.host}/mqtt`);
581
+ const n = I([]), o = I(/* @__PURE__ */ new Map([])), a = I(/* @__PURE__ */ new Map([])), u = p((y) => {
582
+ const b = a.current.get(y.destinationName);
583
+ b && b.forEach((x) => {
584
+ x(y.destinationName, new TextDecoder().decode(y.payloadBytes), y.qos, y.retained);
585
+ }), o.current.forEach((x, A) => {
586
+ new RegExp(A).test(y.destinationName) && x.forEach((q) => {
587
+ q(y.destinationName, new TextDecoder().decode(y.payloadBytes), y.qos, y.retained);
588
+ });
589
+ });
590
+ }, []), s = I(!1), i = {
591
+ cleanSession: !0,
592
+ reconnect: !0,
593
+ keepAliveInterval: 5
594
+ };
595
+ r && (i.userName = r), e && (i.password = e);
596
+ const {
597
+ error: l,
598
+ connected: d,
599
+ sub: c,
600
+ unsub: h,
601
+ pub: g
602
+ } = le(t, {
603
+ onMessage: u,
604
+ onConnected: () => {
605
+ n.current.forEach((y) => {
606
+ c(y).catch((b) => {
607
+ console.warn("Failed to subscribe to", y, b);
608
+ });
609
+ });
610
+ }
611
+ }, i);
612
+ M(() => {
613
+ s.current = d;
614
+ }, [d]);
615
+ const m = p((y, b) => {
616
+ let x;
617
+ typeof y == "string" ? x = new RegExp(`^${y}$`) : x = y;
618
+ const A = x.toString().slice(1, -1);
619
+ let D = o.current.get(A);
620
+ if (D === void 0) {
621
+ D = [b], o.current.set(A, D);
622
+ return;
623
+ }
624
+ D.includes(b) || D.push(b);
625
+ }, []), v = p((y) => {
626
+ o.current.forEach((b, x) => {
627
+ const A = b.filter((D) => D !== y);
628
+ o.current.set(x, A);
629
+ });
630
+ }, []), w = p((y, b) => {
631
+ let x = a.current.get(y);
632
+ if (x === void 0) {
633
+ x = [b], a.current.set(y, x);
634
+ return;
635
+ }
636
+ x.includes(b) || x.push(b);
637
+ }, []), C = p((y, b) => {
638
+ const x = a.current.get(y);
639
+ x !== void 0 && a.current.set(y, x.filter((A) => A !== b));
640
+ }, []);
641
+ return {
642
+ setSubs: p((y) => {
643
+ de(n.current, y) || (s.current && fe(h, n.current).then(() => pe(c, y)).catch((b) => {
644
+ console.warn("Failed to update subscriptions", b);
645
+ }), n.current = y);
646
+ }, [c, h]),
647
+ error: l,
648
+ connected: d,
649
+ bind: m,
650
+ unbind: v,
651
+ bindExact: w,
652
+ unbindExact: C,
653
+ pub: g
654
+ };
655
+ }, T = () => {
656
+ const t = E(), { user: r } = W(), e = new URL(t.lynxClient.baseURL), n = e.protocol === "http:" ? "ws:" : "wss:", o = e.hostname, a = e.port ? `:${e.port}` : "", u = `${n}//${o}${a}/mqtt`;
657
+ let s = r?.email ?? "api-key";
658
+ return t.lynxClient.bearer && (s = "bearer"), he(u, s, t.lynxClient.apiKey);
659
+ }, $e = (t) => {
660
+ const r = T(), { functions: e, refresh: n } = Z(t.id), { devices: o, refresh: a } = Y(t.id), { unbind: u, bind: s, setSubs: i } = r;
661
+ return M(() => (i([`${t.client_id}/#`]), s(/[0-9]+\/evt\/functionx\/updated/, n), s(/[0-9]+\/evt\/devicex\/updated/, a), () => {
662
+ u(n), u(a);
663
+ }), [s, a, n, t, i, u]), {
664
+ installation: t,
665
+ functions: e,
666
+ devices: o,
667
+ mqtt: r
668
+ };
669
+ }, Ve = (t) => {
670
+ const r = T(), { installation: e } = ue(t), { functions: n, refresh: o } = Z(t), { devices: a, refresh: u } = Y(t), { unbind: s, bind: i, setSubs: l } = r;
671
+ return M(() => (l([`${e.client_id}/#`]), i(/[0-9]+\/evt\/functionx\/updated/, o), i(/[0-9]+\/evt\/devicex\/updated/, u), () => {
672
+ s(o), s(u);
673
+ }), [i, u, o, e, l, s]), {
674
+ installation: e,
675
+ functions: n,
676
+ devices: a,
677
+ mqtt: r
678
+ };
679
+ }, Be = (t, r = []) => {
680
+ const [e, n] = f([]);
681
+ O(() => {
682
+ if (t) {
683
+ const c = [];
684
+ for (const h in t.meta) {
685
+ const g = t.meta[h];
686
+ c.push({ key: h, value: g ?? "", protected: !1 });
687
+ }
688
+ for (const h in t.protected_meta) {
689
+ const g = t.protected_meta[h];
690
+ c.push({ key: h, value: g ?? "", protected: !0 });
691
+ }
692
+ c.sort((h, g) => h.key.localeCompare(g.key)), n(c);
693
+ }
694
+ }, [t, ...r]);
695
+ const o = p(() => {
696
+ const c = { meta: {}, protected_meta: {} };
697
+ return e.forEach((h) => {
698
+ h.protected ? c.protected_meta[h.key] = h.value : c.meta[h.key] = h.value;
699
+ }), c;
700
+ }, [e]), a = p((c) => {
701
+ n([...e, c ?? { key: "", value: "", protected: !1 }]);
702
+ }, [e, n]), u = p((c) => {
703
+ n(e.filter((h, g) => g !== c));
704
+ }, [e, n]), s = p((c, h) => {
705
+ n(e.map((g, m) => m === c ? h : g));
706
+ }, [e, n]), i = p((c, h) => {
707
+ n(e.map((g, m) => m === c ? { ...g, key: h } : g));
708
+ }, [e, n]), l = p((c, h) => {
709
+ n(e.map((g, m) => m === c ? { ...g, value: h } : g));
710
+ }, [e, n]), d = p((c, h) => {
711
+ n(e.map((g, m) => m === c ? { ...g, protected: h } : g));
712
+ }, [e, n]);
713
+ return {
714
+ metaList: e,
715
+ compile: o,
716
+ addMeta: a,
717
+ removeMeta: u,
718
+ setMeta: s,
719
+ setMetaKey: i,
720
+ setMetaValue: l,
721
+ setMetaProtected: d
722
+ };
723
+ }, Ke = (t) => {
724
+ const { lynxClient: r } = E(), e = T(), { bind: n, unbind: o, setSubs: a } = e, [u, s] = f(/* @__PURE__ */ new Map()), [i, l] = f(/* @__PURE__ */ new Map()), [d, c] = f(/* @__PURE__ */ new Map()), [h, g] = f(/* @__PURE__ */ new Map()), m = p((w) => {
725
+ const C = i.get(w);
726
+ return C !== void 0 ? C.client_id : 0;
727
+ }, [i]), v = p((w) => {
728
+ const C = u.get(w);
729
+ return C !== void 0 ? C.id : 0;
730
+ }, [u]);
731
+ return M(() => {
732
+ if (t.length === 0)
733
+ return;
734
+ const w = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), N = new Array();
735
+ t.forEach((_) => {
736
+ w.set(_.id, _), C.set(_.client_id, _), N.push(`${_.client_id}/#`);
737
+ });
738
+ let y = !1;
739
+ const b = t.map(async (_) => ({ functions: await r.getFunctions(_.id), installationId: _.id })), x = t.map(async (_) => ({ devices: await r.getDevices(_.id), installationId: _.id })), A = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
740
+ new Promise((_, F) => {
741
+ let L = !1, P = !1;
742
+ Promise.allSettled(b).then((z) => {
743
+ z.forEach((U) => {
744
+ U.status === "fulfilled" && D.set(U.value.installationId, U.value.functions);
745
+ }), L = !0, L && P && _();
746
+ }).catch(F), Promise.allSettled(x).then((z) => {
747
+ z.forEach((U) => {
748
+ U.status === "fulfilled" && A.set(U.value.installationId, U.value.devices);
749
+ }), P = !0, L && P && _();
750
+ }).catch(F);
751
+ }).finally(() => {
752
+ s(() => C), l(() => w), c(() => D), g(() => A), y = !0;
753
+ }).catch((_) => {
754
+ console.warn("Error in work.finally:", _);
755
+ });
756
+ const $ = (_) => {
757
+ if (!y)
758
+ return;
759
+ const F = Number(_.split("/")[0]), L = C.get(F);
760
+ L !== void 0 && r.getFunctions(L.id).then((P) => {
761
+ c((z) => new Map([...z, [L.id, P]]));
762
+ }).catch((P) => {
763
+ console.warn("Failed to update function map for", L.id, P);
764
+ });
765
+ }, V = (_) => {
766
+ if (!y)
767
+ return;
768
+ const F = Number(_.split("/")[0]), L = C.get(F);
769
+ L !== void 0 && r.getDevices(L.id).then((P) => {
770
+ g((z) => new Map([...z, [L.id, P]]));
771
+ }).catch((P) => {
772
+ console.warn("Failed to update device map for", L.id, P);
773
+ });
774
+ };
775
+ return a(N), n(/[0-9]+\/evt\/functionx\/updated/, $), n(/[0-9]+\/evt\/devicex\/updated/, V), () => {
776
+ o($), o(V);
777
+ };
778
+ }, [t, r, n, o, a]), {
779
+ installationMap: i,
780
+ functionMap: d,
781
+ deviceMap: h,
782
+ mqtt: e,
783
+ toClientId: m,
784
+ toInstallationId: v
785
+ };
786
+ }, Qe = (t, r) => {
787
+ const e = typeof t == "string" ? Number.parseInt(t) : t;
788
+ if (isNaN(e))
789
+ throw new Error("invalid installationId");
790
+ const { lynxClient: n } = E(), [o, a] = f({
791
+ meta: {},
792
+ protected_meta: {},
793
+ type: "",
794
+ ...r,
795
+ installation_id: e
796
+ }), u = p((i) => {
797
+ a({ ...o, type: i });
798
+ }, [o, a]), s = p(() => n.createDevice(o), [n, o]);
799
+ return {
800
+ newDevice: o,
801
+ setNewDevice: a,
802
+ create: s,
803
+ setType: u
804
+ };
805
+ }, je = (t, r) => {
806
+ const e = typeof t == "string" ? Number.parseInt(t) : t;
807
+ if (isNaN(e))
808
+ throw new Error("invalid installationId");
809
+ const { lynxClient: n } = E(), [o, a] = f({
810
+ meta: {},
811
+ protected_meta: {},
812
+ type: "",
813
+ ...r,
814
+ installation_id: e
815
+ }), u = p((i) => {
816
+ a({ ...o, type: i });
817
+ }, [o, a]), s = p(() => n.createFunction(o), [n, o]);
818
+ return {
819
+ newFunction: o,
820
+ setNewFunction: a,
821
+ create: s,
822
+ setType: u
823
+ };
824
+ }, Ge = (t, r) => {
825
+ const e = typeof t == "string" ? Number.parseInt(t) : t;
826
+ if (isNaN(e))
827
+ throw new Error("invalid organizationId");
828
+ const [n, o] = f({
829
+ name: "",
830
+ notes: "",
831
+ users: [],
832
+ meta: {},
833
+ protected_meta: {},
834
+ ...r,
835
+ organization_id: e
836
+ }), { lynxClient: a } = E(), u = p(() => a.createInstallation(n), [a, n]);
837
+ return {
838
+ newInstallation: n,
839
+ setNewInstallation: o,
840
+ create: u
841
+ };
842
+ }, ve = {
843
+ installation_id: 0,
844
+ name: "",
845
+ text: ""
846
+ }, He = (t, r) => {
847
+ const e = typeof t == "string" ? Number.parseInt(t) : t, { lynxClient: n } = E(), [o, a] = f({
848
+ ...ve,
849
+ ...r,
850
+ installation_id: e
851
+ }), u = p(() => n.createNotificationMessage(o), [n, o]);
852
+ return {
853
+ newNotificationMessage: o,
854
+ setNewNotificationMessage: a,
855
+ create: u
856
+ };
857
+ }, ge = {
858
+ installation_id: 0,
859
+ name: "",
860
+ notification_message_id: 0,
861
+ notification_output_executor_id: 0,
862
+ config: {}
863
+ }, Je = (t, r) => {
864
+ const e = typeof t == "string" ? Number.parseInt(t) : t, { lynxClient: n } = E(), [o, a] = f({
865
+ ...ge,
866
+ ...r,
867
+ installation_id: e
868
+ }), u = p(() => n.createNotificationOutput(o), [n, o]);
869
+ return {
870
+ newNotificationOutput: o,
871
+ setNewNotificationOutput: a,
872
+ create: u
873
+ };
874
+ }, We = (t) => {
875
+ const { lynxClient: r } = E(), [e, n] = f({
876
+ ...G.getEmptyOAuth2Client(),
877
+ ...t
878
+ }), o = p((c) => {
879
+ n({ ...e, name: c });
880
+ }, [e]), a = p((c) => {
881
+ n({ ...e, allowed_scopes: c });
882
+ }, [e]), u = p((c) => {
883
+ n({ ...e, icon_uri: c });
884
+ }, [e]), s = p((c) => {
885
+ n({ ...e, tos_uri: c });
886
+ }, [e]), i = p((c) => {
887
+ n({ ...e, policy_uri: c });
888
+ }, [e]), l = p((c) => {
889
+ n({ ...e, redirect_uris: c });
890
+ }, [e]), d = p(() => r.createOAuth2Client(e), [r, e]);
891
+ return {
892
+ newClient: e,
893
+ create: d,
894
+ setName: o,
895
+ setScope: a,
896
+ setIconURI: u,
897
+ setTosURI: s,
898
+ setPolicyURI: i,
899
+ setRedirectURIs: l,
900
+ setClient: n
901
+ };
902
+ }, ye = {
903
+ address: {
904
+ address: "",
905
+ city: "",
906
+ country: "",
907
+ zip: ""
908
+ },
909
+ children: [],
910
+ email: "",
911
+ force_sms_login: !1,
912
+ meta: {},
913
+ name: "",
914
+ notes: "",
915
+ parent: 0,
916
+ password_valid_days: 0,
917
+ phone: "",
918
+ protected_meta: {}
919
+ }, Xe = (t, r) => {
920
+ const e = typeof t == "string" ? Number.parseInt(t) : t;
921
+ if (isNaN(e))
922
+ throw new Error("invalid parentId");
923
+ const { lynxClient: n } = E(), [o, a] = f({
924
+ ...ye,
925
+ ...r,
926
+ parent: e
927
+ }), u = p(() => n.createOrganization(o), [n, o]);
928
+ return {
929
+ newOrganization: o,
930
+ setNewOrganization: a,
931
+ create: u
932
+ };
933
+ }, me = {
934
+ address: {
935
+ address: "",
936
+ zip: "",
937
+ city: "",
938
+ country: ""
939
+ },
940
+ assigned_installations: [],
941
+ email: "",
942
+ expire_at: 0,
943
+ first_name: "",
944
+ last_name: "",
945
+ mobile: "",
946
+ note: "",
947
+ organisations: [],
948
+ password: "",
949
+ role: 0,
950
+ sms_login: !1,
951
+ protected_meta: {},
952
+ meta: {}
953
+ }, Ye = (t) => {
954
+ const [r, e] = f({
955
+ ...me,
956
+ ...t
957
+ }), { lynxClient: n } = E(), o = p(() => n.createUser(r), [n, r]);
958
+ return {
959
+ newUser: r,
960
+ setNewUser: e,
961
+ create: o
962
+ };
963
+ }, B = {
964
+ id: 0,
965
+ installation_id: 0,
966
+ name: "",
967
+ text: ""
968
+ }, Ze = (t, r) => {
969
+ const e = typeof t == "string" ? Number.parseInt(t) : t, n = typeof r == "string" ? Number.parseInt(r) : r;
970
+ if (isNaN(e))
971
+ throw new Error("invalid installationId");
972
+ if (isNaN(n))
973
+ throw new Error("invalid messageId");
974
+ const { lynxClient: o } = E(), [a, u] = f(!0), [s, i] = f({
975
+ ...B
976
+ }), [l, d] = f(), c = p(() => {
977
+ e === 0 || n === 0 || (u(!0), o.getNotificationMessage(e, n).then((m) => {
978
+ d((v) => v !== void 0 ? void 0 : v), i(m);
979
+ }).catch((m) => {
980
+ d(m);
981
+ }).finally(() => {
982
+ u(!1);
983
+ }));
984
+ }, [n, e, o]), h = p(() => {
985
+ l !== void 0 && d(void 0), o.updateNotificationMessage(s).then((m) => {
986
+ i(m);
987
+ }).catch((m) => {
988
+ d(m);
989
+ });
990
+ }, [l, o, s]), g = p(() => {
991
+ o.deleteNotificationMessage(s).then(() => {
992
+ i({ ...B });
993
+ }).catch((m) => {
994
+ d(m);
995
+ });
996
+ }, [o, s]);
997
+ return M(() => {
998
+ c();
999
+ }, []), {
1000
+ refresh: c,
1001
+ message: s,
1002
+ setMessage: i,
1003
+ error: l,
1004
+ loading: a,
1005
+ remove: g,
1006
+ update: h
1007
+ };
1008
+ }, et = (t) => {
1009
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
1010
+ if (isNaN(r))
1011
+ throw new Error("invalid installationId");
1012
+ const { lynxClient: e } = E(), [n, o] = f([]), [a, u] = f(!0), [s, i] = f(), l = p(() => {
1013
+ e.getNotificationMessages(r).then((d) => {
1014
+ i((c) => c !== void 0 ? void 0 : c), o(d);
1015
+ }).catch((d) => {
1016
+ i(d);
1017
+ }).finally(() => {
1018
+ u(!1);
1019
+ });
1020
+ }, [r, e]);
1021
+ return M(() => {
1022
+ l();
1023
+ }, []), {
1024
+ refresh: l,
1025
+ notificationMessages: n,
1026
+ error: s,
1027
+ loading: a
1028
+ };
1029
+ }, k = {
1030
+ id: 0,
1031
+ installation_id: 0,
1032
+ name: "",
1033
+ notification_message_id: 0,
1034
+ notification_output_executor_id: 0,
1035
+ config: {}
1036
+ }, tt = (t, r) => {
1037
+ const e = typeof t == "string" ? Number.parseInt(t) : t, n = typeof r == "string" ? Number.parseInt(r) : r;
1038
+ if (isNaN(e))
1039
+ throw new Error("invalid installationId");
1040
+ if (isNaN(n))
1041
+ throw new Error("invalid notificationId");
1042
+ const { lynxClient: o } = E(), [a, u] = f(!0), [s, i] = f({
1043
+ ...k,
1044
+ config: { ...k.config }
1045
+ }), [l, d] = f(), c = p(() => {
1046
+ e === 0 || n === 0 || (u(!0), o.getNotificationOutput(e, n).then((m) => {
1047
+ d((v) => v !== void 0 ? void 0 : v), i(m);
1048
+ }).catch((m) => {
1049
+ d(m);
1050
+ }).finally(() => {
1051
+ u(!1);
1052
+ }));
1053
+ }, [n, e, o]), h = p(() => {
1054
+ l !== void 0 && d(void 0), o.updateNotificationOutput(s).then((m) => {
1055
+ i(m);
1056
+ }).catch((m) => {
1057
+ d(m);
1058
+ });
1059
+ }, [l, o, s]), g = p(() => {
1060
+ o.deleteNotificationOutput(s).then(() => {
1061
+ i({ ...k });
1062
+ }).catch((m) => {
1063
+ d(m);
1064
+ });
1065
+ }, [o, s]);
1066
+ return M(() => {
1067
+ c();
1068
+ }, []), {
1069
+ refresh: c,
1070
+ output: s,
1071
+ setOutput: i,
1072
+ error: l,
1073
+ loading: a,
1074
+ remove: g,
1075
+ update: h
1076
+ };
1077
+ }, we = {
1078
+ id: 0,
1079
+ type: "",
1080
+ name: "",
1081
+ organization_id: 0,
1082
+ config: {},
1083
+ secret: ""
1084
+ }, nt = (t, r) => {
1085
+ const e = typeof t == "string" ? Number.parseInt(t) : t, n = typeof r == "string" ? Number.parseInt(r) : r;
1086
+ if (isNaN(e))
1087
+ throw new Error("invalid installationId");
1088
+ if (isNaN(n))
1089
+ throw new Error("invalid messageId");
1090
+ const { lynxClient: o } = E(), [a, u] = f(!0), [s, i] = f({
1091
+ ...we
1092
+ }), [l, d] = f(), c = p(() => {
1093
+ e === 0 || n === 0 || (u(!0), o.getNotificationOutputExecutor(e, n).then((h) => {
1094
+ d((g) => g !== void 0 ? void 0 : g), i(h);
1095
+ }).catch((h) => {
1096
+ d(h);
1097
+ }).finally(() => {
1098
+ u(!1);
1099
+ }));
1100
+ }, [n, e, o]);
1101
+ return M(() => {
1102
+ c();
1103
+ }, []), {
1104
+ refresh: c,
1105
+ outputExecutor: s,
1106
+ setOutputExecutor: i,
1107
+ error: l,
1108
+ loading: a
1109
+ };
1110
+ }, ot = (t) => {
1111
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
1112
+ if (isNaN(r))
1113
+ throw new Error("invalid installationId");
1114
+ const { lynxClient: e } = E(), [n, o] = f([]), [a, u] = f(!0), [s, i] = f(), l = p(() => {
1115
+ e.getNotificationOutputExecutors(r).then((d) => {
1116
+ i((c) => c !== void 0 ? void 0 : c), o(d);
1117
+ }).catch((d) => {
1118
+ i(d);
1119
+ }).finally(() => {
1120
+ u(!1);
1121
+ });
1122
+ }, [r, e]);
1123
+ return M(() => {
1124
+ l();
1125
+ }, []), {
1126
+ refresh: l,
1127
+ notificationExecutors: n,
1128
+ error: s,
1129
+ loading: a
1130
+ };
1131
+ }, rt = (t) => {
1132
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
1133
+ if (isNaN(r))
1134
+ throw new Error("invalid installationId");
1135
+ const { lynxClient: e } = E(), [n, o] = f([]), [a, u] = f(!0), [s, i] = f(), l = p(() => {
1136
+ e.getNotificationOutputs(r).then((d) => {
1137
+ i((c) => c !== void 0 ? void 0 : c), o(d);
1138
+ }).catch((d) => {
1139
+ i(d);
1140
+ }).finally(() => {
1141
+ u(!1);
1142
+ });
1143
+ }, [r, e]);
1144
+ return M(() => {
1145
+ l();
1146
+ }, []), {
1147
+ refresh: l,
1148
+ notificationOutputs: n,
1149
+ error: s,
1150
+ loading: a
1151
+ };
1152
+ }, Ne = (t) => {
1153
+ const { lynxClient: r } = E(), [e, n] = f(!0), [o, a] = f(), [u, s] = f({ ...G.getOAuth2Client() }), i = p(() => {
1154
+ e || n(!0), r.getOAuth2Client(t).then((c) => {
1155
+ a((h) => h !== void 0 ? void 0 : h), s(c);
1156
+ }).catch((c) => {
1157
+ a(c);
1158
+ }).finally(() => {
1159
+ n(!1);
1160
+ });
1161
+ }, [e, r, t]);
1162
+ M(() => {
1163
+ i();
1164
+ }, [t]);
1165
+ const l = p(() => r.deleteOAuth2Client(u), [u, r]), d = p(() => r.updateOAuth2Client(u), [u, r]);
1166
+ return {
1167
+ refresh: i,
1168
+ client: u,
1169
+ setClient: s,
1170
+ error: o,
1171
+ loading: e,
1172
+ remove: l,
1173
+ update: d
1174
+ };
1175
+ }, st = () => {
1176
+ const { lynxClient: t } = E(), [r, e] = f(!0), [n, o] = f(), [a, u] = f([]), s = p(() => {
1177
+ t.getOAuth2Clients().then((i) => {
1178
+ o((l) => l !== void 0 ? void 0 : l), u(i);
1179
+ }).catch((i) => {
1180
+ o(i);
1181
+ }).finally(() => {
1182
+ e(!1);
1183
+ });
1184
+ }, [t]);
1185
+ return M(() => {
1186
+ s();
1187
+ }, []), {
1188
+ refresh: s,
1189
+ clients: a,
1190
+ error: n,
1191
+ loading: r
1192
+ };
1193
+ }, it = () => {
1194
+ const { lynxClient: t } = E(), [r, e] = f([]), [n] = f(new URLSearchParams(window.location.search)), o = n.get("client_id") ?? "", { client: a } = Ne(o), u = p((s) => {
1195
+ const i = Object.fromEntries(n);
1196
+ return i.scope = s.join(" "), t.consentOAuth2Authorization(i);
1197
+ }, [t, n]);
1198
+ return M(() => {
1199
+ e(n.get("scope")?.split(" ") ?? []);
1200
+ }, [n]), {
1201
+ consent: u,
1202
+ client: a,
1203
+ requestedScopes: r
1204
+ };
1205
+ }, Ee = {
1206
+ address: {
1207
+ address: "",
1208
+ city: "",
1209
+ country: "",
1210
+ zip: ""
1211
+ },
1212
+ children: [],
1213
+ email: "",
1214
+ force_sms_login: !1,
1215
+ meta: {},
1216
+ name: "",
1217
+ notes: "",
1218
+ parent: 0,
1219
+ password_valid_days: 0,
1220
+ phone: "",
1221
+ protected_meta: {},
1222
+ id: 0
1223
+ }, ct = (t) => {
1224
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
1225
+ if (isNaN(r))
1226
+ throw new Error("invalid organizationId");
1227
+ const [e, n] = f({ ...Ee }), [o, a] = f(!0), [u, s] = f(), { lynxClient: i } = E(), l = p(() => {
1228
+ a(!0), i.getOrganization(r).then((h) => {
1229
+ s((g) => g !== void 0 ? void 0 : g), n(h);
1230
+ }).catch((h) => {
1231
+ s(h);
1232
+ }).finally(() => {
1233
+ a(!1);
1234
+ });
1235
+ }, [i, r]);
1236
+ M(() => {
1237
+ l();
1238
+ }, []);
1239
+ const d = p(() => i.updateOrganization(e), [i, e]), c = p(() => i.deleteOrganization(e), [i, e]);
1240
+ return {
1241
+ loading: o,
1242
+ organization: e,
1243
+ setOrganization: n,
1244
+ error: u,
1245
+ update: d,
1246
+ remove: c,
1247
+ refresh: l
1248
+ };
1249
+ }, at = (t) => {
1250
+ const { lynxClient: r } = E(), [e, n] = f(!0), [o, a] = f(), [u, s] = f([]), i = p(() => {
1251
+ n(!0), r.getOrganizations(t === !0).then((c) => {
1252
+ a((h) => h !== void 0 ? void 0 : h), s(c);
1253
+ }).catch((c) => {
1254
+ a(c);
1255
+ }).finally(() => {
1256
+ n(!1);
1257
+ });
1258
+ }, [r, t]);
1259
+ M(() => {
1260
+ i();
1261
+ }, []);
1262
+ const l = p((c) => r.createOrganization(c), [r]), d = p((c) => r.deleteOrganization(c), [r]);
1263
+ return {
1264
+ loading: e,
1265
+ organizations: u,
1266
+ setOrganizations: s,
1267
+ error: o,
1268
+ create: l,
1269
+ remove: d
1270
+ };
1271
+ }, ut = () => {
1272
+ const { lynxClient: t } = E(), [r, e] = f([]), [n, o] = f(), [a, u] = f(!0), s = p(() => {
1273
+ u(!0), t.getRoles().then((i) => {
1274
+ o((l) => l !== void 0 ? void 0 : l), e(i);
1275
+ }).catch((i) => {
1276
+ o(i);
1277
+ }).finally(() => {
1278
+ u(!1);
1279
+ });
1280
+ }, [t]);
1281
+ return M(() => {
1282
+ s();
1283
+ }, []), {
1284
+ loading: a,
1285
+ error: n,
1286
+ roles: r,
1287
+ refresh: s
1288
+ };
1289
+ }, lt = () => {
1290
+ const { lynxClient: t } = E(), [r, e] = f(!0), [n, o] = f(), [a, u] = f([]), s = p(() => {
1291
+ e(!0), t.getTokens().then((d) => {
1292
+ o((c) => c !== void 0 ? void 0 : c), u(d);
1293
+ }).catch((d) => {
1294
+ o(d);
1295
+ }).finally(() => {
1296
+ e(!1);
1297
+ });
1298
+ }, [t]), i = p((d) => t.deleteToken(d), [t]), l = p((d) => t.createToken(d), [t]);
1299
+ return O(() => {
1300
+ s();
1301
+ }, [s]), {
1302
+ tokens: a,
1303
+ remove: i,
1304
+ create: l,
1305
+ refresh: s,
1306
+ loading: r,
1307
+ error: n
1308
+ };
1309
+ }, Ce = {
1310
+ id: 0,
1311
+ address: {
1312
+ address: "",
1313
+ zip: "",
1314
+ city: "",
1315
+ country: ""
1316
+ },
1317
+ assigned_installations: [],
1318
+ email: "",
1319
+ expire_at: 0,
1320
+ first_name: "",
1321
+ last_name: "",
1322
+ mobile: "",
1323
+ note: "",
1324
+ organisations: [],
1325
+ password: "",
1326
+ role: 0,
1327
+ sms_login: !1,
1328
+ protected_meta: {},
1329
+ meta: {}
1330
+ }, dt = (t) => {
1331
+ const r = typeof t == "string" ? Number.parseInt(t) : t;
1332
+ if (isNaN(r))
1333
+ throw new Error("invalid userId");
1334
+ const [e, n] = f({ ...Ce }), [o, a] = f(!0), { lynxClient: u } = E(), [s, i] = f(), l = p(() => {
1335
+ a(!0), u.getUser(r).then((h) => {
1336
+ i((g) => g !== void 0 ? void 0 : g), n(h);
1337
+ }).catch((h) => {
1338
+ i(h);
1339
+ }).finally(() => {
1340
+ a(!1);
1341
+ });
1342
+ }, [u, r]), d = p(() => u.updateUser(e), [u, e]), c = p(() => u.deleteUser(e), [u, e]);
1343
+ return {
1344
+ loading: o,
1345
+ error: s,
1346
+ user: e,
1347
+ setUser: n,
1348
+ update: d,
1349
+ refresh: l,
1350
+ remove: c
1351
+ };
1352
+ }, ft = (t) => {
1353
+ const [r, e] = f([]), [n, o] = f(!0), [a, u] = f(), { lynxClient: s } = E();
1354
+ new URLSearchParams();
1355
+ const i = p(() => {
1356
+ o(!0), s.getUsers(t).then((l) => {
1357
+ u((d) => d !== void 0 ? void 0 : d), e(l);
1358
+ }).catch((l) => {
1359
+ u(l);
1360
+ }).finally(() => {
1361
+ o(!1);
1362
+ });
1363
+ }, [s, t]);
1364
+ return {
1365
+ users: r,
1366
+ setUsers: e,
1367
+ refresh: i,
1368
+ loading: n,
1369
+ error: a
1370
+ };
1371
+ };
1372
+ export {
1373
+ Oe as LynxProvider,
1374
+ De as useConfiguredEdgeApps,
1375
+ Pe as useDevice,
1376
+ Fe as useDeviceMeta,
1377
+ Y as useDevices,
1378
+ Ie as useEdgeApp,
1379
+ Ue as useEdgeAppVersions,
1380
+ ze as useEdgeApps,
1381
+ Se as useFunction,
1382
+ ke as useFunctionMeta,
1383
+ Z as useFunctions,
1384
+ E as useGlobalLynxClient,
1385
+ X as useGlobalPermissions,
1386
+ W as useGlobalUser,
1387
+ Re as useIDTokenAlgorithms,
1388
+ ue as useInstallation,
1389
+ Te as useInstallationInfo,
1390
+ qe as useInstallations,
1391
+ $e as useLiveInstallation,
1392
+ Ve as useLiveInstallationId,
1393
+ T as useMQTT,
1394
+ Be as useMeta,
1395
+ Ke as useMultiLiveInstallation,
1396
+ Qe as useNewDevice,
1397
+ je as useNewFunction,
1398
+ Ge as useNewInstallation,
1399
+ He as useNewNotificationMessage,
1400
+ Je as useNewNotificationOutput,
1401
+ We as useNewOAuth2Client,
1402
+ Xe as useNewOrganization,
1403
+ Ye as useNewUser,
1404
+ Ze as useNotificationMessage,
1405
+ et as useNotificationMessages,
1406
+ tt as useNotificationOutput,
1407
+ nt as useNotificationOutputExecutor,
1408
+ ot as useNotificationOutputExecutors,
1409
+ rt as useNotificationOutputs,
1410
+ Ne as useOAuth2Client,
1411
+ st as useOAuth2Clients,
1412
+ it as useOAuth2Consent,
1413
+ ct as useOrganization,
1414
+ at as useOrganizations,
1415
+ le as usePahoMQTTClient,
1416
+ Le as usePermissionsCheckAll,
1417
+ Ae as usePermissionsCheckAny,
1418
+ ut as useRoles,
1419
+ he as useSimpleMQTT,
1420
+ lt as useTokens,
1421
+ dt as useUser,
1422
+ ft as useUsers
1423
+ };
17
1424
  //# sourceMappingURL=index.js.map