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

@datatester/node-sdk

v1.1.4

Published

datatester node sdk

Downloads

25

Readme

Datatester分流Node.js SDK

使用及说明

import AbClient from '@datatester/node-sdk'
// const AbClient = require('@datatester/node-sdk').default

(async () => {
    // 在rangers应用管理中查询token信息
    const abClient = new AbClient('token')

    // 因为返回的是promise,业务使用上需要自己处理reject行为
    try {
        const conf = await abClient.activate('key', 'decisionId', 'trackId', new Map(), '')
        // 获取key版本配置
        const config = conf.val
    } catch(e) {
        console.error(e)
    }
})()

初始化参数

| 名词 | 类型 | 说明 | 备注 | --- | -- | -- | -- | token | string | app级别的token, 可以在rangers控制台应用列表中查询 | | metaHost| string | 获取meta数据服务host, 默认为AbClient.metaHost.cn | | trackHost| string | 上报实验曝光数据, 默认为AbClient.trackHost.cn | | interval| number | 元数据更新间隔时间,单位秒,默认60s | | metaType| string | 元数据类型, 可选值:'cdn', 'server', 'file' | 对文件读取一次,不会按照interval去更新数据 | metaFilePath| string | 元数据文件本地路径,使用前确保应用对文件有可读权限 | metaType==='file'时候才生效 | enableFile | boolean | 开启日志文件保存 | | dir | string | 日志写入的文件路径, 默认为当前应用启动的根路径, 确保应用对路径有写路径 | enableFile=true情况下日志写入路径, | maxSize | string | 文件最大值 https://github.com/iccicci/rotating-file-stream#size | | level | string | 需要记录的日志等级 可选值:'console','info', 'warn', 'error' | | formatter | function | 对日志做自定义格式化输出 | 参数请参照types/plugins/logger/TLog | | trackMaxNum | number | 一次上报的事件量个数,可选值1-50,默认每10秒会自动上报一次,一次上报50条

接口及参数

接口类型参照types/type.d.ts

参数说明

  • 入参

| 参数 | 类型 | 说明 | |-- | -- | -- | | interval | number | 元数据获取时间间隔 | | experimentId | string | 实验id | | decisionId | string | 决策ID, 分流口径, 和系统中设置的白名单数据行为一致 | | featureId | string | feature flag id | | trackId | string | 上报数据唯一标识 | | attributes | Map<string, any> | 分流的受众数据,和系统中设置的目标受众做比对 |

  • 返回值(TConfig)

| 参数 | 类型 | 说明 | |-- | -- | -- | | val | string | 元数据获取时间间隔 | | vid | string | 实验id | | entity_id | string | 决策ID, 分流口径, 和系统中设置的白名单数据行为一致 |

接口说明

| 接口 | 返回值 | 说明 | |-- | -- | -- | | getExperimentVariantName(experimentId: string, decisionId: string, attributes: Map<string, any>, options?: TOptions) | Promise<string> | 命中分流结果名称 | | getExperimentVariantNameWithInpression(experimentId: string, decisionId: string, trackId: string, attributes: Map<string, any>, options?: TOptions) | Promise<string> | 命中分流结果名称并曝光实验信息| | getExperimentConfigs(experimentId: string, decisionId: string, attributes: Map<string, any>, options?: TOptions) | Promise<TConfig> | 命中分流结果配置信息 | | getExperimentConfigsWithInpression(experimentId: string, decisionId: string, trackId: string, attributes: Map<string, any>, options?: TOptions) | Promise<TConfig> | 命中分流结果配置信息并曝光信息| | getAllExperimentConfigs(decisionId: string, attributes: Map<string, any>, options?: TOptions) | Promise<TConfig> | 获取app下所有实验命中分流结果配置 | | verifyFeatureEnabled(featureId: string, decisionId: string, attributes: Map<string, any>, options?: TOptions) | Promise<boolean> | 检验feature flag是否命中| | getFeatureConfigs(featureId: string, decisionId: string, attributes: Map<string, any>, options?: TOptions) | Promise<TConfig> | feature flag 分流结果配置 | | getFeatureConfigsWithInpression(featureId: string, decisionId: string, trackId: string, attributes: Map<string, any>, options?: TOptions) | Promise<TConfig> | feature flag 分流结果配置并曝光信息| | getAllFeatureConfigs(decisionId: string, attributes: Map<string, any>, options?: TOptions) | Promise<TConfig> | 命中的所有feature flag版本信息 | | getEnabledFeatureIds(decisionId: string, attributes: Map<string, any>, options?: TOptions) | Promise<string[]> | 获取所有命中的feature flag id| | activate(variantKey: string, decisionId: string, trackId: string, attributes: Map<string, any>, defaultValue: unkown, options?: TOptions) | Promise<{val: any}> | 根据key做分流,并上报实验信息; 返回逻辑:命中的实验信息 -> 命中的feature flag信息 -> 传入的默认值| | close() | void | 主动关闭所有元数据服务的schedule job| | setInterval(interval: number) | void | 动态调整获取元数据的间隔时间|

不同场景使用

自定义获取元数据和实验信息曝光地址

  • SaaS服务不同区域的配置
import AbClient from '@datatester/node-sdk'

// metaHost
// cn: AbClient.metaHost.cn 
// sg: AbClient.metaHost.sg
// va: AbClient.metaHost.va 

// trackHost
// cn: AbClient.trackHost.cn 
// sg: AbClient.trackHost.sg
// va: AbClient.trackHost.va 

const abSdk = new AbClient('token', {
    trackHost: AbClient.trackHost.sg
    metaHost: AbClient.metaHost.sg 
})
  • 私有化服务
import AbClient from '@datatester/node-sdk'
const abSdk = new AbClient('token', {
    trackHost: '' // 可访问到的上报http接口的host
    metaHost: ''// 可访问到的获取元数据http接口的host
})
  • 监听内部日志

sdk对外暴露了一个EventEmitter的实现,可以对sdk内部一些日志进行监听

// meta获取成功
abSdk.on('meta.success', data => {})
// meta获取失败
abSdk.on('meta.failure', error => {})
// ...