@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/cjs/index.js CHANGED
@@ -1,17 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("react/jsx-runtime"),n=require("@iotopen/node-lynx");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=s(require("paho-mqtt"));const r={lynxClient:new n.LynxClient(""),newLynxClient:(e,t)=>{}},i=e.createContext(r),o=({children:s,url:a,apiKey:r})=>{const[o,c]=e.useState(new n.LynxClient(a,r)),l=e.useCallback(((e,t)=>c(new n.LynxClient(e,t))),[c]),u=e.useMemo((()=>({lynxClient:o,newLynxClient:l})),[o,l]);return t.jsx(i.Provider,Object.assign({value:u},{children:s}))},c=()=>e.useContext(i),l=e.createContext({user:null,permissions:null}),u=({children:n})=>{const[s,a]=e.useState(null),[r,i]=e.useState(null),[o,u]=e.useState(!0),[d,p]=e.useState(),{lynxClient:f}=c();e.useLayoutEffect((()=>{const e=f.getMe(),t=f.getPermissions();u(!0),Promise.all([e,t]).then((([e,t])=>{a(e),i(t)})).catch((e=>{p(e),a(null),i(null)})).finally((()=>{u(!1)}))}),[f]);const g=e.useMemo((()=>({user:s,permissions:r,loading:o,error:d})),[s,r,o,d]);return t.jsx(l.Provider,Object.assign({value:g},{children:n}))},d=()=>e.useContext(l),p=(t,n,s,r)=>{var i;if(void 0===r){let e;e=(null===(i=null===window||void 0===window?void 0:window.crypto)||void 0===i?void 0:i.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),r=`paho-ws-mqtt-${e}`}const o=e.useRef(new a.default.Client(t,r)),c=e.useRef(s),l=e.useRef(n),u=e.useRef(void 0),[d,p]=e.useState(!1),[f,g]=e.useState(void 0);e.useLayoutEffect((()=>{const e=o,t=u,n=Object.assign(Object.assign({timeout:5},c.current),{onFailure:s=>{g(s),p(o.current.isConnected()),void 0===t.current&&(t.current=window.setInterval((()=>{e.current.isConnected()?clearInterval(t.current):e.current.connect(n)}),1e3))},onSuccess:()=>{g(void 0),p(o.current.isConnected()),void 0!==t.current&&(window.clearInterval(t.current),t.current=void 0)}}),s=l.current;e.current.onConnectionLost=e=>{var t;g(e),p(o.current.isConnected()),null===(t=null==s?void 0:s.onDisconnect)||void 0===t||t.call(s,e)},e.current.onConnected=(e,t)=>{var n;p(o.current.isConnected()),g(void 0),null===(n=null==s?void 0:s.onConnected)||void 0===n||n.call(s,e,t)},s&&(s.onMessage&&(e.current.onMessageArrived=s.onMessage),s.onDelivery&&(e.current.onMessageDelivered=s.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 b=e.useCallback(((e,t)=>new Promise((n=>{o.current.subscribe(e,{qos:t||0,timeout:1,onFailure:e=>{throw e},onSuccess:e=>{n(e.grantedQos)}})}))),[o]),h=e.useCallback(((e,t,n,s)=>{o.current.send(e,t,n,s)}),[o]),v=e.useCallback((e=>new Promise((t=>{o.current.unsubscribe(e,{timeout:1,onSuccess:()=>{t()},onFailure:e=>{throw e}})}))),[o]);return{client:o,connected:d,error:f,sub:b,pub:h,unsub:v}};
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 f(e,t,n,s){return new(n||(n=Promise))((function(a,r){function i(e){try{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,o)}c((s=s.apply(e,t||[])).next())}))}const g={id:0,installation_id:0,type:"",updated:0,created:0,meta:{},protected_meta:{}},b={client_id:0,notes:"",organization_id:0,id:0,name:"",created:0,meta:{},users:[],protected_meta:{}},h={updated:0,created:0,id:0,installation_id:0,type:"",meta:{},protected_meta:{}},v={id:0,created:0,updated:0,name:"",category:"",short_description:"",description:"",source_url:"",tags:[],publisher:{id:0},public:!1,official:!1},y=t=>{const{lynxClient:s}=c(),[a,r]=e.useState(!0),[i,o]=e.useState(),[l,u]=e.useState(Object.assign({},n.zero.getOAuth2Client())),d=e.useCallback((()=>{a||r(!0),s.getOAuth2Client(t).then((e=>{void 0!==i&&o(void 0),u(e)})).catch((e=>{o(e)})).finally((()=>{r(!1)}))}),[a,s,t,i]);e.useEffect((()=>{d()}),[t]);const p=e.useCallback((()=>s.deleteOAuth2Client(l)),[l,s]),f=e.useCallback((()=>s.updateOAuth2Client(l)),[l,s]);return{refresh:d,client:l,setClient:u,error:i,loading:a,remove:p,update:f}},m={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},C={address:{address:"",city:"",country:"",zip:""},children:[],email:"",force_sms_login:!1,meta:{},name:"",notes:"",parent:0,password_valid_days:0,phone:"",protected_meta:{}},w={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:{}},N={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:{}},x={installation_id:0,name:"",text:""},S={id:0,installation_id:0,name:"",text:""},O={installation_id:0,name:"",notification_message_id:0,notification_output_executor_id:0,config:{}},k={id:0,installation_id:0,name:"",notification_message_id:0,notification_output_executor_id:0,config:{}},E={id:0,type:"",name:"",organization_id:0,config:{},secret:""};exports.LynxProvider=({children:e,apiURL:n,apiKey:s})=>t.jsx(o,Object.assign({url:n,apiKey:s},{children:t.jsx(u,{children:e})})),exports.useConfiguredEdgeApps=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid installationId");const{lynxClient:s}=c(),[a,r]=e.useState(!0),[i,o]=e.useState(),[l,u]=e.useState([]),d=e.useCallback((()=>{r(!0),s.getConfiguredEdgeApps(n).then((e=>{void 0!==i&&o(void 0),u(e)})).catch((e=>{o(e)})).finally((()=>{r(!1)}))}),[n,s]);return e.useLayoutEffect((()=>{d()}),[d]),{refresh:d,loading:a,error:i,apps:l}},exports.useDevice=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,a="string"==typeof n?Number.parseInt(n):n;if(isNaN(s)||isNaN(a))throw new Error("invalid installationId or deviceId");const{lynxClient:r}=c(),[i,o]=e.useState(!0),[l,u]=e.useState(Object.assign({},h)),[d,p]=e.useState();e.useLayoutEffect((()=>{r.getDevice(s,a).then((e=>{void 0!==d&&p(void 0),u(e)})).catch((e=>{p(e)})).finally((()=>{o(!1)}))}),[r,s,a]);const f=e.useCallback((()=>new Promise((()=>{if(!l)throw new Error("update on undefined function");return r.updateDevice(l)}))),[r,l]),g=e.useCallback((e=>{l&&u(Object.assign(Object.assign({},l),{type:e}))}),[l,u]),b=e.useCallback((()=>new Promise((()=>{if(!l)throw new Error("delete on undefined function");return r.deleteDevice(l)}))),[l,r]);return{loading:i,error:d,Device:l,setDevice:u,update:f,remove:b,setType:g}},exports.useDeviceMeta=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,a="string"==typeof n?Number.parseInt(n):n,{lynxClient:r}=c();return{createMeta:e.useCallback(((e,t,n,a)=>{const i=n||(null!=n?n:0);return r.createDeviceMeta(s,i,e,t,a)}),[r,s,a]),updateMeta:e.useCallback(((e,t,n,a,i)=>{const o=a||(null!=a?a:0);return r.updateDeviceMeta(s,o,e,t,i,n)}),[r,s,a]),removeMeta:e.useCallback(((e,t,n)=>{const a=t||(null!=t?t:0);return r.deleteDeviceMeta(s,a,e,n)}),[r,s,a])}},exports.useDevices=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t;if(isNaN(s)&&void 0!==s)throw new Error("invalid installationId");const{lynxClient:a}=c(),[r,i]=e.useState(!0),[o,l]=e.useState([]),[u,d]=e.useState(),p=e.useCallback((()=>{if(void 0===s)return i(!1),void l([]);i(!0),a.getDevices(s,n).then((e=>{void 0!==u&&d(void 0),l(e)})).catch((e=>{d(e)})).finally((()=>{i(!1)}))}),[a,s,n]);const g=e.useCallback((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>a.createDevice(e,!0)));return Promise.allSettled(n).then((e=>f(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield a.createDevice(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return a.createDevice(e)}),[a]),b=e.useCallback((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>a.deleteDevice(e,!0)));return Promise.allSettled(n).then((e=>f(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield a.deleteDevice(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return a.deleteDevice(e)}),[a]);return e.useLayoutEffect((()=>{p()}),[p]),{loading:r,error:u,create:g,remove:b,devices:o,refresh:p}},exports.useEdgeApp=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid appId");const{lynxClient:s}=c(),[a,r]=e.useState(!1),[i,o]=e.useState(),[l,u]=e.useState(Object.assign({},v)),d=e.useCallback((()=>{r(!0),s.getEdgeApp(n).then((e=>{void 0!==i&&o(void 0),u(e)})).catch((e=>{o(e)})).finally((()=>{r(!1)}))}),[n,s]);return e.useLayoutEffect((()=>{d()}),[n]),{loading:a,error:i,app:l,setApp:u,refresh:d}},exports.useEdgeAppVersions=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t;if(isNaN(s))throw new Error("invalid appId");const{lynxClient:a}=c(),[r,i]=e.useState(!1),[o,l]=e.useState(),[u,d]=e.useState([]),p=e.useCallback((()=>{i(!0),a.getEdgeAppVersions(s,n).then((e=>{void 0!==o&&l(void 0),d(e)})).catch((e=>{l(e)})).finally((()=>{i(!1)}))}),[a,n]),f=e.useCallback(((e,t)=>a.nameEdgeAppVersion(s,e,t)),[a,s]);return e.useLayoutEffect((()=>{p()}),[s,n]),{loading:r,error:o,versions:u,nameVersion:f,refresh:p}},exports.useEdgeApps=()=>{const{lynxClient:t}=c(),[n,s]=e.useState(!0),[a,r]=e.useState(),[i,o]=e.useState([]),l=e.useCallback((()=>{s(!0),t.getEdgeApps().then((e=>{void 0!==a&&r(void 0),o(e)})).catch((e=>{r(e)})).finally((()=>{s(!1)}))}),[a,t]);return e.useLayoutEffect((()=>{l()}),[]),{apps:i,error:a,loading:n,refresh:l}},exports.useFunction=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,a="string"==typeof n?Number.parseInt(n):n;if(isNaN(s)||isNaN(a))throw new Error("invalid installationId or functionId");const{lynxClient:r}=c(),[i,o]=e.useState(!0),[l,u]=e.useState(Object.assign({},g)),[d,p]=e.useState();e.useLayoutEffect((()=>{r.getFunction(s,a).then((e=>{void 0!==d&&p(void 0),u(e)})).catch((e=>{p(e)})).finally((()=>{o(!1)}))}),[r,s,a]);const f=e.useCallback((()=>new Promise((()=>{if(!l)throw new Error("update on undefined function");return r.updateFunction(l)}))),[r,l]),b=e.useCallback((e=>{l&&u(Object.assign(Object.assign({},l),{type:e}))}),[l,u]),h=e.useCallback((()=>new Promise((()=>{if(!l)throw new Error("delete on undefined function");return r.deleteFunction(l)}))),[l,r]);return{loading:i,error:d,Function:l,setFunction:u,update:f,remove:h,setType:b}},exports.useFunctionMeta=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,a="string"==typeof n?Number.parseInt(n):n,{lynxClient:r}=c();return{createMeta:e.useCallback(((e,t,n,i)=>{const o=n||(null!=a?a:0);return r.createFunctionMeta(s,o,e,t,i)}),[r,s,a]),updateMeta:e.useCallback(((e,t,n,i,o)=>{const c=i||(null!=a?a:0);return r.updateFunctionMeta(s,c,e,t,o,n)}),[r,s,a]),removeMeta:e.useCallback(((e,t,n)=>{const i=t||(null!=a?a:0);return r.deleteFunctionMeta(s,i,e,n)}),[r,s,a])}},exports.useFunctions=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t;if(isNaN(s)&&void 0!==s)throw new Error("invalid installationId");const{lynxClient:a}=c(),[r,i]=e.useState(!0),[o,l]=e.useState([]),[u,d]=e.useState(),p=e.useCallback((()=>{if(void 0===s)return i(!1),void l([]);i(!0),a.getFunctions(s,n).then((e=>(void 0!==u&&d(void 0),l(e),e))).catch((e=>{d(e)})).finally((()=>{i(!1)}))}),[a,s,n]);const g=e.useCallback((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>a.createFunction(e,!0)));return Promise.allSettled(n).then((e=>f(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield a.createFunction(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return a.createFunction(e)}),[a]),b=e.useCallback((function(e){if(Array.isArray(e)){const t=e.pop();if(!t)return Promise.allSettled([]);const n=e.map((e=>a.deleteFunction(e,!0)));return Promise.allSettled(n).then((e=>f(this,void 0,void 0,(function*(){try{e.push({status:"fulfilled",value:yield a.deleteFunction(t)})}catch(t){e.push({status:"rejected",reason:t})}return e}))))}return a.deleteFunction(e)}),[a]);return e.useLayoutEffect((()=>{p()}),[p]),{loading:r,error:u,create:g,remove:b,functions:o,refresh:p}},exports.useGlobalLynxClient=c,exports.useGlobalPermissions=()=>{const{permissions:e}=d();return[e]},exports.useGlobalUser=d,exports.useIDTokenAlgorithms=()=>{const{lynxClient:t}=c(),[n,s]=e.useState(!0),[a,r]=e.useState(),[i,o]=e.useState([]),l=e.useCallback((()=>{s(!0),t.getIDTokenAlgorithms().then((e=>{void 0!==a&&r(void 0),o(e)})).catch((e=>{r(e)})).finally((()=>{s(!1)}))}),[a,t]);return e.useEffect((()=>{l()}),[]),{loading:n,refresh:l,algs:i,error:a}},exports.useInstallation=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid installationId");const{lynxClient:s}=c(),[a,r]=e.useState(!0),[i,o]=e.useState(void 0),[l,u]=e.useState(Object.assign({},b));e.useLayoutEffect((()=>{s.getInstallationRow(n).then((e=>{void 0!==i&&o(void 0),u(e)})).catch((e=>{o(e)})).finally((()=>{r(!1)}))}),[s,n]);const d=e.useCallback((()=>new Promise((()=>{if(!l)throw new Error("update on undefined installation");return s.updateInstallation(l)}))),[s,l]),p=e.useCallback((()=>new Promise((()=>{if(!l)throw new Error("update on undefined installation");return s.deleteInstallation(l)}))),[s,l]);return{installation:l,setInstallation:u,update:d,remove:p,error:i,loading:a}},exports.useInstallationInfo=t=>{const{lynxClient:n}=c(),[s,a]=e.useState([]),[r,i]=e.useState(!0),[o,l]=e.useState(void 0),u=e.useCallback((()=>{i(!0),n.getInstallations(t).then((e=>{void 0!==o&&l(void 0),a(e)})).catch((e=>{l(e)})).finally((()=>{i(!1)}))}),[n]);return e.useLayoutEffect((()=>{u()}),[u]),{installations:s,refresh:u,loading:r,error:o}},exports.useInstallations=t=>{const{lynxClient:n}=c(),[s,a]=e.useState(!0),[r,i]=e.useState([]),[o,l]=e.useState(),u=e.useCallback((()=>{a(!0),n.listInstallations(t).then((e=>{void 0!==o&&l(void 0),i(e)})).catch((e=>{l(e)})).finally((()=>{a(!1)}))}),[n,t]);return{loading:s,error:o,installations:r,refresh:u}},exports.useMeta=(t,n)=>{const[s,a]=e.useState([]),r=n||(t?[t]:[]);e.useLayoutEffect((()=>{if(t){const e=[];for(const n in t.meta){const s=t.meta[n];e.push({key:n,value:s,protected:!1})}for(const n in t.protected_meta){const s=t.protected_meta[n];e.push({key:n,value:s,protected:!0})}e.sort(((e,t)=>e.key.localeCompare(t.key))),a(e)}}),r);const i=e.useCallback((()=>{const e={meta:{},protected_meta:{}};return s.forEach((t=>{t.protected?e.protected_meta[t.key]=t.value:e.meta[t.key]=t.value})),e}),[s]),o=e.useCallback((e=>{a([...s,e||{key:"",value:"",protected:!1}])}),[s,a]),c=e.useCallback((e=>{a(s.filter(((t,n)=>n!==e)))}),[s,a]),l=e.useCallback(((e,t)=>{a(s.map(((n,s)=>s===e?t:n)))}),[s,a]),u=e.useCallback(((e,t)=>{a(s.map(((n,s)=>s==e?Object.assign(Object.assign({},n),{key:t}):n)))}),[s,a]),d=e.useCallback(((e,t)=>{a(s.map(((n,s)=>s==e?Object.assign(Object.assign({},n),{value:t}):n)))}),[s,a]),p=e.useCallback(((e,t)=>{a(s.map(((n,s)=>s==e?Object.assign(Object.assign({},n),{protected:t}):n)))}),[s,a]);return{metaList:s,compile:i,addMeta:o,removeMeta:c,setMeta:l,setMetaKey:u,setMetaValue:d,setMetaProtected:p}},exports.useNewDevice=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t;if(isNaN(s))throw new Error("invalid installationId");const{lynxClient:a}=c(),[r,i]=e.useState(Object.assign(Object.assign({meta:{},protected_meta:{},type:""},n),{installation_id:s})),o=e.useCallback((e=>{i(Object.assign(Object.assign({},r),{type:e}))}),[r,i]),l=e.useCallback((()=>a.createDevice(r)),[a,r]);return{newDevice:r,setNewDevice:i,create:l,setType:o}},exports.useNewFunction=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t;if(isNaN(s))throw new Error("invalid installationId");const{lynxClient:a}=c(),[r,i]=e.useState(Object.assign(Object.assign({meta:{},protected_meta:{},type:""},n),{installation_id:s})),o=e.useCallback((e=>{i(Object.assign(Object.assign({},r),{type:e}))}),[r,i]),l=e.useCallback((()=>a.createFunction(r)),[a,r]);return{newFunction:r,setNewFunction:i,create:l,setType:o}},exports.useNewInstallation=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t;if(isNaN(s))throw new Error("invalid organizationId");const[a,r]=e.useState(Object.assign(Object.assign({name:"",notes:"",users:[],meta:{},protected_meta:{}},n),{organization_id:s})),{lynxClient:i}=c(),o=e.useCallback((()=>i.createInstallation(a)),[i,a]);return{newInstallation:a,setNewInstallation:r,create:o}},exports.useNewNotificationMessage=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,{lynxClient:a}=c(),[r,i]=e.useState(Object.assign(Object.assign(Object.assign({},x),n),{installation_id:s})),o=e.useCallback((()=>a.createNotificationMessage(r)),[a,r]);return{newNotificationMessage:r,setNewNotificationMessage:i,create:o}},exports.useNewNotificationOutput=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,{lynxClient:a}=c(),[r,i]=e.useState(Object.assign(Object.assign(Object.assign({},O),n),{installation_id:s})),o=e.useCallback((()=>a.createNotificationOutput(r)),[a,r]);return{newNotificationOutput:r,setNewNotificationOutput:i,create:o}},exports.useNewOAuth2Client=t=>{const{lynxClient:s}=c(),[a,r]=e.useState(Object.assign(Object.assign({},n.zero.getEmptyOAuth2Client()),t)),i=e.useCallback((e=>{r(Object.assign(Object.assign({},a),{name:e}))}),[a]),o=e.useCallback((e=>{r(Object.assign(Object.assign({},a),{allowed_scopes:e}))}),[a]),l=e.useCallback((e=>{r(Object.assign(Object.assign({},a),{icon_uri:e}))}),[a]),u=e.useCallback((e=>{r(Object.assign(Object.assign({},a),{tos_uri:e}))}),[a]),d=e.useCallback((e=>{r(Object.assign(Object.assign({},a),{policy_uri:e}))}),[a]),p=e.useCallback((e=>{r(Object.assign(Object.assign({},a),{redirect_uris:e}))}),[a]),f=e.useCallback((()=>s.createOAuth2Client(a)),[s,a]);return{newClient:a,create:f,setName:i,setScope:o,setIconURI:l,setTosURI:u,setPolicyURI:d,setRedirectURIs:p,setClient:r}},exports.useNewOrganization=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t;if(isNaN(s))throw new Error("invalid parentId");const{lynxClient:a}=c(),[r,i]=e.useState(Object.assign(Object.assign(Object.assign({},C),n),{parent:s})),o=e.useCallback((()=>a.createOrganization(r)),[a,r]);return{newOrganization:r,setNewOrganization:i,create:o}},exports.useNewUser=t=>{const[n,s]=e.useState(Object.assign(Object.assign({},w),t)),{lynxClient:a}=c(),r=e.useCallback((()=>a.createUser(n)),[a,n]);return{newUser:n,setNewUser:s,create:r}},exports.useNotificationMessage=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,a="string"==typeof n?Number.parseInt(n):n;if(isNaN(s))throw new Error("invalid installationId");if(isNaN(a))throw new Error("invalid messageId");const{lynxClient:r}=c(),[i,o]=e.useState(!0),[l,u]=e.useState(Object.assign({},S)),[d,p]=e.useState(),f=e.useCallback((()=>{0!==s&&0!==a&&(o(!0),r.getNotificationMessage(s,a).then((e=>{void 0!==d&&p(void 0),u(e)})).catch((e=>{p(e)})).finally((()=>{o(!1)})))}),[d,a,s,r]),g=e.useCallback((()=>{void 0!==d&&p(void 0),r.updateNotificationMessage(l).then((e=>{u(e)})).catch((e=>{p(e)}))}),[d,r,l]),b=e.useCallback((()=>{r.deleteNotificationMessage(l).then((()=>{u(Object.assign({},S))})).catch((e=>{p(e)}))}),[r,l]);return e.useEffect((()=>{f()}),[]),{refresh:f,message:l,setMessage:u,error:d,loading:i,remove:b,update:g}},exports.useNotificationMessages=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid installationId");const{lynxClient:s}=c(),[a,r]=e.useState([]),[i,o]=e.useState(!0),[l,u]=e.useState(),d=e.useCallback((()=>{s.getNotificationMessages(n).then((e=>{void 0!==l&&u(void 0),r(e)})).catch((e=>{u(e)})).finally((()=>{o(!1)}))}),[l,n,s]);return e.useEffect((()=>{d()}),[]),{refresh:d,notificationMessages:a,error:l,loading:i}},exports.useNotificationOutput=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,a="string"==typeof n?Number.parseInt(n):n;if(isNaN(s))throw new Error("invalid installationId");if(isNaN(a))throw new Error("invalid notificationId");const{lynxClient:r}=c(),[i,o]=e.useState(!0),[l,u]=e.useState(Object.assign(Object.assign({},k),{config:Object.assign({},k.config)})),[d,p]=e.useState(),f=e.useCallback((()=>{0!==s&&0!==a&&(o(!0),r.getNotificationOutput(s,a).then((e=>{void 0!==d&&p(void 0),u(e)})).catch((e=>{p(e)})).finally((()=>{o(!1)})))}),[d,a,s,r]),g=e.useCallback((()=>{void 0!==d&&p(void 0),r.updateNotificationOutput(l).then((e=>{u(e)})).catch((e=>{p(e)}))}),[d,r,l]),b=e.useCallback((()=>{r.deleteNotificationOutput(l).then((()=>{u(Object.assign({},k))})).catch((e=>{p(e)}))}),[r,l]);return e.useEffect((()=>{f()}),[]),{refresh:f,output:l,setOutput:u,error:d,loading:i,remove:b,update:g}},exports.useNotificationOutputExecutor=(t,n)=>{const s="string"==typeof t?Number.parseInt(t):t,a="string"==typeof n?Number.parseInt(n):n;if(isNaN(s))throw new Error("invalid installationId");if(isNaN(a))throw new Error("invalid messageId");const{lynxClient:r}=c(),[i,o]=e.useState(!0),[l,u]=e.useState(Object.assign({},E)),[d,p]=e.useState(),f=e.useCallback((()=>{0!==s&&0!==a&&(o(!0),r.getNotificationOutputExecutor(s,a).then((e=>{void 0!==d&&p(void 0),u(e)})).catch((e=>{p(e)})).finally((()=>{o(!1)})))}),[d,a,s,r]);return e.useEffect((()=>{f()}),[]),{refresh:f,outputExecutor:l,setOutputExecutor:u,error:d,loading:i}},exports.useNotificationOutputExecutors=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid installationId");const{lynxClient:s}=c(),[a,r]=e.useState([]),[i,o]=e.useState(!0),[l,u]=e.useState(),d=e.useCallback((()=>{s.getNotificationOutputExecutors(n).then((e=>{void 0!==l&&u(void 0),r(e)})).catch((e=>{u(e)})).finally((()=>{o(!1)}))}),[l,n,s]);return e.useEffect((()=>{d()}),[]),{refresh:d,notificationExecutors:a,error:l,loading:i}},exports.useNotificationOutputs=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid installationId");const{lynxClient:s}=c(),[a,r]=e.useState([]),[i,o]=e.useState(!0),[l,u]=e.useState(),d=e.useCallback((()=>{s.getNotificationOutputs(n).then((e=>{void 0!==l&&u(void 0),r(e)})).catch((e=>{u(e)})).finally((()=>{o(!1)}))}),[l,n,s]);return e.useEffect((()=>{d()}),[]),{refresh:d,notificationOutputs:a,error:l,loading:i}},exports.useOAuth2Client=y,exports.useOAuth2Clients=()=>{const{lynxClient:t}=c(),[n,s]=e.useState(!0),[a,r]=e.useState(),[i,o]=e.useState([]),l=e.useCallback((()=>{t.getOAuth2Clients().then((e=>{void 0!==a&&r(void 0),o(e)})).catch((e=>{r(e)})).finally((()=>{s(!1)}))}),[t,a]);return e.useEffect((()=>{l()}),[]),{refresh:l,clients:i,error:a,loading:n}},exports.useOAuth2Consent=()=>{var t;const{lynxClient:n}=c(),[s,a]=e.useState([]),[r]=e.useState(new URLSearchParams(window.location.search)),{client:i}=y(null!==(t=r.get("client_id"))&&void 0!==t?t:""),o=e.useCallback((e=>{const t=Object.fromEntries(r);return t.scope=e.join(" "),n.consentOAuth2Authorization(t)}),[n,r]);return e.useEffect((()=>{var e,t;a(null!==(t=null===(e=r.get("scope"))||void 0===e?void 0:e.split(" "))&&void 0!==t?t:[])}),[r]),{consent:o,client:i,requestedScopes:s}},exports.useOrganization=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid organizationId");const[s,a]=e.useState(Object.assign({},m)),[r,i]=e.useState(!0),[o,l]=e.useState(),{lynxClient:u}=c(),d=e.useCallback((()=>{i(!0),u.getOrganization(n).then((e=>{void 0!==o&&l(void 0),a(e)})).catch((e=>{l(e)})).finally((()=>{i(!1)}))}),[o,u,n]);e.useEffect((()=>{d()}),[]);const p=e.useCallback((()=>u.updateOrganization(s)),[u,s]),f=e.useCallback((()=>u.deleteOrganization(s)),[u,s]);return{loading:r,organization:s,setOrganization:a,error:o,update:p,remove:f,refresh:d}},exports.useOrganizations=t=>{const{lynxClient:n}=c(),[s,a]=e.useState(!0),[r,i]=e.useState(),[o,l]=e.useState([]),u=e.useCallback((()=>{a(!0),n.getOrganizations(!0===t).then((e=>{void 0!==r&&i(void 0),l(e)})).catch((e=>{i(e)})).finally((()=>{a(!1)}))}),[n,t]);e.useEffect((()=>{u()}),[]);const d=e.useCallback((e=>n.createOrganization(e)),[n]),p=e.useCallback((e=>n.deleteOrganization(e)),[n]);return{loading:s,organizations:o,setOrganizations:l,error:r,create:d,remove:p}},exports.usePahoMQTTClient=p,exports.useRoles=()=>{const{lynxClient:t}=c(),[n,s]=e.useState([]),[a,r]=e.useState(),[i,o]=e.useState(!0),l=e.useCallback((()=>{o(!0),t.getRoles().then((e=>{s(e)})).catch((e=>{r(e)})).finally((()=>{o(!1)}))}),[t]);return e.useEffect((()=>{l()}),[]),{loading:i,error:a,roles:n,refresh:l}},exports.useSimpleMQTT=(t,n,s)=>{void 0===t&&(t="http:"===location.protocol?`ws://${location.host}/mqtt`:`wss://${location.host}/mqtt`);const a=e.useRef([]),r=e.useRef(new Map([])),i=e.useRef(new Map([])),o=e.useCallback((e=>{const t=i.current.get(e.destinationName);t&&t.forEach((t=>{t(e.destinationName,e.payloadString,e.qos,e.retained)})),r.current.forEach(((t,n)=>{new RegExp(n).test(e.destinationName)&&t.forEach((t=>{t(e.destinationName,e.payloadString,e.qos,e.retained)}))}))}),[]),c={cleanSession:!0,reconnect:!0,keepAliveInterval:5};n&&(c.userName=n),s&&(c.password=s);const{error:l,connected:u,sub:d,unsub:g,pub:b}=p(t,{onMessage:o,onConnected:()=>{a.current.forEach((e=>{d(e).then().catch()}))}},c),h=e.useCallback(((e,t)=>{let n;n="string"==typeof e?new RegExp(`^${e}$`):e;const s=n.toString().slice(1,-1);let a=r.current.get(s);if(void 0===a)return a=[t],void r.current.set(s,a);a.includes(t)||a.push(t)}),[]),v=e.useCallback((e=>{r.current.forEach(((t,n)=>{const s=t.filter((t=>t!==e));r.current.set(n,s)}))}),[]),y=e.useCallback(((e,t)=>{let n=i.current.get(e);void 0===n&&(n=[t]),n.includes(t)||n.push(t)}),[]),m=e.useCallback(((e,t)=>{const n=i.current.get(e);void 0!==n&&i.current.set(e,n.filter((e=>e!==t)))}),[]),C=e.useCallback((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})(a.current,e)||(u&&function(e,t){return new Promise((n=>{t.forEach((t=>f(this,void 0,void 0,(function*(){try{yield e(t)}catch(e){console.log(e)}})))),n()}))}(g,a.current).then((()=>{(function(e,t){return new Promise((n=>{t.forEach((t=>f(this,void 0,void 0,(function*(){try{yield e(t)}catch(e){console.log(e)}})))),n()}))})(d,e).then().catch()})).catch(),a.current=e)}),[d,g]);return{setSubs:C,error:l,connected:u,bind:h,unbind:v,bindExact:y,unbindExact:m,pub:b}},exports.useTokens=()=>{const{lynxClient:t}=c(),[n,s]=e.useState(!0),[a,r]=e.useState(),[i,o]=e.useState([]),l=e.useCallback((()=>{s(!0),t.getTokens().then((e=>{void 0!==a&&r(void 0),o(e)})).catch((e=>{r(e)})).finally((()=>{s(!1)}))}),[t]),u=e.useCallback((e=>t.deleteToken(e)),[t]),d=e.useCallback((e=>t.createToken(e)),[t]);return e.useLayoutEffect((()=>{l()}),[l]),{tokens:i,remove:u,create:d,refresh:l,loading:n,error:a}},exports.useUser=t=>{const n="string"==typeof t?Number.parseInt(t):t;if(isNaN(n))throw new Error("invalid userId");const[s,a]=e.useState(Object.assign({},N)),[r,i]=e.useState(!0),{lynxClient:o}=c(),[l,u]=e.useState(),d=e.useCallback((()=>{i(!0),o.getUser(n).then((e=>{void 0!==l&&u(void 0),a(e)})).catch((e=>{u(e)})).finally((()=>{i(!1)}))}),[o,n]),p=e.useCallback((()=>o.updateUser(s)),[o,s]),f=e.useCallback((()=>o.deleteUser(s)),[o,s]);return{loading:r,error:l,user:s,setUser:a,update:p,refresh:d,remove:f}},exports.useUsers=t=>{const[n,s]=e.useState([]),[a,r]=e.useState(!0),[i,o]=e.useState(),{lynxClient:l}=c();new URLSearchParams;const u=e.useCallback((()=>{r(!0),l.getUsers(t).then((e=>{void 0!==i&&o(void 0),s(e)})).catch((e=>{o(e)})).finally((()=>{r(!1)}))}),[l,t,i]);return{users:n,setUsers:s,refresh:u,loading:a,error:i}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),e=require("react"),I=require("@iotopen/node-lynx"),W=require("paho-mqtt"),X={lynxClient:new I.LynxClient(""),newLynxClient:(n,r,t)=>{}},Q=e.createContext(X),Y=({children:n,url:r,apiKey:t,bearer:s})=>{const[o,u]=e.useState(new I.LynxClient(r,t,s)),l=e.useCallback((i,d,f)=>{u(new I.LynxClient(i,d,f))},[u]),a=e.useMemo(()=>({lynxClient:o,newLynxClient:l}),[o,l]);return P.jsx(Q.Provider,{value:a,children:n})},w=()=>e.useContext(Q),Z={user:null,permissions:null},G=e.createContext(Z),ee=({children:n})=>{const[r,t]=e.useState(null),[s,o]=e.useState(null),[u,l]=e.useState(!0),[a,i]=e.useState(),{lynxClient:d}=w();e.useLayoutEffect(()=>{const c=d.getMe(),p=d.getPermissions();l(!0),Promise.all([c,p]).then(([g,v])=>{i(h=>h!==void 0?void 0:h),t(g),o(v)}).catch(g=>{i(g),t(null),o(null)}).finally(()=>{l(!1)})},[d]);const f=e.useMemo(()=>({user:r,permissions:s,loading:u,error:a}),[r,s,u,a]);return P.jsx(G.Provider,{value:f,children:n})},z=()=>e.useContext(G),U=()=>{const{permissions:n}=z();return n},te=({children:n,apiURL:r,apiKey:t,bearer:s})=>P.jsx(Y,{url:r,apiKey:t,bearer:s,children:P.jsx(ee,{children:n})}),ne=(...n)=>{const r=U();return r==null?!1:n.every(t=>r[t]!==void 0&&r[t])},se=(...n)=>{const r=U();return r==null?!1:n.some(t=>r[t]!==void 0&&r[t])},oe=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:t}=w(),[s,o]=e.useState(!0),[u,l]=e.useState(),[a,i]=e.useState([]),d=e.useCallback(()=>{o(!0),t.getConfiguredEdgeApps(r).then(f=>{l(c=>c!==void 0?void 0:c),i(f)}).catch(f=>{l(f)}).finally(()=>{o(!1)})},[r,t]);return e.useLayoutEffect(()=>{d()},[d]),{refresh:d,loading:s,error:u,apps:a}},re={updated:0,created:0,id:0,installation_id:0,type:"",meta:{},protected_meta:{}},ae=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,s=typeof r=="string"?Number.parseInt(r):r;if(isNaN(t)||isNaN(s))throw new Error("invalid installationId or deviceId");const{lynxClient:o}=w(),[u,l]=e.useState(!0),[a,i]=e.useState({...re}),[d,f]=e.useState();e.useLayoutEffect(()=>{o.getDevice(t,s).then(v=>{f(h=>h!==void 0?void 0:h),i(v)}).catch(v=>{f(v)}).finally(()=>{l(!1)})},[o,t,s]);const c=e.useCallback(()=>new Promise(()=>{if(!a)throw new Error("update on undefined function");return o.updateDevice(a)}),[o,a]),p=e.useCallback(v=>{a&&i({...a,type:v})},[a,i]),g=e.useCallback(()=>new Promise(()=>{if(!a)throw new Error("delete on undefined function");return o.deleteDevice(a)}),[a,o]);return{loading:u,error:d,Device:a,setDevice:i,update:c,remove:g,setType:p}},ie=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,s=typeof r=="string"?Number.parseInt(r):r,{lynxClient:o}=w(),u=e.useCallback((i,d,f,c)=>{const p=f??s??0;return o.createDeviceMeta(t,p,i,d,c)},[o,t,s]),l=e.useCallback((i,d,f,c,p)=>{const g=c??s??0;return o.updateDeviceMeta(t,g,i,d,p,f)},[o,t,s]),a=e.useCallback((i,d,f)=>{const c=d??s??0;return o.deleteDeviceMeta(t,c,i,f)},[o,t,s]);return{createMeta:u,updateMeta:l,removeMeta:a}},R=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n;if(isNaN(t)&&t!==void 0)throw new Error("invalid installationId");const{lynxClient:s}=w(),[o,u]=e.useState(!0),[l,a]=e.useState([]),[i,d]=e.useState(),f=e.useCallback(()=>{if(t===void 0){u(!1),a([]);return}u(!0),s.getDevices(t,r).then(h=>{d(C=>C!==void 0?void 0:C),a(h)}).catch(h=>{d(h)}).finally(()=>{u(!1)})},[s,t,r]);function c(h){if(Array.isArray(h)){const C=h.pop();if(!C)return Promise.allSettled([]);const b=h.map((m=>s.deleteDevice(m,!0)));return Promise.allSettled(b).then(async m=>{try{m.push({status:"fulfilled",value:await s.deleteDevice(C)})}catch(y){m.push({status:"rejected",reason:y})}return m})}return s.deleteDevice(h)}function p(h){if(Array.isArray(h)){const C=h.pop();if(!C)return Promise.allSettled([]);const b=h.map(m=>s.createDevice(m,!0));return Promise.allSettled(b).then(async m=>{try{m.push({status:"fulfilled",value:await s.createDevice(C)})}catch(y){m.push({status:"rejected",reason:y})}return m})}return s.createDevice(h)}const g=e.useCallback(p,[s,p]),v=e.useCallback(c,[s,c]);return e.useLayoutEffect(()=>{f()},[f]),{loading:o,error:i,create:g,remove:v,devices:l,refresh:f}},ce={id:0,created:0,updated:0,name:"",category:"",short_description:"",description:"",source_url:"",tags:[],publisher:{id:0},public:!1,official:!1},ue=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid appId");const{lynxClient:t}=w(),[s,o]=e.useState(!1),[u,l]=e.useState(),[a,i]=e.useState({...ce}),d=e.useCallback(()=>{o(!0),t.getEdgeApp(r).then(f=>{l(c=>c!==void 0?void 0:c),i(f)}).catch(f=>{l(f)}).finally(()=>{o(!1)})},[r,t]);return e.useLayoutEffect(()=>{d()},[d]),{loading:s,error:u,app:a,setApp:i,refresh:d}},le=()=>{const{lynxClient:n}=w(),[r,t]=e.useState(!0),[s,o]=e.useState(),[u,l]=e.useState([]),a=e.useCallback(()=>{t(!0),n.getEdgeApps().then(i=>{o(d=>d!==void 0?void 0:d),l(i)}).catch(i=>{o(i)}).finally(()=>{t(!1)})},[n]);return e.useLayoutEffect(()=>{a()},[a]),{apps:u,error:s,loading:r,refresh:a}},de=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n;if(isNaN(t))throw new Error("invalid appId");const{lynxClient:s}=w(),[o,u]=e.useState(!1),[l,a]=e.useState(),[i,d]=e.useState([]),f=e.useCallback(()=>{u(!0),s.getEdgeAppVersions(t,r).then(p=>{a(g=>g!==void 0?void 0:g),d(p)}).catch(p=>{a(p)}).finally(()=>{u(!1)})},[s,t,r]),c=e.useCallback((p,g)=>s.nameEdgeAppVersion(t,p,g),[s,t]);return e.useLayoutEffect(()=>{f()},[f]),{loading:o,error:l,versions:i,nameVersion:c,refresh:f}},fe={id:0,installation_id:0,type:"",updated:0,created:0,meta:{},protected_meta:{}},pe=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,s=typeof r=="string"?Number.parseInt(r):r;if(isNaN(t)||isNaN(s))throw new Error("invalid installationId or functionId");const{lynxClient:o}=w(),[u,l]=e.useState(!0),[a,i]=e.useState({...fe}),[d,f]=e.useState();e.useLayoutEffect(()=>{o.getFunction(t,s).then(v=>{f(h=>h!==void 0?void 0:h),i(v)}).catch(v=>{f(v)}).finally(()=>{l(!1)})},[o,t,s]);const c=e.useCallback(()=>new Promise(()=>{if(!a)throw new Error("update on undefined function");return o.updateFunction(a)}),[o,a]),p=e.useCallback(v=>{a&&i({...a,type:v})},[a,i]),g=e.useCallback(()=>new Promise(()=>{if(!a)throw new Error("delete on undefined function");return o.deleteFunction(a)}),[a,o]);return{loading:u,error:d,Function:a,setFunction:i,update:c,remove:g,setType:p}},he=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,s=typeof r=="string"?Number.parseInt(r):r,{lynxClient:o}=w(),u=e.useCallback((i,d,f,c)=>{const p=f??s??0;return o.createFunctionMeta(t,p,i,d,c)},[o,t,s]),l=e.useCallback((i,d,f,c,p)=>{const g=c??s??0;return o.updateFunctionMeta(t,g,i,d,p,f)},[o,t,s]),a=e.useCallback((i,d,f)=>{const c=d??s??0;return o.deleteFunctionMeta(t,c,i,f)},[o,t,s]);return{createMeta:u,updateMeta:l,removeMeta:a}},T=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n;if(isNaN(t)&&t!==void 0)throw new Error("invalid installationId");const{lynxClient:s}=w(),[o,u]=e.useState(!0),[l,a]=e.useState([]),[i,d]=e.useState(),f=e.useCallback(()=>{if(t===void 0){u(!1),a([]);return}u(!0),s.getFunctions(t,r).then(h=>(d(C=>C!==void 0?void 0:C),a(h),h)).catch(h=>{d(h)}).finally(()=>{u(!1)})},[s,t,r]);function c(h){if(Array.isArray(h)){const C=h.pop();if(!C)return Promise.allSettled([]);const b=h.map((m=>s.deleteFunction(m,!0)));return Promise.allSettled(b).then(async m=>{try{m.push({status:"fulfilled",value:await s.deleteFunction(C)})}catch(y){m.push({status:"rejected",reason:y})}return m})}return s.deleteFunction(h)}function p(h){if(Array.isArray(h)){const C=h.pop();if(!C)return Promise.allSettled([]);const b=h.map(m=>s.createFunction(m,!0));return Promise.allSettled(b).then(async m=>{try{m.push({status:"fulfilled",value:await s.createFunction(C)})}catch(y){m.push({status:"rejected",reason:y})}return m})}return s.createFunction(h)}const g=e.useCallback(p,[s,p]),v=e.useCallback(c,[s,c]);return e.useLayoutEffect(()=>{f()},[f]),{loading:o,error:i,create:g,remove:v,functions:l,refresh:f}},ge=()=>{const{lynxClient:n}=w(),[r,t]=e.useState(!0),[s,o]=e.useState(),[u,l]=e.useState([]),a=e.useCallback(()=>{t(!0),n.getIDTokenAlgorithms().then(i=>{o(d=>d!==void 0?void 0:d),l(i)}).catch(i=>{o(i)}).finally(()=>{t(!1)})},[n]);return e.useEffect(()=>{a()},[]),{loading:r,refresh:a,algs:u,error:s}},ye={client_id:0,notes:"",organization_id:0,id:0,name:"",created:0,meta:{},users:[],protected_meta:{}},B=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:t}=w(),[s,o]=e.useState(!0),[u,l]=e.useState(void 0),[a,i]=e.useState({...ye});e.useLayoutEffect(()=>{t.getInstallationRow(r).then(c=>{l(p=>p!==void 0?void 0:p),i(c)}).catch(c=>{l(c)}).finally(()=>{o(!1)})},[t,r]);const d=e.useCallback(()=>new Promise(()=>{if(!a)throw new Error("update on undefined installation");return t.updateInstallation(a)}),[t,a]),f=e.useCallback(()=>new Promise(()=>{if(!a)throw new Error("update on undefined installation");return t.deleteInstallation(a)}),[t,a]);return{installation:a,setInstallation:i,update:d,remove:f,error:u,loading:s}},ve=n=>{const{lynxClient:r}=w(),[t,s]=e.useState([]),[o,u]=e.useState(!0),[l,a]=e.useState(void 0),i=e.useCallback(()=>{u(!0),r.getInstallations(n).then(d=>{a(f=>f!==void 0?void 0:f),s(d)}).catch(d=>{a(d)}).finally(()=>{u(!1)})},[r]);return e.useLayoutEffect(()=>{i()},[i]),{installations:t,refresh:i,loading:o,error:l}},Ce=n=>{const{lynxClient:r}=w(),[t,s]=e.useState(!0),[o,u]=e.useState([]),[l,a]=e.useState(),i=e.useCallback(()=>{s(!0),r.listInstallations(n).then(d=>{a(f=>f!==void 0?void 0:f),u(d)}).catch(d=>{a(()=>d)}).finally(()=>{s(!1)})},[r,n]);return e.useLayoutEffect(()=>{i()},[i]),{loading:t,error:l,installations:o,refresh:i}},K=(n,r,t,s)=>{if(s===void 0){let h;window?.crypto?.randomUUID?h=window.crypto.randomUUID():typeof crypto<"u"&&crypto?.randomUUID?h=crypto.randomUUID():h=Math.random().toString(36).substring(2,15),s=`paho-ws-mqtt-${h}`}const o=e.useRef(new W.Client(n,s)),u=e.useRef(t),l=e.useRef(r),a=e.useRef(void 0),[i,d]=e.useState(!1),[f,c]=e.useState(void 0);e.useLayoutEffect(()=>{const h=o,C=a,b={timeout:5,...u.current,onFailure:y=>{c(y),d(o.current.isConnected()),C.current??=window.setInterval(()=>{h.current.isConnected()?clearInterval(C.current):h.current.connect(b)},5e3)},onSuccess:()=>{c(void 0),d(o.current.isConnected()),C.current!==void 0&&(window.clearInterval(C.current),C.current=void 0)}},m=l.current;h.current.onConnectionLost=y=>{c(y),d(o.current.isConnected()),m?.onDisconnect?.(y)},h.current.onConnected=(y,N)=>{d(o.current.isConnected()),c(void 0),m?.onConnected?.(y,N)},m&&(m.onMessage&&(h.current.onMessageArrived=m.onMessage),m.onDelivery&&(h.current.onMessageDelivered=m.onDelivery));try{h.current.connect(b)}catch{window.setTimeout(()=>{h.current.connect(b)},5e3)}return()=>{try{h.current.disconnect(),C.current!==void 0&&window.clearInterval(C.current)}catch(y){console.log(y)}}},[]);const p=e.useCallback((h,C)=>new Promise(b=>{o.current.subscribe(h,{qos:C??0,timeout:1,onFailure:m=>{throw m},onSuccess:m=>{b(m.grantedQos)}})}),[o]),g=e.useCallback((h,C,b,m)=>{let y;if(typeof C=="string")y=C;else if(ArrayBuffer.isView(C))y=new Uint8Array(C.buffer,C.byteOffset,C.byteLength).slice().buffer;else throw new Error("Payload must be a string or TypedArray");o.current.send(h,y,b,m)},[o]),v=e.useCallback(h=>new Promise(C=>{o.current.unsubscribe(h,{timeout:1,onSuccess:()=>{C()},onFailure:b=>{throw b}})}),[o]);return{client:o,connected:i,error:f,sub:p,pub:g,unsub:v}};function me(n,r){if(n.length===r.length){for(let t=0;t<n.length;t++)if(n[t]!==r[t])return!1;return!0}return!1}function we(n,r){return new Promise(t=>{r.forEach(async s=>{try{await n(s)}catch(o){console.warn("failed to unsubscribe to",s,o)}}),t()})}function be(n,r){return new Promise(t=>{r.forEach(async s=>{try{await n(s)}catch(o){console.warn("failed to subscribe to",s,o)}}),t()})}const H=(n,r,t)=>{n===void 0&&(window!==void 0?n=window.location.protocol==="http:"?`ws://${window.location.host}/mqtt`:`wss://${window.location.host}/mqtt`:n=location.protocol==="http:"?`ws://${location.host}/mqtt`:`wss://${location.host}/mqtt`);const s=e.useRef([]),o=e.useRef(new Map([])),u=e.useRef(new Map([])),l=e.useCallback(y=>{const N=u.current.get(y.destinationName);N&&N.forEach(E=>{E(y.destinationName,new TextDecoder().decode(y.payloadBytes),y.qos,y.retained)}),o.current.forEach((E,x)=>{new RegExp(x).test(y.destinationName)&&E.forEach(q=>{q(y.destinationName,new TextDecoder().decode(y.payloadBytes),y.qos,y.retained)})})},[]),a=e.useRef(!1),i={cleanSession:!0,reconnect:!0,keepAliveInterval:5};r&&(i.userName=r),t&&(i.password=t);const{error:d,connected:f,sub:c,unsub:p,pub:g}=K(n,{onMessage:l,onConnected:()=>{s.current.forEach(y=>{c(y).catch(N=>{console.warn("Failed to subscribe to",y,N)})})}},i);e.useEffect(()=>{a.current=f},[f]);const v=e.useCallback((y,N)=>{let E;typeof y=="string"?E=new RegExp(`^${y}$`):E=y;const x=E.toString().slice(1,-1);let M=o.current.get(x);if(M===void 0){M=[N],o.current.set(x,M);return}M.includes(N)||M.push(N)},[]),h=e.useCallback(y=>{o.current.forEach((N,E)=>{const x=N.filter(M=>M!==y);o.current.set(E,x)})},[]),C=e.useCallback((y,N)=>{let E=u.current.get(y);if(E===void 0){E=[N],u.current.set(y,E);return}E.includes(N)||E.push(N)},[]),b=e.useCallback((y,N)=>{const E=u.current.get(y);E!==void 0&&u.current.set(y,E.filter(x=>x!==N))},[]);return{setSubs:e.useCallback(y=>{me(s.current,y)||(a.current&&we(p,s.current).then(()=>be(c,y)).catch(N=>{console.warn("Failed to update subscriptions",N)}),s.current=y)},[c,p]),error:d,connected:f,bind:v,unbind:h,bindExact:C,unbindExact:b,pub:g}},D=()=>{const n=w(),{user:r}=z(),t=new URL(n.lynxClient.baseURL),s=t.protocol==="http:"?"ws:":"wss:",o=t.hostname,u=t.port?`:${t.port}`:"",l=`${s}//${o}${u}/mqtt`;let a=r?.email??"api-key";return n.lynxClient.bearer&&(a="bearer"),H(l,a,n.lynxClient.apiKey)},Ne=n=>{const r=D(),{functions:t,refresh:s}=T(n.id),{devices:o,refresh:u}=R(n.id),{unbind:l,bind:a,setSubs:i}=r;return e.useEffect(()=>(i([`${n.client_id}/#`]),a(/[0-9]+\/evt\/functionx\/updated/,s),a(/[0-9]+\/evt\/devicex\/updated/,u),()=>{l(s),l(u)}),[a,u,s,n,i,l]),{installation:n,functions:t,devices:o,mqtt:r}},Ee=n=>{const r=D(),{installation:t}=B(n),{functions:s,refresh:o}=T(n),{devices:u,refresh:l}=R(n),{unbind:a,bind:i,setSubs:d}=r;return e.useEffect(()=>(d([`${t.client_id}/#`]),i(/[0-9]+\/evt\/functionx\/updated/,o),i(/[0-9]+\/evt\/devicex\/updated/,l),()=>{a(o),a(l)}),[i,l,o,t,d,a]),{installation:t,functions:s,devices:u,mqtt:r}},Se=(n,r=[])=>{const[t,s]=e.useState([]);e.useLayoutEffect(()=>{if(n){const c=[];for(const p in n.meta){const g=n.meta[p];c.push({key:p,value:g??"",protected:!1})}for(const p in n.protected_meta){const g=n.protected_meta[p];c.push({key:p,value:g??"",protected:!0})}c.sort((p,g)=>p.key.localeCompare(g.key)),s(c)}},[n,...r]);const o=e.useCallback(()=>{const c={meta:{},protected_meta:{}};return t.forEach(p=>{p.protected?c.protected_meta[p.key]=p.value:c.meta[p.key]=p.value}),c},[t]),u=e.useCallback(c=>{s([...t,c??{key:"",value:"",protected:!1}])},[t,s]),l=e.useCallback(c=>{s(t.filter((p,g)=>g!==c))},[t,s]),a=e.useCallback((c,p)=>{s(t.map((g,v)=>v===c?p:g))},[t,s]),i=e.useCallback((c,p)=>{s(t.map((g,v)=>v===c?{...g,key:p}:g))},[t,s]),d=e.useCallback((c,p)=>{s(t.map((g,v)=>v===c?{...g,value:p}:g))},[t,s]),f=e.useCallback((c,p)=>{s(t.map((g,v)=>v===c?{...g,protected:p}:g))},[t,s]);return{metaList:t,compile:o,addMeta:u,removeMeta:l,setMeta:a,setMetaKey:i,setMetaValue:d,setMetaProtected:f}},ke=n=>{const{lynxClient:r}=w(),t=D(),{bind:s,unbind:o,setSubs:u}=t,[l,a]=e.useState(new Map),[i,d]=e.useState(new Map),[f,c]=e.useState(new Map),[p,g]=e.useState(new Map),v=e.useCallback(C=>{const b=i.get(C);return b!==void 0?b.client_id:0},[i]),h=e.useCallback(C=>{const b=l.get(C);return b!==void 0?b.id:0},[l]);return e.useEffect(()=>{if(n.length===0)return;const C=new Map,b=new Map,m=new Array;n.forEach(S=>{C.set(S.id,S),b.set(S.client_id,S),m.push(`${S.client_id}/#`)});let y=!1;const N=n.map(async S=>({functions:await r.getFunctions(S.id),installationId:S.id})),E=n.map(async S=>({devices:await r.getDevices(S.id),installationId:S.id})),x=new Map,M=new Map;new Promise((S,L)=>{let k=!1,_=!1;Promise.allSettled(N).then(O=>{O.forEach(A=>{A.status==="fulfilled"&&M.set(A.value.installationId,A.value.functions)}),k=!0,k&&_&&S()}).catch(L),Promise.allSettled(E).then(O=>{O.forEach(A=>{A.status==="fulfilled"&&x.set(A.value.installationId,A.value.devices)}),_=!0,k&&_&&S()}).catch(L)}).finally(()=>{a(()=>b),d(()=>C),c(()=>M),g(()=>x),y=!0}).catch(S=>{console.warn("Error in work.finally:",S)});const $=S=>{if(!y)return;const L=Number(S.split("/")[0]),k=b.get(L);k!==void 0&&r.getFunctions(k.id).then(_=>{c(O=>new Map([...O,[k.id,_]]))}).catch(_=>{console.warn("Failed to update function map for",k.id,_)})},V=S=>{if(!y)return;const L=Number(S.split("/")[0]),k=b.get(L);k!==void 0&&r.getDevices(k.id).then(_=>{g(O=>new Map([...O,[k.id,_]]))}).catch(_=>{console.warn("Failed to update device map for",k.id,_)})};return u(m),s(/[0-9]+\/evt\/functionx\/updated/,$),s(/[0-9]+\/evt\/devicex\/updated/,V),()=>{o($),o(V)}},[n,r,s,o,u]),{installationMap:i,functionMap:f,deviceMap:p,mqtt:t,toClientId:v,toInstallationId:h}},xe=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n;if(isNaN(t))throw new Error("invalid installationId");const{lynxClient:s}=w(),[o,u]=e.useState({meta:{},protected_meta:{},type:"",...r,installation_id:t}),l=e.useCallback(i=>{u({...o,type:i})},[o,u]),a=e.useCallback(()=>s.createDevice(o),[s,o]);return{newDevice:o,setNewDevice:u,create:a,setType:l}},Me=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n;if(isNaN(t))throw new Error("invalid installationId");const{lynxClient:s}=w(),[o,u]=e.useState({meta:{},protected_meta:{},type:"",...r,installation_id:t}),l=e.useCallback(i=>{u({...o,type:i})},[o,u]),a=e.useCallback(()=>s.createFunction(o),[s,o]);return{newFunction:o,setNewFunction:u,create:a,setType:l}},_e=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n;if(isNaN(t))throw new Error("invalid organizationId");const[s,o]=e.useState({name:"",notes:"",users:[],meta:{},protected_meta:{},...r,organization_id:t}),{lynxClient:u}=w(),l=e.useCallback(()=>u.createInstallation(s),[u,s]);return{newInstallation:s,setNewInstallation:o,create:l}},Le={installation_id:0,name:"",text:""},Oe=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,{lynxClient:s}=w(),[o,u]=e.useState({...Le,...r,installation_id:t}),l=e.useCallback(()=>s.createNotificationMessage(o),[s,o]);return{newNotificationMessage:o,setNewNotificationMessage:u,create:l}},Ae={installation_id:0,name:"",notification_message_id:0,notification_output_executor_id:0,config:{}},Ie=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,{lynxClient:s}=w(),[o,u]=e.useState({...Ae,...r,installation_id:t}),l=e.useCallback(()=>s.createNotificationOutput(o),[s,o]);return{newNotificationOutput:o,setNewNotificationOutput:u,create:l}},Pe=n=>{const{lynxClient:r}=w(),[t,s]=e.useState({...I.zero.getEmptyOAuth2Client(),...n}),o=e.useCallback(c=>{s({...t,name:c})},[t]),u=e.useCallback(c=>{s({...t,allowed_scopes:c})},[t]),l=e.useCallback(c=>{s({...t,icon_uri:c})},[t]),a=e.useCallback(c=>{s({...t,tos_uri:c})},[t]),i=e.useCallback(c=>{s({...t,policy_uri:c})},[t]),d=e.useCallback(c=>{s({...t,redirect_uris:c})},[t]),f=e.useCallback(()=>r.createOAuth2Client(t),[r,t]);return{newClient:t,create:f,setName:o,setScope:u,setIconURI:l,setTosURI:a,setPolicyURI:i,setRedirectURIs:d,setClient:s}},De={address:{address:"",city:"",country:"",zip:""},children:[],email:"",force_sms_login:!1,meta:{},name:"",notes:"",parent:0,password_valid_days:0,phone:"",protected_meta:{}},Fe=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n;if(isNaN(t))throw new Error("invalid parentId");const{lynxClient:s}=w(),[o,u]=e.useState({...De,...r,parent:t}),l=e.useCallback(()=>s.createOrganization(o),[s,o]);return{newOrganization:o,setNewOrganization:u,create:l}},ze={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:{}},Ue=n=>{const[r,t]=e.useState({...ze,...n}),{lynxClient:s}=w(),o=e.useCallback(()=>s.createUser(r),[s,r]);return{newUser:r,setNewUser:t,create:o}},j={id:0,installation_id:0,name:"",text:""},Re=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,s=typeof r=="string"?Number.parseInt(r):r;if(isNaN(t))throw new Error("invalid installationId");if(isNaN(s))throw new Error("invalid messageId");const{lynxClient:o}=w(),[u,l]=e.useState(!0),[a,i]=e.useState({...j}),[d,f]=e.useState(),c=e.useCallback(()=>{t===0||s===0||(l(!0),o.getNotificationMessage(t,s).then(v=>{f(h=>h!==void 0?void 0:h),i(v)}).catch(v=>{f(v)}).finally(()=>{l(!1)}))},[s,t,o]),p=e.useCallback(()=>{d!==void 0&&f(void 0),o.updateNotificationMessage(a).then(v=>{i(v)}).catch(v=>{f(v)})},[d,o,a]),g=e.useCallback(()=>{o.deleteNotificationMessage(a).then(()=>{i({...j})}).catch(v=>{f(v)})},[o,a]);return e.useEffect(()=>{c()},[]),{refresh:c,message:a,setMessage:i,error:d,loading:u,remove:g,update:p}},Te=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:t}=w(),[s,o]=e.useState([]),[u,l]=e.useState(!0),[a,i]=e.useState(),d=e.useCallback(()=>{t.getNotificationMessages(r).then(f=>{i(c=>c!==void 0?void 0:c),o(f)}).catch(f=>{i(f)}).finally(()=>{l(!1)})},[r,t]);return e.useEffect(()=>{d()},[]),{refresh:d,notificationMessages:s,error:a,loading:u}},F={id:0,installation_id:0,name:"",notification_message_id:0,notification_output_executor_id:0,config:{}},qe=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,s=typeof r=="string"?Number.parseInt(r):r;if(isNaN(t))throw new Error("invalid installationId");if(isNaN(s))throw new Error("invalid notificationId");const{lynxClient:o}=w(),[u,l]=e.useState(!0),[a,i]=e.useState({...F,config:{...F.config}}),[d,f]=e.useState(),c=e.useCallback(()=>{t===0||s===0||(l(!0),o.getNotificationOutput(t,s).then(v=>{f(h=>h!==void 0?void 0:h),i(v)}).catch(v=>{f(v)}).finally(()=>{l(!1)}))},[s,t,o]),p=e.useCallback(()=>{d!==void 0&&f(void 0),o.updateNotificationOutput(a).then(v=>{i(v)}).catch(v=>{f(v)})},[d,o,a]),g=e.useCallback(()=>{o.deleteNotificationOutput(a).then(()=>{i({...F})}).catch(v=>{f(v)})},[o,a]);return e.useEffect(()=>{c()},[]),{refresh:c,output:a,setOutput:i,error:d,loading:u,remove:g,update:p}},$e={id:0,type:"",name:"",organization_id:0,config:{},secret:""},Ve=(n,r)=>{const t=typeof n=="string"?Number.parseInt(n):n,s=typeof r=="string"?Number.parseInt(r):r;if(isNaN(t))throw new Error("invalid installationId");if(isNaN(s))throw new Error("invalid messageId");const{lynxClient:o}=w(),[u,l]=e.useState(!0),[a,i]=e.useState({...$e}),[d,f]=e.useState(),c=e.useCallback(()=>{t===0||s===0||(l(!0),o.getNotificationOutputExecutor(t,s).then(p=>{f(g=>g!==void 0?void 0:g),i(p)}).catch(p=>{f(p)}).finally(()=>{l(!1)}))},[s,t,o]);return e.useEffect(()=>{c()},[]),{refresh:c,outputExecutor:a,setOutputExecutor:i,error:d,loading:u}},je=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:t}=w(),[s,o]=e.useState([]),[u,l]=e.useState(!0),[a,i]=e.useState(),d=e.useCallback(()=>{t.getNotificationOutputExecutors(r).then(f=>{i(c=>c!==void 0?void 0:c),o(f)}).catch(f=>{i(f)}).finally(()=>{l(!1)})},[r,t]);return e.useEffect(()=>{d()},[]),{refresh:d,notificationExecutors:s,error:a,loading:u}},Qe=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid installationId");const{lynxClient:t}=w(),[s,o]=e.useState([]),[u,l]=e.useState(!0),[a,i]=e.useState(),d=e.useCallback(()=>{t.getNotificationOutputs(r).then(f=>{i(c=>c!==void 0?void 0:c),o(f)}).catch(f=>{i(f)}).finally(()=>{l(!1)})},[r,t]);return e.useEffect(()=>{d()},[]),{refresh:d,notificationOutputs:s,error:a,loading:u}},J=n=>{const{lynxClient:r}=w(),[t,s]=e.useState(!0),[o,u]=e.useState(),[l,a]=e.useState({...I.zero.getOAuth2Client()}),i=e.useCallback(()=>{t||s(!0),r.getOAuth2Client(n).then(c=>{u(p=>p!==void 0?void 0:p),a(c)}).catch(c=>{u(c)}).finally(()=>{s(!1)})},[t,r,n]);e.useEffect(()=>{i()},[n]);const d=e.useCallback(()=>r.deleteOAuth2Client(l),[l,r]),f=e.useCallback(()=>r.updateOAuth2Client(l),[l,r]);return{refresh:i,client:l,setClient:a,error:o,loading:t,remove:d,update:f}},Ge=()=>{const{lynxClient:n}=w(),[r,t]=e.useState(!0),[s,o]=e.useState(),[u,l]=e.useState([]),a=e.useCallback(()=>{n.getOAuth2Clients().then(i=>{o(d=>d!==void 0?void 0:d),l(i)}).catch(i=>{o(i)}).finally(()=>{t(!1)})},[n]);return e.useEffect(()=>{a()},[]),{refresh:a,clients:u,error:s,loading:r}},Be=()=>{const{lynxClient:n}=w(),[r,t]=e.useState([]),[s]=e.useState(new URLSearchParams(window.location.search)),o=s.get("client_id")??"",{client:u}=J(o),l=e.useCallback(a=>{const i=Object.fromEntries(s);return i.scope=a.join(" "),n.consentOAuth2Authorization(i)},[n,s]);return e.useEffect(()=>{t(s.get("scope")?.split(" ")??[])},[s]),{consent:l,client:u,requestedScopes:r}},Ke={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},He=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid organizationId");const[t,s]=e.useState({...Ke}),[o,u]=e.useState(!0),[l,a]=e.useState(),{lynxClient:i}=w(),d=e.useCallback(()=>{u(!0),i.getOrganization(r).then(p=>{a(g=>g!==void 0?void 0:g),s(p)}).catch(p=>{a(p)}).finally(()=>{u(!1)})},[i,r]);e.useEffect(()=>{d()},[]);const f=e.useCallback(()=>i.updateOrganization(t),[i,t]),c=e.useCallback(()=>i.deleteOrganization(t),[i,t]);return{loading:o,organization:t,setOrganization:s,error:l,update:f,remove:c,refresh:d}},Je=n=>{const{lynxClient:r}=w(),[t,s]=e.useState(!0),[o,u]=e.useState(),[l,a]=e.useState([]),i=e.useCallback(()=>{s(!0),r.getOrganizations(n===!0).then(c=>{u(p=>p!==void 0?void 0:p),a(c)}).catch(c=>{u(c)}).finally(()=>{s(!1)})},[r,n]);e.useEffect(()=>{i()},[]);const d=e.useCallback(c=>r.createOrganization(c),[r]),f=e.useCallback(c=>r.deleteOrganization(c),[r]);return{loading:t,organizations:l,setOrganizations:a,error:o,create:d,remove:f}},We=()=>{const{lynxClient:n}=w(),[r,t]=e.useState([]),[s,o]=e.useState(),[u,l]=e.useState(!0),a=e.useCallback(()=>{l(!0),n.getRoles().then(i=>{o(d=>d!==void 0?void 0:d),t(i)}).catch(i=>{o(i)}).finally(()=>{l(!1)})},[n]);return e.useEffect(()=>{a()},[]),{loading:u,error:s,roles:r,refresh:a}},Xe=()=>{const{lynxClient:n}=w(),[r,t]=e.useState(!0),[s,o]=e.useState(),[u,l]=e.useState([]),a=e.useCallback(()=>{t(!0),n.getTokens().then(f=>{o(c=>c!==void 0?void 0:c),l(f)}).catch(f=>{o(f)}).finally(()=>{t(!1)})},[n]),i=e.useCallback(f=>n.deleteToken(f),[n]),d=e.useCallback(f=>n.createToken(f),[n]);return e.useLayoutEffect(()=>{a()},[a]),{tokens:u,remove:i,create:d,refresh:a,loading:r,error:s}},Ye={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:{}},Ze=n=>{const r=typeof n=="string"?Number.parseInt(n):n;if(isNaN(r))throw new Error("invalid userId");const[t,s]=e.useState({...Ye}),[o,u]=e.useState(!0),{lynxClient:l}=w(),[a,i]=e.useState(),d=e.useCallback(()=>{u(!0),l.getUser(r).then(p=>{i(g=>g!==void 0?void 0:g),s(p)}).catch(p=>{i(p)}).finally(()=>{u(!1)})},[l,r]),f=e.useCallback(()=>l.updateUser(t),[l,t]),c=e.useCallback(()=>l.deleteUser(t),[l,t]);return{loading:o,error:a,user:t,setUser:s,update:f,refresh:d,remove:c}},et=n=>{const[r,t]=e.useState([]),[s,o]=e.useState(!0),[u,l]=e.useState(),{lynxClient:a}=w();new URLSearchParams;const i=e.useCallback(()=>{o(!0),a.getUsers(n).then(d=>{l(f=>f!==void 0?void 0:f),t(d)}).catch(d=>{l(d)}).finally(()=>{o(!1)})},[a,n]);return{users:r,setUsers:t,refresh:i,loading:s,error:u}};exports.LynxProvider=te;exports.useConfiguredEdgeApps=oe;exports.useDevice=ae;exports.useDeviceMeta=ie;exports.useDevices=R;exports.useEdgeApp=ue;exports.useEdgeAppVersions=de;exports.useEdgeApps=le;exports.useFunction=pe;exports.useFunctionMeta=he;exports.useFunctions=T;exports.useGlobalLynxClient=w;exports.useGlobalPermissions=U;exports.useGlobalUser=z;exports.useIDTokenAlgorithms=ge;exports.useInstallation=B;exports.useInstallationInfo=ve;exports.useInstallations=Ce;exports.useLiveInstallation=Ne;exports.useLiveInstallationId=Ee;exports.useMQTT=D;exports.useMeta=Se;exports.useMultiLiveInstallation=ke;exports.useNewDevice=xe;exports.useNewFunction=Me;exports.useNewInstallation=_e;exports.useNewNotificationMessage=Oe;exports.useNewNotificationOutput=Ie;exports.useNewOAuth2Client=Pe;exports.useNewOrganization=Fe;exports.useNewUser=Ue;exports.useNotificationMessage=Re;exports.useNotificationMessages=Te;exports.useNotificationOutput=qe;exports.useNotificationOutputExecutor=Ve;exports.useNotificationOutputExecutors=je;exports.useNotificationOutputs=Qe;exports.useOAuth2Client=J;exports.useOAuth2Clients=Ge;exports.useOAuth2Consent=Be;exports.useOrganization=He;exports.useOrganizations=Je;exports.usePahoMQTTClient=K;exports.usePermissionsCheckAll=ne;exports.usePermissionsCheckAny=se;exports.useRoles=We;exports.useSimpleMQTT=H;exports.useTokens=Xe;exports.useUser=Ze;exports.useUsers=et;
17
2
  //# sourceMappingURL=index.js.map