New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nuclia/protobuf

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuclia/protobuf

JavaScript utility to handle Nuclia protobuffer messages

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
3
Weekly downloads
 
Created
Source

@nuclia/protobuf

JavaScript utility to handle Nuclia protobuffer messages.

Functions

  • NucliaProtobufConverter is a function accepting a buffer and returning a Promise that resolves to a parsed protobuffer message.

  • extractParagraphTexts is a function adding to each Paragraph object a text attribute containing the actual text of the paragraph (by default, Paragraph objects only contain the position of their first and last characters).

Installation

npm install @nuclia/protobuf

or

yarn add @nuclia/protobuf

Usage

When using a webhook with the Nuclia Understanding API, the message sent to the webhook is a protobuffer message. It can be decoded using the NucliaProtobufConverter.

import { NucliaProtobufConverter } from '@nuclia/protobuf';

router.post('/handle', (request, response) => {
  NucliaProtobufConverter(request.body).then((message) => {
    console.log(message);
  });
});

When calling Nuclia Understanding API /pull endpoint, you get a JSON message containing a payload entry with base64 encoded protobuffer message. Processing it could be done as follows:

import { NucliaProtobufConverter } from '@nuclia/protobuf';
import fetch from 'node-fetch';

fetch('https://europe-1.nuclia.cloud/api/v1/processing/pull', {
  headers: {
    'x-stf-nuakey': `Bearer ${NUA_KEY}`,
    'content-type': 'application/json',
  },
  method: 'GET',
})
  .then((res) => res.json())
  .then((data) => {
    if (data.status === 'ok' && data.payload) {
      return NucliaProtobufConverter(Buffer.from(data.payload, 'base64'));
    } else {
      return data;
    }
  })
  .then((res) => console.log(res));

To get paragraphs text, you can use the extractParagraphTexts function:

import { NucliaProtobufConverter, extractParagraphTexts } from '@nuclia/protobuf';

router.post('/handle', (request, response) => {
  NucliaProtobufConverter(request.body).then((message) => {
    console.log(extractParagraphTexts(message).fieldMetadata[0].metadata.metadata.paragraphs);
  });
});

FAQs

Package last updated on 07 Dec 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc