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

apiworks-astro-node-sdk

v1.0.0

Published

Node.js SDK for ApiWorks 星盘 API

Readme

apiworks-astro-node-sdk

Node.js SDK for ApiWorks 星盘 API(astro.apiworks.com)。简化调用星盘、八字、紫微、星宿、运势、AI 报告等接口的代码开发。

功能概览

  • 星盘 (Chart):本命盘、天象盘、行运盘、比较盘、组合盘、三限/次限/法达/日弧等
  • 星座 (Sign):我的星座、星座列表、星座配对
  • 运势 (Scope):日/周/月/年运势
  • 星象事件 (Event):行运星象事件
  • 紫微斗数 (Ziwei):本命盘、排盘、含解读的排盘
  • 星宿 (Naks):27 星宿关系
  • 八字 (Bazi):命盘、流盘、合盘、总结
  • 报告 (Report):桃花、周运、年运、合盘、财运等 AI 报告

安装

npm install apiworks-astro-node-sdk

或从源码安装(在项目目录下):

npm install
npm run build

依赖

  • Node.js >= 14
  • axios >= 1.6
  • zod >= 3.22

快速开始

基本用法

const { AstroCloudClient } = require('apiworks-astro-node-sdk');

// 创建客户端
const client = new AstroCloudClient({
  app_id: 'your-app-id',
  app_key: 'your-app-key'
});
// base_url 默认为 https://cloud.apiworks.com/open/astro,如需可传入 base_url 覆盖

// 本命盘
async function getNatalChart() {
  try {
    const resp = await client.chart_natal({
      birth_dt: '1990-08-14 12:00:00',
      tz: 8,
      longitude: 116.4074,
      latitude: 39.9042
    });
    
    if (resp.code === 0 && resp.data) {
      console.log(resp.data.house, resp.data.planet);
    }
  } catch (error) {
    console.error('Error:', error);
  }
}

getNatalChart();

TypeScript 用法

import { AstroCloudClient, SinglePointQry, ApiResp, AstroDataVo } from 'apiworks-astro-node-sdk';

// 创建客户端
const client = new AstroCloudClient({
  app_id: 'your-app-id',
  app_key: 'your-app-key'
});

// 本命盘
async function getNatalChart() {
  try {
    const qry: SinglePointQry = {
      birth_dt: '1990-08-14 12:00:00',
      tz: 8,
      longitude: 116.4074,
      latitude: 39.9042
    };
    
    const resp: ApiResp<AstroDataVo> = await client.chart_natal(qry);
    
    if (resp.code === 0 && resp.data) {
      console.log(resp.data.house, resp.data.planet);
    }
  } catch (error) {
    console.error('Error:', error);
  }
}

getNatalChart();

更多示例

八字命盘:

import { AstroCloudClient, BaziNatalQry, ApiResp, BaziNatalVO } from 'apiworks-astro-node-sdk';

const client = new AstroCloudClient({ app_id: '...', app_key: '...' });

async function getBaziNatal() {
  const qry: BaziNatalQry = {
    birth_dt: '1990-08-14 12:00:00',
    tz: 8,
    gender: 'male'
  };
  
  const resp: ApiResp<BaziNatalVO> = await client.bazi_natal(qry);
  if (resp.code === 0 && resp.data) {
    console.log(resp.data.pillars, resp.data.flow_decadal);
  }
}

getBaziNatal();

紫微本命盘:

import { AstroCloudClient, ZiweiNatalQry, ApiResp, ZiweiNatalVo } from 'apiworks-astro-node-sdk';

const client = new AstroCloudClient({ app_id: '...', app_key: '...' });

async function getZiweiNatal() {
  const qry: ZiweiNatalQry = {
    birth_dt: '1999-10-17 21:00:00',
    tz: 8,
    gender: 'female'
  };
  
  const resp: ApiResp<ZiweiNatalVo> = await client.ziwei_natal(qry);
  if (resp.code === 0 && resp.data) {
    console.log(resp.data.natal.palaces, resp.data.patterns);
  }
}

getZiweiNatal();

星宿关系:

import { AstroCloudClient, NaksQry, NaksBirthInfo, ApiResp, NaksVo } from 'apiworks-astro-node-sdk';

const client = new AstroCloudClient({ app_id: '...', app_key: '...' });

