@tbox.cn/app-miniapp-container-alipay 0.2.0 → 0.2.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-miniapp-container-alipay",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "tbox 支付宝小程序容器:web-view 承载智能体 H5 + JSAPI 桥代理(通用 my.xxx 透传 + 录音/媒体特殊处理)。tbox-app miniapp-container init 的展开源。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@mini-types/alipay": "^3.0.14",
|
|
26
|
-
"@tbox.cn/app-sdk": "0.
|
|
26
|
+
"@tbox.cn/app-sdk": "0.20.0",
|
|
27
27
|
"typescript": "5.9.3",
|
|
28
28
|
"vitest": "4.1.10"
|
|
29
29
|
},
|
package/pages/ai-agent/index.ts
CHANGED
|
@@ -374,8 +374,14 @@ Page<AiAgentPageData, AiAgentPageExtraThis>({
|
|
|
374
374
|
// 真实厂商壳接入后此分发可删(仅本地联调脚手架)。
|
|
375
375
|
if (apiName === 'getLoginState') {
|
|
376
376
|
const serverBase = resolveH5Base(DEFAULT_H5_BASE, this.query);
|
|
377
|
+
// 会话 β:H5 调用方身份透传(mock enroll 声明主体——翻的是 H5 将续签的同一 guest;
|
|
378
|
+
// 真实厂商 gate 无此 query,仅本地脚手架消费)
|
|
379
|
+
const gateUserId = params?.userId;
|
|
380
|
+
const gateQuery = typeof gateUserId === 'string' && gateUserId
|
|
381
|
+
? `&userId=${encodeURIComponent(gateUserId)}`
|
|
382
|
+
: '';
|
|
377
383
|
this.openAwaitEventNavigateTo(message, {
|
|
378
|
-
url: `/pages/mock-enrollment/index?serverBase=${encodeURIComponent(serverBase)}`,
|
|
384
|
+
url: `/pages/mock-enrollment/index?serverBase=${encodeURIComponent(serverBase)}${gateQuery}`,
|
|
379
385
|
awaitEvent: 'login',
|
|
380
386
|
});
|
|
381
387
|
return;
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
* 转发 webViewContext.postMessage(receipt) → H5 门禁状态机按 loginStatus 收场。
|
|
11
11
|
* 生产/真实厂商壳接入后此页可删(仅本地联调脚手架)。
|
|
12
12
|
*
|
|
13
|
-
* enroll 回调 best-effort
|
|
14
|
-
*
|
|
13
|
+
* enroll 回调 best-effort:统一登录令牌链(POST /api/auth/login {method:'browser'} 拿
|
|
14
|
+
* guest JWT → Bearer 调 mock enroll 路由翻 H5 侧同一访客的会员态——userId 经 gate query
|
|
15
|
+
* 透传,T11 收口:缺省 = 调用方身份)任一步失败忽略——非 mock 档 enroll 路由 404 属预期
|
|
15
16
|
* (mock 路由不在该部署),回执仍按用户操作发出(降级路径与真实链一致)。
|
|
16
17
|
*/
|
|
17
|
-
import { buildMockLoginReceipt,
|
|
18
|
+
import { buildMockLoginReceipt, buildLoginUrl, buildEnrollUrl } from './receipt';
|
|
18
19
|
|
|
19
20
|
interface MockEnrollmentPageExtraThis {
|
|
20
21
|
query: Record<string, string>;
|
|
@@ -46,17 +47,18 @@ Page<Record<string, never>, MockEnrollmentPageExtraThis>({
|
|
|
46
47
|
},
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
|
-
* best-effort 会员态翻转:
|
|
50
|
-
*
|
|
50
|
+
* best-effort 会员态翻转:browser 轴登录拿 guest JWT → Bearer 调 mock enroll 路由,
|
|
51
|
+
* body.userId = H5 调用方身份(gate query 透传;缺省 = 调用方自身)。全部失败忽略——
|
|
52
|
+
* 回执语义只由按钮决定。
|
|
51
53
|
*/
|
|
52
54
|
async enrollMockMemberBestEffort() {
|
|
53
|
-
const
|
|
55
|
+
const loginUrl = buildLoginUrl(this.query.serverBase);
|
|
54
56
|
const enrollUrl = buildEnrollUrl(this.query.serverBase);
|
|
55
|
-
if (!
|
|
57
|
+
if (!loginUrl || !enrollUrl) return;
|
|
56
58
|
try {
|
|
57
|
-
const login = await myRequestJson(
|
|
59
|
+
const login = await myRequestJson(loginUrl, {
|
|
58
60
|
method: 'POST',
|
|
59
|
-
data: {
|
|
61
|
+
data: { method: 'browser' },
|
|
60
62
|
timeout: 3000,
|
|
61
63
|
});
|
|
62
64
|
const token = (login as { token?: unknown } | null)?.token;
|
|
@@ -64,7 +66,9 @@ Page<Record<string, never>, MockEnrollmentPageExtraThis>({
|
|
|
64
66
|
await myRequestJson(enrollUrl, {
|
|
65
67
|
method: 'POST',
|
|
66
68
|
headers: { Authorization: `Bearer ${token}` },
|
|
67
|
-
data:
|
|
69
|
+
data: typeof this.query.userId === 'string' && this.query.userId
|
|
70
|
+
? { userId: this.query.userId }
|
|
71
|
+
: {},
|
|
68
72
|
timeout: 3000,
|
|
69
73
|
});
|
|
70
74
|
} catch {
|
|
@@ -31,8 +31,8 @@ export function buildEnrollUrl(serverBase: unknown): string {
|
|
|
31
31
|
return `${serverBase.replace(/\/+$/, '')}/api/m/provider-mock/demo/member-enroll`;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
export function
|
|
34
|
+
/** 统一登录 URL 构造(browser 轴;与 buildEnrollUrl 同源判定;非 http(s) → '') */
|
|
35
|
+
export function buildLoginUrl(serverBase: unknown): string {
|
|
36
36
|
if (typeof serverBase !== 'string' || !/^https?:\/\//.test(serverBase)) return '';
|
|
37
|
-
return `${serverBase.replace(/\/+$/, '')}/api/auth/
|
|
37
|
+
return `${serverBase.replace(/\/+$/, '')}/api/auth/login`;
|
|
38
38
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* mock 登录门禁页纯函数测试(入会体验闭环 C6):
|
|
3
3
|
* - 三动作回执形态(对齐真实厂商 getLoginState 窄面:loginStatus/message 门控信号);
|
|
4
|
-
* -
|
|
4
|
+
* - 统一登录 / enroll URL 构造(serverBase 归一 + 非法值跳过网络链)。
|
|
5
5
|
* 页 index.ts 含 Page() 调用不可直测(沿 mock-payment 无页测先例——网络/回执链由
|
|
6
6
|
* E2E 手动清单覆盖);special-case 分发锁在 bridge.test 的 url 构造语义。
|
|
7
7
|
*/
|
|
8
8
|
import { describe, expect, it } from 'vitest';
|
|
9
|
-
import { buildMockLoginReceipt,
|
|
9
|
+
import { buildMockLoginReceipt, buildLoginUrl, buildEnrollUrl } from '../pages/mock-enrollment/receipt';
|
|
10
10
|
|
|
11
11
|
describe('buildMockLoginReceipt(getLoginState 门禁回执)', () => {
|
|
12
12
|
it('confirm → success(hasLogin=true,对齐 gate 登录+开卡一体语义)', () => {
|
|
@@ -38,16 +38,16 @@ describe('buildMockLoginReceipt(getLoginState 门禁回执)', () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
describe('mock-enrollment URL 构造(best-effort 网络链)', () => {
|
|
41
|
-
it('合法 serverBase →
|
|
42
|
-
expect(
|
|
41
|
+
it('合法 serverBase → login / enroll 路由(尾斜杠归一)', () => {
|
|
42
|
+
expect(buildLoginUrl('http://127.0.0.1:8000')).toBe('http://127.0.0.1:8000/api/auth/login');
|
|
43
43
|
expect(buildEnrollUrl('http://127.0.0.1:8000/')).toBe('http://127.0.0.1:8000/api/m/provider-mock/demo/member-enroll');
|
|
44
|
-
expect(
|
|
44
|
+
expect(buildLoginUrl('https://lan.example.com:9000/')).toBe('https://lan.example.com:9000/api/auth/login');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it('非法/缺省 serverBase → 空串(跳过网络链,直接回执)', () => {
|
|
48
48
|
expect(buildEnrollUrl(undefined)).toBe('');
|
|
49
49
|
expect(buildEnrollUrl('')).toBe('');
|
|
50
50
|
expect(buildEnrollUrl('ftp://bad.example.com')).toBe('');
|
|
51
|
-
expect(
|
|
51
|
+
expect(buildLoginUrl('alipays://platformapi/startapp')).toBe('');
|
|
52
52
|
});
|
|
53
53
|
});
|