npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@peak-ai/ais-service-discovery

v1.0.0

Published

## Description This repository interfaces Service Discovery, in this instance CloudMap, in order to locate and communicate with different services. As opposed to storing ARN's in environment variables, this library will interface CloudMap to find a servic

Downloads

1,023

Readme

Cloud Application Framework

Description

This repository interfaces Service Discovery, in this instance CloudMap, in order to locate and communicate with different services. As opposed to storing ARN's in environment variables, this library will interface CloudMap to find a service by a user friendly naming convention, and will understand what 'type' of service you've requested, and use the correct code to communicate/call that service.

Services supported

  • Lambda (request|call).
  • SNS (publish). // subscribe not supported by SNS.
  • SQS (queue|listen),
  • Automation//SSM task (automate | script).
  • Step function (state-machine).

Examples:

Import

const ServiceDiscovery = require('@peak-ai/ais-service-discovery');

Call a function

await ServiceDiscovery.request('namespace.service->handler',  body);

Publish an SNS event

await ServiceDiscovery.publish('namspace.service-name->topic', event, {
  ...opts,
  attributes: { // Matches params.MessageAttributes from aws-sdk
    tenant: {
      DataType: 'String',
      StringValue: 'foo',
    },
  },
});

Add message to queue

await ServiceDiscovery.queue('namespace.service-name->queue-name', message, opts // optional);

List to queue

const messages = await ServiceDiscovery.listen('namespace.service-name->queue-name', opts // optional);
messages.on('message', (message) => {

});

Register a service (Cloudformation)

CloudMapService:
  Type: AWS::ServiceDiscovery::Service
  Properties:
    Description: discover handlers for ais-service-segment-explorer
    Name: segment-explorer
    NamespaceId: ${cf:ais-${opt:stage}-service-discovery.NamespaceId}

CreateRefreshSegmentInstance:
  Type: "AWS::ServiceDiscovery::Instance"
  Properties:
    InstanceAttributes:
      arn: ${self:service}-${opt:stage}-refresh-segment
      type: function
    InstanceId: refresh-segment
    ServiceId:
      Ref: CloudMapService

Upcoming Beta version

We're releasing an update which allows you to configure and write modular 'backends' for the core service discovery library.

In this new version we're also introducing Typescript.

For example (previous):

const ServiceDiscovery = require('@peak-ai/ais-service-discovery-js');
ServiceDiscovery.request('latest.service->instance', request);

The above example only deals with AWS, and there's no way to reconfigure this behaviour.

This is fairly limiting, especially for testing locally. We came up with the idea of being able to 'mock' or 'stub' these requests locally, for a faster development process.

New example:

import { WithMockedBackend, WithAWSBackend } from "@peak-ai/ais-service-discovery-js";

// Config to decide what to do locally
const config = {
  "latest.service->instance": {
    resolver: { mockedResponse: { message: 'Hello World' } },
  },
};

// Responds with mocked responses
const local = WithMockedBackend(config);
const res = await local.request('latest.service->instance', request);

// Communicates via SQS
const prod = WithAWSBackend();
await prod.queue('latest.service->instance', request);

Integration Tests

Prerequisites

  1. AWS Account Access
  2. Run the infrastructure CDK plan, found in ./examples/infrastructure (follow the instructions in the README there).
  3. Ensure you have your AWS_PROFILE, and AWS_REGION env vars set correctly.

Run integration tests

$ yarn run test:integration