async function getNaksRelations() {
  const qry: NaksQry = {
    birth_info: {
      birth_dt: '1990-01-15 00:00:00',
      tz: 8
    },
    others_birth_info: [
      {
        birth_dt: '1992-03-20 00:00:00',
        tz: 8
      }
    ]
  };
  
  const resp: ApiResp<NaksVo> = await client.naks_relations(qry);
  if (resp.code === 0 && resp.data) {
    console.log(resp.data.natal_naks_info, resp.data.others_natal_relation);
  }
}

getNaksRelations();

双点星盘(行运/比较盘):

import { AstroCloudClient, DoublePointQry, TimeAndLocation, ApiResp, AstroDataVo } from 'apiworks-astro-node-sdk';

const client = new AstroCloudClient({ app_id: '...', app_key: '...' });

async function getTransitChart() {
  const qry: DoublePointQry = {
    user_list: [
      {
        birth_dt: '1990-08-14 12:00:00',
        tz: 8,
        longitude: 116.4,
        latitude: 39.9
      },
      {
        birth_dt: '2025-02-26 12:00:00',
        tz: 8,
        longitude: 116.4,
        latitude: 39.9
      }
    ]
  };
  
  // 行运盘
  const transitResp: ApiResp<AstroDataVo> = await client.chart_transit(qry);
  // 比较盘
  const comparisonResp: ApiResp<AstroDataVo> = await client.chart_comparison(qry);
  
  if (transitResp.code === 0 && transitResp.data) {
    console.log(transitResp.data.planet, transitResp.data.house);
  }
}

getTransitChart();

报告(桃花/合盘/周运等):

import { AstroCloudClient, RomanticCreateQry, TimeAndLocation, ApiResp, AstroReportVo } from 'apiworks-astro-node-sdk';

const client = new AstroCloudClient({ app_id: '...', app_key: '...' });

async function createRomanticReport() {
  const qry: RomanticCreateQry = {
    user_birth_point: {
      birth_dt: '1990-01-01 13:14:15',
      tz: 8,
      longitude: 116.4,
      latitude: 39.9
    },
    user_current_point: {
      birth_dt: '2025-11-26 13:14:15',
      tz: 8,
      longitude: 116.4,
      latitude: 39.9
    },
    user_id: 'user-123'
  };
  
  const resp: ApiResp<AstroReportVo> = await client.report_romantic(qry);
  if (resp.code === 0 && resp.data && resp.data.serial_no) {
    const serial_no = resp.data.serial_no; // 可用 report_get / report_get_html 拉取报告
    console.log('Report serial number:', serial_no);
  }
}

createRomanticReport();

API 响应格式

所有接口均返回 ApiResp<T> 类型,包含 codemsgdataexe_time 字段,其中 data 为与接口对应的响应类型(如 BaziNatalVONaksVoAstroDataVo 等):

const resp: ApiResp<BaziNatalVO> = await client.bazi_natal(qry);
if (resp.code === 0 && resp.data) {
  const data: BaziNatalVO = resp.data; // 强类型,IDE 可补全
  console.log(data.pillars);
}

验证 SDK 是否可用

用真实接口调用一次本命盘,确认网络与凭证正常:

# 在项目根目录,先安装依赖
npm install

# 设置你的 app_id / app_key 后执行(不要提交到仓库)
export APIWORKS_APP_ID="你的app_id"
export APIWORKS_APP_KEY="你的app_key"
node scripts/verify_sdk.ts

成功会打印 验证通过,SDK 可用。;若 code != 0 或报错,请检查凭证与网络。

项目结构

apiworks-astro-node-sdk/
├── src/
│   ├── apiworks_astro_sdk/
│   │   ├── models/
│   │   │   ├── common.ts     # ApiResp, TimeAndLocation
│   │   │   ├── requests.ts   # 各类请求模型
│   │   │   ├── responses.ts  # 各类响应模型
│   │   │   └── index.ts      # 模型导出
│   │   ├── client.ts         # AstroCloudClient
│   │   └── index.ts          # 客户端导出
│   └── index.ts              # 主导出
├── scripts/
│   └── verify_sdk.ts         # SDK 验证脚本
├── package.json
├── tsconfig.json
└── README.md

License

MIT