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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polyv/request-plugin-polyv-business

v2.8.1

Published

用途:保利威业务数据插件,用于在请求中自动插入业务相关的参数。

Readme

PolyvBusinessRequestPlugin

用途:保利威业务数据插件,用于在请求中自动插入业务相关的参数。

PS:该插件仅适用于 api.polyv.net 下的接口

实例化参数

| 参数名 | 用途 | 类型 | 默认值 | | ------------------ | ------------------ | ---------- | ------ | | usePolyvBusiness | 是否使用业务数据 | boolean | true | | getBusinessData | 获取业务数据的方法 | function | - |

请求选项

| 参数名 | 用途 | 类型 | 默认值 | | ------------------ | ---------------- | ------------------- | ------ | | usePolyvBusiness | 是否使用业务数据 | boolean | true | | businessData | 业务数据 | PolyvBusinessData | - |

业务数据类型

PolyvBusinessData 类型如下:

| 参数名 | 用途 | 类型 | 默认值 | | ------------ | --------------- | -------- | ------ | | sourceType | 来源类型 | string | - | | sourceId | 来源 id | string | - | | channelId | 频道号 | string | - | | viewerId | 用户 id | string | - | | unionId | 用户系统唯一 id | string | - |

使用方式

import { PolyvRequest } from '@polyv/request-core';
import { PolyvBusinessRequestPlugin } from '@polyv/request-plugin-polyv-business';

// 自定义获取业务数据的方法
const requester = new PolyvRequest({
  requestPlugins: [
    new PolyvBusinessRequestPlugin({
      getBusinessData: async options => {
        // 可以在这里实现自定义的业务数据获取逻辑
        return {
          sourceType: 'yourSourceType',
          sourceId: 'yourSourceId',
          channelId: 'yourChannelId',
          viewerId: 'yourViewerId',
          unionId: 'yourUnionId',
        };
      },
    }),
  ],
});

// 在某个请求中禁用业务数据
requester.get(
  '/api/data',
  {},
  {
    usePolyvBusiness: false,
  },
);

// 在某个请求中使用特定的业务数据
requester.get(
  '/api/data',
  {},
  {
    businessData: {
      sourceType: 'specificSourceType',
      sourceId: 'specificSourceId',
    },
  },
);

保利威域名配置

提供 PickDomainInfo 范型生成域名配置类型,formatDomainInfo 格式化域名配置,如果没有传入相关的配置则使用内部默认值。

import { type PickDomainInfo } from '@polyv/request-plugin-polyv-business';

type MyDomainInfo = PickDomainInfo<'chatWsDomain' | 'chatApiDomain' | 'polyvApiDomain'>;

const myDomainInfo: MyDomainInfo = { ... };

formatDomainInfo(myDomainInfo).chatApiDomain;

插件处理逻辑

  1. 插件会在请求中自动插入业务相关的参数,如 sourceType、sourceId、channelId、viewerId、unionId 等
  2. 插件会根据请求的 URL 判断需要插入哪些参数:
    • 对于 /live/v4/watch/common 接口,插入 sourceType 和 sourceId
    • 对于 /live/v4/watch/viewer 接口,插入 sourceType、sourceId、viewerId 和 userId
    • 对于 /live/v4/channel 接口,插入 channelId
    • 对于其他接口,插入 channelId 和 viewerId
  3. 如果你使用了 @polyv/request-plugin-authorize-token 令牌插件,本插件会根据 URL 判断是否使用 token 和 tokenField:
    • 对于 /live/v4/watch/common 接口,会自动插入 useToken 为 false 禁用 token 插入
    • 对于 /live/v3 接口,会将 tokenField 设置为 token,其他接口设置为 viewerToken
import { PolyvRequest } from '@polyv/request-core';
import { AuthorizeTokenRequestPlugin } from '@polyv/request-plugin-authorize-token';
import { PolyvBusinessRequestPlugin } from '@polyv/request-plugin-polyv-business';

const requester = new PolyvRequest({
  baseUrl: 'https://api.polyv.net',
  requestPlugins: [
    new AuthorizeTokenRequestPlugin({
      getTokenInfo: () => {
        return {
          // 只需要传入 token 即可
          token: 'yourToken',
        };
      },
    }),
    new PolyvBusinessRequestPlugin({
      getBusinessData: async options => {
        // 可以在这里实现自定义的业务数据获取逻辑
        return {
          channelId: 'yourChannelId',
          viewerId: 'yourViewerId',
        };
      },
    }),
  ],
});

// 不会插入 token
requester.get('/live/v4/watch/common/xxx/xx/x', {});

// 会插入 token,token 字段为 'token'
requester.get('/live/v3/xxx/xx/x', {});

// 会插入 token,token 字段为 'viewerToken'
requester.get('/live/v4/xxx/xx/x', {});