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

@chuyik/open-platform-plugin

v1.2.2

Published

TSW 开放平台插件

Downloads

2

Readme

TSW 开放平台插件

Install

yarn add @tswjs/open-platform-plugin

Usage

在项目的 TSW 配置文件中,进行如下引用:

const OpenPlatformPlugin = require("@tswjs/open-platform-plugin");

module.exports = {
  plugins: [
    new OpenPlatformPlugin({
      appid: "tsw1431",
      appkey: "PwPaD4RRAsrSdRZjQSc3fbKM",
      reportStrategy: "always",
      // 只支持同步写法
      getUid: (request) => {
        const cookie = request.headers.cookie;

        if (!cookie) return;

        const uid = /quid=([^;]*);?/g.exec(cookie);
        return uid ? uid[2] : '';
      },
      // 同步或者异步函数
      getProxyInfo: () => {
        return {
          "port": 80,
          "name": "2.0demo",
          "group": "TSW",
          "groupName": "TSW团队",
          "desc": "2.0demo测试环境",
          "order": 30,
          "owner": "demoUser",
          "alphaList": ["demoUser"]
        };
      },
      // 请求回调函数
      hooks: {
        // 请求开始前回调,返回 false 则提前返回
        beforeStart(payload) {
          const { req, context } = payload
          if (req.method === 'HEAD') return false
        },
        // 结束开始前回调,返回 false 则提前返回
        beforeFinish(payload) {
          const { req, context } = payload
          if (req.method === 'HEAD') return false
        },
      },
    })
  ]
};

Config

appid

  • String
  • 必填

项目在 TSW 开放平台 申请的应用 id。

appkey

  • String
  • 必填

项目在 TSW 开放平台 申请的应用 key。

reportStrategy

  • "always" | "never" | "proxied"
  • 选填
  • 默认值:proxied

always,表示在任何情况下都上报日志数据。 never,表示在任何情况下都不上报日志数据。 proxied,表示在被代理时上报数据。

getUid

  • () => string 同步函数
  • 选填
  • 默认值:() => {}

从每个请求中提取用户 uid

getProxyInfo

  • Function 同步或者异步函数
  • 选填
  • 默认值 () => {}

返回值如果为 undefined,表示这台机器不被允许通过代理到达。

hooks.beforeStart

  • Function 同步函数
  • 选填

返回值如果为 false,则不做 uid 提取和匹配检查。

hooks.beforeFinish

  • Function 同步函数
  • 选填

返回值如果为 false,则跳过上报逻辑。

如果返回一个对象,那么根据对象参数不同有几种情况:

{
  "port": 80,
  "name": "2.0demo",
  "group": "TSW",
  "groupName": "TSW团队",
  "desc": "2.0demo测试环境",
  "order": 30,
  "owner": "demoUser",
  "alphaOnly": false,
  "alphaList": ["demoUser"]
}

alphaOnly

  • 默认为 false
  • 若值为 false,认为这台机器会被注册到开放平台上,可以通过在开放平台上配置代理到达。
  • 若值为 true,认为这台机器只是负责染色号码以记录日志。不可从开放平台配置代理。一般生产环境开启此参数。

alphaList

表示本机希望抓包的用户列表,值的比对对象是 getUid 方法返回值。

alphaList.includes(getUid())