@heybox/hb-sdk 0.4.3 → 0.4.4

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @heybox/hb-sdk
2
2
 
3
- 黑盒外部小程序前端 SDK。业务页面运行在黑盒父容器创建的 iframe 沙盒中,通过这个 SDK 等待容器 ready、获取登录态、唤起登录、分享、读取窗口信息、使用隔离 storage,以及发起受控网络请求。
3
+ 黑盒外部小程序前端 SDK。业务页面运行在黑盒父容器创建的 iframe 沙盒中,通过这个 SDK 等待容器 ready、获取登录态、唤起登录、分享、展示基础 UI、使用设备能力、控制容器导航、读取窗口信息、使用隔离 storage,以及发起受控网络请求。
4
4
 
5
5
  ## 快速开始
6
6
 
@@ -110,6 +110,53 @@ await share.screenshot({
110
110
  });
111
111
  ```
112
112
 
113
+ ### 基础 UI
114
+
115
+ ```ts
116
+ import { ui } from '@heybox/hb-sdk';
117
+
118
+ await ui.showToast({
119
+ message: '保存成功',
120
+ status: 'success',
121
+ });
122
+
123
+ await ui.showLoading({
124
+ dismissible: true,
125
+ });
126
+
127
+ await ui.hideLoading();
128
+ ```
129
+
130
+ `showToast()` 的 `message` 会 trim 后发送给宿主,不能为空,最长 120 个字符;`status` 只支持 `success` 和 `error`,不传时展示普通文本 toast。loading 是全局单例,多次 `showLoading()` 会覆盖当前配置,`hideLoading()` 在未展示时也会成功。
131
+
132
+ ### 设备能力
133
+
134
+ ```ts
135
+ import { device } from '@heybox/hb-sdk';
136
+
137
+ await device.vibrate({
138
+ intensity: 'light',
139
+ delay: 0,
140
+ });
141
+
142
+ await device.setClipboard({
143
+ text: 'hello',
144
+ });
145
+ ```
146
+
147
+ `vibrate()` 的 `intensity` 默认为 `light`,还支持 `medium` 和 `heavy`;`delay` 默认为 `0`,必须是 `0..5000` 的整数毫秒。`setClipboard()` 第一版只支持文本写入,`text` 必须是非空字符串,最长 10000 个字符,不会自动 trim 写入内容,也不提供读取或清空剪贴板能力。
148
+
149
+ ### 导航控制
150
+
151
+ ```ts
152
+ import { navigation } from '@heybox/hb-sdk';
153
+
154
+ await navigation.reload();
155
+ await navigation.close();
156
+ ```
157
+
158
+ `navigation.close()` 请求宿主关闭当前小程序容器,`navigation.reload()` 请求宿主重载当前小程序页面/容器。调用后 JS 上下文可能被宿主销毁,不保证后续代码继续执行;这两个能力不接受 `reason`、`force`、`confirm` 或 `fallbackUrl` 等扩展参数。
159
+
113
160
  ### 窗口信息
114
161
 
115
162
  ```ts
@@ -307,7 +354,7 @@ CLI 登录态只供 CLI 命令访问黑盒接口时复用,不会注入 iframe
307
354
 
308
355
  - 调用模块能力前会自动等待 `ready()`,但业务仍建议在页面启动阶段显式 `await ready()`,便于集中处理握手失败。
309
356
  - `user.getInfo()` 不会触发登录;登录必须由业务在用户操作后调用 `auth.login()`。
310
- - 分享、截图、storage 和网络请求只开放稳定窄接口,不透传黑盒客户端内部协议参数。
357
+ - 分享、截图、UI、设备、导航、storage 和网络请求只开放稳定窄接口,不透传黑盒客户端内部协议参数。
311
358
  - `network.request()` 的 `validateStatus` 只在 SDK 本地执行,不会被序列化给父容器。
312
359
  - `on()` 返回取消监听函数;组件卸载或页面销毁时应主动取消监听。
313
360
  - 使用 `createMiniProgramSDK()` 创建独立实例后,不再需要时应调用 `destroy()`。
