@pisell/pisellos 2.2.90 → 2.2.91
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/core/index.d.ts +1 -0
- package/dist/core/index.js +7 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/server/modules/products/index.js +8 -3
- package/dist/server/modules/products/types.d.ts +1 -0
- package/dist/server/utils/product.d.ts +4 -0
- package/dist/server/utils/product.js +34 -0
- package/dist/types/index.d.ts +2 -0
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +4 -0
- package/lib/server/modules/products/index.js +6 -0
- package/lib/server/modules/products/types.d.ts +1 -0
- package/lib/server/utils/product.d.ts +4 -0
- package/lib/server/utils/product.js +27 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -403,6 +403,13 @@ var PisellOSCore = /*#__PURE__*/function () {
|
|
|
403
403
|
}
|
|
404
404
|
return destroy;
|
|
405
405
|
}()
|
|
406
|
+
}, {
|
|
407
|
+
key: "setContext",
|
|
408
|
+
value: function setContext(ctx) {
|
|
409
|
+
this.context = _objectSpread(_objectSpread({}, this.context), ctx);
|
|
410
|
+
this.log("\u4E0A\u4E0B\u6587\u5DF2\u66F4\u65B0: ".concat(JSON.stringify(Object.keys(ctx))));
|
|
411
|
+
}
|
|
412
|
+
|
|
406
413
|
/**
|
|
407
414
|
* 验证上下文参数
|
|
408
415
|
*/
|
|
@@ -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 } from "./examples";
|
|
@@ -31,7 +31,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
31
31
|
import { BaseModule } from "../../../modules/BaseModule";
|
|
32
32
|
import { RequestModeENUM } from "../../../plugins";
|
|
33
33
|
import { ProductsHooks } from "./types";
|
|
34
|
-
import { applyDetailValueToProducts, applyPriceDataToProducts, perfMark } from "../../utils/product";
|
|
34
|
+
import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* IndexDB 存储名称
|
|
@@ -426,7 +426,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
426
426
|
key: "prepareProductsWithPrice",
|
|
427
427
|
value: (function () {
|
|
428
428
|
var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext, options) {
|
|
429
|
-
var tTotal, targetIds, isIncremental, _priceData$length, products, ids, idSet, tIds, i, tPrice, priceData, context, tFormat, processedProducts, errorMessage;
|
|
429
|
+
var tTotal, targetIds, isIncremental, _priceData$length, _this$core, products, ids, idSet, tIds, i, tPrice, priceData, context, tFormat, processedProducts, errorMessage;
|
|
430
430
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
431
431
|
while (1) switch (_context4.prev = _context4.next) {
|
|
432
432
|
case 0:
|
|
@@ -481,7 +481,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
481
481
|
});
|
|
482
482
|
context = _objectSpread({
|
|
483
483
|
schedule_date: schedule_date,
|
|
484
|
-
priceData: priceData
|
|
484
|
+
priceData: priceData,
|
|
485
|
+
locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale
|
|
485
486
|
}, extraContext); // 3. 通过格式化器流程处理商品
|
|
486
487
|
tFormat = performance.now();
|
|
487
488
|
_context4.next = 17;
|
|
@@ -638,12 +639,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
638
639
|
console.log("[ProductsModule] \uD83D\uDCB0 \u5E94\u7528\u4EF7\u683C\u6570\u636E\u5230 ".concat(products.length, " \u4E2A\u5546\u54C1"));
|
|
639
640
|
return applyPriceDataToProducts(products, context.priceData);
|
|
640
641
|
};
|
|
642
|
+
var i18nFormatter = function i18nFormatter(products, context) {
|
|
643
|
+
return applyI18nToProducts(products, context.locale);
|
|
644
|
+
};
|
|
641
645
|
var detailValueFormatter = function detailValueFormatter(products, context) {
|
|
642
646
|
return applyDetailValueToProducts(products, context);
|
|
643
647
|
};
|
|
644
648
|
|
|
645
649
|
// 将价格格式化器注册为第一个格式化器
|
|
646
650
|
this.formatters.unshift(priceFormatter);
|
|
651
|
+
this.formatters.push(i18nFormatter);
|
|
647
652
|
this.formatters.push(detailValueFormatter);
|
|
648
653
|
this.isPriceFormatterRegistered = true;
|
|
649
654
|
console.log('[ProductsModule] ✅ 内置价格格式化器已注册(第 1 个)');
|
|
@@ -10,6 +10,10 @@ export declare function perfMark(label: string, durationMs: number, meta?: Recor
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function applyPriceDataToProducts(products: ProductData[], priceData: LoadProductsPriceData[]): ProductData[];
|
|
12
12
|
export declare const getIsSessionProduct: (product: ProductData) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 根据 locale 将商品的 i18n 字段覆盖到对应原始字段
|
|
15
|
+
*/
|
|
16
|
+
export declare function applyI18nToProducts(products: ProductData[], locale?: string): ProductData[];
|
|
13
17
|
/**
|
|
14
18
|
* 将详情值数据应用到商品列表
|
|
15
19
|
* @param products 商品列表
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
5
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
10
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
11
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -186,6 +190,36 @@ var getIsOpenDetailModal = function getIsOpenDetailModal(product, context) {
|
|
|
186
190
|
scheduleTimeSlots: scheduleTimeSlots
|
|
187
191
|
};
|
|
188
192
|
};
|
|
193
|
+
var I18N_FIELD_MAP = {
|
|
194
|
+
title_i18n: 'title',
|
|
195
|
+
subtitle_i18n: 'subtitle',
|
|
196
|
+
description_i18n: 'description',
|
|
197
|
+
cover_i18n: 'cover'
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 根据 locale 将商品的 i18n 字段覆盖到对应原始字段
|
|
202
|
+
*/
|
|
203
|
+
export function applyI18nToProducts(products, locale) {
|
|
204
|
+
if (!locale) return products;
|
|
205
|
+
return products.map(function (product) {
|
|
206
|
+
var _patched;
|
|
207
|
+
var patched = null;
|
|
208
|
+
for (var _i = 0, _Object$entries = Object.entries(I18N_FIELD_MAP); _i < _Object$entries.length; _i++) {
|
|
209
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
210
|
+
i18nKey = _Object$entries$_i[0],
|
|
211
|
+
originalKey = _Object$entries$_i[1];
|
|
212
|
+
var i18nDict = product[i18nKey];
|
|
213
|
+
if (!i18nDict) continue;
|
|
214
|
+
var localizedValue = i18nDict[locale];
|
|
215
|
+
if (localizedValue) {
|
|
216
|
+
if (!patched) patched = _objectSpread({}, product);
|
|
217
|
+
patched[originalKey] = localizedValue;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return (_patched = patched) !== null && _patched !== void 0 ? _patched : product;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
189
223
|
var formatDataKey = function formatDataKey(data) {
|
|
190
224
|
var _data$option, _data$bundle;
|
|
191
225
|
var _data = _objectSpread({}, data);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export interface PisellCore {
|
|
|
52
52
|
validateContext: (config: ModuleContextConfig) => boolean;
|
|
53
53
|
serverOptions?: ServerOptions;
|
|
54
54
|
server?: any;
|
|
55
|
+
setContext: (ctx: Partial<BusinessContext>) => void;
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* 业务上下文接口
|
|
@@ -59,6 +60,7 @@ export interface PisellCore {
|
|
|
59
60
|
export interface BusinessContext {
|
|
60
61
|
userId?: string;
|
|
61
62
|
companyId?: string;
|
|
63
|
+
locale?: string;
|
|
62
64
|
[key: string]: any;
|
|
63
65
|
}
|
|
64
66
|
/**
|
package/lib/core/index.d.ts
CHANGED
package/lib/core/index.js
CHANGED
|
@@ -235,6 +235,10 @@ var PisellOSCore = class {
|
|
|
235
235
|
this.plugins.clear();
|
|
236
236
|
this.log("PisellOS 核心已销毁");
|
|
237
237
|
}
|
|
238
|
+
setContext(ctx) {
|
|
239
|
+
this.context = { ...this.context, ...ctx };
|
|
240
|
+
this.log(`上下文已更新: ${JSON.stringify(Object.keys(ctx))}`);
|
|
241
|
+
}
|
|
238
242
|
/**
|
|
239
243
|
* 验证上下文参数
|
|
240
244
|
*/
|
|
@@ -284,6 +284,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
284
284
|
* @private
|
|
285
285
|
*/
|
|
286
286
|
async prepareProductsWithPrice(schedule_date, extraContext, options) {
|
|
287
|
+
var _a, _b;
|
|
287
288
|
const tTotal = performance.now();
|
|
288
289
|
const targetIds = options == null ? void 0 : options.productIds;
|
|
289
290
|
const isIncremental = targetIds && targetIds.length > 0;
|
|
@@ -319,6 +320,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
319
320
|
const context = {
|
|
320
321
|
schedule_date,
|
|
321
322
|
priceData,
|
|
323
|
+
locale: (_b = (_a = this.core) == null ? void 0 : _a.context) == null ? void 0 : _b.locale,
|
|
322
324
|
...extraContext
|
|
323
325
|
};
|
|
324
326
|
const tFormat = performance.now();
|
|
@@ -417,10 +419,14 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
417
419
|
console.log(`[ProductsModule] 💰 应用价格数据到 ${products.length} 个商品`);
|
|
418
420
|
return (0, import_product.applyPriceDataToProducts)(products, context.priceData);
|
|
419
421
|
};
|
|
422
|
+
const i18nFormatter = (products, context) => {
|
|
423
|
+
return (0, import_product.applyI18nToProducts)(products, context.locale);
|
|
424
|
+
};
|
|
420
425
|
const detailValueFormatter = (products, context) => {
|
|
421
426
|
return (0, import_product.applyDetailValueToProducts)(products, context);
|
|
422
427
|
};
|
|
423
428
|
this.formatters.unshift(priceFormatter);
|
|
429
|
+
this.formatters.push(i18nFormatter);
|
|
424
430
|
this.formatters.push(detailValueFormatter);
|
|
425
431
|
this.isPriceFormatterRegistered = true;
|
|
426
432
|
console.log("[ProductsModule] ✅ 内置价格格式化器已注册(第 1 个)");
|
|
@@ -10,6 +10,10 @@ export declare function perfMark(label: string, durationMs: number, meta?: Recor
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function applyPriceDataToProducts(products: ProductData[], priceData: LoadProductsPriceData[]): ProductData[];
|
|
12
12
|
export declare const getIsSessionProduct: (product: ProductData) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 根据 locale 将商品的 i18n 字段覆盖到对应原始字段
|
|
15
|
+
*/
|
|
16
|
+
export declare function applyI18nToProducts(products: ProductData[], locale?: string): ProductData[];
|
|
13
17
|
/**
|
|
14
18
|
* 将详情值数据应用到商品列表
|
|
15
19
|
* @param products 商品列表
|
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var product_exports = {};
|
|
21
21
|
__export(product_exports, {
|
|
22
22
|
applyDetailValueToProducts: () => applyDetailValueToProducts,
|
|
23
|
+
applyI18nToProducts: () => applyI18nToProducts,
|
|
23
24
|
applyPriceDataToProducts: () => applyPriceDataToProducts,
|
|
24
25
|
getIsSessionProduct: () => getIsSessionProduct,
|
|
25
26
|
perfMark: () => perfMark
|
|
@@ -155,6 +156,31 @@ var getIsOpenDetailModal = (product, context) => {
|
|
|
155
156
|
scheduleTimeSlots
|
|
156
157
|
};
|
|
157
158
|
};
|
|
159
|
+
var I18N_FIELD_MAP = {
|
|
160
|
+
title_i18n: "title",
|
|
161
|
+
subtitle_i18n: "subtitle",
|
|
162
|
+
description_i18n: "description",
|
|
163
|
+
cover_i18n: "cover"
|
|
164
|
+
};
|
|
165
|
+
function applyI18nToProducts(products, locale) {
|
|
166
|
+
if (!locale)
|
|
167
|
+
return products;
|
|
168
|
+
return products.map((product) => {
|
|
169
|
+
let patched = null;
|
|
170
|
+
for (const [i18nKey, originalKey] of Object.entries(I18N_FIELD_MAP)) {
|
|
171
|
+
const i18nDict = product[i18nKey];
|
|
172
|
+
if (!i18nDict)
|
|
173
|
+
continue;
|
|
174
|
+
const localizedValue = i18nDict[locale];
|
|
175
|
+
if (localizedValue) {
|
|
176
|
+
if (!patched)
|
|
177
|
+
patched = { ...product };
|
|
178
|
+
patched[originalKey] = localizedValue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return patched ?? product;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
158
184
|
var formatDataKey = (data) => {
|
|
159
185
|
var _a, _b, _c, _d;
|
|
160
186
|
const _data = {
|
|
@@ -258,6 +284,7 @@ function applyDetailValueToProducts(products, context) {
|
|
|
258
284
|
// Annotate the CommonJS export names for ESM import in node:
|
|
259
285
|
0 && (module.exports = {
|
|
260
286
|
applyDetailValueToProducts,
|
|
287
|
+
applyI18nToProducts,
|
|
261
288
|
applyPriceDataToProducts,
|
|
262
289
|
getIsSessionProduct,
|
|
263
290
|
perfMark
|
package/lib/types/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export interface PisellCore {
|
|
|
52
52
|
validateContext: (config: ModuleContextConfig) => boolean;
|
|
53
53
|
serverOptions?: ServerOptions;
|
|
54
54
|
server?: any;
|
|
55
|
+
setContext: (ctx: Partial<BusinessContext>) => void;
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* 业务上下文接口
|
|
@@ -59,6 +60,7 @@ export interface PisellCore {
|
|
|
59
60
|
export interface BusinessContext {
|
|
60
61
|
userId?: string;
|
|
61
62
|
companyId?: string;
|
|
63
|
+
locale?: string;
|
|
62
64
|
[key: string]: any;
|
|
63
65
|
}
|
|
64
66
|
/**
|