@hauslo/util-nats-client
v0.1.6
Published
```js const Log = require("debug"); const { start, NatsClient } = require("@hauslo/util-nats-client");
Downloads
1
Readme
@hauslo/util-nats-client
const Log = require("debug");
const { start, NatsClient } = require("@hauslo/util-nats-client");
const namespace = "authorization-svc";
const log = Log(namespace);
Log.enable(namespace);
const { stop, client: nats } = start({
config: {
namespace
urls: ["nats://nats:4222"]
}
log,
options: {}
});
const client = new NatsClient({ client: nats, namespace, service: true });
client.respond("user.role", "grant", async (metadata = { auth }, message = { user, service }) => {
if (!auth?.service){
throw new Error("Unauthorized");
}
// ...
return { user, service };
});
// ...