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

hc-service-client

v1.3.0-alpha.2

Published

Service Client Extension for Honeybee

Downloads

51

Readme

ServiceClient

hc-service-client

本项目支持两种用法,如下介绍为在honeybee extension中使用的方法。

直接使用ServiceClient请参考: 这里 !!!

在honeycomb extension中的例子

{
  extension: {
    serviceClient: {
      module: 'hc-service-client',
      config: {
        otm: {
          endpoint: 'http://otm.com/v2',
          accessKeySecret: 'xxx',
          headerExtension: ['otm']
        },
        azk: {
          endpoint: 'http://algorithm.com/',
          accessKeySecret: 'xxx',
          workApp: 'test',
          headerExtension: ['azk']
        },
        brain: {
          endpoint: 'http://brain_domain.com/',
          accessKeySecret: 'xxx',
          headerExtension: [
            function (req, serviceCfg) {
              return {
                'X-Access-User': req.session.id
              };
            }
          ]
        }
      }
    }
  }
}

配置详情如下。

配置

hc-service-client的配置结构:

{
  [serviceCode]: {
    endpoint,
    accessKeyId,
    accessKeySecret,
    signatureApproach,
    headerExtension,
    disableFileSignature,
    headers,
    timeout
  }
}

| options | desc | default | | -------------------- | ---------------------------------------- | --------- | | endpoint | 远程的endpoint | 必填 | | accessKeyId | 调用的用户标志 | anonymous | | accessKeySecret | 调用的签名密钥,原token/systemToken | 必填 | | signatureApproach | 签名方式 enum: [systemCall, userAuth] | 默认 systemCall | | disableFileSignature | 禁用文件签名 | false | | headerExtension | 根据环境动态修改header的扩展 | [] | | headers | 使用serviceClient的默认发送headers,优先级高于headerExtension | {} | | timeout | 请求的超时时间(单位ms) | 60000 | | signatureHeader | 签名请求头,默认 systemCall -> signature, userAuth -> Authorization | | | responseWrapper | 处理返回结果的function | 默认函数,返回结果result.code!== 'SUCCESS'时作为错误处理,否则将result.data作为结果返回,详见SERVICE_CLIENT文档responseWrapper参数介绍 |

headerExtension

其他参数介绍见 这里

headerExtension是一个数组,数组中元素支持动态扩展header,

支持

  • 函数, function (req, serviceCfg) ,返回 header
  • object,直接写header内容
  • 内置扩展, 'otm' 、 'azk' 、'gateway'

如:

{
  otm: {
    endpoint: 'http://xxx',
    accessKeyId: 'DonaldTrump',
    accessKeySecret: config.systemToken,
    headerExtension: [
      function (req, serviceCfg) {
        return {
          'X-Access-TenantCode': req.session.tenant || serviceCfg.defaultTenant
        };
      },
      {
        'X-Access-WorkApp': 'city_brain'
      },
      'otm'
    ]
  }
}

如上配置,三个类型返回的header会merge到一起,再最终请求时带上。

用法

const otm = req.getService('otm');
otm.get('/api/workspaces', {}, (err, data) => {});
const azk = req.getService('azk');
azk.get('/api/workspaces', {}, (err, data) => {});