@tbox.cn/app-module-indoor-navigation 0.0.0-stage → 1.0.0-alpha.21

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tbox.cn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # module-indoor-navigation 室内导航业务模块
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 室内导航业务组件:B 端按商场配置导航服务(数据来源 + 导航 H5 地址——经通用服务配置
4
+ GET/PUT,写入 `services['indoor-navigation.handoff'].instances[mallId]`);运行时按
5
+ 当前商场配置与本系统门店 `merchantId` 生成完整 HTTPS 跳转目标。
6
+
7
+ > 状态:室内导航一期任务 1(2026-11-25)。**纯配置组件**——本模块自身零工具/卡片/路由
8
+ > 注册面;C 端门店详情的导航按钮、承载页与返回交互归前端与宿主(任务 2 前端部分),
9
+ > 门店详情 HTTP 与对话出卡的跳转目标增强归门店组件(任务 2)。
10
+
11
+ ## 服务契约
12
+
13
+ - 槽位:`indoor-navigation.handoff`(本模块 `owns`;契约见
14
+ `@tbox.cn/app-contracts-mall` `services/indoor-navigation.ts`)。
15
+ - Port:`IndoorNavigationHandoffPort.resolveHandoffUrl(q, merchantId)` ——
16
+ 输入 = 当前请求的商场范围 + 查到的门店 ID 原字符串;输出 = 完整 HTTPS 跳转地址或
17
+ `undefined`。当前商场未配置、配置无效或门店标识缺失 → `undefined`
18
+ (门店照常展示,无目标即无按钮——**不产出目标不是错误**)。
19
+
20
+ ## 运行时消费配方(任务 2——门店详情 HTTP 与对话出卡两条路径共用)
21
+
22
+ 契约三件(TIER1 单源,`@tbox.cn/app-contracts-mall` services/indoor-navigation):
23
+
24
+ - `INDOOR_NAVIGATION_SERVICE = 'indoor-navigation'`(ctx.services 键——本模块 register
25
+ 期注册本尊,消费方 `ctx.services.resolve?.(INDOOR_NAVIGATION_SERVICE)` 取用);
26
+ - `IndoorNavigationService { resolveJumpUrl(mallId, merchantId) → Promise<string | undefined> }`
27
+ (消费方结构类型子集消费——模块间禁互相 import,键与形状经 TIER1 双钉死);
28
+ - `indoorNavigationUrlSchema`(输出形状约束——完整 HTTPS ≤2048,消费侧 safeParse 同源判定)。
29
+
30
+ ```ts
31
+ import { INDOOR_NAVIGATION_SERVICE, type IndoorNavigationService } from '@tbox.cn/app-contracts-mall';
32
+ const svc = ctx.services.resolve?.(INDOOR_NAVIGATION_SERVICE) as IndoorNavigationService | undefined;
33
+ const url = svc && await svc.resolveJumpUrl(scope.mallId, shop.merchantId);
34
+ // → string | undefined;投影为门店详情数据上的可选字段 indoorNavigation: { url }
35
+ ```
36
+
37
+ 辅助语义(实现收口 `resolveIndoorNavigationTarget`——本模块导出,直接消费方可用):
38
+
39
+ - 无商圈 scope / 门店标识缺失(空串/全空白)→ `undefined`(消费侧短路,零解析成本);
40
+ - 槽级预期缺席(未配置/商场实例缺席/禁用)→ `undefined`;
41
+ - 配置无效(供应商 adapter 判定非 HTTPS/缺路由片段等)→ `undefined`;
42
+ - 装配缺口(registry 缺席、绑定不可解析等)→ 原样上抛(fail-visible——不得静默
43
+ 折损成「未配置」)。
44
+
45
+ ## B 端配置协定(交接前端/运营)
46
+
47
+ - 表单沿用动态表单:数据来源(供应商候选只含本组件已供给厂商)+ 导航 H5 地址
48
+ (必填 HTTPS,保留原路径、参数和片段——third_id 之类门店标识参数由后端生成,
49
+ 不在表单填写)。
50
+ - 保存 = 通用服务配置 PUT(**整节点替换**):先把其他商场的 `instances[mallId]` 键
51
+ 原样带回,再写当前商场——编辑 A 不会丢 B 的配置。
52
+ - 未配置的商场:门店照常展示,无跳转目标(非 503/非错误)。默认投递档
53
+ (`.real-env/config/mock`)本槽显式零激活——真实注册链上未配置导航的商场恒无目标;
54
+ 演示供给链接仅在显式激活 `instances` 的演示环境生效(2026-11-25 返修)。
55
+
56
+ ## 供给商
57
+
58
+ - 真实厂商供给见对应 provider 私有包(厂商连接唯一真源;候选范围
59
+ `selectionScope: 'supplied-services'`——只在本组件选择器可见);演示数据经
60
+ `provider-mock` 同槽供给(默认装配零 503)。
@@ -0,0 +1,70 @@
1
+ // src/server/index.ts
2
+ import { INDOOR_NAVIGATION_SERVICE } from "@tbox.cn/app-contracts-mall";
3
+
4
+ // src/server/ports.ts
5
+ import {
6
+ INDOOR_NAVIGATION_HANDOFF_SERVICE,
7
+ isMissingIndoorNavigationMerchantId,
8
+ mallScopeOf,
9
+ toMallQueryContext
10
+ } from "@tbox.cn/app-contracts-mall";
11
+ import { isExpectedProviderAbsence } from "@tbox.cn/app-contracts";
12
+ async function resolveIndoorNavigationTarget(reqCtx, ctx, merchantId) {
13
+ const scope = mallScopeOf(reqCtx);
14
+ if (!scope.mallId) return void 0;
15
+ if (isMissingIndoorNavigationMerchantId(merchantId)) return void 0;
16
+ if (!ctx.integrations) {
17
+ throw new Error("\u5BA4\u5185\u5BFC\u822A\u89E3\u6790\u5931\u8D25\uFF1A\u672A\u88C5\u914D\u96C6\u6210\u914D\u7F6E\uFF08integrations registry \u7F3A\u5E2D\uFF09");
18
+ }
19
+ let port;
20
+ try {
21
+ port = await ctx.integrations.resolveService({
22
+ service: INDOOR_NAVIGATION_HANDOFF_SERVICE,
23
+ scope,
24
+ request: reqCtx
25
+ });
26
+ } catch (e) {
27
+ if (isExpectedProviderAbsence(e)) return void 0;
28
+ throw e;
29
+ }
30
+ const q = toMallQueryContext(reqCtx);
31
+ return port.resolveHandoffUrl(q, merchantId);
32
+ }
33
+
34
+ // src/server/service.ts
35
+ function scopeRequestOf(mallId) {
36
+ return {
37
+ identity: { userId: "", source: "anonymous" },
38
+ attributes: { mall: { mallId } }
39
+ };
40
+ }
41
+ function createIndoorNavigationService(ctx) {
42
+ return {
43
+ async resolveJumpUrl(mallId, merchantId) {
44
+ return resolveIndoorNavigationTarget(scopeRequestOf(mallId), ctx, merchantId);
45
+ }
46
+ };
47
+ }
48
+
49
+ // src/server/index.ts
50
+ var cards = {};
51
+ var serverModule = {
52
+ declaration: {
53
+ moduleId: "indoor-navigation"
54
+ },
55
+ cards,
56
+ register(ctx) {
57
+ if (ctx.integrations) {
58
+ ctx.services.register(
59
+ INDOOR_NAVIGATION_SERVICE,
60
+ createIndoorNavigationService(ctx)
61
+ );
62
+ }
63
+ }
64
+ };
65
+
66
+ export {
67
+ resolveIndoorNavigationTarget,
68
+ createIndoorNavigationService,
69
+ serverModule
70
+ };
@@ -0,0 +1,10 @@
1
+ // src/client/index.ts
2
+ var clientModule = {
3
+ cards: {},
4
+ register(_ctx) {
5
+ }
6
+ };
7
+
8
+ export {
9
+ clientModule
10
+ };
@@ -0,0 +1,13 @@
1
+ import { ClientContext } from '@tbox.cn/app-agent-sdk-client';
2
+
3
+ /**
4
+ * 室内导航客户端入口:零卡片组件(C 端门店详情导航按钮由任务 2 前端在宿主接入实现,
5
+ * 不属本模块装配面);cards 恒空 map 保留装配形状(模块单包双端同构)。
6
+ */
7
+
8
+ declare const clientModule: {
9
+ cards: {};
10
+ register(_ctx: ClientContext): void;
11
+ };
12
+
13
+ export { clientModule };
@@ -0,0 +1,6 @@
1
+ import {
2
+ clientModule
3
+ } from "../chunk-SAE553C6.js";
4
+ export {
5
+ clientModule
6
+ };
@@ -0,0 +1,6 @@
1
+ export { createIndoorNavigationService, resolveIndoorNavigationTarget, serverModule } from './server/index.js';
2
+ export { clientModule } from './client/index.js';
3
+ import '@tbox.cn/app-agent-sdk-server';
4
+ import '@tbox.cn/app-contracts';
5
+ import '@tbox.cn/app-contracts-mall';
6
+ import '@tbox.cn/app-agent-sdk-client';
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import {
2
+ createIndoorNavigationService,
3
+ resolveIndoorNavigationTarget,
4
+ serverModule
5
+ } from "./chunk-DRCBGYO6.js";
6
+ import {
7
+ clientModule
8
+ } from "./chunk-SAE553C6.js";
9
+ export {
10
+ clientModule,
11
+ createIndoorNavigationService,
12
+ resolveIndoorNavigationTarget,
13
+ serverModule
14
+ };
@@ -0,0 +1,35 @@
1
+ import { ServerContext } from '@tbox.cn/app-agent-sdk-server';
2
+ import { RequestContext } from '@tbox.cn/app-contracts';
3
+ import { IndoorNavigationService } from '@tbox.cn/app-contracts-mall';
4
+
5
+ /**
6
+ * 室内导航跳转目标合成(任务 2 消费契约的唯一形状——门店详情 HTTP 与对话出卡共用):
7
+ * 输入 = 当前请求的商场范围 + 查到的 merchantId;输出 = 完整 HTTPS 跳转地址或 undefined。
8
+ * 当前商场未配置、配置无效或门店标识缺失 → undefined(门店照常展示,无目标即无按钮)。
9
+ */
10
+ declare function resolveIndoorNavigationTarget(reqCtx: RequestContext, ctx: ServerContext, merchantId: string): Promise<string | undefined>;
11
+
12
+ /**
13
+ * 服务工厂(ctx 闭包注册期绑定——实例分裂免疫;integrations registry 缺席时
14
+ * 由 register 侧决定不注册——消费方 resolve 缺席降级 undefined)。
15
+ * 注册键 = contracts-mall `INDOOR_NAVIGATION_SERVICE`('indoor-navigation')。
16
+ */
17
+ declare function createIndoorNavigationService(ctx: ServerContext): IndoorNavigationService;
18
+
19
+ /**
20
+ * 室内导航注册:B 端配置面经通用服务编辑器(GET/PUT services/indoor-navigation.handoff);
21
+ * 运行时以 ctx.services 本尊(键 'indoor-navigation'——TIER1 INDOOR_NAVIGATION_SERVICE,
22
+ * 任务 2 门店详情双链路消费缝隙)承载跳转目标解析,内部经槽供给链(provider adapter)
23
+ * 生成链接。本模块零工具/卡片/路由注册面;按钮、承载页与返回交互归前端与宿主(任务 2
24
+ * 前端部分)。服务实例与解析经 ctx 注入,register 只注册不解析。
25
+ */
26
+
27
+ declare const serverModule: {
28
+ declaration: {
29
+ moduleId: string;
30
+ };
31
+ cards: {};
32
+ register(ctx: ServerContext): void;
33
+ };
34
+
35
+ export { createIndoorNavigationService, resolveIndoorNavigationTarget, serverModule };
@@ -0,0 +1,10 @@
1
+ import {
2
+ createIndoorNavigationService,
3
+ resolveIndoorNavigationTarget,
4
+ serverModule
5
+ } from "../chunk-DRCBGYO6.js";
6
+ export {
7
+ createIndoorNavigationService,
8
+ resolveIndoorNavigationTarget,
9
+ serverModule
10
+ };
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-module-indoor-navigation",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-alpha.21",
4
+ "type": "module",
5
+ "description": "室内导航业务模块:按商场配置生成本系统门店的室内导航 H5 跳转目标(B 端经通用服务配置面管理;跳转目标解析供给槽 Port)",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ },
11
+ "./server": {
12
+ "types": "./dist/server/index.d.ts",
13
+ "import": "./dist/server/index.js"
14
+ },
15
+ "./client": {
16
+ "types": "./dist/client/index.d.ts",
17
+ "import": "./dist/client/index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "dependencies": {
22
+ "@tbox.cn/app-contracts-mall": "1.0.0-alpha.21",
23
+ "@tbox.cn/app-contracts": "1.0.0-alpha.21",
24
+ "@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.21",
25
+ "@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.21"
26
+ },
27
+ "peerDependencies": {
28
+ "zod": "3.25.76"
29
+ },
30
+ "devDependencies": {
31
+ "@types/express": "4.17.25",
32
+ "@types/node": "24.13.3",
33
+ "@types/supertest": "7.2.1",
34
+ "typescript": "5.9.3",
35
+ "vitest": "4.1.10",
36
+ "zod": "3.25.76",
37
+ "tsup": "8.5.1",
38
+ "express": "4.22.2",
39
+ "supertest": "7.2.2"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "src",
44
+ "tests",
45
+ "tbox.module.json",
46
+ "tsconfig.json",
47
+ "tsup.config.ts",
48
+ "README.md",
49
+ "LICENSE"
50
+ ],
51
+ "engines": {
52
+ "node": ">=20.0.0"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "license": "MIT",
58
+ "scripts": {
59
+ "typecheck": "tsc --noEmit",
60
+ "test": "vitest run",
61
+ "build": "tsup"
62
+ }
6
63
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 室内导航客户端入口:零卡片组件(C 端门店详情导航按钮由任务 2 前端在宿主接入实现,
3
+ * 不属本模块装配面);cards 恒空 map 保留装配形状(模块单包双端同构)。
4
+ */
5
+ import type { ClientContext, ClientModule } from '@tbox.cn/app-agent-sdk-client';
6
+
7
+ export const clientModule = {
8
+ cards: {},
9
+ register(_ctx: ClientContext): void {
10
+ // 无注册面(零卡片/零页面;跳转承载归宿主 web-view 承载页)
11
+ },
12
+ } satisfies ClientModule;
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * module-indoor-navigation 主入口(package.json exports "." 指向)。
3
+ * 消费方通常走 ./server / ./client 子路径;主入口聚合导出便于直接引用。
4
+ */
5
+ export * from './server';
6
+ export * from './client';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 室内导航注册:B 端配置面经通用服务编辑器(GET/PUT services/indoor-navigation.handoff);
3
+ * 运行时以 ctx.services 本尊(键 'indoor-navigation'——TIER1 INDOOR_NAVIGATION_SERVICE,
4
+ * 任务 2 门店详情双链路消费缝隙)承载跳转目标解析,内部经槽供给链(provider adapter)
5
+ * 生成链接。本模块零工具/卡片/路由注册面;按钮、承载页与返回交互归前端与宿主(任务 2
6
+ * 前端部分)。服务实例与解析经 ctx 注入,register 只注册不解析。
7
+ */
8
+ import type { ServerContext, ServerModule } from '@tbox.cn/app-agent-sdk-server';
9
+ import { INDOOR_NAVIGATION_SERVICE } from '@tbox.cn/app-contracts-mall';
10
+ import { createIndoorNavigationService } from './service';
11
+
12
+ export { resolveIndoorNavigationTarget } from './ports';
13
+ export { createIndoorNavigationService } from './service';
14
+
15
+ const cards = {} as const;
16
+
17
+ export const serverModule = {
18
+ declaration: {
19
+ moduleId: 'indoor-navigation',
20
+ },
21
+ cards,
22
+ register(ctx: ServerContext): void {
23
+ // 服务本尊注册(register 期一次;integrations registry 缺席 = 无配置面语义 →
24
+ // 不注册——消费方 resolve 缺席降级 undefined,门店照常展示,无逐请求告警噪声)
25
+ if (ctx.integrations) {
26
+ ctx.services.register(
27
+ INDOOR_NAVIGATION_SERVICE,
28
+ createIndoorNavigationService(ctx),
29
+ );
30
+ }
31
+ },
32
+ } satisfies ServerModule;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * indoor-navigation.handoff 槽供给解析 + 跳转目标合成(单消费通道——fail-soft 谱)。
3
+ * 模块零 provider import,经 ctx.integrations registry 解析;实例绑定决定配置范围
4
+ * (services['indoor-navigation.handoff'].instances[mallId])。
5
+ *
6
+ * 与活动玩法域 503/502 二分的有意分歧:跳转目标是可选增强——
7
+ * - 当前商场未配置(槽级预期缺席 SERVICE_NOT_CONFIGURED / INSTANCE_NOT_FOUND /
8
+ * INSTANCE_DISABLED,isExpectedProviderAbsence 单源)→ undefined;
9
+ * - 配置无效、门店标识缺失 → 供给侧 adapter resolveHandoffUrl 结构化返回 undefined;
10
+ * - 其余(BINDING_UNRESOLVED 等装配缺口、registry 缺席)→ 原样上抛 fail-visible
11
+ * (不得把装配事故静默折损成「未配置」)。
12
+ * 无商圈 scope 同样 undefined(无 scope 语境不可判配置范围;非业务错误)。
13
+ */
14
+ import type {
15
+ IndoorNavigationHandoffPort,
16
+ MallQueryContext,
17
+ } from '@tbox.cn/app-contracts-mall';
18
+ import {
19
+ INDOOR_NAVIGATION_HANDOFF_SERVICE,
20
+ isMissingIndoorNavigationMerchantId,
21
+ mallScopeOf,
22
+ toMallQueryContext,
23
+ } from '@tbox.cn/app-contracts-mall';
24
+ import { isExpectedProviderAbsence } from '@tbox.cn/app-contracts';
25
+ import type { RequestContext } from '@tbox.cn/app-contracts';
26
+ import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
27
+
28
+ /**
29
+ * 室内导航跳转目标合成(任务 2 消费契约的唯一形状——门店详情 HTTP 与对话出卡共用):
30
+ * 输入 = 当前请求的商场范围 + 查到的 merchantId;输出 = 完整 HTTPS 跳转地址或 undefined。
31
+ * 当前商场未配置、配置无效或门店标识缺失 → undefined(门店照常展示,无目标即无按钮)。
32
+ */
33
+ export async function resolveIndoorNavigationTarget(
34
+ reqCtx: RequestContext,
35
+ ctx: ServerContext,
36
+ merchantId: string,
37
+ ): Promise<string | undefined> {
38
+ const scope = mallScopeOf(reqCtx);
39
+ if (!scope.mallId) return undefined;
40
+ // 门店标识缺失单源判定(消费侧短路——零解析成本;供给侧 adapter 同判兜底直调方)
41
+ if (isMissingIndoorNavigationMerchantId(merchantId)) return undefined;
42
+ if (!ctx.integrations) {
43
+ // 装配缺口 fail-visible(与「未配置」区分——不静默折损)
44
+ throw new Error('室内导航解析失败:未装配集成配置(integrations registry 缺席)');
45
+ }
46
+ let port: IndoorNavigationHandoffPort;
47
+ try {
48
+ port = (await ctx.integrations.resolveService({
49
+ service: INDOOR_NAVIGATION_HANDOFF_SERVICE,
50
+ scope,
51
+ request: reqCtx,
52
+ })) as IndoorNavigationHandoffPort;
53
+ } catch (e) {
54
+ if (isExpectedProviderAbsence(e)) return undefined;
55
+ throw e;
56
+ }
57
+ const q: MallQueryContext = toMallQueryContext(reqCtx);
58
+ return port.resolveHandoffUrl(q, merchantId);
59
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 室内导航服务本尊(ctx.services 键 `indoor-navigation`——任务 2 门店详情双链路消费缝隙)。
3
+ * 与 mall-directory 服务同模式(跨模块 Port + ctx 铁律:键与形状经 TIER1 契约单源
4
+ * ——contracts-mall services/indoor-navigation 三件同锁;本模块注册实现超集;
5
+ * 消费方结构类型子集消费,零模块间 import);实现 = 槽供给链收口(resolveIndoorNavigationTarget)。
6
+ *
7
+ * mallId 入参是任务 2 从门店查询同一 reqCtx 解析出的商场范围(非任意越权键——
8
+ * 配置查找本地语义);合成请求上下文仅承载该范围(无用户身份语义——跳转目标与用户
9
+ * 无关,门店标识参数仅承载 merchantId)。
10
+ */
11
+ import type { RequestContext } from '@tbox.cn/app-contracts';
12
+ import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
13
+ import type { IndoorNavigationService } from '@tbox.cn/app-contracts-mall';
14
+ import { resolveIndoorNavigationTarget } from './ports';
15
+
16
+ /** 合成请求上下文(仅承载 mallId 范围——无身份/凭据语义;slot scope = { mallId }) */
17
+ function scopeRequestOf(mallId: string): RequestContext {
18
+ return {
19
+ identity: { userId: '', source: 'anonymous' },
20
+ attributes: { mall: { mallId } },
21
+ };
22
+ }
23
+
24
+ /**
25
+ * 服务工厂(ctx 闭包注册期绑定——实例分裂免疫;integrations registry 缺席时
26
+ * 由 register 侧决定不注册——消费方 resolve 缺席降级 undefined)。
27
+ * 注册键 = contracts-mall `INDOOR_NAVIGATION_SERVICE`('indoor-navigation')。
28
+ */
29
+ export function createIndoorNavigationService(ctx: ServerContext): IndoorNavigationService {
30
+ return {
31
+ async resolveJumpUrl(mallId: string, merchantId: string): Promise<string | undefined> {
32
+ return resolveIndoorNavigationTarget(scopeRequestOf(mallId), ctx, merchantId);
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "module-indoor-navigation",
4
+ "name": "室内导航",
5
+ "description": "室内导航:B 端按商场配置导航服务地址;运行时按当前商场配置与本系统门店标识生成室内导航 H5 跳转目标(未配置或门店标识缺失不产出目标,门店照常展示);按钮与承载页归前端与宿主",
6
+ "kind": "business",
7
+ "risk": {
8
+ "level": "low",
9
+ "writeBoundary": "source"
10
+ },
11
+ "distribution": {
12
+ "defaultMode": "codegen"
13
+ },
14
+ "dependencies": {
15
+ "modules": [
16
+ {
17
+ "id": "contracts-mall",
18
+ "required": true
19
+ }
20
+ ]
21
+ },
22
+ "env": [],
23
+ "declare": {
24
+ "handlers": [],
25
+ "tools": [],
26
+ "cards": [],
27
+ "routes": [],
28
+ "pages": [],
29
+ "tabs": [],
30
+ "resources": [],
31
+ "consumes": [
32
+ {
33
+ "service": "indoor-navigation.handoff",
34
+ "optional": false
35
+ }
36
+ ],
37
+ "owns": [
38
+ {
39
+ "service": "indoor-navigation.handoff"
40
+ }
41
+ ],
42
+ "skills": []
43
+ }
44
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * 双商场隔离 e2e(真实 createIntegrationsRegistry 求值链 + 槽实例差异化配置):
3
+ * 验收口径——同一应用给两个商场配置不同地址:编辑 A 后 B 的配置仍在,运行时各自解析
4
+ * 正确;未配置的商场返回 undefined(预期缺席映射)。
5
+ * 供给 adapter 在测试侧同形 stub(本模块零 provider import——workspace-dag 铁律:
6
+ * 中性 stub 供给名;真实厂商 adapter 的双商场求值归 provider 包同套件覆盖)。
7
+ * fixture 经契约真实 `parseIntegrationsConfig`(zod strictObject——非法节点即拒)。
8
+ */
9
+ import { describe, expect, it } from 'vitest';
10
+ import {
11
+ createAuthStrategyRegistry,
12
+ createEnvironmentSecretProvider,
13
+ createIntegrationsRegistry,
14
+ createServerContext,
15
+ } from '@tbox.cn/app-agent-sdk-server';
16
+ import {
17
+ parseIntegrationsConfig,
18
+ type IntegrationsConfig,
19
+ type RequestContext,
20
+ } from '@tbox.cn/app-contracts';
21
+ import { INDOOR_NAVIGATION_HANDOFF_SERVICE } from '@tbox.cn/app-contracts-mall';
22
+ import { resolveIndoorNavigationTarget } from '../src/server/ports';
23
+ import { createIndoorNavigationService } from '../src/server/service';
24
+ import { serverModule } from '../src/server';
25
+
26
+ const SLOT = INDOOR_NAVIGATION_HANDOFF_SERVICE;
27
+ const IMPL = 'stub-indoor-navigation@1'; // 中性 stub 供给键(catalog 供给唯一命中派生——键值形态同真实供给)
28
+
29
+ const URL_BJ = 'https://nav.bj.example.com/universal/#/ar_v4?sdk_version=v4';
30
+ const URL_SH = 'https://nav.sh.example.com/map/#/ar_v4?image_channel=1';
31
+
32
+ /** B 端两商场配置后 integrations.json 服务节点形态(整节点替换——instances 键集 = 白名单) */
33
+ const rawConfig: { services: Record<string, { provider: string; instances: Record<string, { config: Record<string, unknown> }> }> } = {
34
+ services: {
35
+ [SLOT]: {
36
+ provider: 'stub-nav',
37
+ instances: {
38
+ 'mall-bj': { config: { h5Url: URL_BJ } },
39
+ 'mall-sh': { config: { h5Url: URL_SH } },
40
+ },
41
+ },
42
+ },
43
+ };
44
+
45
+ /** 测试侧同形供给 stub:按实例 config 合成目标 URL(形态同真实 adapter——配置→链接) */
46
+ function makeCtx(config: IntegrationsConfig) {
47
+ const registry = createIntegrationsRegistry({
48
+ integrations: config,
49
+ catalog: {
50
+ providers: {
51
+ 'stub-nav': { [IMPL]: { provider: 'stub-nav', implementation: IMPL, credentialType: '-', owner: 'stub-nav-owner', services: [SLOT] } },
52
+ },
53
+ services: {},
54
+ credentialTypes: {},
55
+ },
56
+ ownerOf: { [SLOT]: 'module-indoor-navigation' },
57
+ authStrategies: createAuthStrategyRegistry(),
58
+ secretProvider: createEnvironmentSecretProvider({ source: {}, production: false }),
59
+ instanceIdOf: (scope) => scope['mallId'] ?? '',
60
+ });
61
+ registry.registerAdapter('stub-nav', IMPL, (input) => ({
62
+ resolveHandoffUrl: async (_q: unknown, merchantId: string) =>
63
+ typeof input.config?.['h5Url'] === 'string'
64
+ ? `${input.config['h5Url']}&third_id=${encodeURIComponent(merchantId)}`
65
+ : undefined,
66
+ }));
67
+ return createServerContext({ integrations: registry });
68
+ }
69
+
70
+ const reqCtx = (mallId: string): RequestContext => ({
71
+ identity: { userId: 'u', source: 'local' as const },
72
+ attributes: { mall: { mallId } },
73
+ });
74
+
75
+ describe('双商场隔离(真实 registry 求值链——实例键控配置)', () => {
76
+ it('fixture 经契约真实解析(zod strictObject——非法服务节点即拒)', () => {
77
+ expect(() => parseIntegrationsConfig(rawConfig)).not.toThrow();
78
+ });
79
+
80
+ it('两商场各自解析正确(不同地址、同门店标识互不串)', async () => {
81
+ const ctx = makeCtx(parseIntegrationsConfig(rawConfig));
82
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-bj'), ctx, 'BT0012S125'))
83
+ .resolves.toBe(`${URL_BJ}&third_id=BT0012S125`);
84
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-sh'), ctx, 'BT0012S125'))
85
+ .resolves.toBe(`${URL_SH}&third_id=BT0012S125`);
86
+ });
87
+
88
+ it('未配置的商场 → undefined(INSTANCE_NOT_FOUND 预期缺席映射——非错误)', async () => {
89
+ const ctx = makeCtx(parseIntegrationsConfig(rawConfig));
90
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-gz'), ctx, 'BT0012S125'))
91
+ .resolves.toBeUndefined();
92
+ });
93
+
94
+ it('「编辑 A 不动 B」:PUT 整节点替换后的重读求值——A 改新地址,B 原值仍在', async () => {
95
+ // B 端保存协定:GET 原服务节点 → 改 instances['mall-bj'] → PUT 回整节点(B 键原样带回)
96
+ const edited = structuredClone(rawConfig);
97
+ edited.services[SLOT].instances['mall-bj'] = {
98
+ config: { h5Url: 'https://nav.bj.example.com/v2/#/ar_v4?sdk_version=v4' },
99
+ };
100
+ const ctx = makeCtx(parseIntegrationsConfig(edited));
101
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-bj'), ctx, 'S1'))
102
+ .resolves.toBe('https://nav.bj.example.com/v2/#/ar_v4?sdk_version=v4&third_id=S1');
103
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-sh'), ctx, 'S1'))
104
+ .resolves.toBe(`${URL_SH}&third_id=S1`);
105
+ });
106
+
107
+ it('ctx.services 本尊(键 indoor-navigation——任务 2 缝隙)经真实 registry 双商场求值', async () => {
108
+ const ctx = makeCtx(parseIntegrationsConfig(rawConfig));
109
+ const svc = createIndoorNavigationService(ctx);
110
+ await expect(svc.resolveJumpUrl('mall-bj', 'BT0012S125')).resolves.toBe(`${URL_BJ}&third_id=BT0012S125`);
111
+ await expect(svc.resolveJumpUrl('mall-sh', '001')).resolves.toBe(`${URL_SH}&third_id=001`);
112
+ await expect(svc.resolveJumpUrl('mall-gz', 'BT0012S125')).resolves.toBeUndefined();
113
+ await expect(svc.resolveJumpUrl('mall-bj', '')).resolves.toBeUndefined();
114
+ });
115
+
116
+ it('serverModule.register:integrations 在场才注册本尊(缺席 = 消费方 resolve 缺席降级)', () => {
117
+ const registered: Array<[string, unknown]> = [];
118
+ const regCtx = (integrations: unknown) =>
119
+ ({ integrations, services: { register: (k: string, v: unknown) => registered.push([k, v]) } }) as never;
120
+ serverModule.register(regCtx(makeCtx(parseIntegrationsConfig(rawConfig))));
121
+ expect(registered).toHaveLength(1);
122
+ expect(registered[0][0]).toBe('indoor-navigation');
123
+ serverModule.register(regCtx(undefined));
124
+ expect(registered).toHaveLength(1); // 未重复注册
125
+ });
126
+
127
+ it('实例 config 缺失 → 供给侧 undefined 透传', async () => {
128
+ const broken = structuredClone(rawConfig);
129
+ broken.services[SLOT].instances['mall-bj'] = { config: {} };
130
+ const ctx = makeCtx(parseIntegrationsConfig(broken));
131
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-bj'), ctx, 'S1'))
132
+ .resolves.toBeUndefined();
133
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-sh'), ctx, 'S1'))
134
+ .resolves.toBe(`${URL_SH}&third_id=S1`);
135
+ });
136
+ });
@@ -0,0 +1,98 @@
1
+ /**
2
+ * 跳转目标合成单元测试(resolveIndoorNavigationTarget——fail-soft 谱收口):
3
+ * - resolveService 入参契约(service 常量 + flat scope {mallId} + 原样 request);
4
+ * - 预期缺席三码(SERVICE_NOT_CONFIGURED / INSTANCE_NOT_FOUND / INSTANCE_DISABLED)→ undefined;
5
+ * - 无商圈 / 门店标识缺失(供给侧 undefined)→ undefined;
6
+ * - registry 缺席与未知错误 fail-visible 原样上抛(装配事故不得静默折损成「未配置」)。
7
+ * 真链路(registry × 实例差异化配置)见 handoff-malls.test.ts;供给 adapter 属 provider 包
8
+ * (本模块零 provider import——workspace-dag 铁律,测试侧 stub 同形)。
9
+ */
10
+ import { describe, expect, it, vi } from 'vitest';
11
+ import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
12
+ import type { RequestContext } from '@tbox.cn/app-contracts';
13
+ import type { IndoorNavigationHandoffPort } from '@tbox.cn/app-contracts-mall';
14
+ import { INDOOR_NAVIGATION_HANDOFF_SERVICE } from '@tbox.cn/app-contracts-mall';
15
+ import { resolveIndoorNavigationTarget } from '../src/server/ports';
16
+
17
+ const stubCtx = (integrations?: unknown): ServerContext =>
18
+ ({ integrations }) as unknown as ServerContext;
19
+
20
+ const reqCtx = (mallId: string): RequestContext => ({
21
+ identity: { userId: 'u', source: 'guest' as const },
22
+ attributes: { mall: { mallId } },
23
+ });
24
+
25
+ const stubPort = (url: string | undefined): IndoorNavigationHandoffPort => ({
26
+ resolveHandoffUrl: vi.fn(async () => url),
27
+ });
28
+
29
+ describe('resolveIndoorNavigationTarget 消费契约(任务 2 接口形状)', () => {
30
+ it('resolveService 入参契约:service 常量 + flat scope {mallId} + request 原样', async () => {
31
+ const resolveService = vi.fn(async () => stubPort('https://nav.example.cn/#/ar_v4?third_id=M1'));
32
+ const ctx = reqCtx('mall-a');
33
+ const got = await resolveIndoorNavigationTarget(ctx, stubCtx({ resolveService }), 'M1');
34
+ expect(got).toBe('https://nav.example.cn/#/ar_v4?third_id=M1');
35
+ expect(resolveService).toHaveBeenCalledWith({
36
+ service: INDOOR_NAVIGATION_HANDOFF_SERVICE,
37
+ scope: { mallId: 'mall-a' },
38
+ request: ctx,
39
+ });
40
+ });
41
+
42
+ it('门店标识缺失 → undefined(消费侧短路——不解析槽、不调 Port;供给侧同判兜底)', async () => {
43
+ const resolveService = vi.fn();
44
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-a'), stubCtx({ resolveService }), '')).resolves.toBeUndefined();
45
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-a'), stubCtx({ resolveService }), ' ')).resolves.toBeUndefined();
46
+ expect(resolveService).not.toHaveBeenCalled();
47
+ });
48
+
49
+ it('供给侧 resolveHandoffUrl 的 undefined 原样透传(配置无效/标识由供给判定)', async () => {
50
+ await expect(
51
+ resolveIndoorNavigationTarget(reqCtx('mall-a'), stubCtx({ resolveService: async () => stubPort(undefined) }), 'M1'),
52
+ ).resolves.toBeUndefined();
53
+ });
54
+ });
55
+
56
+ describe('预期缺席 → undefined(跳转目标是可选增强,非业务错误)', () => {
57
+ it.each([
58
+ ['槽未配置', 'PROVIDER_SERVICE_NOT_CONFIGURED'],
59
+ ['商场实例缺席', 'PROVIDER_INSTANCE_NOT_FOUND'],
60
+ ['商场实例禁用', 'PROVIDER_INSTANCE_DISABLED'],
61
+ ])('%s → undefined', async (_name, code) => {
62
+ await expect(
63
+ resolveIndoorNavigationTarget(
64
+ reqCtx('mall-a'),
65
+ stubCtx({ resolveService: async () => { throw Object.assign(new Error('x'), { code }); } }),
66
+ 'M1',
67
+ ),
68
+ ).resolves.toBeUndefined();
69
+ });
70
+
71
+ it('无商圈 scope → undefined(非业务错误,不进供给链)', async () => {
72
+ const resolveService = vi.fn();
73
+ await expect(
74
+ resolveIndoorNavigationTarget({ identity: { userId: 'u', source: 'guest' as const } }, stubCtx({ resolveService }), 'M1'),
75
+ ).resolves.toBeUndefined();
76
+ expect(resolveService).not.toHaveBeenCalled();
77
+ });
78
+ });
79
+
80
+ describe('装配缺口 fail-visible(与「未配置」区分)', () => {
81
+ it('integrations registry 缺席 → 原样上抛', async () => {
82
+ await expect(resolveIndoorNavigationTarget(reqCtx('mall-a'), stubCtx(undefined), 'M1')).rejects.toThrow(/未装配集成配置/);
83
+ });
84
+
85
+ it.each([
86
+ ['绑定不可解析', 'PROVIDER_BINDING_UNRESOLVED'],
87
+ ['provider 未命中 catalog', 'PROVIDER_NOT_FOUND'],
88
+ ['供给未实施', 'PROVIDER_NOT_IMPLEMENTED'],
89
+ ])('%s → 原样上抛(不折损 undefined)', async (_name, code) => {
90
+ await expect(
91
+ resolveIndoorNavigationTarget(
92
+ reqCtx('mall-a'),
93
+ stubCtx({ resolveService: async () => { throw Object.assign(new Error('x'), { code }); } }),
94
+ 'M1',
95
+ ),
96
+ ).rejects.toMatchObject({ code });
97
+ });
98
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "jsx": "react-jsx",
5
+ "types": ["node"]
6
+ },
7
+ "include": ["src", "tests"]
8
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: 'src/index.ts',
6
+ 'server/index': 'src/server/index.ts',
7
+ 'client/index': 'src/client/index.ts',
8
+ },
9
+ format: ['esm'],
10
+ target: 'node20',
11
+ platform: 'node',
12
+ outDir: 'dist',
13
+ clean: true,
14
+ sourcemap: false,
15
+ dts: { compilerOptions: { incremental: false } },
16
+ external: [
17
+ '@tbox.cn/app-agent-sdk-client',
18
+ '@tbox.cn/app-agent-ui-kit',
19
+ '@tbox.cn/app-agent-sdk-server',
20
+ '@tbox.cn/app-contracts',
21
+ '@tbox.cn/app-contracts-mall',
22
+ 'react',
23
+ 'react-dom',
24
+ 'zod',
25
+ '@mastra/core',
26
+ 'express',
27
+ ],
28
+ });