How to use the @grpc/grpc-js.Metadata function in @grpc/grpc-js

To help you get started, we’ve selected a few @grpc/grpc-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LN-Zap / zap-desktop / lnd / util.js View on Github external
export const createMacaroonCreds = async macaroonPath => {
  const metadata = new Metadata()

  if (macaroonPath) {
    // If the macaroon is already in hex format, add as is.
    const isHex = /^[0-9a-fA-F]+$/.test(macaroonPath)
    if (isHex) {
      metadata.add('macaroon', macaroonPath)
    }
    // Otherwise, treat it as a file path - load the file and convert to hex.
    else {
      const macaroon = await readFile(macaroonPath).catch(e => {
        const error = new Error(`Macaroon path could not be accessed: ${e.message}`)
        error.code = 'LND_GRPC_MACAROON_ERROR'
        throw error
      })
      metadata.add('macaroon', macaroon.toString('hex'))
    }
github LN-Zap / node-lnd-grpc / src / utils / createMacaroonCreds.js View on Github external
const createMacaroonCreds = async macaroonPath => {
  const metadata = new Metadata()
  let lndMacaroon

  if (macaroonPath) {
    // If the macaroon is already in hex format, add as is.
    const isHex = /^[0-9a-fA-F]+$/.test(macaroonPath)
    if (isHex) {
      lndMacaroon = macaroonPath
    }
    // If it's not a filepath, then assume it is a base64url encoded string.
    else if (macaroonPath === basename(macaroonPath)) {
      lndMacaroon = decodeMacaroon(macaroonPath)
    }
    // Otherwise, treat it as a file path - load the file and convert to hex.
    else {
      const macaroon = await readFile(untildify(macaroonPath)).catch(e => {
        const error = new Error(`Macaroon path could not be accessed: ${e.message}`)
github googleapis / nodejs-pubsub / test / message-stream.ts View on Github external
cancel(): void {
    const status = {
      code: 1,
      details: 'Canceled.',
      metadata: new Metadata(),
    };

    process.nextTick(() => {
      this.emit('status', status);
      this.end();
    });
  }
  destroy(err?: Error): void {
github cjihrig / grpc-server-js / test / deadline.js View on Github external
it('works with deadlines', () => {
    const barrier = new Barrier();
    const metadata = new Grpc.Metadata();
    const {
      path,
      requestSerialize: serialize,
      responseDeserialize: deserialize
    } = client.unary;

    metadata.set('grpc-timeout', '100m');
    client.makeUnaryRequest(path, serialize, deserialize, {}, metadata, {}, (error, response) => {
      Assert.strictEqual(error.code, Grpc.status.DEADLINE_EXCEEDED);
      Assert.strictEqual(error.details, 'Deadline exceeded');
      barrier.pass();
    });

    return barrier;
  });
github cjihrig / grpc-server-js / test / server-credentials.js View on Github external
function altMetadataUpdater (serviceUrl, callback) {
        const metadata = new Grpc.Metadata();

        metadata.set('other_plugin_key', 'other_plugin_value');
        callback(null, metadata);
      }
github cjihrig / grpc-server-js / test / errors.js View on Github external
before(async () => {
    const trailerMetadata = new Grpc.Metadata();

    server = new Server();
    trailerMetadata.add('trailer-present', 'yes');

    server.addService(TestServiceClient.service, {
      unary (call, cb) {
        const req = call.request;

        if (req.error) {
          const details = req.message || 'Requested error';

          cb({
            code: Grpc.status.UNKNOWN,
            details
          }, null, trailerMetadata);
        } else {
github googleapis / nodejs-pubsub / src / message-stream.ts View on Github external
constructor(err: Error) {
    super(
      `Failed to connect to channel. Reason: ${
        process.env.DEBUG_GRPC ? err.stack : err.message
      }`
    );
    this.code = err.message.includes('deadline')
      ? status.DEADLINE_EXCEEDED
      : status.UNKNOWN;
    this.details = err.message;
    this.metadata = new Metadata();
  }
}
github grpc / grpc-web / net / grpc / gateway / examples / echo / node-server / server.js View on Github external
function copyMetadata(call) {
  var metadata = call.metadata.getMap();
  var response_metadata = new grpc.Metadata();
  for (var key in metadata) {
    response_metadata.set(key, metadata[key]);
  }
  return response_metadata;
}