apaas-oapi-client 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ name: Node.js CI & Publish
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ build-test-publish:
9
+ runs-on: ubuntu-latest
10
+
11
+ strategy:
12
+ matrix:
13
+ node-version: [22.x]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+
18
+ - name: Use Node.js ${{ matrix.node-version }}
19
+ uses: actions/setup-node@v3
20
+ with:
21
+ node-version: ${{ matrix.node-version }}
22
+ registry-url: 'https://registry.npmjs.org/'
23
+
24
+ - name: Install dependencies
25
+ run: npm install
26
+
27
+ - name: Build
28
+ run: npm run build
29
+
30
+ - name: Run Tests
31
+ run: npm test
32
+
33
+ - name: Debug npm token
34
+ run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc && cat ~/.npmrc
35
+
36
+ - name: Publish to npm
37
+ run: npm publish --access public
38
+ env:
39
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0] - 2025-06-30
6
+ ### Added
7
+ - 🎉 初始化 aPaaS OpenAPI Node.js SDK
8
+ - ✅ 获取 accessToken
9
+ - ✅ records 查询(支持分页迭代)
10
+ - ✅ record 单条查询
11
+ - ✅ record 单条更新、批量更新
12
+ - ✅ record 单条删除、批量删除
13
+ - ✅ 内置 Bottleneck 限流器
14
+ - ✅ 自定义日志等级
15
+
16
+ ---
17
+
18
+ ## [Unreleased]
19
+ - ✨ 新功能开发中...
package/README.md CHANGED
@@ -0,0 +1,27 @@
1
+ # apaas-oapi-client
2
+
3
+ [![npm version](https://img.shields.io/npm/v/apaas-oapi-client.svg)](https://www.npmjs.com/package/apaas-oapi-client)
4
+ [![license](https://img.shields.io/npm/l/apaas-oapi-client.svg)](LICENSE)
5
+
6
+ 🚀 **aPaaS OpenAPI Node.js 客户端 SDK**
7
+
8
+ 封装 aPaaS 平台 RESTful API 的 Node.js SDK,简化接口调用,内置限流与 token 缓存功能。
9
+
10
+ ---
11
+
12
+ ## ✨ **功能特性**
13
+
14
+ - ✅ 获取 accessToken
15
+ - ✅ records 查询(支持分页迭代)
16
+ - ✅ record 单条查询
17
+ - ✅ record 单条更新、批量更新
18
+ - ✅ record 单条删除、批量删除
19
+ - ✅ 内置 Bottleneck 限流器
20
+ - ✅ 自定义日志等级
21
+
22
+ ---
23
+
24
+ ## 📦 **安装**
25
+
26
+ ```bash
27
+ npm install apaas-oapi-client
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var dayjs = require('dayjs');
4
4
  var axios = require('axios');
5
+ var Bottleneck = require('bottleneck');
5
6
 
6
7
  /**
7
8
  * 日志等级枚举
@@ -16,7 +17,32 @@ var LoggerLevel;
16
17
  LoggerLevel[LoggerLevel["trace"] = 5] = "trace";
17
18
  })(LoggerLevel || (LoggerLevel = {}));
18
19
 
19
- const { functionLimiter } = require('./limiter');
20
+ /**
21
+ * 默认 apaas 限流配置
22
+ */
23
+ const apaasLimiterOptions = {
24
+ minTime: 200, // 每秒最多发起 5 个数据库操作
25
+ reservoir: 20, // 最多同时查询 50 个数据库操作
26
+ reservoirRefreshAmount: 20, // 每次查询完毕后,重置为 50 个数据库操作
27
+ reservoirRefreshInterval: 1000 // 重置时间间隔为 1 秒
28
+ };
29
+ /**
30
+ * 创建限流器
31
+ * @param fn 被限流函数
32
+ * @param options 自定义限流配置
33
+ * @returns 包装后的限流函数
34
+ */
35
+ async function functionLimiter(fn, options = {}) {
36
+ const limiter = new Bottleneck({
37
+ minTime: options.minTime || apaasLimiterOptions.minTime,
38
+ reservoir: options.reservoir || apaasLimiterOptions.reservoir,
39
+ reservoirRefreshAmount: options.reservoirRefreshAmount || apaasLimiterOptions.reservoirRefreshAmount,
40
+ reservoirRefreshInterval: options.reservoirRefreshInterval || apaasLimiterOptions.reservoirRefreshInterval
41
+ });
42
+ const wrapped = limiter.wrap(fn);
43
+ return wrapped();
44
+ }
45
+
20
46
  /**
21
47
  * aPaaS OpenAPI 客户端
22
48
  */
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "exports": {
5
- "./node-sdk": "./dist/index.js"
5
+ "./node-sdk": "./dist/index.js",
6
+ ".": "./dist/index.js"
6
7
  },
7
8
  "main": "dist/index.js",
8
9
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import dayjs from 'dayjs';
2
2
  import axios, { AxiosInstance } from 'axios';
3
3
  import { LoggerLevel } from './logger';
4
- const { functionLimiter } = require('./limiter');
4
+ import { functionLimiter } from './limiter';
5
5
 
6
6
  /**
7
7
  * Client 初始化配置