@tbox.cn/app-provider-aibee 0.0.0-stage → 1.0.0-alpha.22
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 +21 -0
- package/README.md +92 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/server/index.d.ts +69 -0
- package/dist/server/index.js +79 -0
- package/package.json +47 -3
- package/schemas/indoor-navigation.config.json +22 -0
- package/src/index.ts +2 -0
- package/src/server/index.ts +45 -0
- package/src/server/indoor-navigation.ts +134 -0
- package/tbox.module.json +40 -0
- package/tsconfig.json +7 -0
- package/tsup.config.ts +22 -0
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,93 @@
|
|
|
1
|
-
#
|
|
1
|
+
# provider-aibee Provider 包
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
爱笔(aibee)室内导航**供应商供给**:`indoor-navigation.handoff` 单槽(credentialType `-`
|
|
4
|
+
——普通 config 单字段 `h5Url`,无凭据链)。每次跳转目标生成只依赖当前商场实例配置
|
|
5
|
+
(五层合并后的有效 config),无本地数据、无上游 API、无缓存。
|
|
6
|
+
|
|
7
|
+
本包随 mall 画像默认装配,支持 registry 分发与本地 pack/tgz 装配。
|
|
8
|
+
主入口 `.` 导出包身份 `providerId`;`./server` 导出服务注册与链接生成能力。
|
|
9
|
+
安装包只提供供应商候选;导航目标需按商场显式配置 `h5Url` 并激活实例。
|
|
10
|
+
|
|
11
|
+
## 商场配置(integrations 服务级——每商场一份)
|
|
12
|
+
|
|
13
|
+
- **配置字段**(schema = `schemas/indoor-navigation.config.json`):`h5Url` 单字段必填
|
|
14
|
+
(B 端表单名「导航 H5 地址」)——爱笔提供的当前商场 HTTPS 地址,保留原路径、参数和
|
|
15
|
+
片段。**no `x-tbox-global`(按实例差异化——配置写服务节点
|
|
16
|
+
`services['indoor-navigation.handoff'].instances[mallId].config`,不进模块级全局表单)**。
|
|
17
|
+
- **写入协议**:B 端复用通用服务配置 GET/PUT(整节点替换——更新当前商场时先 GET 回读
|
|
18
|
+
`instances` map、改当前键再 PUT 整节点,其他商场的配置保真)。
|
|
19
|
+
- **候选范围**:`selectionScope: 'supplied-services'`——爱笔只出现在室内导航组件及其
|
|
20
|
+
服务选择器中(应用级/其他模块不可见)。
|
|
21
|
+
- **实例激活**:`instances.<mallId>` 显式键控;本包零隐式默认实例。未配置/白名单外/
|
|
22
|
+
禁用由 registry 显性失败 → 消费方映射**跳转目标缺席**(不产出按钮,非 503)。
|
|
23
|
+
默认投递档(`.real-env/config/mock`)下本槽**显式零激活**(`instances: {}`)——
|
|
24
|
+
未配置导航的商场恒无跳转目标;演示链接仅在显式激活 instances 的演示环境生效。
|
|
25
|
+
|
|
26
|
+
## 链接生成(wire 单点 = `src/server/indoor-navigation.ts`)
|
|
27
|
+
|
|
28
|
+
- 门店标识承载:`third_id` 路由参数写入 hash 路由参数段(#/ar_v4? 后),值 =
|
|
29
|
+
本系统门店 `merchantId` 原字符串经 `encodeURIComponent` **编码一次**('001' 保持原值;
|
|
30
|
+
不 trim、不转数字)。
|
|
31
|
+
- 原路径、查询参数与片段逐字保留(字符串手术,不经 URL 重序列化 normalize);
|
|
32
|
+
已有 `third_id` **按解码后的参数名**剔除(`%74hird_id` 等百分号编码形态即等价写法——
|
|
33
|
+
URL 解析后同为 third_id;malformed 百分号键不误杀,原样保留)——**同一链接只保留一个
|
|
34
|
+
third_id**;其余参数原样;新增的参数只有 `third_id`。
|
|
35
|
+
- `mallId` 只用于内部选配置实例,跳转地址不携带商圈标识。
|
|
36
|
+
- **地址校验单源 = 最终输出契约**(返修轮钉死):配置 h5Url 与生成产物同用
|
|
37
|
+
`indoorNavigationUrlSchema` safeParse(完整可解析 HTTPS、≤2048——消费侧同判,长度按
|
|
38
|
+
JavaScript 字符串口径即 UTF-16 计数);`https:nav.example.com` 缺斜杠伪形态及超长
|
|
39
|
+
产物在此显性拒绝,表单引导给 `format: uri`——三面(表单/运行时/详情消费)一致。
|
|
40
|
+
- **保存长度上限 = 1462(third_id 按编码当量预留)**(返修第五/六轮):写面 pattern
|
|
41
|
+
lookahead `(?=.{0,1462}$)` = 2048 输出契约 − 追加预留 586(`&third_id=`/`?third_id=`
|
|
42
|
+
段符 10 + 门店 ID ≤64 UTF-16 单元按 encodeURIComponent **最坏膨胀当量 ×9**=576
|
|
43
|
+
——BMP 汉字每单元九倍;ASCII-only 预留(×3)对 64 汉字 ID 产物 2432 越界的缝隙
|
|
44
|
+
于此收口)。**64 汉字 ID 追加 1462 地址产物恰 2048**(保存/运行时口径闭合);更长
|
|
45
|
+
门店 ID 的残余场景由运行时产物复跑契约兜底(undefined,门店照常展示)。ajv
|
|
46
|
+
maxLength(码点口径 2048)恒不先拦。
|
|
47
|
+
- **实际路由片段判定**(返修第四轮——写面与运行时同判双锁):恰一个字面 `#` 且其开启
|
|
48
|
+
`#/` 路由段(首 `#` 后以 `/` 开头、全串不再有字面 `#`;`%2F` 开头不按解码等价放行)——
|
|
49
|
+
`#wrong#/ar_v4` 类非路由片段(third_id 曾被追加到错误路由段)保存 400、运行时
|
|
50
|
+
undefined;写面 pattern `^(?=.{0,1462}$)https://[^#\s]+#/[^#\s]+$` 与
|
|
51
|
+
`validH5Url` 同判单源。
|
|
52
|
+
- **fail-soft 语义(与 hupo 域 502 的有意分歧)**:配置缺席(槽解析层预期缺席)、
|
|
53
|
+
配置非法(过不了输出契约/不可解析/缺路由片段)、门店标识缺失 → `undefined`
|
|
54
|
+
(消费方照常展示门店)。schema 是表单引导非写入门禁(P16),校验单点在生成时刻。
|
|
55
|
+
|
|
56
|
+
链接形态:
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
https://ar-activities-test.aibee.cn/universal/#/ar_v4?sdk_version=v4&image_channel=1&third_id=BT0012S125
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 消费配方(任务 2 接入门店详情 HTTP 与对话出卡时)
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import type { IndoorNavigationHandoffPort } from '@tbox.cn/app-contracts-mall';
|
|
66
|
+
import { INDOOR_NAVIGATION_HANDOFF_SERVICE, mallScopeOf } from '@tbox.cn/app-contracts-mall';
|
|
67
|
+
import { isExpectedProviderAbsence } from '@tbox.cn/app-contracts';
|
|
68
|
+
|
|
69
|
+
async function resolveNavigationTarget(
|
|
70
|
+
reqCtx: RequestContext, ctx: ServerContext, merchantId: string,
|
|
71
|
+
): Promise<string | undefined> {
|
|
72
|
+
const scope = mallScopeOf(reqCtx);
|
|
73
|
+
if (!scope.mallId) return undefined;
|
|
74
|
+
try {
|
|
75
|
+
const port = (await ctx.integrations.resolveService({
|
|
76
|
+
service: INDOOR_NAVIGATION_HANDOFF_SERVICE,
|
|
77
|
+
scope,
|
|
78
|
+
request: reqCtx,
|
|
79
|
+
})) as IndoorNavigationHandoffPort;
|
|
80
|
+
return await port.resolveHandoffUrl(toMallQueryContext(reqCtx), merchantId);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (isExpectedProviderAbsence(e)) return undefined; // 未配置/实例缺席/禁用 → 无目标
|
|
83
|
+
throw e; // 装配缺口等其余失败照常上抛
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 联调约定(一期后端任务边界)
|
|
89
|
+
|
|
90
|
+
- 门店映射(merchantId ↔ 爱笔地图门店)由爱笔线下核对并维护;联调用本系统真实返回 ID
|
|
91
|
+
验证(含同品牌不同分店场景)。测试地址即可完成配置回路,不支持爱笔测试域名之外
|
|
92
|
+
的降级数据。
|
|
93
|
+
- 承载页、域名白名单、真机导航归宿主与联合联调(见 docs/plans/indoor-navigation/)。
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ServiceAdapterInput, ServerContext } from '@tbox.cn/app-agent-sdk-server';
|
|
2
|
+
import { IndoorNavigationHandoffPort, MallQueryContext } from '@tbox.cn/app-contracts-mall';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 爱笔(aibee)室内导航 adapter(indoor-navigation.handoff 槽供给)。
|
|
6
|
+
*
|
|
7
|
+
* 业务语义:按当前商场实例配置的爱笔 H5 地址生成本系统门店的跳转链接——
|
|
8
|
+
* 链接形状是爱笔 wire 词汇(#/ar_v4 路由参数承载 third_id),单点收拢在本文件;
|
|
9
|
+
* 商场范围(mallId)只在槽解析层用于选取配置实例,生成链接时不携带商圈内部标识,
|
|
10
|
+
* 唯一入参 = 本系统门店 merchantId 原字符串(encodeURIComponent 编码一次)。
|
|
11
|
+
*
|
|
12
|
+
* 「不产出目标」不是错误(与 hupo 域 503/502 二分的有意分歧):当前商场配置缺席/
|
|
13
|
+
* 配置非法/门店标识缺失 → 结构化 undefined(不 throw——消费方渲染层照常展示门店,
|
|
14
|
+
* 见契约 services/indoor-navigation.ts)。构造期零校验(schema 是表单引导非写入门禁
|
|
15
|
+
* ——P16):校验单点在 resolveHandoffUrl 的生成时刻,非法配置 fail-soft
|
|
16
|
+
* (运营改对前门店照常展示,不出 502)。
|
|
17
|
+
*
|
|
18
|
+
* 地址校验单源复用最终输出契约 `indoorNavigationUrlSchema`(完整 https:// ≤2048——
|
|
19
|
+
* 消费侧 safeParse 同判;表述单义:能产出的链接必然过消费方校验,表单/运行时/详情
|
|
20
|
+
* 三面一致)。旧参数按解码后的参数名匹配 third_id(%74hird_id 形态即编码等价——
|
|
21
|
+
* 同一链接只保留一个 third_id);其余参数逐字保留(不 decode/re-encode)。
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
declare const AIBEE_PROVIDER = "aibee";
|
|
25
|
+
declare const AIBEE_INDOOR_NAVIGATION_IMPL = "aibee-indoor-navigation@1";
|
|
26
|
+
/** 门店标识承载参数名(爱笔文档固定 third_id;同一链接只保留一个) */
|
|
27
|
+
declare const AIBEE_THIRD_ID_PARAM = "third_id";
|
|
28
|
+
/**
|
|
29
|
+
* 爱笔跳转链接生成(wire 单点):
|
|
30
|
+
* - 在首个 `#` 后的路由参数段追加 `third_id=<编码后门店ID>`(原路由与参数形态保留);
|
|
31
|
+
* - 原链接已有的 third_id 参数(含编码等价形态)剔除——同一链接只保留一个;
|
|
32
|
+
* - 其余参数逐字保留(不 decode/re-encode——避免破坏运营粘贴的原始编码形态);
|
|
33
|
+
* - 字符串手术而非 URL 重序列化(结构性 normalize 不得漂移原路径/参数/片段);
|
|
34
|
+
* - 产出复跑最终输出契约(indoorNavigationUrlSchema——消费者同判;超长等边缘 →
|
|
35
|
+
* undefined,不产出消费方终将拒绝的链接)。
|
|
36
|
+
* 任一输入非法(非法地址 / 门店标识缺失——契约单源 isMissingIndoorNavigationMerchantId)
|
|
37
|
+
* → undefined。
|
|
38
|
+
*/
|
|
39
|
+
declare function buildAibeeHandoffUrl(h5Url: unknown, merchantId: string): string | undefined;
|
|
40
|
+
/** config 键名(与 schemas/indoor-navigation.config.json 同锁——B 端「导航 H5 地址」) */
|
|
41
|
+
declare const AIBEE_H5_URL_CONFIG_KEY = "h5Url";
|
|
42
|
+
/** 爱笔室内导航供给实现(结构类型满足 IndoorNavigationHandoffPort)。 */
|
|
43
|
+
declare class AibeeIndoorNavigationServiceImpl implements IndoorNavigationHandoffPort {
|
|
44
|
+
#private;
|
|
45
|
+
constructor(input: Pick<ServiceAdapterInput, 'config'>);
|
|
46
|
+
resolveHandoffUrl(_q: MallQueryContext, merchantId: string): Promise<string | undefined>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* provider-aibee Provider 注册入口(server-only)。
|
|
51
|
+
* 供给声明见 tbox.module.json declare.providers(id: 'aibee' + selectionScope:
|
|
52
|
+
* 'supplied-services'——候选范围只出现在供给槽归属的室内导航组件;indoor-navigation.handoff
|
|
53
|
+
* 单槽 × credentialType '-'(普通 config 单字段 h5Url,无 credentialRef/凭据链))。
|
|
54
|
+
* 本包零隐式默认实例声明——激活恒显式(服务节点 instances 按商场键控),未配置/
|
|
55
|
+
* 白名单外 mallId 由 registry 显性失败(SERVICE_NOT_CONFIGURED / INSTANCE_NOT_FOUND /
|
|
56
|
+
* INSTANCE_DISABLED),消费方经 isExpectedProviderAbsence 映射为 undefined(门店照常展示)。
|
|
57
|
+
* 配置内非法地址、门店标识缺失同样不抛错(resolveHandoffUrl → undefined)——
|
|
58
|
+
* 与 hupo 域 fail-visible 502 的有意分歧:本域没有可降级的服务面,跳转目标是可选增强。
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
declare const serverModule: {
|
|
62
|
+
declaration: {
|
|
63
|
+
moduleId: string;
|
|
64
|
+
};
|
|
65
|
+
cards: {};
|
|
66
|
+
register(ctx: ServerContext): void;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { AIBEE_H5_URL_CONFIG_KEY, AIBEE_INDOOR_NAVIGATION_IMPL, AIBEE_PROVIDER, AIBEE_THIRD_ID_PARAM, AibeeIndoorNavigationServiceImpl, buildAibeeHandoffUrl, serverModule };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/server/indoor-navigation.ts
|
|
2
|
+
import { indoorNavigationUrlSchema, isMissingIndoorNavigationMerchantId } from "@tbox.cn/app-contracts-mall";
|
|
3
|
+
var AIBEE_PROVIDER = "aibee";
|
|
4
|
+
var AIBEE_INDOOR_NAVIGATION_IMPL = "aibee-indoor-navigation@1";
|
|
5
|
+
var AIBEE_THIRD_ID_PARAM = "third_id";
|
|
6
|
+
function validH5Url(raw) {
|
|
7
|
+
if (typeof raw !== "string") return void 0;
|
|
8
|
+
if (!indoorNavigationUrlSchema.safeParse(raw).success) return void 0;
|
|
9
|
+
let parsed;
|
|
10
|
+
try {
|
|
11
|
+
parsed = new URL(raw);
|
|
12
|
+
} catch {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
if (parsed.protocol !== "https:" || !parsed.hostname) return void 0;
|
|
16
|
+
const hashIndex = raw.indexOf("#");
|
|
17
|
+
if (hashIndex === -1 || raw.indexOf("#", hashIndex + 1) !== -1) return void 0;
|
|
18
|
+
if (!parsed.hash.startsWith("#/")) return void 0;
|
|
19
|
+
return raw;
|
|
20
|
+
}
|
|
21
|
+
function isThirdIdPair(pair) {
|
|
22
|
+
const eq = pair.indexOf("=");
|
|
23
|
+
const rawKey = eq === -1 ? pair : pair.slice(0, eq);
|
|
24
|
+
try {
|
|
25
|
+
return decodeURIComponent(rawKey) === AIBEE_THIRD_ID_PARAM;
|
|
26
|
+
} catch {
|
|
27
|
+
return rawKey === AIBEE_THIRD_ID_PARAM;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function buildAibeeHandoffUrl(h5Url, merchantId) {
|
|
31
|
+
const url = validH5Url(h5Url);
|
|
32
|
+
if (!url || isMissingIndoorNavigationMerchantId(merchantId)) return void 0;
|
|
33
|
+
const hashIndex = url.indexOf("#");
|
|
34
|
+
if (hashIndex === -1) return void 0;
|
|
35
|
+
const hashBody = url.slice(hashIndex + 1);
|
|
36
|
+
const markIndex = hashBody.indexOf("?");
|
|
37
|
+
const route = markIndex === -1 ? hashBody : hashBody.slice(0, markIndex);
|
|
38
|
+
const rawParams = markIndex === -1 ? "" : hashBody.slice(markIndex + 1);
|
|
39
|
+
const kept = rawParams === "" ? [] : rawParams.split("&").filter((pair) => pair !== "" && !isThirdIdPair(pair));
|
|
40
|
+
kept.push(`${AIBEE_THIRD_ID_PARAM}=${encodeURIComponent(merchantId)}`);
|
|
41
|
+
const result = `${url.slice(0, hashIndex + 1)}${route}?${kept.join("&")}`;
|
|
42
|
+
return indoorNavigationUrlSchema.safeParse(result).success ? result : void 0;
|
|
43
|
+
}
|
|
44
|
+
var AIBEE_H5_URL_CONFIG_KEY = "h5Url";
|
|
45
|
+
var AibeeIndoorNavigationServiceImpl = class {
|
|
46
|
+
#h5Url;
|
|
47
|
+
constructor(input) {
|
|
48
|
+
this.#h5Url = input.config?.[AIBEE_H5_URL_CONFIG_KEY];
|
|
49
|
+
}
|
|
50
|
+
async resolveHandoffUrl(_q, merchantId) {
|
|
51
|
+
return buildAibeeHandoffUrl(this.#h5Url, merchantId);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var aibeeIndoorNavigationFactory = (input) => new AibeeIndoorNavigationServiceImpl(input);
|
|
55
|
+
|
|
56
|
+
// src/server/index.ts
|
|
57
|
+
var cards = {};
|
|
58
|
+
var serverModule = {
|
|
59
|
+
declaration: {
|
|
60
|
+
moduleId: "provider-aibee"
|
|
61
|
+
},
|
|
62
|
+
cards,
|
|
63
|
+
register(ctx) {
|
|
64
|
+
ctx.integrations?.registerAdapter?.(
|
|
65
|
+
AIBEE_PROVIDER,
|
|
66
|
+
AIBEE_INDOOR_NAVIGATION_IMPL,
|
|
67
|
+
aibeeIndoorNavigationFactory
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
AIBEE_H5_URL_CONFIG_KEY,
|
|
73
|
+
AIBEE_INDOOR_NAVIGATION_IMPL,
|
|
74
|
+
AIBEE_PROVIDER,
|
|
75
|
+
AIBEE_THIRD_ID_PARAM,
|
|
76
|
+
AibeeIndoorNavigationServiceImpl,
|
|
77
|
+
buildAibeeHandoffUrl,
|
|
78
|
+
serverModule
|
|
79
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-provider-aibee",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "provider-aibee 爱笔室内导航供应商供给:indoor-navigation.handoff 槽 adapter(按商场配置的爱笔 H5 地址 + merchantId 编码生成跳转链接 + JSON Schema)。",
|
|
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
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@tbox.cn/app-contracts": "1.0.0-alpha.22",
|
|
19
|
+
"@tbox.cn/app-contracts-mall": "1.0.0-alpha.22",
|
|
20
|
+
"@tbox.cn/app-agent-sdk-server": "1.0.0-alpha.22"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "24.13.3",
|
|
24
|
+
"typescript": "5.9.3",
|
|
25
|
+
"vitest": "4.1.10",
|
|
26
|
+
"tsup": "8.5.1"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"src",
|
|
31
|
+
"schemas",
|
|
32
|
+
"tbox.module.json",
|
|
33
|
+
"tsconfig.json",
|
|
34
|
+
"tsup.config.ts",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20.0.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "restricted"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"build": "tsup"
|
|
49
|
+
}
|
|
6
50
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "爱笔室内导航商场配置",
|
|
4
|
+
"x-tbox-enforced": true,
|
|
5
|
+
"description": "室内导航跳转业务连接面:仅「导航 H5 地址」单字段——爱笔提供的当前商场页面地址,按商场各配一份(跨商场部署互不共享)。third_id 由后端按本系统门店 ID 生成并追加,不在此填写;页面与 H5 的打开、承载和返回交互归前端与宿主。地址须为完整 https:// URL(format: uri——含单一 #/ 路由片段与既有参数,原样保留,示例 https://ar-activities-test.aibee.cn/universal/#/ar_v4?sdk_version=v4);非 HTTPS(http:/ftp: 及缺斜杠的 https: 伪形态)、全串多字面 #、# 后非 / 开头的非路由片段、或超长(>2048,UTF-16 口径)值由服务端生成跳转时按输出契约显性拒绝(跳转地址与消费侧同用 indoorNavigationUrlSchema 校验——不产出目标,门店照常展示;保存环节经 x-tbox-enforced 同口径先行拦截)。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"h5Url": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"title": "导航 H5 地址",
|
|
11
|
+
"description": "爱笔提供的当前商场 HTTPS 地址,保留原路径、参数和片段(示例形态 https://ar-activities-test.aibee.cn/universal/#/ar_v4?sdk_version=v4&image_channel=1);本系统按所选门店在该地址的路由参数中追加 third_id,同一链接只保留一个 third_id;须为完整 https:// 地址且含单一 #/ 路由片段(如 #/ar_v4——首 # 后以 / 开头、全串不得再出现字面 #)。长度上限按 JavaScript 字符串口径(UTF-16 ≤1462)——已为 third_id 追加按门店 ID 实际编码当量预留空间(预留构成:`&third_id=`/`?third_id=` 段符 10 + 门店 ID ≤64 UTF-16 单元按 encodeURIComponent 最坏膨胀当量(BMP 汉字每单元 ×9=576;emoji 双单元 ×6 低于此)——合计 586,上限 1462):64 汉字门店 ID 追加 1462 地址产物恰 2048,保存与运行时口径闭合;超长门店 ID 的残余场景由运行时输出契约兜底(不产出目标,门店照常展示)——保存时按本 schema 字段级校验(x-tbox-enforced),http://、空串、全空白、#wrong 类非路由片段或超长值在配置环节返回明确字段错误",
|
|
12
|
+
"format": "uri",
|
|
13
|
+
"pattern": "^(?=.{0,1462}$)https://[^#\\s]+#/[^#\\s]+$",
|
|
14
|
+
"minLength": 1,
|
|
15
|
+
"maxLength": 2048
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"required": [
|
|
19
|
+
"h5Url"
|
|
20
|
+
],
|
|
21
|
+
"additionalProperties": true
|
|
22
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provider-aibee Provider 注册入口(server-only)。
|
|
3
|
+
* 供给声明见 tbox.module.json declare.providers(id: 'aibee' + selectionScope:
|
|
4
|
+
* 'supplied-services'——候选范围只出现在供给槽归属的室内导航组件;indoor-navigation.handoff
|
|
5
|
+
* 单槽 × credentialType '-'(普通 config 单字段 h5Url,无 credentialRef/凭据链))。
|
|
6
|
+
* 本包零隐式默认实例声明——激活恒显式(服务节点 instances 按商场键控),未配置/
|
|
7
|
+
* 白名单外 mallId 由 registry 显性失败(SERVICE_NOT_CONFIGURED / INSTANCE_NOT_FOUND /
|
|
8
|
+
* INSTANCE_DISABLED),消费方经 isExpectedProviderAbsence 映射为 undefined(门店照常展示)。
|
|
9
|
+
* 配置内非法地址、门店标识缺失同样不抛错(resolveHandoffUrl → undefined)——
|
|
10
|
+
* 与 hupo 域 fail-visible 502 的有意分歧:本域没有可降级的服务面,跳转目标是可选增强。
|
|
11
|
+
*/
|
|
12
|
+
import type { ServerContext, ServerModule } from '@tbox.cn/app-agent-sdk-server';
|
|
13
|
+
import {
|
|
14
|
+
AIBEE_INDOOR_NAVIGATION_IMPL,
|
|
15
|
+
AIBEE_PROVIDER,
|
|
16
|
+
aibeeIndoorNavigationFactory,
|
|
17
|
+
} from './indoor-navigation';
|
|
18
|
+
|
|
19
|
+
export {};
|
|
20
|
+
export {
|
|
21
|
+
AIBEE_PROVIDER,
|
|
22
|
+
AIBEE_INDOOR_NAVIGATION_IMPL,
|
|
23
|
+
AIBEE_THIRD_ID_PARAM,
|
|
24
|
+
AIBEE_H5_URL_CONFIG_KEY,
|
|
25
|
+
AibeeIndoorNavigationServiceImpl,
|
|
26
|
+
buildAibeeHandoffUrl,
|
|
27
|
+
} from './indoor-navigation';
|
|
28
|
+
|
|
29
|
+
const cards = {} as const;
|
|
30
|
+
|
|
31
|
+
export const serverModule = {
|
|
32
|
+
declaration: {
|
|
33
|
+
moduleId: 'provider-aibee',
|
|
34
|
+
},
|
|
35
|
+
cards,
|
|
36
|
+
register(ctx: ServerContext): void {
|
|
37
|
+
// adapter 注册(v2 双键:厂商名 aibee + implementation;config = 五层合并后当前商场
|
|
38
|
+
// 配置——services['indoor-navigation.handoff'].instances[mallId].config.h5Url)
|
|
39
|
+
ctx.integrations?.registerAdapter?.(
|
|
40
|
+
AIBEE_PROVIDER,
|
|
41
|
+
AIBEE_INDOOR_NAVIGATION_IMPL,
|
|
42
|
+
aibeeIndoorNavigationFactory,
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
} satisfies ServerModule;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 爱笔(aibee)室内导航 adapter(indoor-navigation.handoff 槽供给)。
|
|
3
|
+
*
|
|
4
|
+
* 业务语义:按当前商场实例配置的爱笔 H5 地址生成本系统门店的跳转链接——
|
|
5
|
+
* 链接形状是爱笔 wire 词汇(#/ar_v4 路由参数承载 third_id),单点收拢在本文件;
|
|
6
|
+
* 商场范围(mallId)只在槽解析层用于选取配置实例,生成链接时不携带商圈内部标识,
|
|
7
|
+
* 唯一入参 = 本系统门店 merchantId 原字符串(encodeURIComponent 编码一次)。
|
|
8
|
+
*
|
|
9
|
+
* 「不产出目标」不是错误(与 hupo 域 503/502 二分的有意分歧):当前商场配置缺席/
|
|
10
|
+
* 配置非法/门店标识缺失 → 结构化 undefined(不 throw——消费方渲染层照常展示门店,
|
|
11
|
+
* 见契约 services/indoor-navigation.ts)。构造期零校验(schema 是表单引导非写入门禁
|
|
12
|
+
* ——P16):校验单点在 resolveHandoffUrl 的生成时刻,非法配置 fail-soft
|
|
13
|
+
* (运营改对前门店照常展示,不出 502)。
|
|
14
|
+
*
|
|
15
|
+
* 地址校验单源复用最终输出契约 `indoorNavigationUrlSchema`(完整 https:// ≤2048——
|
|
16
|
+
* 消费侧 safeParse 同判;表述单义:能产出的链接必然过消费方校验,表单/运行时/详情
|
|
17
|
+
* 三面一致)。旧参数按解码后的参数名匹配 third_id(%74hird_id 形态即编码等价——
|
|
18
|
+
* 同一链接只保留一个 third_id);其余参数逐字保留(不 decode/re-encode)。
|
|
19
|
+
*/
|
|
20
|
+
import type {
|
|
21
|
+
IndoorNavigationHandoffPort,
|
|
22
|
+
MallQueryContext,
|
|
23
|
+
} from '@tbox.cn/app-contracts-mall';
|
|
24
|
+
import { indoorNavigationUrlSchema, isMissingIndoorNavigationMerchantId } from '@tbox.cn/app-contracts-mall';
|
|
25
|
+
import type { ServiceAdapterInput, ServiceAdapterFactory } from '@tbox.cn/app-agent-sdk-server';
|
|
26
|
+
|
|
27
|
+
export const AIBEE_PROVIDER = 'aibee';
|
|
28
|
+
export const AIBEE_INDOOR_NAVIGATION_IMPL = 'aibee-indoor-navigation@1';
|
|
29
|
+
|
|
30
|
+
/** 门店标识承载参数名(爱笔文档固定 third_id;同一链接只保留一个) */
|
|
31
|
+
export const AIBEE_THIRD_ID_PARAM = 'third_id';
|
|
32
|
+
|
|
33
|
+
// ===== 链接生成(纯函数单点——契约语义与爱笔 wire 形态同锁于测试) =====
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 校验并提取合法配置地址:最终输出契约(indoorNavigationUrlSchema——完整 https://
|
|
37
|
+
* 前缀、≤2048、零首尾空白)+ 可解析且携带主机名 + **实际路由片段**(爱笔地址形态恒为
|
|
38
|
+
* `…/path?query#/ar_v4?<params>`——首个 `#` 必须开启 `#/` 路由段,全串不得再有字面
|
|
39
|
+
* `#`;`#wrong…` 类非路由片段在此显性拒绝)。任一不满足 → undefined。
|
|
40
|
+
* 与写面 pattern(schemas/indoor-navigation.config.json——x-tbox-enforced)同判双锁:
|
|
41
|
+
* 保存过、运行时无目标的缝隙在本对判定清单上不可能再开(长度口径同用 JavaScript
|
|
42
|
+
* 字符串口径——契约 zod .max 即 UTF-16 计数,写面 pattern lookahead 同口径)。
|
|
43
|
+
* 契约先行:URL 解析会对 special scheme 自动补 `//`(`https:nav.example.com` 会规整为
|
|
44
|
+
* `https://nav...`)——先按输出契约锁字面前缀,`https:` 缺斜杠形态在此显性拒绝。
|
|
45
|
+
*/
|
|
46
|
+
function validH5Url(raw: unknown): string | undefined {
|
|
47
|
+
if (typeof raw !== 'string') return undefined;
|
|
48
|
+
if (!indoorNavigationUrlSchema.safeParse(raw).success) return undefined;
|
|
49
|
+
let parsed: URL;
|
|
50
|
+
try {
|
|
51
|
+
parsed = new URL(raw);
|
|
52
|
+
} catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (parsed.protocol !== 'https:' || !parsed.hostname) return undefined;
|
|
56
|
+
// 实际路由片段判定(与写面 pattern 同判):恰一个字面 #,且其开启 #/ 路由段——
|
|
57
|
+
// `#wrong#/ar_v4` 首段非 / 开头(third_id 会追加到错误路由),显性拒绝;fragment
|
|
58
|
+
// 内二次字面 # 亦拒(合法 URL 该形态应编码 %23)
|
|
59
|
+
const hashIndex = raw.indexOf('#');
|
|
60
|
+
if (hashIndex === -1 || raw.indexOf('#', hashIndex + 1) !== -1) return undefined;
|
|
61
|
+
if (!parsed.hash.startsWith('#/')) return undefined;
|
|
62
|
+
return raw;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 路由参数是否承载 third_id:按解码后的参数名匹配(`%74hird_id` 解码即 third_id——
|
|
67
|
+
* 百分号编码是参数名的等价写法);malformed 百分号序列(decode 抛)按原样兜底,
|
|
68
|
+
* decode 不出的键不误杀。仅判定参数名,值形态不参与。
|
|
69
|
+
*/
|
|
70
|
+
function isThirdIdPair(pair: string): boolean {
|
|
71
|
+
const eq = pair.indexOf('=');
|
|
72
|
+
const rawKey = eq === -1 ? pair : pair.slice(0, eq);
|
|
73
|
+
try {
|
|
74
|
+
return decodeURIComponent(rawKey) === AIBEE_THIRD_ID_PARAM;
|
|
75
|
+
} catch {
|
|
76
|
+
return rawKey === AIBEE_THIRD_ID_PARAM;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 爱笔跳转链接生成(wire 单点):
|
|
82
|
+
* - 在首个 `#` 后的路由参数段追加 `third_id=<编码后门店ID>`(原路由与参数形态保留);
|
|
83
|
+
* - 原链接已有的 third_id 参数(含编码等价形态)剔除——同一链接只保留一个;
|
|
84
|
+
* - 其余参数逐字保留(不 decode/re-encode——避免破坏运营粘贴的原始编码形态);
|
|
85
|
+
* - 字符串手术而非 URL 重序列化(结构性 normalize 不得漂移原路径/参数/片段);
|
|
86
|
+
* - 产出复跑最终输出契约(indoorNavigationUrlSchema——消费者同判;超长等边缘 →
|
|
87
|
+
* undefined,不产出消费方终将拒绝的链接)。
|
|
88
|
+
* 任一输入非法(非法地址 / 门店标识缺失——契约单源 isMissingIndoorNavigationMerchantId)
|
|
89
|
+
* → undefined。
|
|
90
|
+
*/
|
|
91
|
+
export function buildAibeeHandoffUrl(
|
|
92
|
+
h5Url: unknown,
|
|
93
|
+
merchantId: string,
|
|
94
|
+
): string | undefined {
|
|
95
|
+
const url = validH5Url(h5Url);
|
|
96
|
+
if (!url || isMissingIndoorNavigationMerchantId(merchantId)) return undefined;
|
|
97
|
+
const hashIndex = url.indexOf('#');
|
|
98
|
+
if (hashIndex === -1) return undefined;
|
|
99
|
+
const hashBody = url.slice(hashIndex + 1);
|
|
100
|
+
const markIndex = hashBody.indexOf('?');
|
|
101
|
+
const route = markIndex === -1 ? hashBody : hashBody.slice(0, markIndex);
|
|
102
|
+
const rawParams = markIndex === -1 ? '' : hashBody.slice(markIndex + 1);
|
|
103
|
+
const kept = rawParams === ''
|
|
104
|
+
? []
|
|
105
|
+
: rawParams.split('&').filter((pair) => pair !== '' && !isThirdIdPair(pair));
|
|
106
|
+
kept.push(`${AIBEE_THIRD_ID_PARAM}=${encodeURIComponent(merchantId)}`);
|
|
107
|
+
const result = `${url.slice(0, hashIndex + 1)}${route}?${kept.join('&')}`;
|
|
108
|
+
return indoorNavigationUrlSchema.safeParse(result).success ? result : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** config 键名(与 schemas/indoor-navigation.config.json 同锁——B 端「导航 H5 地址」) */
|
|
112
|
+
export const AIBEE_H5_URL_CONFIG_KEY = 'h5Url';
|
|
113
|
+
|
|
114
|
+
/** 爱笔室内导航供给实现(结构类型满足 IndoorNavigationHandoffPort)。 */
|
|
115
|
+
export class AibeeIndoorNavigationServiceImpl implements IndoorNavigationHandoffPort {
|
|
116
|
+
readonly #h5Url: unknown;
|
|
117
|
+
|
|
118
|
+
constructor(input: Pick<ServiceAdapterInput, 'config'>) {
|
|
119
|
+
// mallId/scope 语义止于槽解析层(实例 config 五层合并即当前商场配置);
|
|
120
|
+
// 构造期零校验——非法配置在生成时刻 fail-soft(见头注)
|
|
121
|
+
this.#h5Url = input.config?.[AIBEE_H5_URL_CONFIG_KEY];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async resolveHandoffUrl(
|
|
125
|
+
_q: MallQueryContext,
|
|
126
|
+
merchantId: string,
|
|
127
|
+
): Promise<string | undefined> {
|
|
128
|
+
return buildAibeeHandoffUrl(this.#h5Url, merchantId);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** adapter 工厂(registry 双键注册:aibee × aibee-indoor-navigation@1;config = 五层合并后当前商场配置) */
|
|
133
|
+
export const aibeeIndoorNavigationFactory: ServiceAdapterFactory = (input) =>
|
|
134
|
+
new AibeeIndoorNavigationServiceImpl(input) as unknown;
|
package/tbox.module.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"id": "provider-aibee",
|
|
4
|
+
"name": "爱笔室内导航",
|
|
5
|
+
"description": "爱笔(aibee)室内导航供应商供给:按商场配置的爱笔 H5 地址生成本系统门店跳转链接(third_id 路由参数承载 merchantId,编码一次;原路径、参数和片段保留),不落本地数据",
|
|
6
|
+
"kind": "business",
|
|
7
|
+
"risk": {
|
|
8
|
+
"level": "low",
|
|
9
|
+
"writeBoundary": "source"
|
|
10
|
+
},
|
|
11
|
+
"distribution": {
|
|
12
|
+
"defaultMode": "codegen"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"modules": []
|
|
16
|
+
},
|
|
17
|
+
"env": [],
|
|
18
|
+
"declare": {
|
|
19
|
+
"handlers": [],
|
|
20
|
+
"tools": [],
|
|
21
|
+
"cards": [],
|
|
22
|
+
"routes": [],
|
|
23
|
+
"pages": [],
|
|
24
|
+
"tabs": [],
|
|
25
|
+
"providers": {
|
|
26
|
+
"id": "aibee",
|
|
27
|
+
"selectionScope": "supplied-services",
|
|
28
|
+
"slots": [
|
|
29
|
+
{
|
|
30
|
+
"service": "indoor-navigation.handoff",
|
|
31
|
+
"credentialType": "-",
|
|
32
|
+
"provider": "aibee",
|
|
33
|
+
"implementation": "aibee-indoor-navigation@1",
|
|
34
|
+
"configSchema": "schemas/indoor-navigation.config.json"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"consumes": []
|
|
39
|
+
}
|
|
40
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
},
|
|
8
|
+
format: ['esm'],
|
|
9
|
+
target: 'node20',
|
|
10
|
+
platform: 'node',
|
|
11
|
+
outDir: 'dist',
|
|
12
|
+
clean: true,
|
|
13
|
+
sourcemap: false,
|
|
14
|
+
// dts worker 以命令行式传参会撞 TS5074(incremental 需单文件 emit 或 tsBuildInfoFile);
|
|
15
|
+
// 声明产物一次性构建无需增量——仅 dts 关闭,typecheck 的增量缓存不受影响。
|
|
16
|
+
dts: { compilerOptions: { incremental: false } },
|
|
17
|
+
external: [
|
|
18
|
+
'@tbox.cn/app-agent-sdk-server',
|
|
19
|
+
'@tbox.cn/app-contracts',
|
|
20
|
+
'@tbox.cn/app-contracts-mall',
|
|
21
|
+
],
|
|
22
|
+
});
|