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

@cycleplatform/internal-api

v1.2.1

Published

An API client to utilize Cycle's Internal API (inside a container)

Downloads

15

Readme

Cycle Internal API Client For NodeJS

An API client for NodeJS to access Cycle's Internal API that is mounted inside every container running on the platform.

For detailed documentation, please see the official Cycle Docs

What is this library?

Inside every container running on Cycle, there is a Unix socket mounted at /var/run/cycle/api/api.sock. You can send HTTP requests over this socket to access information about the local environment, access secrets, certificates, and much more. This library is a client for NodeJS to make accessing the Internal API a breeze.

How do I use it?

This library can only be used from inside a container running on Cycle.

First, install this library using npm install @cycleplatform/internal-api. From there, you can utilize the different modules in order to access information about the platform.

For example, to fetch information about the hub this instance is running in, do:

import { Hub } from "@cycleplatform/internal-api";

async function test() {
  const resp = await Hub.getHub();

  if (!resp.ok) {
    throw new Error(
      `Unable to fetch hub: ${resp.error.title} - ${resp.error.detail}`
    );
  }

  console.log("My Hub: ", resp.value.data);
}

test();

For more detailed information, see the official docs at Cycle Docs.

Do I need to use Typescript?

Nope! Though you will miss out on many benefits it offers, such as logically ensuring you check for errors before attempting to use a payload.

If we modify our example above to remove error checking:

import { Hub } from "@cycleplatform/internal-api";

async function test() {
  const resp = await Hub.getHub();

  // This will produce an error in Typescript, because it can't guarantee that we received a valid response from the API.
  // If you're using plain Javascript, this will still execute, but if you get an error it will crash.
  console.log("My Hub: ", resp.value.data);
}

test();

Of course, use whichever you are most comfortable with/works for your project.

Testing

Due to the fact that this library is only usable from inside a container running on Cycle, and our CLI streaming tools aren't released yet, running npm test on this library will create a container complete with Jest and a suite of tests that can be uploaded and run on the platform. It is tagged as cycleplatform/internal-api-test. Please deploy onto Cycle and run it before submitting a PR.

Contributing

We accept issues and PRs from the community! This library is issued under an MIT license so feel free to pull and modify to your needs. Any and all feedback is greatly appreciated!