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

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