@cortexapps/plugin-core

中文文档
3.1.0发布于 2026/04/21MITESM + CJS近 30 天下载 5901

Core helpers for creating a Cortex plugin

原始使用文档
文档目录9 节
  1. CortexApi
  2. pluginInit
  3. proxyFetch
  4. Using proxyFetch with octokit
  5. getContext
  6. Component library
  7. Deprecation and Migration from 2.x
  8. Component details
  9. Available components

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(), getContext() and pluginInit().

pluginInit

Call pluginInit() as early as possible to trigger the iframe host to inject theme styles into your plugin.

Parameters

None

Returns

void

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

nametypedescription
inputRequestInputSee browser fetch
infoRequestInfoSee 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

nametypedescription
entityCortexEntity?Details about the entity associated with the page the plugin is being rendered if applicable, otherwise null. See Cortex Entity for more details.
locationPluginContextLocationWhich location type this plugin is being rendered. Location for more details.
userCortexUserSee 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

Deprecation and Migration from 2.x

The component library is deprecated for versions >=3.0.0 and only critical fixes will be supported. Please use https://www.npmjs.com/package/@cortexapps/react-plugin-ui for React components and documentation.

To help in your migration, plugin-core/components have been converted to use react-plugin-ui, but it requires some steps to fully migrate:

  1. Install both @cortexapps/[email protected] and @cortexapps/[email protected] as dependencies
  2. Include import "@cortexapps/react-plugin-ui/index.css"; global styling
  3. When your application boots, call CortexApi.pluginInit(); to subscribe to theme changes
  4. Be sure that your plugin is utilizing <PluginProvider> context wrapper. This provides dark/light mode classes on <body>

These steps should enable your component to switch between dark/light modes and visually match our component styling.

The new styling applies CSS resets to base elements (such as ul/li)--some minor visual adjustments may be required in some areas of your plugin if they are affected.

Component details

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.

版本与发布记录

@cortexapps/plugin-core 共发布 41 个版本,首次发布于 2023/04/22;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.1.0latest2026/04/216 个月前
3.0.02025/04/281.5 年前
3.0.0-beta.5beta2025/04/221.6 年前
3.0.0-beta.42025/04/081.6 年前
3.0.0-beta.32025/04/081.6 年前
3.0.0-beta.22025/04/081.6 年前

其他发布通道:alpha → 3.0.0-alpha.3,beta → 3.0.0-beta.5。

关于 @cortexapps/plugin-core 的常见问题

@cortexapps/plugin-core 是什么?

Core helpers for creating a Cortex plugin

如何安装 @cortexapps/plugin-core?

在项目目录运行 npm install @cortexapps/plugin-core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cortexapps/plugin-core 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cortexapps__plugin-core 是否存在。

@cortexapps/plugin-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cortexapps/plugin-core 可以商用吗?

@cortexapps/plugin-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cortexapps/plugin-core 的下载量有多少?

根据 npm 官方下载统计,@cortexapps/plugin-core 在 2026/10/11 – 2026/11/09 这 30 天内被下载 5,901 次,日均约 197 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cortexapps/plugin-core 还在维护吗?

最新版本 3.1.0 发布于 2026/04/21(6 个月前);至今共发布 41 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/04/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。