@trimjs/web-app 0.6.0 → 0.6.1
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 +20 -38
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
SDK for building apps that run inside the Trim host environment.
|
|
4
4
|
|
|
5
|
-
`@trimjs/web-app` provides a single JavaScript API for common host capabilities, including page title updates, file operations, file authorization, app settings, and App Auth route flows. It works in supported web iframe hosts and mobile WebView hosts.
|
|
5
|
+
`@trimjs/web-app` provides a single JavaScript API for common host capabilities, including page title updates, file operations, file authorization, app settings, and App Auth route flows. It works in supported web iframe hosts, Trim Extension Host, and mobile WebView hosts.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -82,6 +82,23 @@ ready(): Promise<void>
|
|
|
82
82
|
|
|
83
83
|
Waits until the SDK initialization is complete. Most apps do not need to call this explicitly because SDK methods wait for initialization automatically.
|
|
84
84
|
|
|
85
|
+
### reconnectHost (optional)
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
reconnectHost(): Promise<void>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Retries Web host discovery after initialization failed or no host was found. Initialization already discovers hosts automatically, so most apps do not need this method. Use it for a “Retry connection” action when a host becomes available later, without reloading the page.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
await app.reconnectHost();
|
|
95
|
+
if (!app.isStandaloneWeb) {
|
|
96
|
+
// Explicitly retry the operation that needs the host.
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Completion does not guarantee that a host was found; check `isStandaloneWeb` after awaiting the call. Concurrent calls share one attempt. Existing connections and mobile runtimes are left unchanged. This method does not refresh login sessions or replay failed business requests.
|
|
101
|
+
|
|
85
102
|
### setTitle
|
|
86
103
|
|
|
87
104
|
```ts
|
|
@@ -508,7 +525,7 @@ Indicates whether the current runtime is a web host.
|
|
|
508
525
|
isStandaloneWeb: boolean;
|
|
509
526
|
```
|
|
510
527
|
|
|
511
|
-
Indicates whether the current runtime is a standalone browser page without
|
|
528
|
+
Indicates whether the current runtime is a standalone browser page without a connected host. Read this after initialization or a reconnection attempt completes.
|
|
512
529
|
|
|
513
530
|
## Types
|
|
514
531
|
|
|
@@ -568,45 +585,10 @@ type AppBridgeResponse<T> = {
|
|
|
568
585
|
|
|
569
586
|
## Platform Notes
|
|
570
587
|
|
|
571
|
-
The SDK normalizes supported host APIs across web iframe hosts and mobile WebView hosts. Some APIs may require a recent host version. When an API is unavailable, the SDK throws an error or returns `undefined` depending on the method behavior.
|
|
588
|
+
The SDK normalizes supported host APIs across web iframe hosts, Trim Extension Host, and mobile WebView hosts. Web pages automatically probe for Trim Extension Host; iframe pages try their parent host first. Top-level pages enter standalone browser mode if no host is found before discovery times out. Some APIs may require a recent host version. When an API is unavailable, the SDK throws an error or returns `undefined` depending on the method behavior.
|
|
572
589
|
|
|
573
590
|
For route-based App Auth flows, use `openAppAuth()` to start the flow and `parseAppAuthCallback()` on the callback page to read the result.
|
|
574
591
|
|
|
575
592
|
## License
|
|
576
593
|
|
|
577
594
|
MIT
|
|
578
|
-
## Desktop 官方应用会话凭据(0.5.0)
|
|
579
|
-
|
|
580
|
-
`getHostCapabilities()` 返回宿主运行环境和协议能力,不代表应用已获授权。
|
|
581
|
-
`getSessionCredentials()` 无授权参数,仅支持 Desktop 中通过宿主核验的官方内嵌应用。
|
|
582
|
-
每次调用读取所属账号的当前会话,返回 `{ code: 0, msg: '', data: { secret, token? } }`。
|
|
583
|
-
应用应仅在当前请求中使用结果,不缓存、不打印、不写入 localStorage。
|
|
584
|
-
|
|
585
|
-
失败返回 `code: 1`、`data: null` 和稳定 `error`:`NOT_SUPPORTED`、`FORBIDDEN`、
|
|
586
|
-
`SESSION_UNAVAILABLE` 或 `CONNECTION_CLOSED`。握手及调用超时有界;Desktop 失败不得回退
|
|
587
|
-
到浏览器存储。普通 Web 继续使用原有存储方案,手机仍使用 `getUserMessage`。
|
|
588
|
-
认证和静默续期由 Desktop 负责,SDK 不新增自动保存、重试或登录提示。
|
|
589
|
-
|
|
590
|
-
本能力需要新版 Desktop 宿主;旧宿主、独立浏览器和手机不提供本能力。
|
|
591
|
-
旧 SDK 可继续使用新版宿主已有方法,但不会自动获得新的保存能力。
|
|
592
|
-
0.5.0 已发布到 npm,下游可安装正式版本。
|
|
593
|
-
|
|
594
|
-
## 顶层页面与扩展宿主
|
|
595
|
-
|
|
596
|
-
顶层 Web 页面也会探测 Trim Extension Host。iframe 优先连接原生宿主,
|
|
597
|
-
未连接时再探测扩展;移动端继续使用现有 UA 判定和桥接。
|
|
598
|
-
没有安装扩展时,顶层页面在探测超时后进入独立网页模式。
|
|
599
|
-
|
|
600
|
-
若首次未发现宿主,可在同一个实例上重新探测:
|
|
601
|
-
|
|
602
|
-
```ts
|
|
603
|
-
await app.reconnectHost();
|
|
604
|
-
await app.ready();
|
|
605
|
-
if (!app.isStandaloneWeb) {
|
|
606
|
-
// 重新发起之前失败的业务请求。
|
|
607
|
-
}
|
|
608
|
-
```
|
|
609
|
-
|
|
610
|
-
`reconnectHost()` 合并并发重试,保留已建立的宿主连接,不自动重放业务请求,
|
|
611
|
-
也不负责刷新 NAS 登录态。扩展登录与本地 HTTP 代理认证是两条链路:
|
|
612
|
-
扩展不会自动向 localhost 同步 NAS Cookie,本地联调需单独配置认证。
|