text: "use strict";module.exports=function(c){require("source-map-support").install();var S=require("./core/opcua-iiot-core-connector"),s=require("path"),I=require("underscore"),r=require("better-assert");try{c.nodes.registerType("OPCUA-IIoT-Connector",function(e){c.nodes.createNode(this,e),this.discoveryUrl=e.discoveryUrl||null,this.endpoint=e.endpoint,this.endpointMustExist=e.endpointMustExist||!1,this.keepSessionAlive=e.keepSessionAlive,this.loginEnabled=e.loginEnabled,this.name=e.name,this.showErrors=e.showErrors,this.securityPolicy=e.securityPolicy,this.messageSecurityMode=e.securityMode,this.publicCertificateFile=e.publicCertificateFile,this.privateKeyFile=e.privateKeyFile,this.defaultSecureTokenLifetime=e.defaultSecureTokenLifetime||12e4,this.autoSelectRightEndpoint=e.autoSelectRightEndpoint,this.strategyMaxRetry=e.strategyMaxRetry||1e4,this.strategyInitialDelay=e.strategyInitialDelay||500,this.strategyMaxDelay=e.strategyMaxDelay||3e4,this.strategyRandomisationFactor=e.strategyRandomisationFactor||.2,this.requestedSessionTimeout=e.requestedSessionTimeout||6e4,this.connectionStartDelay=e.connectionStartDelay||2e3,this.reconnectDelay=e.reconnectDelay||1e3,this.connectionStopDelay=e.connectionStopDelay||2e3,this.maxBadSessionRequests=e.maxBadSessionRequests||10;var t=S.initConnectorNode(this);S.core.assert(t.bianco.iiot),t.setMaxListeners(0),S.internalDebugLog("Open Connector Node"),t.bianco.iiot.stateMachine=S.createStatelyMachine(),S.internalDebugLog("Start FSM: "+t.bianco.iiot.stateMachine.getMachineState()),S.detailDebugLog("FSM events:"+t.bianco.iiot.stateMachine.getMachineEvents());var i=null,n=null,o=null,a=S.core.getNodeOPCUAClientPath();t.securedCommunication=t.securityPolicy&&"None"!==t.securityPolicy&&t.messageSecurityMode&&"NONE"!==t.messageSecurityMode,S.detailDebugLog("config: "+t.publicCertificateFile),S.detailDebugLog("config: "+t.privateKeyFile),S.detailDebugLog("securedCommunication: "+t.securedCommunication.toString()),t.bianco.iiot.initCertificatesAndKeys=function(){t.securedCommunication?(null!==t.publicCertificateFile&&""!==t.publicCertificateFile||(t.publicCertificateFile=s.join(a,"/certificates/client_selfsigned_cert_2048.pem"),S.detailDebugLog("default key: "+t.publicCertificateFile)),null!==t.privateKeyFile&&""!==t.privateKeyFile||(t.privateKeyFile=s.join(a,"/certificates/PKI/own/private/private_key.pem"),S.detailDebugLog("default key: "+t.privateKeyFile))):(t.publicCertificateFile=null,t.privateKeyFile=null)},t.loginEnabled&&(t.credentials?(t.bianco.iiot.userIdentity={userName:t.credentials.user,password:t.credentials.password},S.internalDebugLog("Connecting With Login Data On "+t.endpoint)):t.error(new Error("Login Enabled But No Credentials"),{payload:""})),t.bianco.iiot.updateServerOptions=function(){t.bianco.iiot.initCertificatesAndKeys(),t.bianco.iiot.opcuaClientOptions={securityPolicy:t.securityPolicy||"None",securityMode:t.messageSecurityMode||"NONE",defaultSecureTokenLifetime:t.defaultSecureTokenLifetime||12e4,keepSessionAlive:t.keepSessionAlive,certificateFile:t.publicCertificateFile,privateKeyFile:t.privateKeyFile,endpoint_must_exist:t.endpointMustExist,requestedSessionTimeout:t.requestedSessionTimeout||6e4,connectionStrategy:{maxRetry:t.strategyMaxRetry||2e3,initialDelay:t.strategyInitialDelay||1e3,maxDelay:t.strategyMaxDelay||3e4,randomisationFactor:t.strategyRandomisationFactor||.2}}},t.bianco.iiot.connectOPCUAEndpoint=function(){S.checkEndpoint(t)&&(S.internalDebugLog("Connecting To Endpoint "+t.endpoint),t.bianco.iiot.updateServerOptions(),S.detailDebugLog("Options "+JSON.stringify(t.bianco.iiot.opcuaClientOptions)),t.bianco.iiot.opcuaClient=new S.core.nodeOPCUA.OPCUAClient(t.bianco.iiot.opcuaClientOptions),S.detailDebugLog("New OPC UA client was created for endpoint "+t.endpoint),t.autoSelectRightEndpoint&&t.bianco.iiot.autoSelectEndpointFromConnection(),t.bianco.iiot.connectToClient())},t.bianco.iiot.connectToClient=function(){S.checkEndpoint(t)&&(t.bianco.iiot.stateMachine.unlock(),t.bianco.iiot.opcuaClient.connect(t.endpoint,function(e){S.core.isInitializedBiancoIIoTNode(t)?e?(t.bianco.iiot.stateMachine.lock().stopopcua(),t.bianco.iiot.handleError(e)):(S.internalDebugLog("Client Is Connected To "+t.endpoint),t.bianco.iiot.stateMachine.open()):S.internalDebugLog("bianco.iiot not valid on connect resolve")}))},t.bianco.iiot.renewConnection=function(e){S.core.isInitializedBiancoIIoTNode(t)?t.bianco.iiot.opcuaDirectDisconnect(function(){t.bianco.iiot.renewFiniteStateMachine(),t.bianco.iiot.stateMachine.idle().initopcua(),e()}):S.internalDebugLog("bianco.iiot not valid on renew connection")},t.bianco.iiot.endpointMatchForConnecting=function(e){S.internalDebugLog("Auto Endpoint "+e.endpointUrl.toString()+" "+e.securityPolicyUri.toString());var i=e.securityMode.key||e.securityMode,o=e.securityPolicyUri.includes("SecurityPolicy#")?e.securityPolicyUri.split("#")[1]:e.securityPolicyUri;return S.internalDebugLog("node-mode:"+t.messageSecurityMode+" securityMode: "+i),S.internalDebugLog("node-policy:"+t.securityPolicy+" securityPolicy: "+o),i===t.messageSecurityMode&&o===t.securityPolicy},t.bianco.iiot.selectEndpointFromSettings=function(o){o.getEndpoints(function(e,i){e?(S.internalDebugLog("Auto Switch To Endpoint Error "+e),t.showErrors&&t.error(e,{payload:"Get Endpoints Request Error"})):i.forEach(function(e){t.bianco.iiot.endpointMatchForConnecting(e)&&(t.endpoint=e.endpointUrl,S.internalDebugLog("Auto Switch To Endpoint "+t.endpoint))}),o.disconnect(function(e){e?(S.internalDebugLog("Endpoints Auto Request Error "+e),t.showErrors&&t.error(e,{payload:"Discover Client Disconnect Error"})):S.internalDebugLog("Endpoints Auto Request Done With Endpoint "+t.endpoint)})})},t.bianco.iiot.autoSelectEndpointFromConnection=function(){S.internalDebugLog("Auto Searching For Endpoint On "+t.endpoint);var i=t.bianco.iiot.opcuaClientOptions.endpoint_must_exist;t.bianco.iiot.opcuaClientOptions.endpoint_must_exist=!1;var e=new S.core.nodeOPCUA.OPCUAClient(t.bianco.iiot.opcuaClientOptions);e.connect(t.endpoint).then(function(){S.internalDebugLog("Auto Searching Endpoint Connected To "+t.endpoint),t.bianco.iiot.selectEndpointFromSettings(e),t.bianco.iiot.opcuaClientOptions.endpoint_must_exist=i}).catch(function(e){S.internalDebugLog("Get Auto Endpoint Request Error "+e.message),S.core.isInitializedBiancoIIoTNode(t)&&(t.bianco.iiot.opcuaClientOptions.endpoint_must_exist=i)})},t.bianco.iiot.startSession=function(i){return S.internalDebugLog("Request For New Session From "+i),t.bianco.iiot.isInactiveOnOPCUA()?(S.internalDebugLog("State Is Not Active While Start Session-> "+t.bianco.iiot.stateMachine.getMachineState()),void(t.showErrors&&t.error(new Error("OPC UA Connector Is Not Active"),{payload:"Create Session Error"}))):"OPEN"!==t.bianco.iiot.stateMachine.getMachineState()?(S.internalDebugLog("Session Request Not Allowed On State "+t.bianco.iiot.stateMachine.getMachineState()),void(t.showErrors&&t.error(new Error("OPC UA Connector Is Not Open"),{payload:"Create Session Error"}))):t.bianco.iiot.opcuaClient?(t.bianco.iiot.stateMachine.sessionrequest(),void t.bianco.iiot.opcuaClient.createSession(t.bianco.iiot.userIdentity||{}).then(function(e){e.requestedMaxReferencesPerNode=1e5,t.bianco.iiot.opcuaSession=e,t.bianco.iiot.stateMachine.sessionactive(),S.detailDebugLog("Session Created On "+t.endpoint+" For "+i),S.logSessionInformation(t),t.bianco.iiot.opcuaSession.on("session_closed",function(e){t.bianco.iiot.handleSessionClose(e)})}).catch(function(e){S.core.isInitializedBiancoIIoTNode(t)?(t.bianco.iiot.stateMachine.lock().stopopcua(),t.bianco.iiot.handleError(e)):S.internalDebugLog(e.message),t.emit("session_error",e)})):(S.internalDebugLog("OPC UA Client Connection Is Not Valid On State "+t.bianco.iiot.stateMachine.getMachineState()),void(t.showErrors&&t.error(new Error("OPC UA Client Connection Is Not Valid"),{payload:"Create Session Error"})))},t.bianco.iiot.resetBadSession=function(){S.core.isInitializedBiancoIIoTNode(t)&&(t.bianco.iiot.sessionNodeRequests+=1,S.detailDebugLog("Session Node Requests At Connector No.: "+t.bianco.iiot.sessionNodeRequests),t.showErrors&&S.internalDebugLog("!!!!!!!!!!!!!!!!!!!!!   BAD SESSION ON CONNECTOR   !!!!!!!!!!!!!!!!!!".bgWhite.red),t.bianco.iiot.sessionNodeRequests>t.maxBadSessionRequests&&(S.internalDebugLog("Reset Bad Session Request On State "+t.bianco.iiot.stateMachine.getMachineState()),t.bianco.iiot.resetOPCUAConnection("ToManyBadSessionRequests")))},t.bianco.iiot.isInactiveOnOPCUA=function(){var e=t.bianco.iiot.stateMachine.getMachineState();return"STOPPED"===e||"END"===e||"RENEW"===e||"RECONFIGURED"===e},t.bianco.iiot.resetOPCUAConnection=function(e){if(S.detailDebugLog(e+" Request For New OPC UA Connection"),S.core.isInitializedBiancoIIoTNode(t)){if(t.bianco.iiot.isInactiveOnOPCUA())return;t.bianco.iiot.stateMachine.lock().renew(),t.emit("reset_opcua_connection"),t.bianco.iiot.closeSession(function(){t.bianco.iiot.renewConnection(function(){S.detailDebugLog("OPC UA Connection Reset Done")})})}},t.bianco.iiot.closeSession=function(i){if(t.bianco.iiot.opcuaClient&&t.bianco.iiot.opcuaSession){S.detailDebugLog("Close Session And Remove Subscriptions From Session On State "+t.bianco.iiot.stateMachine.getMachineState());try{t.bianco.iiot.opcuaSession.removeAllListeners(),t.bianco.iiot.opcuaClient.closeSession(t.bianco.iiot.opcuaSession,t.bianco.iiot.hasOpcUaSubscriptions,function(e){e&&t.bianco.iiot.handleError(e),i()})}catch(e){t.bianco.iiot.handleError(e),i()}finally{t.bianco.iiot.opcuaSession=null}}else S.internalDebugLog("Close Session Without Session On State "+t.bianco.iiot.stateMachine.getMachineState()),i()},t.bianco.iiot.handleError=function(e){S.internalDebugLog("Handle Error On "+t.endpoint+" err: "+e),t.showErrors&&t.error(e,{payload:"Handle Connector Error"})},t.bianco.iiot.handleSessionClose=function(e){S.internalDebugLog("Session Closed With StatusCode "+e),t.bianco.iiot.isInactiveOnOPCUA()?S.detailDebugLog("Connector Is Not Active On OPC UA While Session Close Event"):(S.logSessionInformation(t),"SESSIONRESTART"!==t.bianco.iiot.stateMachine.getMachineState()&&t.bianco.iiot.stateMachine.lock().sessionclose())},t.bianco.iiot.disconnectNodeOPCUA=function(i){if(S.internalDebugLog("OPC UA Disconnect Connector On State "+t.bianco.iiot.stateMachine.getMachineState()),t.bianco.iiot.opcuaClient){S.internalDebugLog("Close Node Disconnect Connector From "+t.endpoint);try{t.bianco.iiot.opcuaClient.disconnect(function(e){e&&t.bianco.iiot.handleError(e),S.internalDebugLog("Close Node Done For Connector On "+t.endpoint),i()})}catch(e){t.bianco.iiot.handleError(e),i()}finally{t.bianco.iiot.opcuaClient=null}}else S.internalDebugLog("Close Node Done For Connector Without Client On "+t.endpoint),i()},t.on("close",function(e){if(t.removeAllListeners(),S.core.isInitializedBiancoIIoTNode(t))if(t.bianco.iiot.resetAllTimer(),t.bianco.iiot.isInactiveOnOPCUA())S.detailDebugLog("OPC UA Client Is Not Active On Close Node"),S.core.resetBiancoNode(t),e();else{S.detailDebugLog("OPC UA Client Is Active On Close Node With State "+t.bianco.iiot.stateMachine.getMachineState());var i=t.bianco.iiot.stateMachine.getMachineState();t.bianco.iiot.opcuaClient&&"CLOSE"!==i&&"SESSIONCLOSED"!==i?t.bianco.iiot.closeConnector(function(){S.core.resetBiancoNode(t),e()}):(S.internalDebugLog(t.bianco.iiot.stateMachine.getMachineState()+" -> !!!  CHECK CONNECTOR STATE ON CLOSE  !!!".bgWhite.red),S.core.resetBiancoNode(t),e())}else e()}),t.bianco.iiot.opcuaDisconnect=function(e){0<t.bianco.iiot.registeredNodeList.length?(S.internalDebugLog("Connector Has Registered Nodes And Can Not Close The Node -> Count: "+t.bianco.iiot.registeredNodeList.length),o&&(clearTimeout(o),o=null),o=setTimeout(function(){S.core.isInitializedBiancoIIoTNode(t)&&t.bianco.iiot.closeConnector(e)},t.connectionStopDelay)):t.bianco.iiot.opcuaDirectDisconnect(e)},t.bianco.iiot.opcuaDirectDisconnect=function(i){S.detailDebugLog("OPC UA Disconnect From Connector "+t.bianco.iiot.stateMachine.getMachineState()),t.bianco.iiot.disconnectNodeOPCUA(function(){t.bianco.iiot.stateMachine.lock().close();var e=t.bianco.iiot.stateMachine.getMachineState();S.detailDebugLog("Disconnected On State "+e),t.bianco.iiot.isInactiveOnOPCUA()||"CLOSED"===e||(console.log(e),i(),r(!1)),i()})},t.bianco.iiot.closeConnector=function(e){S.detailDebugLog("Close Connector "+t.bianco.iiot.stateMachine.getMachineState()),t.bianco.iiot.isInactiveOnOPCUA()?(S.detailDebugLog("OPC UA Client Is Not Active On Close Connector"),e()):t.bianco.iiot.opcuaClient?t.bianco.iiot.opcuaDisconnect(e):(S.detailDebugLog("OPC UA Client Is Not Valid On Close Connector"),e())},t.bianco.iiot.restartWithNewSettings=function(e,i){S.internalDebugLog("Renew With Flex Connector Request On State "+t.bianco.iiot.stateMachine.getMachineState()),t.bianco.iiot.stateMachine.lock().reconfigure(),t.bianco.iiot.setNewParameters(e),t.bianco.iiot.initCertificatesAndKeys(),t.bianco.iiot.renewConnection(i)},t.bianco.iiot.setNewParameters=function(e){t.discoveryUrl=e.discoveryUrl||t.discoveryUrl,t.endpoint=e.endpoint||t.endpoint,t.keepSessionAlive=e.keepSessionAlive||t.keepSessionAlive,t.securityPolicy=e.securityPolicy||t.securityPolicy,t.messageSecurityMode=e.securityMode||t.messageSecurityMode,t.name=e.name||t.name,t.showErrors=e.showErrors||t.showErrors,t.publicCertificateFile=e.publicCertificateFile||t.publicCertificateFile,t.privateKeyFile=e.privateKeyFile||t.privateKeyFile,t.defaultSecureTokenLifetime=e.defaultSecureTokenLifetime||t.defaultSecureTokenLifetime,t.endpointMustExist=e.endpointMustExist||t.endpointMustExist,t.autoSelectRightEndpoint=e.autoSelectRightEndpoint||t.autoSelectRightEndpoint,t.strategyMaxRetry=e.strategyMaxRetry||t.strategyMaxRetry,t.strategyInitialDelay=e.strategyInitialDelay||t.strategyInitialDelay,t.strategyMaxDelay=e.strategyMaxDelay||t.strategyMaxDelay,t.strategyRandomisationFactor=e.strategyRandomisationFactor||t.strategyRandomisationFactor,t.requestedSessionTimeout=e.requestedSessionTimeout||t.requestedSessionTimeout,t.connectionStartDelay=e.connectionStartDelay||t.connectionStartDelay,t.reconnectDelay=e.reconnectDelay||t.reconnectDelay},t.bianco.iiot.resetOPCUAObjects=function(){S.detailDebugLog("Reset All OPC UA Objects"),t.bianco.iiot.sessionNodeRequests=0,t.bianco.iiot.opcuaClient&&t.bianco.iiot.opcuaClient.removeAllListeners(),t.bianco.iiot.opcuaClient=null,t.bianco.iiot.opcuaSession&&t.bianco.iiot.opcuaSession.removeAllListeners(),t.bianco.iiot.opcuaSession=null},t.bianco.iiot.subscribeFSMEvents=function(e){if(!S.core.isInitializedBiancoIIoTNode(t))throw Error("undefined state of node "+t.id);e.onIDLE=function(e,i,o){S.detailDebugLog("Connector IDLE Event FSM"),t.bianco.iiot.resetOPCUAObjects()},e.onINITOPCUA=function(e,i,o){S.detailDebugLog("Connector Init OPC UA Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&(t.bianco.iiot.resetOPCUAObjects(),t.bianco.iiot.resetAllTimer(),t.bianco.iiot.initCertificatesAndKeys(),n&&(clearTimeout(n),n=null),S.detailDebugLog("connecting OPC UA with delay of msec: "+t.connectionStartDelay),n=setTimeout(function(){if(S.core.isInitializedBiancoIIoTNode(t))try{t.bianco.iiot.connectOPCUAEndpoint()}catch(e){t.bianco.iiot.handleError(e),t.bianco.iiot.resetOPCUAObjects(),t.bianco.iiot.stateMachine.lock().stopopcua()}},t.connectionStartDelay),t.emit("connector_init"))},e.onOPEN=function(e,i,o){S.detailDebugLog("Connector Open Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&(S.internalDebugLog("Client Connected To "+t.endpoint),S.detailDebugLog("Client Options "+JSON.stringify(t.bianco.iiot.opcuaClientOptions)),t.bianco.iiot.startSession("Open Event"),t.emit("connection_started",t.bianco.iiot.opcuaClient))},e.onSESSIONREQUESTED=function(e,i,o){S.detailDebugLog("Connector Session Request Event FSM")},e.onSESSIONACTIVE=function(e,i,o){S.detailDebugLog("Connector Session Active Event FSM"),t.bianco.iiot.sessionNodeRequests=0,t.emit("session_started",t.bianco.iiot.opcuaSession)},e.onSESSIONCLOSED=function(e,i,o){S.detailDebugLog("Connector Session Close Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&(t.bianco.iiot.opcuaSession=null),t.emit("session_closed")},e.onSESSIONRESTART=function(e,i,o){S.detailDebugLog("Connector Session Restart Event FSM"),t.emit("session_restart")},e.onCLOSED=function(e,i,o){S.detailDebugLog("Connector Client Close Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&(t.bianco.iiot.opcuaClient&&t.bianco.iiot.opcuaClient.removeAllListeners(),t.bianco.iiot.opcuaClient=null),t.emit("connection_closed")},e.onLOCKED=function(e,i,o){S.detailDebugLog("Connector Lock Event FSM")},e.onUNLOCKED=function(e,i,o){S.detailDebugLog("Connector Unlock Event FSM")},e.onSTOPPED=function(e,i,o){S.detailDebugLog("Connector Stopped Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&t.bianco.iiot.resetAllTimer(),t.emit("connection_stopped")},e.onEND=function(e,i,o){S.detailDebugLog("Connector End Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&t.bianco.iiot.resetAllTimer(),t.emit("connection_end")},e.onRECONFIGURED=function(e,i,o){S.detailDebugLog("Connector Reconfigure Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&t.bianco.iiot.resetAllTimer(),t.emit("connection_reconfigure")},e.onRENEW=function(e,i,o){S.detailDebugLog("Connector Renew Event FSM"),S.core.isInitializedBiancoIIoTNode(t)&&t.bianco.iiot.resetAllTimer(),t.emit("connection_renew")}},t.bianco.iiot.resetAllTimer=function(){S.detailDebugLog("Reset All Timer"),n&&(clearTimeout(n),n=null),i&&(clearTimeout(i),i=null),o&&(clearTimeout(o),o=null)},t.bianco.iiot.registeredNodeList={},t.bianco.iiot.renewFiniteStateMachine=function(){t.bianco.iiot.stateMachine=null,t.bianco.iiot.stateMachine=S.createStatelyMachine(),r("IDLE"===t.bianco.iiot.stateMachine.getMachineState()),t.bianco.iiot.subscribeFSMEvents(t.bianco.iiot.stateMachine)},t.bianco.iiot.registerForOPCUA=function(e){e?(S.internalDebugLog("Register In Connector NodeId: "+e.id),S.core.isInitializedBiancoIIoTNode(t)?((t.bianco.iiot.registeredNodeList[e.id]=e).on("opcua_client_not_ready",function(){S.core.isInitializedBiancoIIoTNode(t)&&"END"!==t.bianco.iiot.stateMachine.getMachineState()&&t.bianco.iiot.resetBadSession()}),1===Object.keys(t.bianco.iiot.registeredNodeList).length&&(S.internalDebugLog("Start Connector OPC UA Connection"),t.bianco.iiot.renewFiniteStateMachine(),t.bianco.iiot.stateMachine.idle().initopcua())):S.internalDebugLog("Node Not Initialized With Bianco To Register In Connector")):S.internalDebugLog("Node Not Valid To Register In Connector")},t.bianco.iiot.deregisterForOPCUA=function(e,i){if(!e)return S.internalDebugLog("Node Not Valid To Deregister In Connector"),void i();if(e.removeAllListeners("opcua_client_not_ready"),S.core.isInitializedBiancoIIoTNode(t))if(S.internalDebugLog("Deregister In Connector NodeId: "+e.id),delete t.bianco.iiot.registeredNodeList[e.id],"STOPPED"!==t.bianco.iiot.stateMachine.getMachineState()&&"END"!==t.bianco.iiot.stateMachine.getMachineState())if(0===Object.keys(t.bianco.iiot.registeredNodeList).length)if(t.bianco.iiot.stateMachine.lock().stopopcua(),t.bianco.iiot.opcuaClient){S.detailDebugLog("OPC UA Direct Disconnect On Unregister Of All Nodes");try{t.bianco.iiot.opcuaClient.disconnect(function(e){e&&t.bianco.iiot.handleError(e),i()})}catch(e){t.bianco.iiot.handleError(e),i()}finally{t.bianco.iiot.opcuaClient.removeAllListeners()}}else i();else i();else i();else S.internalDebugLog("Node Not Initialized With Bianco To Deregister In Connector")}},{credentials:{user:{type:"text"},password:{type:"password"}}})}catch(e){S.internalDebugLog(e.message)}c.httpAdmin.get("/opcuaIIoT/client/discover/:id/:discoveryUrl",c.auth.needsPermission("opcua.discovery"),function(e,t){var n=c.nodes.getNode(e.params.id),a=decodeURIComponent(e.params.discoveryUrl);(S.internalDebugLog("Get Discovery Request "+JSON.stringify(e.params)+" for "+a),n)?a&&!a.includes("opc.tcp://")?t.json([]):(0,S.core.nodeOPCUA.perform_findServersRequest)(a,function(e,i){if(e)S.internalDebugLog("Perform Find Servers Request "+e),n.showErrors&&n.error(e,{payload:""}),t.json([]);else{var o=[];i.forEach(function(e){e.discoveryUrls.forEach(function(e){e.toString()!==a&&o.push(e.toString())})}),t.json(o)}}):(S.internalDebugLog("Get Discovery Request None Node "+JSON.stringify(e.params)),t.json([]))}),c.httpAdmin.get("/opcuaIIoT/client/endpoints/:id/:endpointUrl",c.auth.needsPermission("opcua.endpoints"),function(e,o){var t=c.nodes.getNode(e.params.id),i=decodeURIComponent(e.params.endpointUrl);if(S.internalDebugLog("Get Endpoints Request "+JSON.stringify(e.params)+" for "+i),t)if(i&&!i.includes("opc.tcp://"))o.json([]);else{var n=t.bianco.iiot.opcuaClientOptions.endpoint_must_exist;t.bianco.iiot.opcuaClientOptions.endpoint_must_exist=!1;var a=new S.core.nodeOPCUA.OPCUAClient(t.bianco.iiot.opcuaClientOptions);a.connect(i).then(function(){S.internalDebugLog("Get Endpoints Connected For Request"),a.getEndpoints(function(e,i){e?(t.showErrors&&t.error(e,{payload:""}),S.internalDebugLog("Get Endpoints Request Error "+e),o.json([])):(S.internalDebugLog("Sending Endpoints For Request"),o.json(i)),a.disconnect(function(){S.internalDebugLog("Get Endpoints Request Disconnect")}),t.bianco.iiot.opcuaClientOptions.endpoint_must_exist=n})}).catch(function(e){S.core.isInitializedBiancoIIoTNode(t)&&(t.bianco.iiot.opcuaClientOptions.endpoint_must_exist=n),S.internalDebugLog("Get Endpoints Request Error "+e.message),o.json([])})}else S.internalDebugLog("Get Endpoints Request None Node "+JSON.stringify(e.params)),o.json([])}),c.httpAdmin.get("/opcuaIIoT/plain/DataTypeIds",c.auth.needsPermission("opcuaIIoT.plain.datatypes"),function(e,i){i.json(I.toArray(I.invert(S.core.nodeOPCUA.DataTypeIds)))}),c.httpAdmin.get("/opcuaIIoT/plain/AttributeIds",c.auth.needsPermission("opcuaIIoT.plain.attributeids"),function(e,i){i.json(I.toArray(I.invert(S.core.nodeOPCUA.AttributeIds)))}),c.httpAdmin.get("/opcuaIIoT/plain/StatusCodes",c.auth.needsPermission("opcuaIIoT.plain.statuscodes"),function(e,i){i.json(I.toArray(I.invert(S.core.nodeOPCUA.StatusCodes)))}),c.httpAdmin.get("/opcuaIIoT/plain/ObjectTypeIds",c.auth.needsPermission("opcuaIIoT.plain.objecttypeids"),function(e,i){i.json(S.core.nodeOPCUA.ObjectTypeIds)}),c.httpAdmin.get("/opcuaIIoT/plain/VariableTypeIds",c.auth.needsPermission("opcuaIIoT.plain.variabletypeids"),function(e,i){i.json(S.core.nodeOPCUA.VariableTypeIds)}),c.httpAdmin.get("/opcuaIIoT/plain/ReferenceTypeIds",c.auth.needsPermission("opcuaIIoT.plain.referencetypeids"),function(e,i){i.json(S.core.nodeOPCUA.ReferenceTypeIds)}),c.httpAdmin.get("/opcuaIIoT/xmlsets/public",c.auth.needsPermission("opcuaIIoT.xmlsets"),function(e,i){var o=[];o.push(S.core.nodeOPCUA.di_nodeset_filename),o.push(S.core.nodeOPCUA.adi_nodeset_filename),o.push("public/vendor/opc-foundation/xml/Opc.ISA95.NodeSet2.xml"),o.push("public/vendor/opc-foundation/xml/Opc.Ua.Adi.NodeSet2.xml"),o.push("public/vendor/opc-foundation/xml/Opc.Ua.Di.NodeSet2.xml"),o.push("public/vendor/opc-foundation/xml/Opc.Ua.Gds.NodeSet2.xml"),o.push("public/vendor/harting/10_di.xml"),o.push("public/vendor/harting/20_autoid.xml"),o.push("public/vendor/harting/30_aim.xml"),i.json(o)}),c.httpAdmin.get("/opcuaIIoT/list/DataTypeIds",c.auth.needsPermission("opcuaIIoT.list.datatypeids"),function(e,i){var o,t=S.core.nodeOPCUA.DataTypeIds,n=I.toArray(I.invert(t)),a=[],c=!0,s=!1,r=void 0;try{for(var l,u=n[Symbol.iterator]();!(c=(l=u.next()).done);c=!0)o=l.value,a.push({nodeId:"i="+t[o],label:o})}catch(e){s=!0,r=e}finally{try{c||null==u.return||u.return()}finally{if(s)throw r}}i.json(a)}),c.httpAdmin.get("/opcuaIIoT/list/EventTypeIds",c.auth.needsPermission("opcuaIIoT.list.eventtypeids"),function(e,i){var o,t=S.core.nodeOPCUA.ObjectTypeIds,n=I.invert(t),a=I.filter(n,function(e){return-1<e.indexOf("Event")}),c=[],s=!0,r=!1,l=void 0;try{for(var u,d=a[Symbol.iterator]();!(s=(u=d.next()).done);s=!0)o=u.value,c.push({nodeId:"i="+t[o],label:o})}catch(e){r=!0,l=e}finally{try{s||null==d.return||d.return()}finally{if(r)throw l}}i.json(c)}),c.httpAdmin.get("/opcuaIIoT/list/InstanceTypeIds",c.auth.needsPermission("opcuaIIoT.list.instancetypeids"),function(e,i){var o,t=S.core.nodeOPCUA.ObjectTypeIds,n=S.core.nodeOPCUA.VariableTypeIds,a=I.toArray(I.invert(t)),c=I.toArray(I.invert(n)),s=[],r=!0,l=!1,u=void 0;try{for(var d,p=a[Symbol.iterator]();!(r=(d=p.next()).done);r=!0)o=d.value,s.push({nodeId:"i="+t[o],label:o})}catch(e){l=!0,u=e}finally{try{r||null==p.return||p.return()}finally{if(l)throw u}}var b=!0,g=!1,y=void 0;try{for(var C,h=c[Symbol.iterator]();!(b=(C=h.next()).done);b=!0)o=C.value,s.push({nodeId:"i="+t[o],label:o})}catch(e){g=!0,y=e}finally{try{b||null==h.return||h.return()}finally{if(g)throw y}}i.json(s)}),c.httpAdmin.get("/opcuaIIoT/list/VariableTypeIds",c.auth.needsPermission("opcuaIIoT.list.variabletypeids"),function(e,i){var o,t=S.core.nodeOPCUA.VariableTypeIds,n=I.toArray(I.invert(t)),a=[],c=!0,s=!1,r=void 0;try{for(var l,u=n[Symbol.iterator]();!(c=(l=u.next()).done);c=!0)o=l.value,a.push({nodeId:"i="+t[o],label:o})}catch(e){s=!0,r=e}finally{try{c||null==u.return||u.return()}finally{if(s)throw r}}i.json(a)}),c.httpAdmin.get("/opcuaIIoT/list/ReferenceTypeIds",c.auth.needsPermission("opcuaIIoT.list.referencetypeids"),function(e,i){var o,t=S.core.nodeOPCUA.ReferenceTypeIds,n=I.toArray(I.invert(t)),a=[],c=!0,s=!1,r=void 0;try{for(var l,u=n[Symbol.iterator]();!(c=(l=u.next()).done);c=!0)o=l.value,a.push({nodeId:"i="+t[o],label:o})}catch(e){s=!0,r=e}finally{try{c||null==u.return||u.return()}finally{if(s)throw r}}i.json(a)}),c.httpAdmin.get("/opcuaIIoT/list/FilterTypes",c.auth.needsPermission("opcuaIIoT.list.filterids"),function(e,i){var o=[];o.push({name:"dataType",label:"Data Type"}),o.push({name:"dataValue",label:"Data Value"}),o.push({name:"nodeClass",label:"Node Class"}),o.push({name:"typeDefinition",label:"Type Definition"}),o.push({name:"browseName",label:"Browse Name"}),o.push({name:"nodeId",label:"Node Id"}),i.json(o)})};
  //# sourceMappingURL=maps/opcua-iiot-connector.js.map
  