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

hjs-client

v0.1.0

Published

JavaScript client for HJS API

Downloads

11

Readme

HJS JavaScript 客户端

License: MIT

适用于 HJS API 的 JavaScript 客户端库 — 一个结构化事件追溯服务。

📦 安装

从 GitHub 安装(当前)

npm install https://github.com/schchit/hjs-api/tree/main/client-js

🚀 快速开始

const HJSClient = require('hjs-client');

const client = new HJSClient('https://hjs-api.onrender.com');

async function example() {
  // 记录一次判断
  const record = await client.recordJudgment(
    '[email protected]',
    'loan_approved',
    { amount: 100000 }
  );
  console.log('✅ 记录成功:', record);

  // 根据 ID 查询
  const judgment = await client.getJudgment(record.id);
  console.log('✅ 查询成功:', judgment);
}

example();

📚 API 说明

new HJSClient(baseURL)

创建客户端实例。baseURL 默认指向 https://hjs-api.onrender.com

recordJudgment(entity, action, scope)

记录一次判断。返回 { id, status, timestamp }

| 参数 | 类型 | 必填 | 说明 | |------|------|------|------| | entity | string | ✅ | 做出判断的主体 | | action | string | ✅ | 判断的动作 | | scope | object | ❌ | 附加信息(如金额、权限等) |

getJudgment(id)

根据 ID 获取判断记录。

🧪 测试

cd /workspaces/hjs-api/test-client
node test.js

预期输出:

✅ 记录成功: { id: 'jgd_...', status: 'recorded', timestamp: '...' }
✅ 查询成功: { id: 'jgd_...', entity: '[email protected]', action: 'test_action', ... }

📘 TypeScript 使用示例

客户端包含完整的 TypeScript 类型定义。以下是一个完整的示例:

安装

npm install /workspaces/hjs-api/client-js
# 或发布后:
# npm install hjs-client

示例代码

import HJSClient from 'hjs-client';

const client = new HJSClient('https://hjs-api.onrender.com');

async function runTest() {
  try {
    // 记录一次判断
    console.log('🧪 测试 recordJudgment...');
    const record = await client.recordJudgment(
      '[email protected]',
      'test_action',
      { test: true, source: 'typescript-test' }
    );
    
    console.log('✅ 记录成功:', record);
    console.log('   ID:', record.id);
    console.log('   状态:', record.status);  // TypeScript 知道这里只能是 'recorded'

    // 查询判断记录
    console.log('\n🧪 测试 getJudgment...');
    const judgment = await client.getJudgment(record.id);
    
    console.log('✅ 查询成功:', judgment);
    console.log('   主体:', judgment.entity);
    console.log('   动作:', judgment.action);
    console.log('   范围:', judgment.scope);
    console.log('   记录时间:', judgment.recorded_at);

  } catch (error) {
    if (error instanceof Error) {
      console.error('❌ 测试失败:', error.message);
    }
  }
}

runTest();

预期输出

🧪 测试 recordJudgment...
✅ 记录成功: { id: 'jgd_...', status: 'recorded', timestamp: '...' }

🧪 测试 getJudgment...
✅ 查询成功: { 
  id: 'jgd_...', 
  entity: '[email protected]', 
  action: 'test_action', 
  scope: { test: true, source: 'typescript-test' },
  timestamp: '...', 
  recorded_at: '...' 
}

类型定义

客户端导出以下类型:

interface JudgmentRecord {
  id: string
  status: 'recorded'
  timestamp: string
}

interface FullJudgment extends JudgmentRecord {
  entity: string
  action: string
  scope: Record<string, any>
  recorded_at: string
}