@tbox.cn/app-contracts 0.1.3 → 0.9.0
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/dist/cards.d.ts +171 -4
- package/dist/context-slot.d.ts +23 -0
- package/dist/host-effect.d.ts +66 -0
- package/dist/identity.d.ts +15 -4
- package/dist/index.d.ts +9 -0
- package/dist/integrations-config.d.ts +3 -0
- package/dist/memory-tool.d.ts +64 -0
- package/dist/memory.d.ts +94 -0
- package/dist/no-inline-secrets.d.ts +1 -0
- package/dist/pre-tool.d.ts +56 -0
- package/dist/protocol.d.ts +90 -3
- package/dist/providers.d.ts +368 -0
- package/dist/runtime.d.ts +12 -2
- package/dist/runtime.js +509 -3
- package/dist/skill.d.ts +49 -0
- package/package.json +14 -10
- package/tests/__snapshots__/integrations-config-parity.test.ts.snap +354 -0
- package/tests/integrations-config-parity.test.ts +81 -0
- package/tests/integrations-config.test.ts +274 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`integrations-config 迁移等价锁(C1-5) > P1 wanda 素材 parse:结构快照锁定(迁移零漂移) 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"config": {
|
|
6
|
+
"baseUrl": "<VAR>",
|
|
7
|
+
"clientId": "<VAR>",
|
|
8
|
+
"freeCouponClaimMode": "<VAR>",
|
|
9
|
+
"miniAppId": "<VAR>",
|
|
10
|
+
"requestTimeoutMs": 8000,
|
|
11
|
+
"tenantId": "<VAR>",
|
|
12
|
+
"xSignVer": "<VAR>",
|
|
13
|
+
},
|
|
14
|
+
"credentialRef": "secret://wanda-c-signed",
|
|
15
|
+
"defaultInstanceId": "<VAR>",
|
|
16
|
+
"modules": {
|
|
17
|
+
"module-customer-service": {
|
|
18
|
+
"resources": {
|
|
19
|
+
"customer-service-faq-kb": {
|
|
20
|
+
"ref": "customer-service-faq-wanda",
|
|
21
|
+
"type": "knowledge",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
"provider": "wanda",
|
|
27
|
+
"services": {
|
|
28
|
+
"auth.alipay-login": {
|
|
29
|
+
"instances": {
|
|
30
|
+
"*": {
|
|
31
|
+
"config": {
|
|
32
|
+
"mockAuth": "<VAR>",
|
|
33
|
+
"mockMemberId": "<VAR>",
|
|
34
|
+
"mockOpenId": "<VAR>",
|
|
35
|
+
"mockVisitorAuth": "<VAR>",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
"mall.info": {},
|
|
41
|
+
"member.account": {},
|
|
42
|
+
"member.benefits": {},
|
|
43
|
+
"member.card": {},
|
|
44
|
+
"member.enrollment": {},
|
|
45
|
+
"member.profile": {},
|
|
46
|
+
"parking.payment": {},
|
|
47
|
+
"parking.query": {},
|
|
48
|
+
"parking.vehicle": {},
|
|
49
|
+
"promotion.acquisition": {},
|
|
50
|
+
"promotion.activities": {},
|
|
51
|
+
"promotion.entitlements": {},
|
|
52
|
+
"promotion.offers": {},
|
|
53
|
+
"shopping-guide.categories": {},
|
|
54
|
+
"shopping-guide.directory": {},
|
|
55
|
+
"shopping-guide.shops": {},
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
exports[`integrations-config 迁移等价锁(C1-5) > P2 joycity 素材 parse(ByInstance 直改形态):结构快照锁定 1`] = `
|
|
61
|
+
{
|
|
62
|
+
"config": {
|
|
63
|
+
"baseUrl": "https://m-crm-t.joycity.mobi",
|
|
64
|
+
"requestTimeoutMs": 8000,
|
|
65
|
+
},
|
|
66
|
+
"credentialRefByInstance": {
|
|
67
|
+
"10669": "secret://joycity-10669-c-signed",
|
|
68
|
+
"10895": "secret://joycity-10895-c-signed",
|
|
69
|
+
},
|
|
70
|
+
"defaultInstanceId": "10669",
|
|
71
|
+
"instances": [
|
|
72
|
+
{
|
|
73
|
+
"attributes": {
|
|
74
|
+
"location": {
|
|
75
|
+
"address": "浙江省杭州市拱墅区丽水路 2 号",
|
|
76
|
+
"lat": 30.2741,
|
|
77
|
+
"lon": 120.1551,
|
|
78
|
+
},
|
|
79
|
+
"miniAppId": "2021006179639711",
|
|
80
|
+
},
|
|
81
|
+
"id": "10669",
|
|
82
|
+
"name": "杭州大悦城",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"attributes": {
|
|
86
|
+
"location": {
|
|
87
|
+
"address": "陕西省西安市雁塔区朱雀大街 388 号",
|
|
88
|
+
"lat": 34.2658,
|
|
89
|
+
"lon": 108.9505,
|
|
90
|
+
},
|
|
91
|
+
"miniAppId": "2021006179639711",
|
|
92
|
+
},
|
|
93
|
+
"id": "10895",
|
|
94
|
+
"name": "西安大悦城",
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
"modules": {
|
|
98
|
+
"module-customer-service": {
|
|
99
|
+
"resources": {
|
|
100
|
+
"customer-service-faq-kb": {
|
|
101
|
+
"ref": "customer-service-faq-v3",
|
|
102
|
+
"type": "knowledge",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
"provider": "joycity",
|
|
108
|
+
"services": {
|
|
109
|
+
"auth.alipay-login": {
|
|
110
|
+
"config": {
|
|
111
|
+
"alipayAppId": "2021006179639711",
|
|
112
|
+
},
|
|
113
|
+
"instances": {
|
|
114
|
+
"10669": {},
|
|
115
|
+
"10895": {},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
"mall.info": {
|
|
119
|
+
"implementation": "joycity-mall-info@1",
|
|
120
|
+
"instances": {
|
|
121
|
+
"10669": {
|
|
122
|
+
"config": {
|
|
123
|
+
"address": "浙江省杭州市拱墅区丽水路 2 号",
|
|
124
|
+
"latitude": 30.2741,
|
|
125
|
+
"longitude": 120.1551,
|
|
126
|
+
"name": "杭州大悦城",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
"10895": {
|
|
130
|
+
"config": {
|
|
131
|
+
"address": "陕西省西安市雁塔区朱雀大街 388 号",
|
|
132
|
+
"latitude": 34.2658,
|
|
133
|
+
"longitude": 108.9505,
|
|
134
|
+
"name": "西安大悦城",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
"provider": "joycity",
|
|
139
|
+
},
|
|
140
|
+
"member.account": {
|
|
141
|
+
"instances": {
|
|
142
|
+
"10669": {
|
|
143
|
+
"config": {
|
|
144
|
+
"alipayAppId": "2021006179639711",
|
|
145
|
+
"enrollUrl": "alipays://platformapi/startapp?appId=2021006179639711&page=v/index/index?url=https%3A%2F%2Fm-crm-t.joycity.mobi%2Fv%2Fuser%2Finfo%2Findex%3Fmid%3D10669",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
"10895": {
|
|
149
|
+
"config": {
|
|
150
|
+
"alipayAppId": "2021006179639711",
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
"member.benefits": {
|
|
156
|
+
"instances": {
|
|
157
|
+
"10669": {
|
|
158
|
+
"config": {
|
|
159
|
+
"alipayAppId": "2021006179639711",
|
|
160
|
+
"enrollUrl": "alipays://platformapi/startapp?appId=2021006179639711&page=v/index/index?url=https%3A%2F%2Fm-crm-t.joycity.mobi%2Fv%2Fuser%2Finfo%2Findex%3Fmid%3D10669",
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
"10895": {
|
|
164
|
+
"config": {
|
|
165
|
+
"alipayAppId": "2021006179639711",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
"member.card": {
|
|
171
|
+
"instances": {
|
|
172
|
+
"10669": {
|
|
173
|
+
"config": {
|
|
174
|
+
"alipayAppId": "2021006179639711",
|
|
175
|
+
"enrollUrl": "alipays://platformapi/startapp?appId=2021006179639711&page=v/index/index?url=https%3A%2F%2Fm-crm-t.joycity.mobi%2Fv%2Fuser%2Finfo%2Findex%3Fmid%3D10669",
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
"10895": {
|
|
179
|
+
"config": {
|
|
180
|
+
"alipayAppId": "2021006179639711",
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
"member.enrollment": {
|
|
186
|
+
"instances": {
|
|
187
|
+
"10669": {
|
|
188
|
+
"config": {
|
|
189
|
+
"alipayAppId": "2021006179639711",
|
|
190
|
+
"enrollUrl": "alipays://platformapi/startapp?appId=2021006179639711&page=v/index/index?url=https%3A%2F%2Fm-crm-t.joycity.mobi%2Fv%2Fuser%2Finfo%2Findex%3Fmid%3D10669",
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
"10895": {
|
|
194
|
+
"config": {
|
|
195
|
+
"alipayAppId": "2021006179639711",
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
"member.profile": {
|
|
201
|
+
"instances": {
|
|
202
|
+
"10669": {
|
|
203
|
+
"config": {
|
|
204
|
+
"alipayAppId": "2021006179639711",
|
|
205
|
+
"enrollUrl": "alipays://platformapi/startapp?appId=2021006179639711&page=v/index/index?url=https%3A%2F%2Fm-crm-t.joycity.mobi%2Fv%2Fuser%2Finfo%2Findex%3Fmid%3D10669",
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
"10895": {
|
|
209
|
+
"config": {
|
|
210
|
+
"alipayAppId": "2021006179639711",
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
"parking.payment": {
|
|
216
|
+
"config": {
|
|
217
|
+
"memberMallId": "12988",
|
|
218
|
+
"parkId": "100017",
|
|
219
|
+
"parkingMallId": "12988",
|
|
220
|
+
"pointsBenefitTitles": [
|
|
221
|
+
"商场积分抵扣Pro",
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
"instances": {
|
|
225
|
+
"10669": {},
|
|
226
|
+
"10895": {},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
"parking.query": {
|
|
230
|
+
"config": {
|
|
231
|
+
"memberMallId": "12988",
|
|
232
|
+
"parkId": "100017",
|
|
233
|
+
"parkingMallId": "12988",
|
|
234
|
+
"pointsBenefitTitles": [
|
|
235
|
+
"商场积分抵扣Pro",
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
"instances": {
|
|
239
|
+
"10669": {},
|
|
240
|
+
"10895": {},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
"parking.vehicle": {
|
|
244
|
+
"config": {
|
|
245
|
+
"memberMallId": "12988",
|
|
246
|
+
"parkId": "100017",
|
|
247
|
+
"parkingMallId": "12988",
|
|
248
|
+
"pointsBenefitTitles": [
|
|
249
|
+
"商场积分抵扣Pro",
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
"instances": {
|
|
253
|
+
"10669": {},
|
|
254
|
+
"10895": {},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
"promotion.acquisition": {
|
|
258
|
+
"instances": {
|
|
259
|
+
"10669": {
|
|
260
|
+
"config": {
|
|
261
|
+
"baseUrl": "https://m-crm.joycity.mobi",
|
|
262
|
+
"mallMappingId": "10669",
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
"10895": {
|
|
266
|
+
"config": {
|
|
267
|
+
"baseUrl": "https://m-crm-t.joycity.mobi",
|
|
268
|
+
"mallMappingId": "10895",
|
|
269
|
+
},
|
|
270
|
+
"credentialRef": "secret://joycity-10895-c-signed-marketing",
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
"promotion.activities": {
|
|
275
|
+
"instances": {
|
|
276
|
+
"10669": {
|
|
277
|
+
"config": {
|
|
278
|
+
"baseUrl": "https://m-crm.joycity.mobi",
|
|
279
|
+
"mallMappingId": "10669",
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
"10895": {
|
|
283
|
+
"config": {
|
|
284
|
+
"baseUrl": "https://m-crm-t.joycity.mobi",
|
|
285
|
+
"mallMappingId": "10895",
|
|
286
|
+
},
|
|
287
|
+
"credentialRef": "secret://joycity-10895-c-signed-marketing",
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
"promotion.entitlements": {
|
|
292
|
+
"instances": {
|
|
293
|
+
"10669": {
|
|
294
|
+
"config": {
|
|
295
|
+
"baseUrl": "https://m-crm.joycity.mobi",
|
|
296
|
+
"mallMappingId": "10669",
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
"10895": {
|
|
300
|
+
"config": {
|
|
301
|
+
"baseUrl": "https://m-crm-t.joycity.mobi",
|
|
302
|
+
"mallMappingId": "10895",
|
|
303
|
+
},
|
|
304
|
+
"credentialRef": "secret://joycity-10895-c-signed-marketing",
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
"promotion.offers": {
|
|
309
|
+
"instances": {
|
|
310
|
+
"10669": {
|
|
311
|
+
"config": {
|
|
312
|
+
"baseUrl": "https://m-crm.joycity.mobi",
|
|
313
|
+
"mallMappingId": "10669",
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
"10895": {
|
|
317
|
+
"config": {
|
|
318
|
+
"baseUrl": "https://m-crm-t.joycity.mobi",
|
|
319
|
+
"mallMappingId": "10895",
|
|
320
|
+
},
|
|
321
|
+
"credentialRef": "secret://joycity-10895-c-signed-marketing",
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
"shopping-guide.catalog": {
|
|
326
|
+
"config": {
|
|
327
|
+
"alipayAppId": "2021006179639711",
|
|
328
|
+
},
|
|
329
|
+
"instances": {
|
|
330
|
+
"10669": {},
|
|
331
|
+
"10895": {},
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
"shopping-guide.categories": {
|
|
335
|
+
"config": {
|
|
336
|
+
"alipayAppId": "2021006179639711",
|
|
337
|
+
},
|
|
338
|
+
"instances": {
|
|
339
|
+
"10669": {},
|
|
340
|
+
"10895": {},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
"shopping-guide.shops": {
|
|
344
|
+
"config": {
|
|
345
|
+
"alipayAppId": "2021006179639711",
|
|
346
|
+
},
|
|
347
|
+
"instances": {
|
|
348
|
+
"10669": {},
|
|
349
|
+
"10895": {},
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
}
|
|
354
|
+
`;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* integrations-config 迁移等价锁(C1-5):app-sdk → contracts 搬移 + ByInstance 直切后,
|
|
3
|
+
* 真实素材(.real-env/config 全档)经新链 parse 输出锁定 + 直切防线(旧 ByScope 键拒 +
|
|
4
|
+
* 更名指引)+ demand meta additive 等价。
|
|
5
|
+
*
|
|
6
|
+
* P1/P2:wanda(含 ${VAR} 占位——值 opaque,zod 直过)与 joycity(ByInstance 形态)parse 快照。
|
|
7
|
+
* P3:拼错键 / 内联 secret / 空 instances 数组 / 重复 id 拒绝行为(与既有测试矩阵同型)。
|
|
8
|
+
* P5:旧 ByScope 键素材(内联构造)→ 拒绝 + 错误文案含更名指引(直切兜底)。
|
|
9
|
+
* (P6 demand meta additive 归 toolkit module-schema 测试——serviceNeedContribSchema 属 descriptor 侧)
|
|
10
|
+
*/
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { parseIntegrationsConfig, assertNoInlineSecrets } from '../src/index';
|
|
15
|
+
|
|
16
|
+
const REAL_ENV = join(import.meta.dirname ?? '.', '..', '..', '..', '.real-env', 'config');
|
|
17
|
+
|
|
18
|
+
function loadRealEnv(vendor: string): unknown {
|
|
19
|
+
return JSON.parse(readFileSync(join(REAL_ENV, vendor, 'integrations.json'), 'utf8'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 结构摘要(快照稳定器:值含 ${VAR} 与实例名——锁键集与层级形状而非动态值) */
|
|
23
|
+
function shape(value: unknown): unknown {
|
|
24
|
+
if (Array.isArray(value)) return value.map(shape);
|
|
25
|
+
if (value && typeof value === 'object') {
|
|
26
|
+
return Object.fromEntries(Object.entries(value as Record<string, unknown>).map(([k, v]) => [k, shape(v)]));
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'string') return value.startsWith('${') ? '<VAR>' : value;
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('integrations-config 迁移等价锁(C1-5)', () => {
|
|
33
|
+
it('P1 wanda 素材 parse:结构快照锁定(迁移零漂移)', () => {
|
|
34
|
+
const parsed = parseIntegrationsConfig(loadRealEnv('wanda'));
|
|
35
|
+
expect(shape(parsed)).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('P2 joycity 素材 parse(ByInstance 直改形态):结构快照锁定', () => {
|
|
39
|
+
const parsed = parseIntegrationsConfig(loadRealEnv('joycity'));
|
|
40
|
+
expect(shape(parsed)).toMatchSnapshot();
|
|
41
|
+
const raw = loadRealEnv('joycity') as Record<string, unknown>;
|
|
42
|
+
expect(raw.credentialRefByInstance).toBeDefined();
|
|
43
|
+
expect(raw.credentialRefByScope).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('P3 拒绝矩阵:拼错键 / 内联 secret / 空 instances / 重复 id', () => {
|
|
47
|
+
// 拼错键(strict 拒)
|
|
48
|
+
expect(() => parseIntegrationsConfig({ services: {}, servicesTypo: {} })).toThrow();
|
|
49
|
+
// 内联 secret(防线单点)
|
|
50
|
+
expect(() => parseIntegrationsConfig({ services: {}, apiKey: 'sk-live' })).toThrow(/内联密钥/);
|
|
51
|
+
// 空 instances 数组
|
|
52
|
+
expect(() => parseIntegrationsConfig({ services: {}, instances: [] })).toThrow(/空数组非法/);
|
|
53
|
+
// 重复 id
|
|
54
|
+
expect(() =>
|
|
55
|
+
parseIntegrationsConfig({
|
|
56
|
+
services: {},
|
|
57
|
+
instances: [
|
|
58
|
+
{ id: 'm1', name: 'a' },
|
|
59
|
+
{ id: 'm1', name: 'b' },
|
|
60
|
+
],
|
|
61
|
+
}),
|
|
62
|
+
).toThrow(/重复/);
|
|
63
|
+
// 断言单点仍导出可用
|
|
64
|
+
expect(() => assertNoInlineSecrets({ password: 'x' })).toThrow(/内联密钥/);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('P5 旧 ByScope 键素材 → 拒绝 + 错误文案含更名指引(直切兜底)', () => {
|
|
68
|
+
expect(() =>
|
|
69
|
+
parseIntegrationsConfig({ services: {}, configByScope: { 'mall-1': { baseUrl: 'x' } } }),
|
|
70
|
+
).toThrow(/configByInstance/);
|
|
71
|
+
expect(() =>
|
|
72
|
+
parseIntegrationsConfig({ services: {}, credentialRefByScope: { 'mall-1': 'secret://a' } }),
|
|
73
|
+
).toThrow(/credentialRefByInstance/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('P4 搬移完整性:assertNoInlineSecrets 与 parse 同源自 contracts 公开面', async () => {
|
|
77
|
+
const mod = await import('../src/index');
|
|
78
|
+
expect(typeof mod.parseIntegrationsConfig).toBe('function');
|
|
79
|
+
expect(typeof mod.assertNoInlineSecrets).toBe('function');
|
|
80
|
+
});
|
|
81
|
+
});
|