0.1.6 • Published 3 years ago

@hauslo/util-nats-client v0.1.6

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

@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 };
});

// ...
0.1.6

3 years ago

0.1.5

3 years ago