bjchy-udg-sdk 1.8.4 → 1.8.5

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.
Files changed (3) hide show
  1. package/README.md +11 -0
  2. package/package.json +1 -1
  3. package/src/index.js +13 -1
package/README.md CHANGED
@@ -587,3 +587,14 @@ curl -X POST https://udg.vule.cn/api/execute -H 'X-Admin-Key: <ADMIN_KEY>' -H 'C
587
587
  ```
588
588
 
589
589
  `keys` 也可写成 `[{"name":"street","direction":1}]`;方向支持 `1/-1/2d/2dsphere/text/hashed`;不传 `name` 时按 MongoDB 惯例生成索引名;重复创建幂等。`dropCollection` 删非空集合必须显式带 `force:true`(否则报错并告知集合内文档数)。
590
+
591
+ ## 已注册的网关服务(本地预发布 1.8.3-ykbg.0)
592
+
593
+ `await client.callService(service, operation, data, { db: 'mongo' })` 调用
594
+ `POST /api/services/<service>/<operation>`,沿用 SDK 的 appid、鉴权、续期和 EJSON。
595
+ 服务名和操作名必须为字母开头的字母数字或连字符,不能传任意 URL 或可执行代码。
596
+ `db` 缺省使用 `init.defaultDb`;网关仍须注册具体服务并执行租户授权。
597
+
598
+ 本次内置可选 YKBG 扩展(租户 wx7c21e61ce2640cff),支持 capabilities、function、external。
599
+ 普通 CRUD 仍使用 `client.database('mongo')`;syl 上传使用小程序 `wx.uploadFile`。
600
+ 扩展需要配套网关代码和 `YKBG_ENABLED=true`,不是现有已部署接口的保证。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bjchy-udg-sdk",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "description": "Universal Data Gateway SDK - 跨端统一数据访问(微信小程序 / Web / Node.js),API 兼容微信云开发",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
package/src/index.js CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
  const { Database } = require('./database')
25
25
  const { command, UdgRegExp } = require('./command')
26
- const { rawPost, postAuthed, fetchServerTime, UdgRequestError } = require('./request')
26
+ const { post, rawPost, postAuthed, fetchServerTime, UdgRequestError } = require('./request')
27
27
  const { AuthManager } = require('./auth')
28
28
  const { AiNamespace } = require('./ai')
29
29
  const { WxNamespace } = require('./wx')
@@ -160,6 +160,18 @@ class UdgClient {
160
160
  return new Database(this._ctx, dbKey || this._ctx.defaultDb)
161
161
  }
162
162
 
163
+ /** Call a gateway-registered service; no arbitrary URL or executable code. */
164
+ async callService(service, operation, data, options) {
165
+ if (!/^[a-z][a-z0-9-]*$/.test(service) || !/^[a-zA-Z][a-zA-Z0-9-]*$/.test(operation)) {
166
+ throw new Error('服务名或操作名不合法')
167
+ }
168
+ await ensureAppid(this._ctx)
169
+ return post(this._ctx, '/api/services/' + service + '/' + operation, {
170
+ db: (options && options.db) || this._ctx.defaultDb,
171
+ data: data === undefined ? {} : data
172
+ })
173
+ }
174
+
163
175
  /* ===================== 认证 ===================== */
164
176
 
165
177
  /**