@pisell/pisellos 2.3.81 → 2.3.83
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/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/BookingContext/index.d.ts +3 -0
- package/dist/modules/BookingContext/index.js +42 -13
- package/dist/modules/BookingContext/types.d.ts +4 -4
- package/dist/modules/BookingContext/types.js +3 -3
- package/dist/modules/ProductList/clientDataVariants.d.ts +23 -0
- package/dist/modules/ProductList/clientDataVariants.js +165 -11
- package/dist/modules/ProductList/index.d.ts +14 -0
- package/dist/modules/ProductList/index.js +78 -11
- package/dist/solution/BaseSales/index.d.ts +16 -1
- package/dist/solution/BaseSales/index.js +531 -273
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/UnifiedBookingSales/index.js +2 -2
- package/dist/utils/platform.d.ts +8 -0
- package/dist/utils/platform.js +15 -0
- package/lib/modules/BookingContext/index.d.ts +3 -0
- package/lib/modules/BookingContext/index.js +35 -8
- package/lib/modules/BookingContext/types.d.ts +4 -4
- package/lib/modules/BookingContext/types.js +3 -3
- package/lib/modules/ProductList/clientDataVariants.d.ts +23 -0
- package/lib/modules/ProductList/clientDataVariants.js +147 -11
- package/lib/modules/ProductList/index.d.ts +14 -0
- package/lib/modules/ProductList/index.js +59 -1
- package/lib/solution/BaseSales/index.d.ts +16 -1
- package/lib/solution/BaseSales/index.js +258 -66
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/UnifiedBookingSales/index.js +2 -2
- package/lib/utils/platform.d.ts +8 -0
- package/lib/utils/platform.js +22 -0
- package/package.json +1 -1
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// 导出评估器
|
|
2
|
-
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
-
|
|
4
|
-
// 导出适配器
|
|
5
|
-
export { PromotionAdapter } from "./adapter";
|
|
6
|
-
export { default } from "./adapter";
|
|
7
|
-
|
|
8
|
-
// 导出策略配置示例常量
|
|
9
|
-
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
|
|
@@ -19,12 +19,15 @@ export declare class BookingContextModule extends BaseModule implements Module,
|
|
|
19
19
|
protected defaultVersion: string;
|
|
20
20
|
private request;
|
|
21
21
|
private store;
|
|
22
|
+
private otherParams;
|
|
22
23
|
/** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
|
|
23
24
|
private lastConfigQueryKey;
|
|
24
25
|
/** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
|
|
25
26
|
private lastResourcesQueryKey;
|
|
26
27
|
constructor(name?: string, version?: string);
|
|
27
28
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
29
|
+
/** 同步父级解决方案的运行态参数;platform 变化后会自然切换 config endpoint/cache key。 */
|
|
30
|
+
updateOtherParams(params: Record<string, any>): void;
|
|
28
31
|
loadBookingConfig(params?: LoadBookingConfigParams, options?: {
|
|
29
32
|
forceRefresh?: boolean;
|
|
30
33
|
}): Promise<BookingContextConfig | null>;
|
|
@@ -26,6 +26,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
26
26
|
import dayjs from 'dayjs';
|
|
27
27
|
import { BaseModule } from "../BaseModule";
|
|
28
28
|
import { RequestModeENUM } from "../../plugins/request";
|
|
29
|
+
import { normalizeRuntimePlatform } from "../../utils/platform";
|
|
29
30
|
import { BookingContextEvent } from "./types";
|
|
30
31
|
import { formatResourceListAndMap } from "./utils/formatResourceList";
|
|
31
32
|
export * from "./types";
|
|
@@ -40,6 +41,8 @@ var DEFAULT_BOOKING_CONFIG_PARAMS = {
|
|
|
40
41
|
item_type: 'appointment_booking',
|
|
41
42
|
sub_type: 'ticket'
|
|
42
43
|
};
|
|
44
|
+
var BOOKING_CONFIG_ENDPOINT = '/core/board/management/config';
|
|
45
|
+
var H5_BOOKING_CONFIG_ENDPOINT = '/core/board/config';
|
|
43
46
|
var BOARD_CONFIG_CACHE = {
|
|
44
47
|
useCache: true,
|
|
45
48
|
cache: {
|
|
@@ -153,6 +156,24 @@ export function buildBookingConfigQueryKey() {
|
|
|
153
156
|
});
|
|
154
157
|
return JSON.stringify(sorted);
|
|
155
158
|
}
|
|
159
|
+
function resolveBookingConfigRequest(platform) {
|
|
160
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
161
|
+
var isH5 = normalizeRuntimePlatform(platform) === 'h5';
|
|
162
|
+
var endpoint = isH5 ? H5_BOOKING_CONFIG_ENDPOINT : BOOKING_CONFIG_ENDPOINT;
|
|
163
|
+
var query = isH5 ? {
|
|
164
|
+
item_type: params.item_type || DEFAULT_BOOKING_CONFIG_PARAMS.item_type
|
|
165
|
+
} : _objectSpread(_objectSpread({}, DEFAULT_BOOKING_CONFIG_PARAMS), params);
|
|
166
|
+
var keys = Object.keys(query).sort();
|
|
167
|
+
var sortedQuery = {};
|
|
168
|
+
keys.forEach(function (key) {
|
|
169
|
+
sortedQuery[key] = query[key];
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
endpoint: endpoint,
|
|
173
|
+
query: query,
|
|
174
|
+
key: "".concat(endpoint, ":").concat(JSON.stringify(sortedQuery))
|
|
175
|
+
};
|
|
176
|
+
}
|
|
156
177
|
|
|
157
178
|
/** 稳定序列化资源列表查询(date + bookingIds),用于跳过重复 loadResources。 */
|
|
158
179
|
export function buildBookingResourcesQueryKey() {
|
|
@@ -176,6 +197,7 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
176
197
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
177
198
|
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
178
199
|
_defineProperty(_assertThisInitialized(_this), "store", _objectSpread({}, EMPTY_STATE));
|
|
200
|
+
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
179
201
|
/** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
|
|
180
202
|
_defineProperty(_assertThisInitialized(_this), "lastConfigQueryKey", null);
|
|
181
203
|
/** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
|
|
@@ -201,6 +223,7 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
201
223
|
}
|
|
202
224
|
throw new Error('BookingContextModule 需要 request 插件支持');
|
|
203
225
|
case 5:
|
|
226
|
+
this.otherParams = options.otherParams || {};
|
|
204
227
|
this.store = {
|
|
205
228
|
bookingConfig: null,
|
|
206
229
|
resourcesOrigin: [],
|
|
@@ -218,7 +241,7 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
218
241
|
if (initialState.date) {
|
|
219
242
|
this.store.date = initialState.date;
|
|
220
243
|
}
|
|
221
|
-
case
|
|
244
|
+
case 11:
|
|
222
245
|
case "end":
|
|
223
246
|
return _context.stop();
|
|
224
247
|
}
|
|
@@ -228,16 +251,22 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
228
251
|
return _initialize.apply(this, arguments);
|
|
229
252
|
}
|
|
230
253
|
return initialize;
|
|
231
|
-
}()
|
|
254
|
+
}() /** 同步父级解决方案的运行态参数;platform 变化后会自然切换 config endpoint/cache key。 */
|
|
255
|
+
}, {
|
|
256
|
+
key: "updateOtherParams",
|
|
257
|
+
value: function updateOtherParams(params) {
|
|
258
|
+
this.otherParams = params || {};
|
|
259
|
+
}
|
|
232
260
|
}, {
|
|
233
261
|
key: "loadBookingConfig",
|
|
234
262
|
value: function () {
|
|
235
263
|
var _loadBookingConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
236
|
-
var
|
|
264
|
+
var _this$otherParams,
|
|
265
|
+
_this2 = this;
|
|
237
266
|
var params,
|
|
238
267
|
options,
|
|
268
|
+
requestConfig,
|
|
239
269
|
configKey,
|
|
240
|
-
query,
|
|
241
270
|
sharedKey,
|
|
242
271
|
_sharedBookingConfigC,
|
|
243
272
|
cached,
|
|
@@ -250,14 +279,14 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
250
279
|
case 0:
|
|
251
280
|
params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
|
|
252
281
|
options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
|
|
253
|
-
|
|
282
|
+
requestConfig = resolveBookingConfigRequest((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.platform, params);
|
|
283
|
+
configKey = requestConfig.key;
|
|
254
284
|
if (!(!options.forceRefresh && this.store.bookingConfig != null && this.lastConfigQueryKey === configKey)) {
|
|
255
|
-
_context3.next =
|
|
285
|
+
_context3.next = 6;
|
|
256
286
|
break;
|
|
257
287
|
}
|
|
258
288
|
return _context3.abrupt("return", this.store.bookingConfig);
|
|
259
|
-
case
|
|
260
|
-
query = _objectSpread(_objectSpread({}, DEFAULT_BOOKING_CONFIG_PARAMS), params);
|
|
289
|
+
case 6:
|
|
261
290
|
sharedKey = buildSharedCacheKey(this.request, configKey);
|
|
262
291
|
if (!(!options.forceRefresh && sharedBookingConfigCache.has(sharedKey))) {
|
|
263
292
|
_context3.next = 12;
|
|
@@ -277,7 +306,7 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
277
306
|
case 0:
|
|
278
307
|
_context2.prev = 0;
|
|
279
308
|
_context2.next = 3;
|
|
280
|
-
return _this2.request.get(
|
|
309
|
+
return _this2.request.get(requestConfig.endpoint, requestConfig.query, BOARD_CONFIG_CACHE);
|
|
281
310
|
case 3:
|
|
282
311
|
res = _context2.sent;
|
|
283
312
|
_config = (_res$data = res === null || res === void 0 ? void 0 : res.data) !== null && _res$data !== void 0 ? _res$data : null;
|
|
@@ -411,9 +440,9 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
411
440
|
}, {
|
|
412
441
|
key: "isBookingContextReady",
|
|
413
442
|
value: function isBookingContextReady() {
|
|
414
|
-
var _ref3, _params$date2;
|
|
443
|
+
var _this$otherParams2, _ref3, _params$date2;
|
|
415
444
|
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
416
|
-
var configKey =
|
|
445
|
+
var configKey = resolveBookingConfigRequest((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform, params.bookingConfigParams).key;
|
|
417
446
|
var dateInput = (_ref3 = (_params$date2 = params.date) !== null && _params$date2 !== void 0 ? _params$date2 : this.store.date) !== null && _ref3 !== void 0 ? _ref3 : dayjs();
|
|
418
447
|
var queryDate = toScheduleQueryDate(dateInput);
|
|
419
448
|
var resourcesKey = buildBookingResourcesQueryKey({
|
|
@@ -428,7 +457,7 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
428
457
|
key: "initBookingContext",
|
|
429
458
|
value: function () {
|
|
430
459
|
var _initBookingContext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
431
|
-
var _ref4, _params$date3;
|
|
460
|
+
var _ref4, _params$date3, _this$otherParams3;
|
|
432
461
|
var params,
|
|
433
462
|
dateInput,
|
|
434
463
|
queryDate,
|
|
@@ -450,7 +479,7 @@ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
450
479
|
}
|
|
451
480
|
return _context6.abrupt("return", this.getState());
|
|
452
481
|
case 6:
|
|
453
|
-
configKey =
|
|
482
|
+
configKey = resolveBookingConfigRequest((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.platform, params.bookingConfigParams).key;
|
|
454
483
|
resourcesKey = buildBookingResourcesQueryKey({
|
|
455
484
|
date: queryDate,
|
|
456
485
|
bookingIds: params.bookingIds
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BookingContext 子模块:承载「预约 UI 上下文」三件套。
|
|
3
3
|
*
|
|
4
|
-
* - bookingConfig:来自 `/core/board/management/config` 的整套预约配置(service_time / resource_tab /
|
|
4
|
+
* - bookingConfig:来自 staff `/core/board/management/config` 或 H5 `/core/board/config` 的整套预约配置(service_time / resource_tab /
|
|
5
5
|
* appointment_subject / subject_require / stock_setting / basic / capacity 等)。
|
|
6
6
|
* - resourcesOrigin / resourcesOriginMap:来自 `/schedule/resource/list` 的资源全集,含 times / event_list /
|
|
7
7
|
* combined_resource 等运行态信息,是 getResourceByIds / getResourceTimeIsUsable 的输入。
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - 默认由 `loadBookingConfig` / `loadResources` 拉取并写入 store;也支持消费方 `set*` 直接灌入(复用 ticketBooking 已拉到的数据)。
|
|
12
12
|
* - 所有读 API 返回浅克隆(数组)或原引用(map / config),避免 UI 写穿。
|
|
13
13
|
*/
|
|
14
|
-
/** `loadBookingConfig`
|
|
14
|
+
/** `loadBookingConfig` 入参;H5 公共接口只消费 `item_type`。 */
|
|
15
15
|
export interface LoadBookingConfigParams {
|
|
16
16
|
item_type?: string;
|
|
17
17
|
sub_type?: string;
|
|
@@ -42,7 +42,7 @@ export interface InitBookingContextParams {
|
|
|
42
42
|
export type BookingContextResource = Record<string, any>;
|
|
43
43
|
export type BookingContextResourceMap = Record<string, BookingContextResource>;
|
|
44
44
|
/**
|
|
45
|
-
* 形参 booking_config(结构来自
|
|
45
|
+
* 形参 booking_config(结构来自 staff management 或 H5 board config 接口的 `data`)。
|
|
46
46
|
* OS 不强制 schema,保留 `Record<string, any>` 兼容现网;常用路径文档化在 SDK docs。
|
|
47
47
|
*/
|
|
48
48
|
export type BookingContextConfig = Record<string, any>;
|
|
@@ -80,7 +80,7 @@ export interface BookingContextModuleAPI {
|
|
|
80
80
|
getState(): BookingContextState;
|
|
81
81
|
/** 一键清空,destroy / 切租户场景用。 */
|
|
82
82
|
clear(): void;
|
|
83
|
-
/**
|
|
83
|
+
/** 按运行平台拉取 board config 并写入 store。 */
|
|
84
84
|
loadBookingConfig(params?: LoadBookingConfigParams): Promise<BookingContextConfig | null>;
|
|
85
85
|
/** 拉取资源全集并写入 store(`/schedule/resource/list`)。 */
|
|
86
86
|
loadResources(params?: LoadBookingResourcesParams): Promise<BookingContextResource[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BookingContext 子模块:承载「预约 UI 上下文」三件套。
|
|
3
3
|
*
|
|
4
|
-
* - bookingConfig:来自 `/core/board/management/config` 的整套预约配置(service_time / resource_tab /
|
|
4
|
+
* - bookingConfig:来自 staff `/core/board/management/config` 或 H5 `/core/board/config` 的整套预约配置(service_time / resource_tab /
|
|
5
5
|
* appointment_subject / subject_require / stock_setting / basic / capacity 等)。
|
|
6
6
|
* - resourcesOrigin / resourcesOriginMap:来自 `/schedule/resource/list` 的资源全集,含 times / event_list /
|
|
7
7
|
* combined_resource 等运行态信息,是 getResourceByIds / getResourceTimeIsUsable 的输入。
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - 所有读 API 返回浅克隆(数组)或原引用(map / config),避免 UI 写穿。
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
/** `loadBookingConfig`
|
|
15
|
+
/** `loadBookingConfig` 入参;H5 公共接口只消费 `item_type`。 */
|
|
16
16
|
|
|
17
17
|
/** `loadResources` 入参,与 info2 `getResourceList` 一致。 */
|
|
18
18
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* 形参 booking_config(结构来自
|
|
27
|
+
* 形参 booking_config(结构来自 staff management 或 H5 board config 接口的 `data`)。
|
|
28
28
|
* OS 不强制 schema,保留 `Record<string, any>` 兼容现网;常用路径文档化在 SDK docs。
|
|
29
29
|
*/
|
|
30
30
|
|
|
@@ -17,7 +17,30 @@ export interface ResolveClientDataVariantsParams {
|
|
|
17
17
|
handledByOsServer: boolean;
|
|
18
18
|
scheduleList?: unknown;
|
|
19
19
|
menuList?: unknown;
|
|
20
|
+
/** Quote fast paths require hydrated relations; legacy list resolution does not. */
|
|
21
|
+
requireCompleteDataVariantRelations?: boolean;
|
|
22
|
+
/** Quote fast paths require every referenced rule; legacy list resolution is best-effort. */
|
|
23
|
+
requireEvaluatorReady?: boolean;
|
|
20
24
|
}
|
|
25
|
+
export type ResolveClientDataVariantsResult = {
|
|
26
|
+
status: 'handled-by-os-server' | 'empty' | 'data-variants-unavailable' | 'evaluator-unavailable' | 'evaluator-not-ready';
|
|
27
|
+
products: ProductData[];
|
|
28
|
+
} | {
|
|
29
|
+
status: 'resolved';
|
|
30
|
+
products: ProductData[];
|
|
31
|
+
} | {
|
|
32
|
+
status: 'error';
|
|
33
|
+
products: ProductData[];
|
|
34
|
+
error: unknown;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Strict client-side Data Variant resolution for quote fast paths.
|
|
38
|
+
*
|
|
39
|
+
* Unlike resolveClientDataVariants, callers can distinguish a complete local
|
|
40
|
+
* result from a capability/readiness/error fallback and decide to query the
|
|
41
|
+
* remote product endpoint instead.
|
|
42
|
+
*/
|
|
43
|
+
export declare function tryResolveClientDataVariants({ core, otherParams, products, queryPayload, handledByOsServer, scheduleList: explicitScheduleList, menuList: explicitMenuList, requireCompleteDataVariantRelations, requireEvaluatorReady, }: ResolveClientDataVariantsParams): ResolveClientDataVariantsResult;
|
|
21
44
|
/**
|
|
22
45
|
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
23
46
|
*
|
|
@@ -13,13 +13,74 @@ export function isProductQueryHandledByOsServer(core, request) {
|
|
|
13
13
|
var requestBaseUrl = String((request === null || request === void 0 ? void 0 : request.baseUrl) || '/shop').replace(/\/+$/, '');
|
|
14
14
|
return server.hasRoute('post', "".concat(requestBaseUrl, "/product/query")) === true;
|
|
15
15
|
}
|
|
16
|
+
function getBundleItems(product) {
|
|
17
|
+
if (!Array.isArray(product.bundle_group)) return [];
|
|
18
|
+
return product.bundle_group.flatMap(function (group) {
|
|
19
|
+
return Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : [];
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function hasCompleteDataVariantRelations(products) {
|
|
23
|
+
return products.every(function (product) {
|
|
24
|
+
return Array.isArray(product === null || product === void 0 ? void 0 : product.data_variants);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function hasAnyDataVariants(products) {
|
|
28
|
+
return products.some(function (product) {
|
|
29
|
+
var _product$data_variant;
|
|
30
|
+
return (((_product$data_variant = product.data_variants) === null || _product$data_variant === void 0 ? void 0 : _product$data_variant.length) || 0) > 0 || getBundleItems(product).some(function (item) {
|
|
31
|
+
return Array.isArray(item === null || item === void 0 ? void 0 : item.data_variants) && item.data_variants.length > 0;
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function collectReferencedRuleIds(products) {
|
|
36
|
+
var ids = new Set();
|
|
37
|
+
var remember = function remember(variants) {
|
|
38
|
+
if (!Array.isArray(variants)) return;
|
|
39
|
+
variants.forEach(function (variant) {
|
|
40
|
+
var _variant$data_variant;
|
|
41
|
+
var id = String((_variant$data_variant = variant === null || variant === void 0 ? void 0 : variant.data_variant_rule_id) !== null && _variant$data_variant !== void 0 ? _variant$data_variant : '').trim();
|
|
42
|
+
if (id) ids.add(id);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
products.forEach(function (product) {
|
|
46
|
+
remember(product.data_variants);
|
|
47
|
+
getBundleItems(product).forEach(function (item) {
|
|
48
|
+
return remember(item === null || item === void 0 ? void 0 : item.data_variants);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
return ids;
|
|
52
|
+
}
|
|
53
|
+
function isEvaluatorReady(evaluator, products) {
|
|
54
|
+
if (typeof evaluator.isReady === 'function') {
|
|
55
|
+
if (evaluator.isReady() === false) return false;
|
|
56
|
+
}
|
|
57
|
+
if (evaluator.isReady === false || evaluator.ready === false) return false;
|
|
58
|
+
|
|
59
|
+
// The built-in evaluator is installed before its strategy request completes.
|
|
60
|
+
// A referenced Data Variant cannot be evaluated authoritatively until those
|
|
61
|
+
// configs have arrived. Evaluators without this capability remain compatible.
|
|
62
|
+
if (typeof evaluator.getStrategyConfigs === 'function') {
|
|
63
|
+
var configs = evaluator.getStrategyConfigs();
|
|
64
|
+
if (!Array.isArray(configs) || configs.length === 0) return false;
|
|
65
|
+
var availableRuleIds = new Set(configs.map(function (config) {
|
|
66
|
+
var _config$metadata$id, _config$metadata;
|
|
67
|
+
return String((_config$metadata$id = config === null || config === void 0 || (_config$metadata = config.metadata) === null || _config$metadata === void 0 ? void 0 : _config$metadata.id) !== null && _config$metadata$id !== void 0 ? _config$metadata$id : '').trim();
|
|
68
|
+
}).filter(Boolean));
|
|
69
|
+
return Array.from(collectReferencedRuleIds(products)).every(function (id) {
|
|
70
|
+
return availableRuleIds.has(id);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
16
76
|
/**
|
|
17
|
-
*
|
|
77
|
+
* Strict client-side Data Variant resolution for quote fast paths.
|
|
18
78
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
79
|
+
* Unlike resolveClientDataVariants, callers can distinguish a complete local
|
|
80
|
+
* result from a capability/readiness/error fallback and decide to query the
|
|
81
|
+
* remote product endpoint instead.
|
|
21
82
|
*/
|
|
22
|
-
export function
|
|
83
|
+
export function tryResolveClientDataVariants(_ref) {
|
|
23
84
|
var _core$context, _scheduleModule$getSc, _core$context2, _core$context3, _strategyContext$busi;
|
|
24
85
|
var core = _ref.core,
|
|
25
86
|
_ref$otherParams = _ref.otherParams,
|
|
@@ -28,11 +89,59 @@ export function resolveClientDataVariants(_ref) {
|
|
|
28
89
|
queryPayload = _ref.queryPayload,
|
|
29
90
|
handledByOsServer = _ref.handledByOsServer,
|
|
30
91
|
explicitScheduleList = _ref.scheduleList,
|
|
31
|
-
explicitMenuList = _ref.menuList
|
|
32
|
-
|
|
92
|
+
explicitMenuList = _ref.menuList,
|
|
93
|
+
_ref$requireCompleteD = _ref.requireCompleteDataVariantRelations,
|
|
94
|
+
requireCompleteDataVariantRelations = _ref$requireCompleteD === void 0 ? true : _ref$requireCompleteD,
|
|
95
|
+
_ref$requireEvaluator = _ref.requireEvaluatorReady,
|
|
96
|
+
requireEvaluatorReady = _ref$requireEvaluator === void 0 ? true : _ref$requireEvaluator;
|
|
97
|
+
if (handledByOsServer) {
|
|
98
|
+
return {
|
|
99
|
+
status: 'handled-by-os-server',
|
|
100
|
+
products: products
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (products.length === 0) {
|
|
104
|
+
return {
|
|
105
|
+
status: 'empty',
|
|
106
|
+
products: products
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (requireCompleteDataVariantRelations && !hasCompleteDataVariantRelations(products)) {
|
|
110
|
+
return {
|
|
111
|
+
status: 'data-variants-unavailable',
|
|
112
|
+
products: products
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Explicit empty arrays mean the query hydrated the relation and there is no
|
|
117
|
+
// rule to apply. This is an authoritative local base-price result even when
|
|
118
|
+
// no evaluator has been installed.
|
|
119
|
+
if (!hasAnyDataVariants(products)) {
|
|
120
|
+
return {
|
|
121
|
+
status: 'resolved',
|
|
122
|
+
products: products
|
|
123
|
+
};
|
|
124
|
+
}
|
|
33
125
|
var evaluator = core === null || core === void 0 || (_core$context = core.context) === null || _core$context === void 0 ? void 0 : _core$context.dataVariantEvaluator;
|
|
34
126
|
if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
|
|
35
|
-
return
|
|
127
|
+
return {
|
|
128
|
+
status: 'evaluator-unavailable',
|
|
129
|
+
products: products
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
if (requireEvaluatorReady && !isEvaluatorReady(evaluator, products)) {
|
|
134
|
+
return {
|
|
135
|
+
status: 'evaluator-not-ready',
|
|
136
|
+
products: products
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return {
|
|
141
|
+
status: 'error',
|
|
142
|
+
products: products,
|
|
143
|
+
error: error
|
|
144
|
+
};
|
|
36
145
|
}
|
|
37
146
|
var strategyContext = queryPayload.strategy_context && _typeof(queryPayload.strategy_context) === 'object' ? queryPayload.strategy_context : {};
|
|
38
147
|
var fatherModule = String(otherParams.fatherModule || '').trim();
|
|
@@ -43,7 +152,7 @@ export function resolveClientDataVariants(_ref) {
|
|
|
43
152
|
var businessData = {
|
|
44
153
|
products: products,
|
|
45
154
|
scheduleDateTime: queryPayload.schedule_datetime || queryPayload.schedule_date,
|
|
46
|
-
scheduleList: Array.isArray(explicitScheduleList) ? explicitScheduleList : Array.isArray(moduleScheduleList) ? moduleScheduleList : Array.isArray(contextScheduleList) ? contextScheduleList : [],
|
|
155
|
+
scheduleList: Array.isArray(explicitScheduleList) && explicitScheduleList.length > 0 ? explicitScheduleList : Array.isArray(moduleScheduleList) && moduleScheduleList.length > 0 ? moduleScheduleList : Array.isArray(contextScheduleList) ? contextScheduleList : [],
|
|
47
156
|
menuList: Array.isArray(explicitMenuList) ? explicitMenuList : Array.isArray(otherParams.menuList) ? otherParams.menuList : Array.isArray(contextMenuList) ? contextMenuList : [],
|
|
48
157
|
customerId: queryPayload.customer_id,
|
|
49
158
|
channel: strategyContext.channel,
|
|
@@ -54,9 +163,54 @@ export function resolveClientDataVariants(_ref) {
|
|
|
54
163
|
};
|
|
55
164
|
try {
|
|
56
165
|
var result = evaluator.resolveProducts(businessData);
|
|
57
|
-
|
|
166
|
+
if (!Array.isArray(result === null || result === void 0 ? void 0 : result.products)) {
|
|
167
|
+
return {
|
|
168
|
+
status: 'error',
|
|
169
|
+
products: products,
|
|
170
|
+
error: new Error('Data Variant evaluator returned an invalid product list')
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
status: 'resolved',
|
|
175
|
+
products: result.products
|
|
176
|
+
};
|
|
58
177
|
} catch (error) {
|
|
59
|
-
|
|
60
|
-
|
|
178
|
+
return {
|
|
179
|
+
status: 'error',
|
|
180
|
+
products: products,
|
|
181
|
+
error: error
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 未启用商品 OS 路由时,在客户端补做 Data Variant 解析。
|
|
188
|
+
*
|
|
189
|
+
* 商品列表和预约报价必须共用这个边界,避免 H5 的弹窗报价绕过客户端智能定价。
|
|
190
|
+
* OS Server 已接管时直接信任服务端结果,确保同一批商品只评估一次。
|
|
191
|
+
*/
|
|
192
|
+
export function resolveClientDataVariants(_ref2) {
|
|
193
|
+
var core = _ref2.core,
|
|
194
|
+
_ref2$otherParams = _ref2.otherParams,
|
|
195
|
+
otherParams = _ref2$otherParams === void 0 ? {} : _ref2$otherParams,
|
|
196
|
+
products = _ref2.products,
|
|
197
|
+
queryPayload = _ref2.queryPayload,
|
|
198
|
+
handledByOsServer = _ref2.handledByOsServer,
|
|
199
|
+
explicitScheduleList = _ref2.scheduleList,
|
|
200
|
+
explicitMenuList = _ref2.menuList;
|
|
201
|
+
var result = tryResolveClientDataVariants({
|
|
202
|
+
core: core,
|
|
203
|
+
otherParams: otherParams,
|
|
204
|
+
products: products,
|
|
205
|
+
queryPayload: queryPayload,
|
|
206
|
+
handledByOsServer: handledByOsServer,
|
|
207
|
+
scheduleList: explicitScheduleList,
|
|
208
|
+
menuList: explicitMenuList,
|
|
209
|
+
requireCompleteDataVariantRelations: false,
|
|
210
|
+
requireEvaluatorReady: false
|
|
211
|
+
});
|
|
212
|
+
if (result.status === 'error') {
|
|
213
|
+
console.error('[ClientDataVariants] Data Variant 客户端解析失败', result.error);
|
|
61
214
|
}
|
|
215
|
+
return result.products;
|
|
62
216
|
}
|
|
@@ -9,6 +9,7 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
9
9
|
private store;
|
|
10
10
|
private request;
|
|
11
11
|
private otherParams;
|
|
12
|
+
private rawProductPriceSources;
|
|
12
13
|
constructor(name?: string, version?: string);
|
|
13
14
|
initialize(core: PisellCore, options: any): Promise<void>;
|
|
14
15
|
/**
|
|
@@ -36,6 +37,19 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
36
37
|
schedule_date?: string;
|
|
37
38
|
channel?: string;
|
|
38
39
|
}): Promise<any>;
|
|
40
|
+
/**
|
|
41
|
+
* Remember raw remote product records before client-side Data Variant
|
|
42
|
+
* evaluation. Quote-only reads can then always start from a clean baseline.
|
|
43
|
+
*/
|
|
44
|
+
rememberRawProductQueryResult(products: Array<ProductData | Record<string, any>>): void;
|
|
45
|
+
private replaceRawProductQueryResult;
|
|
46
|
+
/**
|
|
47
|
+
* Return isolated raw price sources for the requested products.
|
|
48
|
+
*
|
|
49
|
+
* Missing IDs are intentionally omitted so callers can remotely fetch only
|
|
50
|
+
* the incomplete part of a batch quote.
|
|
51
|
+
*/
|
|
52
|
+
getRawProductPriceSources(ids: number[]): Map<number, ProductData>;
|
|
39
53
|
getProducts(): Promise<ProductData[]>;
|
|
40
54
|
getProduct(id: number): Promise<ProductData | undefined>;
|
|
41
55
|
getProductByIds(ids: number[]): Promise<ProductData[] | undefined>;
|