@@ -348,12 +395,12 @@ export default defineConfig({
348
395
 
349
396
  ## 导出
350
397
 
351
- 默认导出 `hbSDK`,包含 `ready`、`on`、`off`、`auth`、`user`、`share`、`viewport`、`storage`、`network`。
398
+ 默认导出 `hbSDK`,包含 `ready`、`on`、`off`、`auth`、`user`、`share`、`viewport`、`storage`、`network`、`ui`、`device`、`navigation`。
352
399
 
353
400
  常用命名导出:
354
401
 
355
402
  - `ready`、`on`、`off`
356
- - `auth`、`user`、`share`、`viewport`、`storage`、`network`
403
+ - `auth`、`user`、`share`、`viewport`、`storage`、`network`、`ui`、`device`、`navigation`
357
404
  - `createMiniProgramSDK`、`MiniProgramSDK`
358
405
  - `HbMiniProgramSDKError`、`HbMiniProgramNetworkError`
359
406
  - 各模块公开类型,例如 `MiniProgramNetworkRequestConfig`、`MiniProgramNetworkResponse`、`MiniProgramUserInfoResult`
@@ -5,7 +5,7 @@ var fs = require('node:fs/promises');
5
5
  var path = require('node:path');
6
6
  var require$$0 = require('fs');
7
7
  var require$$1 = require('path');
8
- var index = require('./index-ovy_xoLn.cjs');
8
+ var index = require('./index-Bboot1us.cjs');
9
9
  require('node:module');
10
10
  require('os');
11
11
  require('readline');
@@ -5,8 +5,8 @@ var fs = require('node:fs');
5
5
  var fs$1 = require('node:fs/promises');
6
6
  var path = require('node:path');
7
7
  var promises = require('node:readline/promises');
8
- var session = require('./session-BQs0wf65.cjs');
9
- var index = require('./index-ovy_xoLn.cjs');
8
+ var session = require('./session-DiyDXvXu.cjs');
9
+ var index = require('./index-Bboot1us.cjs');
10
10
  var node_crypto = require('node:crypto');
11
11
 
12
12
  var re = {exports: {}};
@@ -3328,7 +3328,7 @@ async function createDefaultCosClient(uploadToken) {
3328
3328
  };
3329
3329
  }
3330
3330
  async function loadCosConstructor() {
3331
- const cosModule = await Promise.resolve().then(function () { return require('./index-DQAFCtK1.cjs'); }).then(function (n) { return n.index; });
3331
+ const cosModule = await Promise.resolve().then(function () { return require('./index-D7-awGYB.cjs'); }).then(function (n) { return n.index; });
3332
3332
  return cosModule.default;
3333
3333
  }
3334
3334
  function formatSize(bytes) {
@@ -9,7 +9,7 @@ var node_url = require('node:url');
9
9
  var net = require('node:net');
10
10
  var node_http = require('node:http');
11
11
  var browser = require('./browser-RAy8e8cV.cjs');
12
- var index = require('./index-ovy_xoLn.cjs');
12
+ var index = require('./index-Bboot1us.cjs');
13
13
  require('node:process');
14
14
  require('node:buffer');
15
15
  require('node:util');
@@ -4,7 +4,7 @@ var fs$1 = require('node:fs');
4
4
  var fs = require('node:fs/promises');
5
5
  var os = require('node:os');
6
6
  var path = require('node:path');
7
- var index = require('./index-ovy_xoLn.cjs');
7
+ var index = require('./index-Bboot1us.cjs');
8
8
  require('node:module');
9
9
  require('path');
10
10
  require('os');
@@ -234,19 +234,19 @@ function requireArgument () {
234
234
 
235
235
  var command = {};
236
236
 
237
- const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-ovy_xoLn.cjs', document.baseURI).href)));
237
+ const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-Bboot1us.cjs', document.baseURI).href)));
238
238
  function __require$4() { return require$5("node:events"); }
239
239
 
240
- const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-ovy_xoLn.cjs', document.baseURI).href)));
240
+ const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-Bboot1us.cjs', document.baseURI).href)));
241
241
  function __require$3() { return require$4("node:child_process"); }
242
242
 
243
- const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-ovy_xoLn.cjs', document.baseURI).href)));
243
+ const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-Bboot1us.cjs', document.baseURI).href)));
244
244
  function __require$2() { return require$3("node:path"); }
245
245
 
246
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-ovy_xoLn.cjs', document.baseURI).href)));
246
+ const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-Bboot1us.cjs', document.baseURI).href)));
247
247
  function __require$1() { return require$2("node:fs"); }
248
248
 
249
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-ovy_xoLn.cjs', document.baseURI).href)));
249
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-Bboot1us.cjs', document.baseURI).href)));
250
250
  function __require() { return require$1("node:process"); }
251
251
 
252
252
  var help = {};
@@ -13092,7 +13092,7 @@ function readErrorMessage(error, options = {}) {
13092
13092
  }
13093
13093
 
13094
13094
  const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
13095
- const BUILT_CLI_VERSION = '0.4.3';
13095
+ const BUILT_CLI_VERSION = '0.4.4';
13096
13096
  const PACKAGE_JSON_CANDIDATES = [
13097
13097
  path.resolve(__dirname, '..', '..', 'package.json'),
13098
13098
  path.resolve(__dirname, '..', 'package.json'),
@@ -13249,31 +13249,31 @@ function createCommandLoggerResolver(options) {
13249
13249
  };
13250
13250
  }
13251
13251
  const defaultClearLoginStatus = async (...args) => {
13252
- const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-CoZhlwxt.cjs'); });
13252
+ const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-BQo2pIkq.cjs'); });
13253
13253
  return clearLoginStatus(...args);
13254
13254
  };
13255
13255
  const defaultLoginToHeybox = async (...args) => {
13256
- const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-CoZhlwxt.cjs'); });
13256
+ const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-BQo2pIkq.cjs'); });
13257
13257
  return loginToHeybox(...args);
13258
13258
  };
13259
13259
  const defaultPrintLoginStatus = async (...args) => {
13260
- const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-CoZhlwxt.cjs'); });
13260
+ const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-BQo2pIkq.cjs'); });
13261
13261
  return printLoginStatus(...args);
13262
13262
  };
13263
13263
  const defaultRunCreateCommand = async (...args) => {
13264
- const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-BV4h2BTs.cjs'); });
13264
+ const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-DAW1oAnH.cjs'); });
13265
13265
  return runCreateCommand(...args);
13266
13266
  };
13267
13267
  const defaultRunDeployCommand = async (...args) => {
13268
- const { runDeployCommand } = await Promise.resolve().then(function () { return require('./deploy-Bz0-WpHy.cjs'); }).then(function (n) { return n.deploy; });
13268
+ const { runDeployCommand } = await Promise.resolve().then(function () { return require('./deploy-BaLyuR1X.cjs'); }).then(function (n) { return n.deploy; });
13269
13269
  return runDeployCommand(...args);
13270
13270
  };
13271
13271
  const defaultRunDevCommand = async (...args) => {
13272
- const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-DgX88vaK.cjs'); });
13272
+ const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-BA_4fnzO.cjs'); });
13273
13273
  return runDevCommand(...args);
13274
13274
  };
13275
13275
  const defaultRunDoctorCommand = async (...args) => {
13276
- const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-BIZoQ6go.cjs'); });
13276
+ const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-Bbv8Lzu_.cjs'); });
13277
13277
  return runDoctorCommand(...args);
13278
13278
  };
13279
13279
  function resolveStandaloneLogger(options, verbose) {
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var index$2 = require('./index-ovy_xoLn.cjs');
3
+ var index$2 = require('./index-Bboot1us.cjs');
4
4
  var require$$0$2 = require('fs');
5
5
  var require$$2$1 = require('crypto');
6
6
  var require$$1$2 = require('path');
7
7
  var require$$0$3 = require('assert');
8
8
  var require$$4$2 = require('events');
9
9
  var require$$1$1 = require('util');
10
- var deploy = require('./deploy-Bz0-WpHy.cjs');
10
+ var deploy = require('./deploy-BaLyuR1X.cjs');
11
11
  var require$$0$5 = require('net');
12
12
  var require$$0$4 = require('url');
13
13
  var require$$2$2 = require('http');
@@ -2,9 +2,9 @@
2
2
 
3
3
  var node_crypto = require('node:crypto');
4
4
  var node_http = require('node:http');
5
- var session = require('./session-BQs0wf65.cjs');
5
+ var session = require('./session-DiyDXvXu.cjs');
6
6
  var browser = require('./browser-RAy8e8cV.cjs');
7
- var index = require('./index-ovy_xoLn.cjs');
7
+ var index = require('./index-Bboot1us.cjs');
8
8
  require('node:path');
9
9
  require('fs');
10
10
  require('constants');
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var path = require('node:path');
4
- var index = require('./index-ovy_xoLn.cjs');
4
+ var index = require('./index-Bboot1us.cjs');
5
5
  var require$$0$2 = require('fs');
6
6
  var require$$0 = require('constants');
7
7
  var require$$0$1 = require('stream');
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./cli-chunks/index-ovy_xoLn.cjs');
3
+ var index = require('./cli-chunks/index-Bboot1us.cjs');
4
4
  require('node:module');
5
5
  require('node:fs');
6
6
  require('node:fs/promises');