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

@cortexapps/plugin-core

v2.3.3

Published

Core helpers for creating a Cortex plugin

Downloads

6,125

Readme

semantic-release: angular

@cortexapps/plugin-core

This package provides an easy-to-use bridge between Cortex plugins and the Cortex web app.

Install it with

yarn add @cortexapps/plugin-core

or

npm install @cortexapps/plugin-core

CortexApi

The primary entity exposed is CortexApi, which has the methods proxyFetch() and getContext().

proxyFetch

NOTE: As of 1.3.0, the global fetch method is monkey patched to call proxyFetch() under the hood. This means that you can use fetch() as you normally would in a Cortex plugin and it will automatically be proxied through Cortex.

proxyFetch provides a method for plugins to make API requests through a Cortex proxy in order to avoid browser CORS restrictions and securely add authentication. Its signature is nearly identical to the native browser fetch() method, but some properties have been flattened for transfer across the iframe bridge.

Parameters

| name | type | description | | ----- | ------------ | --------------------------------------------------------------------------- | | input | RequestInput | See browser fetch | | info | RequestInfo | See browser fetch |

Returns

Promise<ShimResponse> - nearly identical to browser response. See source code for more details.

Example

import { CortexApi } from '@cortexapps/plugin-core';

const commentOnPullRequest = async ({
  comment: string,
  owner: string,
  pullNumber: string | number,
  repo: string,
}) => {
  const response = await CortexApi.proxyFetch(
    `https://api.github.com/${owner}/${repo}/pulls/${pullNumber}/comments`,
    {
      body: comment,
      method: 'POST',
    }
  );

  return response.json();
};

Using proxyFetch with octokit

NOTE: As of 1.3.0, using an octokit plugin (or adjusting other libraries) is not necessary as the global fetch method is shimmed by default.

Use the octokitPlugin to easily use octokit in a Cortex plugin.

import { CortexApi, octokitPlugin } from '@cortexapps/plugin-core';
import { Octokit, type RestEndpointMethodTypes } from "@octokit/rest";

const CortexOctokit = Octoki.plugin(octokitPlugin);

const getWorkflow = async (options: {
  id: number;
  owner: string;
  repo: string;
}): Promise<
  RestEndpointMethodTypes["actions"]["getWorkflow"]["response"]["data"]
> {
  const { owner, repo, id } = options;
  const octokit = new CortexOctokit({ CortexApi });

  const workflow = await octokit.actions.getWorkflow({
    owner,
    repo,
    workflow_id: id,
  });

  return workflow.data;
};

getContext

NOTE: As of 1.2.0, context is also available via the useCortexContext hook.

Parameters

None

Returns

| name | type | description | | -------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | entity | CortexEntity? | Details about the entity associated with the page the plugin is being rendered if applicable, otherwise null. See Cortex Entity for more details. | | location | PluginContextLocation | Which location type this plugin is being rendered. Location for more details. | | user | CortexUser | See Cortex User for more details. |

Example

import { CortexApi } from '@cortexapps/plugin-core';

const getCurrentUser = async () => {
  const response = await CortexApi.getContext();
  const resJson = await response.json();

  return resJson.user;
};

Component library

Check out the component library in Storybook by running it locally with yarn storybook.

Import your components from @cortexapps/plugin-core/components to use them in the app.

import React from 'react';
import { Button } from '@cortexapps/plugin-core/components';

interface SubmitButtonProps extends React.PropsWithChildren;

const SubmitButton: React.FC<SubmitButtonProps> = ({ children }) => {
  return (
    <Button type="submit">{children}</Button>
  );
};

export default SubmitButton;

Available components

  • Anchor
  • Badge
  • Box
  • Breadcrumb
  • Button
  • Card
  • Checkbox
  • Clickable
    • A convenient wrapper for rendering an <a> or a <button> (depending on the props) without the typical <a> or <button> styling
  • Dropdown
  • FancyToggle
  • FormLabel
  • an icon set (courtesy of Phosphor icons)
  • Input
  • Label
  • LinearPercentage
  • List
  • Loader
  • Logo
    • This is the Cortex logo!
  • Modal
  • Pill
  • Portal
    • You probably don't need to worry about this one -- this is what we use internally for rendering modals and similar
  • ProgressBar
  • Stack
    • A super useful component for applying even spacing between children
  • Tabs
  • Tag
  • Text
  • Title
  • Toggle
  • Typeahead

See the typings and Storybook for more details.