
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
happner-client
Advanced tools
The client for happner-2 and happner cluster services.
npm install happner-client
var HappnerClient = require('happner-client');
var client = new HappnerClient({
requestTimeout: 10 * 1000, // (default) milliseconds timeout on api request (set ack)
responseTimeout: 20 * 1000, // (default) timeout awaiting response
logger: null // (defualt) optional happner-logger
});
var optionalInfo = {
// meta data for login
///////////////////// in $origin
}
client.connect(
{ // connection
host: 'localhost',
port: 55000
},
{ // options
protocol: 'https',
username: '_ADMIN',
password: 'happn',
allowSelfSignedCerts: true,
info: {}
}
).then(...).catch(...); // also supports callback
// connection can be defaulted (eg. in browser)
client.connect(null, {username: '_ADMIN', password: 'happn'}, function (e) {
})
client.on('connected', function () {
// event fired on successful connection to server
});
client.on('reconnected', function () {
// event fired on successful reconnection to server
});
client.on('disconnected', function () {
// event fired when disconnected from server
});
client.on('reconnecting', function () {
// event fired when attempting to reconnect
});
client.on('error', function (e) {
// includes model verification mismatches
});
var kitchenModel = {
fridge: {
version: '^1.0.0', // requires that server has matching version of fridge component
methods: {
getTemperature: {
// optional parameters for clientside validation
params: [
{name: 'shelves', type: 'array'}
]
}
}
}
};
var kitchen = client.construct(kitchenModel);
// with callback
kitchen.exchange.fridge.getTemperature(['top', 'middle'], function (e, temps) {});
// with promise
kitchen.exchange.fridge.getTemperature(['top', 'middle'])
.then(function (temps) {})
.catch(function (e) {})
kitchen.event.fridge.on('/eventName', function (data) {});
NB: this will only work if you connect before you construct
//initialize the client with discover Methods true
const client = new HappnerClient({ discoverMethods: true });
//set up your model, declaring which components you wish to discover
var model = {
component1: {
version: '^1.0.0'
//no need for method declarations
},
component2: {
version: '^1.0.0'
//no need for method declarations
}
};
//on connection the remote mesh schema will be pulled
await client.connect(null, {
username: '_ADMIN',
password: 'xxx'
});
//on construct the components in the model will be updated with the available methods
const createdApi = createdClient.construct(model);
await createdApi.component1.discoveredMethod();
//assuming we have connected
//var client = new HappnerClient(...
//client.connect(...
var dataClient = client.dataClient();
//dataClient is the underlying happn-3 client for the happner-client connection, so you have all the happn-3 goodness:
dataClient.on('/test/point', function(data){
}).then(...);
dataClient.set('/test/point', {my: 'data'}).then(...)
dataClient.get('/test/point').then(...)
dataClient.remove('/test/point').then(...)
see this test for a full demonstration
Assuming served from happner-2 packaged /api/client
script
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- includes Happner.HappnerClient -->
<script src="/api/client"></script>
</head>
<body>
<script>
var client = new Happner.HappnerClient({
requestTimeout: 10 * 1000,
responseTimeout: 20 * 1000
});
var model = {
'component': {
version: '^2.0.0',
methods: {
method1: {}
}
}
};
var api = client.construct(model);
client.connect()
.then(function () {
// subscribe to events (requires connected)
api.event.component.on('test/event', function (data, meta) {
console.log('EVENT', meta.path);
});
})
.catch(function (error) {
console.error('connection error', error);
});
// repeat call on exchange
setInterval(function () {
api.exchange.component.method1()
.then(function (reply) {
console.log('REPLY', reply);
})
.catch(function (error) {
console.error('ERROR', error);
});
}, 1000);
</script>
</body>
</html>
FAQs
The client for happner-2 and happner cluster services
The npm package happner-client receives a total of 161 weekly downloads. As such, happner-client popularity was classified as not popular.
We found that happner-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.