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

@relaycorp/awala-endpoint-internet

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@relaycorp/awala-endpoint-internet

JS library to make it easier for a server-side app to exchange messages with the Awala Internet Endpoint

  • 1.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-93.75%
Maintainers
0
Weekly downloads
 
Created
Source

@relaycorp/awala-endpoint-internet

High-level JS library to process Awala Internet Endpoint-compatible CloudEvents.

Convert incoming CloudEvent to service message

To convert an incoming service message wrapped in a CloudEvent, simply call makeIncomingServiceMessage.

For example, the following Fastify route accepts CloudEvents in binary mode and the converts them to service messages:

import { CloudEventV1, HTTP } from 'cloudevents';
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';

export async function registerEventReceiver(server: FastifyInstance): Promise<void> {
  // Accept any content type
  server.removeAllContentTypeParsers();
  server.addContentTypeParser('*', { parseAs: 'buffer' }, (_req, payload, next) => {
    next(null, payload);
  });

  server.post('/', async (request, reply) => {
    let event: CloudEventV1<Buffer>;
    try {
      event = HTTP.toEvent({ headers: request.headers, body: request.body });
    } catch (err) {
      // Malformed CloudEvent
      return reply.status(400).send({ reason: err.message });
    }

    const message = makeIncomingServiceMessage(event);
    request.log.info({ parcelId: message.parcelId }, 'Incoming service message');

    return reply.status(204).send();
  });
}

Convert outgoing service message to CloudEvent

To convert an outgoing service message to a CloudEvent, simply call makeOutgoingCloudEvent.

For example:

import { makeOutgoingCloudEvent, OutgoingServiceMessage } from '@relaycorp/awala-endpoint-internet';

const outgoingServiceMessage: OutgoingServiceMessage = {
  recipientId: '<Insert Awala endpoint id of recipient>',
  contentType: 'application/vnd.your-company.your-service.Greeting',
  data: Buffer.from('Hello, world!'),
};
const outgoingEvent = makeOutgoingCloudEvent(outgoingServiceMessage);

Finally, send the outgoingEvent to the Awala Internet Endpoint using your cloudevents emitter. For example:

import { httpTransport, emitterFor } from 'cloudevents';

const emit = emitterFor(httpTransport('https://cloudevents-broker.com'));
emit(event);

API documentation

See API documentation.

Keywords

FAQs

Package last updated on 21 Sep 2024

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