@pisell/pisellos 1.0.95 → 1.0.105
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/effects/index.d.ts +2 -2
- package/dist/model/strategy/type.d.ts +1 -1
- package/dist/modules/Customer/index.js +1 -1
- package/dist/modules/Customer/types.d.ts +1 -1
- package/dist/modules/Discount/types.d.ts +2 -0
- package/dist/modules/Payment/types.d.ts +7 -7
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/types.d.ts +1 -1
- package/dist/modules/Schedule/type.d.ts +7 -7
- package/dist/modules/Schedule/types.d.ts +9 -9
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/solution/ShopDiscount/utils.d.ts +2 -2
- package/dist/solution/ShopDiscount/utils.js +17 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/task.d.ts +2 -2
- package/dist/utils/watch.d.ts +2 -2
- package/lib/core/index.js +27 -28
- package/lib/effects/index.d.ts +2 -2
- package/lib/effects/index.js +3 -7
- package/lib/model/strategy/adapter/walletPass/evaluator.js +3 -2
- package/lib/model/strategy/adapter/walletPass/example.js +21 -21
- package/lib/model/strategy/adapter/walletPass/index.js +2 -4
- package/lib/model/strategy/adapter/walletPass/locales.js +10 -10
- package/lib/model/strategy/adapter/walletPass/utils.js +6 -12
- package/lib/model/strategy/index.js +7 -10
- package/lib/model/strategy/strategy-example.js +19 -19
- package/lib/model/strategy/type.d.ts +1 -1
- package/lib/modules/Account/index.js +9 -10
- package/lib/modules/AccountList/index.js +14 -11
- package/lib/modules/BaseModule.js +6 -3
- package/lib/modules/Cart/index.js +14 -9
- package/lib/modules/Cart/utils/cartProduct.js +3 -6
- package/lib/modules/Customer/constants.js +1 -1
- package/lib/modules/Customer/index.js +19 -16
- package/lib/modules/Customer/types.d.ts +1 -1
- package/lib/modules/Date/index.js +10 -6
- package/lib/modules/Date/types.js +1 -0
- package/lib/modules/Discount/index.js +11 -6
- package/lib/modules/Discount/types.d.ts +2 -0
- package/lib/modules/Guests/index.js +10 -15
- package/lib/modules/Order/index.js +10 -7
- package/lib/modules/Payment/cash.js +1 -1
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +1 -1
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.js +86 -73
- package/lib/modules/Payment/types.d.ts +7 -7
- package/lib/modules/Payment/utils.js +3 -6
- package/lib/modules/Payment/walletpass.js +33 -33
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/index.js +6 -5
- package/lib/modules/ProductList/index.js +5 -3
- package/lib/modules/Resource/index.js +8 -12
- package/lib/modules/Rules/index.js +17 -23
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.js +8 -5
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +9 -9
- package/lib/modules/Schedule/utils.js +2 -4
- package/lib/modules/Step/index.js +7 -4
- package/lib/modules/Summary/index.js +9 -4
- package/lib/plugins/request.js +34 -33
- package/lib/plugins/window.js +101 -113
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +85 -127
- package/lib/solution/BookingByStep/utils/capacity.js +10 -15
- package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +4 -8
- package/lib/solution/BookingByStep/utils/stock.js +3 -6
- package/lib/solution/BookingByStep/utils/timeslots.js +24 -27
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +19 -14
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +3 -3
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +6 -6
- package/lib/solution/BookingTicket/utils/scan/index.js +3 -1
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +10 -9
- package/lib/solution/BuyTickets/index.js +15 -15
- package/lib/solution/Checkout/index.js +216 -211
- package/lib/solution/Checkout/utils/index.js +18 -22
- package/lib/solution/RegisterAndLogin/config.js +2 -2
- package/lib/solution/RegisterAndLogin/index.js +114 -110
- package/lib/solution/RegisterAndLogin/utils.js +9 -9
- package/lib/solution/ShopDiscount/index.js +16 -13
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/solution/ShopDiscount/utils.d.ts +2 -2
- package/lib/solution/ShopDiscount/utils.js +12 -3
- package/lib/types/index.d.ts +1 -1
- package/lib/utils/task.d.ts +2 -2
- package/lib/utils/task.js +3 -3
- package/lib/utils/watch.d.ts +2 -2
- package/lib/utils/watch.js +5 -7
- package/package.json +18 -18
package/dist/effects/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
type EffectCallback = (payload: any) => void | Promise<void | {
|
|
1
|
+
declare type EffectCallback = (payload: any) => void | Promise<void | {
|
|
2
2
|
status: boolean;
|
|
3
3
|
message?: string;
|
|
4
4
|
}>;
|
|
5
|
-
type UnsubscribeFunction = () => void;
|
|
5
|
+
declare type UnsubscribeFunction = () => void;
|
|
6
6
|
declare class EffectsManager {
|
|
7
7
|
private listeners;
|
|
8
8
|
on(event: string, callback: EffectCallback): UnsubscribeFunction;
|
|
@@ -225,4 +225,4 @@ export interface EngineOptions {
|
|
|
225
225
|
/**
|
|
226
226
|
* 运算符处理器
|
|
227
227
|
*/
|
|
228
|
-
export type OperatorHandler = (fieldValue: any, compareValue: any, rule: ConditionRule) => boolean;
|
|
228
|
+
export declare type OperatorHandler = (fieldValue: any, compareValue: any, rule: ConditionRule) => boolean;
|
|
@@ -153,7 +153,7 @@ export var CustomerModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
153
153
|
skip: skip,
|
|
154
154
|
num: num,
|
|
155
155
|
sort_by: SORT_BY,
|
|
156
|
-
with: ['latestWalletDetail.wallet', 'contactsInfo'],
|
|
156
|
+
with: ['latestWalletDetail.wallet', 'contactsInfo', 'formRecord'],
|
|
157
157
|
search_wallet_flag: 1,
|
|
158
158
|
search_wallet_pass_flag: 1
|
|
159
159
|
}, search && {
|
|
@@ -33,7 +33,7 @@ export interface ShopCustomer extends ICustomer {
|
|
|
33
33
|
* walletDetails.wallet: 用户所有wallet
|
|
34
34
|
* latestWalletDetail.wallet: 用户最新wallet
|
|
35
35
|
*/
|
|
36
|
-
type CustomerWith = 'formRecord' | 'walletDetails.wallet' | 'latestWalletDetail.wallet';
|
|
36
|
+
declare type CustomerWith = 'formRecord' | 'walletDetails.wallet' | 'latestWalletDetail.wallet';
|
|
37
37
|
/**
|
|
38
38
|
* 获取客户列表参数
|
|
39
39
|
*/
|
|
@@ -581,12 +581,12 @@ export declare enum PaymentHooks {
|
|
|
581
581
|
OnOrderAmountChanged = "payment:onOrderAmountChanged",
|
|
582
582
|
OnPaymentSyncError = "payment:onPaymentSyncError",
|
|
583
583
|
OnPaymentSyncSuccess = "payment:onPaymentSyncSuccess",
|
|
584
|
-
OnWalletRecommendListUpdated =
|
|
585
|
-
OnWalletRecommendListCleared =
|
|
586
|
-
OnUserIdentificationCodesUpdated =
|
|
587
|
-
OnUserIdentificationCodesCleared =
|
|
588
|
-
OnWalletCacheCleared =
|
|
589
|
-
OnSearchIdentificationCodeCompleted =
|
|
584
|
+
OnWalletRecommendListUpdated = 0,
|
|
585
|
+
OnWalletRecommendListCleared = 0,
|
|
586
|
+
OnUserIdentificationCodesUpdated = 0,
|
|
587
|
+
OnUserIdentificationCodesCleared = 0,
|
|
588
|
+
OnWalletCacheCleared = 0,
|
|
589
|
+
OnSearchIdentificationCodeCompleted = 0
|
|
590
590
|
}
|
|
591
591
|
/**
|
|
592
592
|
* 钱包推荐扣款请求参数
|
|
@@ -740,7 +740,7 @@ export interface SearchIdentificationCodeResponse {
|
|
|
740
740
|
/**
|
|
741
741
|
* 搜索识别码结果类型
|
|
742
742
|
*/
|
|
743
|
-
export type SearchIdentificationCodeResult = {
|
|
743
|
+
export declare type SearchIdentificationCodeResult = {
|
|
744
744
|
type: 'walletCode';
|
|
745
745
|
data: SearchIdentificationCodeItem[];
|
|
746
746
|
} | {
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ScheduleItem = {
|
|
1
|
+
export declare type ScheduleItem = {
|
|
2
2
|
/** 颜色 */
|
|
3
3
|
color: string;
|
|
4
4
|
/** 创建时间 */
|
|
@@ -65,7 +65,7 @@ export type ScheduleItem = {
|
|
|
65
65
|
schedule_id: number;
|
|
66
66
|
}[];
|
|
67
67
|
};
|
|
68
|
-
export type ScheduleFormOtherValue = {
|
|
68
|
+
export declare type ScheduleFormOtherValue = {
|
|
69
69
|
/** 截止模式
|
|
70
70
|
* 1: 永不截止
|
|
71
71
|
* 2: 按日期截止
|
|
@@ -79,11 +79,11 @@ export type ScheduleFormOtherValue = {
|
|
|
79
79
|
includeStatus: boolean;
|
|
80
80
|
type: 'standard' | 'time-slots' | 'designation';
|
|
81
81
|
};
|
|
82
|
-
export type ExcIncDate = {
|
|
82
|
+
export declare type ExcIncDate = {
|
|
83
83
|
start: string;
|
|
84
84
|
end: string;
|
|
85
85
|
};
|
|
86
|
-
export type ScheduleFormData = {
|
|
86
|
+
export declare type ScheduleFormData = {
|
|
87
87
|
/** 颜色 */
|
|
88
88
|
color: string;
|
|
89
89
|
/** 日程名称 */
|
|
@@ -131,20 +131,20 @@ export type ScheduleFormData = {
|
|
|
131
131
|
start_time: any;
|
|
132
132
|
end_time: any;
|
|
133
133
|
};
|
|
134
|
-
export type CalendarDataItem = {
|
|
134
|
+
export declare type CalendarDataItem = {
|
|
135
135
|
date: string;
|
|
136
136
|
color: string[];
|
|
137
137
|
isExcluded: boolean;
|
|
138
138
|
schedule_ids?: number[];
|
|
139
139
|
[key: string]: any;
|
|
140
140
|
};
|
|
141
|
-
export type RequestData<Data> = {
|
|
141
|
+
export declare type RequestData<Data> = {
|
|
142
142
|
data: Data;
|
|
143
143
|
status: boolean;
|
|
144
144
|
message: string;
|
|
145
145
|
code: number;
|
|
146
146
|
};
|
|
147
|
-
export type ResponseListData<Data> = {
|
|
147
|
+
export declare type ResponseListData<Data> = {
|
|
148
148
|
status: boolean;
|
|
149
149
|
message: string;
|
|
150
150
|
code: number;
|
|
@@ -4,7 +4,7 @@ export interface ScheduleState {
|
|
|
4
4
|
availabilityDateList: ScheduleAvailabilityDateItem[];
|
|
5
5
|
otherProductsIds: number[];
|
|
6
6
|
}
|
|
7
|
-
export type ScheduleAvailabilityDateItem = {
|
|
7
|
+
export declare type ScheduleAvailabilityDateItem = {
|
|
8
8
|
date: string;
|
|
9
9
|
schedule_id: number[];
|
|
10
10
|
product_ids: number[];
|
|
@@ -24,7 +24,7 @@ export interface LoadScheduleAvailableDateParams {
|
|
|
24
24
|
}
|
|
25
25
|
export interface ScheduleModuleAPI {
|
|
26
26
|
}
|
|
27
|
-
export type ScheduleItem = {
|
|
27
|
+
export declare type ScheduleItem = {
|
|
28
28
|
/** 颜色 */
|
|
29
29
|
color: string;
|
|
30
30
|
/** 创建时间 */
|
|
@@ -91,7 +91,7 @@ export type ScheduleItem = {
|
|
|
91
91
|
schedule_id: number;
|
|
92
92
|
}[];
|
|
93
93
|
};
|
|
94
|
-
export type ScheduleFormOtherValue = {
|
|
94
|
+
export declare type ScheduleFormOtherValue = {
|
|
95
95
|
/** 截止模式
|
|
96
96
|
* 1: 永不截止
|
|
97
97
|
* 2: 按日期截止
|
|
@@ -105,11 +105,11 @@ export type ScheduleFormOtherValue = {
|
|
|
105
105
|
includeStatus: boolean;
|
|
106
106
|
type: 'standard' | 'time-slots' | 'designation';
|
|
107
107
|
};
|
|
108
|
-
export type ExcIncDate = {
|
|
108
|
+
export declare type ExcIncDate = {
|
|
109
109
|
start: string;
|
|
110
110
|
end: string;
|
|
111
111
|
};
|
|
112
|
-
export type ScheduleFormData = {
|
|
112
|
+
export declare type ScheduleFormData = {
|
|
113
113
|
/** 颜色 */
|
|
114
114
|
color: string;
|
|
115
115
|
/** 日程名称 */
|
|
@@ -157,20 +157,20 @@ export type ScheduleFormData = {
|
|
|
157
157
|
start_time: any;
|
|
158
158
|
end_time: any;
|
|
159
159
|
};
|
|
160
|
-
export type CalendarDataItem = {
|
|
160
|
+
export declare type CalendarDataItem = {
|
|
161
161
|
date: string;
|
|
162
162
|
color: string[];
|
|
163
163
|
isExcluded: boolean;
|
|
164
164
|
schedule_ids?: number[];
|
|
165
165
|
[key: string]: any;
|
|
166
166
|
};
|
|
167
|
-
export type RequestData<Data> = {
|
|
167
|
+
export declare type RequestData<Data> = {
|
|
168
168
|
data: Data;
|
|
169
169
|
status: boolean;
|
|
170
170
|
message: string;
|
|
171
171
|
code: number;
|
|
172
172
|
};
|
|
173
|
-
export type ResponseListData<Data> = {
|
|
173
|
+
export declare type ResponseListData<Data> = {
|
|
174
174
|
status: boolean;
|
|
175
175
|
message: string;
|
|
176
176
|
code: number;
|
|
@@ -181,7 +181,7 @@ export type ResponseListData<Data> = {
|
|
|
181
181
|
skip: number;
|
|
182
182
|
};
|
|
183
183
|
};
|
|
184
|
-
export type ScheduleAllMap = Record<string, {
|
|
184
|
+
export declare type ScheduleAllMap = Record<string, {
|
|
185
185
|
minTime: dayjs.Dayjs | null;
|
|
186
186
|
maxTime: dayjs.Dayjs | null;
|
|
187
187
|
minTimeStr: string | null;
|
|
@@ -343,7 +343,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
343
343
|
};
|
|
344
344
|
setOtherData(key: string, value: any): void;
|
|
345
345
|
getOtherData(key: string): any;
|
|
346
|
-
getProductTypeById(id: number): Promise<"
|
|
346
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
347
347
|
/**
|
|
348
348
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
349
349
|
*
|
|
@@ -6,7 +6,7 @@ import { CartItem, ProductData } from '../../../modules';
|
|
|
6
6
|
* 3. 格式化资源相关 格式化资源列表 --> 格式化资源 --> 获取时间切片列表 --> 判断单个时间切片是否可用 formatResources
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
type DateType = Dayjs;
|
|
9
|
+
declare type DateType = Dayjs;
|
|
10
10
|
export interface TimeSliceItem {
|
|
11
11
|
start_time: string;
|
|
12
12
|
end_time: string;
|
|
@@ -115,7 +115,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
115
115
|
* 获取当前的客户搜索条件
|
|
116
116
|
* @returns 当前搜索条件
|
|
117
117
|
*/
|
|
118
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
118
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
119
119
|
/**
|
|
120
120
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
121
121
|
* @returns 客户状态
|
|
@@ -11,7 +11,7 @@ export declare enum ShopDiscountHooks {
|
|
|
11
11
|
onRulesListChange = "shopDiscount:onRulesListChange",
|
|
12
12
|
onLoadPrepareCalcResult = "shopDiscount:onLoadPrepareCalcResult"
|
|
13
13
|
}
|
|
14
|
-
export type Customer = {
|
|
14
|
+
export declare type Customer = {
|
|
15
15
|
id: string | number;
|
|
16
16
|
name: string;
|
|
17
17
|
email: string;
|
|
@@ -12,13 +12,13 @@ export declare const isAllNormalProduct: (items: any[]) => boolean;
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
15
|
-
export declare const getDiscountListAmountTotal: (discount: Discount[]) =>
|
|
15
|
+
export declare const getDiscountListAmountTotal: (discount: Discount[]) => Discount;
|
|
16
16
|
/**
|
|
17
17
|
* 获取折扣金额 计算每个折扣的金额
|
|
18
18
|
* @param discount
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
|
-
export declare const getDiscountListAmount: (discount: Discount[]) =>
|
|
21
|
+
export declare const getDiscountListAmount: (discount: Discount[]) => Discount;
|
|
22
22
|
export interface ScheduleItem {
|
|
23
23
|
id: number;
|
|
24
24
|
name: string | {
|
|
@@ -457,10 +457,24 @@ export var filterDiscountListByBookingTime = function filterDiscountListByBookin
|
|
|
457
457
|
return discountList;
|
|
458
458
|
}
|
|
459
459
|
return discountList.filter(function (discount) {
|
|
460
|
-
var _discount$metadata2
|
|
461
|
-
if (
|
|
460
|
+
var _discount$metadata2;
|
|
461
|
+
if ((discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.validity_type) === "custom_schedule_validity") {
|
|
462
|
+
var _discount$custom_sche;
|
|
463
|
+
return getDateIsInSchedule(bookingTime, ((_discount$custom_sche = discount.custom_schedule_snapshot) === null || _discount$custom_sche === void 0 ? void 0 : _discount$custom_sche.data) || []);
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
var isHasStart = !!discount.start_date && !!discount.start_time;
|
|
467
|
+
var startDate = dayjs("".concat(discount.start_date, " ").concat(discount.start_time));
|
|
468
|
+
var bookingTimeDayjs = dayjs(bookingTime);
|
|
469
|
+
|
|
470
|
+
// 判断预约时间是否在开始时间之后
|
|
471
|
+
var isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
|
|
472
|
+
|
|
473
|
+
// 判断预约时间是否在过期时间之前(expire_time 为空时为长期有效)
|
|
474
|
+
var isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore(dayjs(discount.expire_time)) : true;
|
|
475
|
+
return isAfterStart && isBeforeExpire;
|
|
476
|
+
} catch (error) {
|
|
462
477
|
return true;
|
|
463
478
|
}
|
|
464
|
-
return getDateIsInSchedule(bookingTime, ((_discount$custom_sche = discount.custom_schedule_snapshot) === null || _discount$custom_sche === void 0 ? void 0 : _discount$custom_sche.data) || []);
|
|
465
479
|
});
|
|
466
480
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface ModuleOptions {
|
|
|
27
27
|
initialState?: Record<string, any>;
|
|
28
28
|
otherParams?: Record<string, any>;
|
|
29
29
|
}
|
|
30
|
-
export type EventHandler = (data?: any) => void;
|
|
30
|
+
export declare type EventHandler = (data?: any) => void;
|
|
31
31
|
export interface PisellCore {
|
|
32
32
|
registerPlugin: (plugin: Plugin, options?: PluginOptions) => void;
|
|
33
33
|
getPlugin: <T extends Plugin>(name: string) => T | null;
|
package/dist/utils/task.d.ts
CHANGED
package/dist/utils/watch.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* 监听模块
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
|
-
export type WatchEventCallback = (...args: any[]) => void;
|
|
6
|
-
export type WatchEventItem = {
|
|
5
|
+
export declare type WatchEventCallback = (...args: any[]) => void;
|
|
6
|
+
export declare type WatchEventItem = {
|
|
7
7
|
key: string;
|
|
8
8
|
callback: WatchEventCallback;
|
|
9
9
|
};
|
package/lib/core/index.js
CHANGED
|
@@ -26,13 +26,13 @@ module.exports = __toCommonJS(core_exports);
|
|
|
26
26
|
var import_createStore = require("../store/createStore");
|
|
27
27
|
var import_effects = require("../effects");
|
|
28
28
|
var PisellOSCore = class {
|
|
29
|
+
plugins = /* @__PURE__ */ new Map();
|
|
30
|
+
modules = /* @__PURE__ */ new Map();
|
|
31
|
+
stores = /* @__PURE__ */ new Map();
|
|
32
|
+
effects = new import_effects.EffectsManager();
|
|
33
|
+
debug = false;
|
|
34
|
+
context = {};
|
|
29
35
|
constructor(options) {
|
|
30
|
-
this.plugins = /* @__PURE__ */ new Map();
|
|
31
|
-
this.modules = /* @__PURE__ */ new Map();
|
|
32
|
-
this.stores = /* @__PURE__ */ new Map();
|
|
33
|
-
this.effects = new import_effects.EffectsManager();
|
|
34
|
-
this.debug = false;
|
|
35
|
-
this.context = {};
|
|
36
36
|
this.debug = (options == null ? void 0 : options.debug) || false;
|
|
37
37
|
this.context = (options == null ? void 0 : options.context) || {};
|
|
38
38
|
this.initialize(options);
|
|
@@ -48,7 +48,7 @@ var PisellOSCore = class {
|
|
|
48
48
|
this.registerModule(item.module, item.options);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
this.log("PisellOS
|
|
51
|
+
this.log("PisellOS \u6838\u5FC3\u521D\u59CB\u5316\u5B8C\u6210");
|
|
52
52
|
}
|
|
53
53
|
// 日志方法
|
|
54
54
|
log(message, level = "info") {
|
|
@@ -71,12 +71,12 @@ var PisellOSCore = class {
|
|
|
71
71
|
// 插件相关方法
|
|
72
72
|
registerPlugin(plugin, options) {
|
|
73
73
|
if (this.plugins.has(plugin.name)) {
|
|
74
|
-
this.log(
|
|
74
|
+
this.log(`\u63D2\u4EF6 ${plugin.name} \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6`, "warn");
|
|
75
75
|
}
|
|
76
76
|
if (options == null ? void 0 : options.dependencies) {
|
|
77
77
|
for (const dep of options.dependencies) {
|
|
78
78
|
if (!this.plugins.has(dep)) {
|
|
79
|
-
throw new Error(
|
|
79
|
+
throw new Error(`\u6CE8\u518C\u63D2\u4EF6 ${plugin.name} \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u63D2\u4EF6 ${dep}`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -84,14 +84,14 @@ var PisellOSCore = class {
|
|
|
84
84
|
const result = plugin.initialize();
|
|
85
85
|
if (result instanceof Promise) {
|
|
86
86
|
result.catch((err) => {
|
|
87
|
-
this.log(
|
|
87
|
+
this.log(`\u63D2\u4EF6 ${plugin.name} \u521D\u59CB\u5316\u5931\u8D25: ${err.message}`, "error");
|
|
88
88
|
throw err;
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
this.plugins.set(plugin.name, plugin);
|
|
92
|
-
this.log(
|
|
92
|
+
this.log(`\u63D2\u4EF6 ${plugin.name} v${plugin.version} \u6CE8\u518C\u6210\u529F`);
|
|
93
93
|
} catch (error) {
|
|
94
|
-
this.log(
|
|
94
|
+
this.log(`\u63D2\u4EF6 ${plugin.name} \u521D\u59CB\u5316\u8FC7\u7A0B\u4E2D\u51FA\u9519: ${error}`, "error");
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -104,12 +104,12 @@ var PisellOSCore = class {
|
|
|
104
104
|
// 模块相关方法
|
|
105
105
|
registerModule(module2, options) {
|
|
106
106
|
if (this.modules.has(module2.name)) {
|
|
107
|
-
this.log(
|
|
107
|
+
this.log(`\u6A21\u5757 ${module2.name} \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6`, "warn");
|
|
108
108
|
}
|
|
109
109
|
if (options == null ? void 0 : options.dependencies) {
|
|
110
110
|
for (const dep of options.dependencies) {
|
|
111
111
|
if (!this.modules.has(dep)) {
|
|
112
|
-
throw new Error(
|
|
112
|
+
throw new Error(`\u6CE8\u518C\u6A21\u5757 ${module2.name} \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u6A21\u5757 ${dep}`);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -117,7 +117,7 @@ var PisellOSCore = class {
|
|
|
117
117
|
for (const plugin of options.plugins) {
|
|
118
118
|
if (!this.plugins.has(plugin)) {
|
|
119
119
|
throw new Error(
|
|
120
|
-
|
|
120
|
+
`\u6CE8\u518C\u6A21\u5757 ${module2.name} \u5931\u8D25\uFF1A\u7F3A\u5C11\u4F9D\u8D56\u63D2\u4EF6 ${plugin}`
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -126,10 +126,9 @@ var PisellOSCore = class {
|
|
|
126
126
|
(options == null ? void 0 : options.initialState) || {},
|
|
127
127
|
module2.name,
|
|
128
128
|
(path, value) => {
|
|
129
|
-
console.log("core
|
|
129
|
+
console.log("core \u68C0\u6D4B\u5230\u6A21\u5757\u503C\u66F4\u65B0", module2.name, path, value);
|
|
130
130
|
this.effects.emit(`${module2.name}:changed`, { path, value });
|
|
131
|
-
if (module2.storeChange)
|
|
132
|
-
module2.storeChange(path, value);
|
|
131
|
+
if (module2.storeChange) module2.storeChange(path, value);
|
|
133
132
|
}
|
|
134
133
|
);
|
|
135
134
|
this.stores.set(module2.name, proxy);
|
|
@@ -137,14 +136,14 @@ var PisellOSCore = class {
|
|
|
137
136
|
const result = module2.initialize(this, { store: proxy, ...options });
|
|
138
137
|
if (result instanceof Promise) {
|
|
139
138
|
result.catch((err) => {
|
|
140
|
-
this.log(
|
|
139
|
+
this.log(`\u6A21\u5757 ${module2.name} \u521D\u59CB\u5316\u5931\u8D25: ${err.message}`, "error");
|
|
141
140
|
throw err;
|
|
142
141
|
});
|
|
143
142
|
}
|
|
144
143
|
this.modules.set(module2.name, module2);
|
|
145
|
-
this.log(
|
|
144
|
+
this.log(`\u6A21\u5757 ${module2.name} v${module2.version} \u6CE8\u518C\u6210\u529F`);
|
|
146
145
|
} catch (error) {
|
|
147
|
-
this.log(
|
|
146
|
+
this.log(`\u6A21\u5757 ${module2.name} \u521D\u59CB\u5316\u8FC7\u7A0B\u4E2D\u51FA\u9519: ${error}`, "error");
|
|
148
147
|
throw error;
|
|
149
148
|
}
|
|
150
149
|
}
|
|
@@ -168,9 +167,9 @@ var PisellOSCore = class {
|
|
|
168
167
|
if (module2.destroy) {
|
|
169
168
|
try {
|
|
170
169
|
await Promise.resolve(module2.destroy());
|
|
171
|
-
this.log(
|
|
170
|
+
this.log(`\u6A21\u5757 ${name} \u5DF2\u9500\u6BC1`);
|
|
172
171
|
} catch (error) {
|
|
173
|
-
this.log(
|
|
172
|
+
this.log(`\u9500\u6BC1\u6A21\u5757 ${name} \u65F6\u51FA\u9519: ${error}`, "error");
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
175
|
}
|
|
@@ -179,14 +178,14 @@ var PisellOSCore = class {
|
|
|
179
178
|
if (plugin.destroy) {
|
|
180
179
|
try {
|
|
181
180
|
await Promise.resolve(plugin.destroy());
|
|
182
|
-
this.log(
|
|
181
|
+
this.log(`\u63D2\u4EF6 ${name} \u5DF2\u9500\u6BC1`);
|
|
183
182
|
} catch (error) {
|
|
184
|
-
this.log(
|
|
183
|
+
this.log(`\u9500\u6BC1\u63D2\u4EF6 ${name} \u65F6\u51FA\u9519: ${error}`, "error");
|
|
185
184
|
}
|
|
186
185
|
}
|
|
187
186
|
}
|
|
188
187
|
this.plugins.clear();
|
|
189
|
-
this.log("PisellOS
|
|
188
|
+
this.log("PisellOS \u6838\u5FC3\u5DF2\u9500\u6BC1");
|
|
190
189
|
}
|
|
191
190
|
/**
|
|
192
191
|
* 验证上下文参数
|
|
@@ -196,7 +195,7 @@ var PisellOSCore = class {
|
|
|
196
195
|
const value = this.context[rule.name];
|
|
197
196
|
if (rule.required && (value === void 0 || value === null)) {
|
|
198
197
|
this.log(
|
|
199
|
-
|
|
198
|
+
`\u6A21\u5757 ${config.name} \u7F3A\u5C11\u5FC5\u9700\u7684\u4E0A\u4E0B\u6587\u53C2\u6570: ${rule.name}`,
|
|
200
199
|
"error"
|
|
201
200
|
);
|
|
202
201
|
return false;
|
|
@@ -204,7 +203,7 @@ var PisellOSCore = class {
|
|
|
204
203
|
if (rule.validate && value !== void 0 && value !== null) {
|
|
205
204
|
if (!rule.validate(value)) {
|
|
206
205
|
this.log(
|
|
207
|
-
|
|
206
|
+
`\u6A21\u5757 ${config.name} \u4E0A\u4E0B\u6587\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25: ${rule.name} - ${rule.message || "\u9A8C\u8BC1\u5931\u8D25"}`,
|
|
208
207
|
"error"
|
|
209
208
|
);
|
|
210
209
|
return false;
|
package/lib/effects/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
type EffectCallback = (payload: any) => void | Promise<void | {
|
|
1
|
+
declare type EffectCallback = (payload: any) => void | Promise<void | {
|
|
2
2
|
status: boolean;
|
|
3
3
|
message?: string;
|
|
4
4
|
}>;
|
|
5
|
-
type UnsubscribeFunction = () => void;
|
|
5
|
+
declare type UnsubscribeFunction = () => void;
|
|
6
6
|
declare class EffectsManager {
|
|
7
7
|
private listeners;
|
|
8
8
|
on(event: string, callback: EffectCallback): UnsubscribeFunction;
|
package/lib/effects/index.js
CHANGED
|
@@ -23,13 +23,10 @@ __export(effects_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(effects_exports);
|
|
25
25
|
var EffectsManager = class {
|
|
26
|
-
|
|
27
|
-
this.listeners = /* @__PURE__ */ new Map();
|
|
28
|
-
}
|
|
26
|
+
listeners = /* @__PURE__ */ new Map();
|
|
29
27
|
on(event, callback) {
|
|
30
28
|
var _a;
|
|
31
|
-
if (!this.listeners.has(event))
|
|
32
|
-
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
29
|
+
if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
33
30
|
(_a = this.listeners.get(event)) == null ? void 0 : _a.add(callback);
|
|
34
31
|
return () => {
|
|
35
32
|
this.off(event, callback);
|
|
@@ -69,8 +66,7 @@ var EffectsManager = class {
|
|
|
69
66
|
}
|
|
70
67
|
async emit(event, payload) {
|
|
71
68
|
const callbacks = this.listeners.get(event);
|
|
72
|
-
if (!callbacks)
|
|
73
|
-
return { status: true, data: [] };
|
|
69
|
+
if (!callbacks) return { status: true, data: [] };
|
|
74
70
|
return new Promise(async (resolve) => {
|
|
75
71
|
const res = [];
|
|
76
72
|
for (const cb of callbacks) {
|
|
@@ -44,9 +44,10 @@ var defaultStrategyMetadataCustom = {
|
|
|
44
44
|
deductTaxAndFee: true
|
|
45
45
|
};
|
|
46
46
|
var WalletPassEvaluator = class {
|
|
47
|
+
engine;
|
|
48
|
+
strategyConfigs = [];
|
|
49
|
+
locale = "en";
|
|
47
50
|
constructor() {
|
|
48
|
-
this.strategyConfigs = [];
|
|
49
|
-
this.locale = "en";
|
|
50
51
|
this.engine = new import__.StrategyEngine({
|
|
51
52
|
debug: false,
|
|
52
53
|
enableTrace: false
|
|
@@ -5,13 +5,13 @@ var products = [
|
|
|
5
5
|
product_id: 60734,
|
|
6
6
|
price: 80,
|
|
7
7
|
quantity: 1,
|
|
8
|
-
name: "
|
|
8
|
+
name: "\u5546\u54C1A"
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
product_id: 60735,
|
|
12
12
|
price: 50,
|
|
13
13
|
quantity: 2,
|
|
14
|
-
name: "
|
|
14
|
+
name: "\u5546\u54C1B"
|
|
15
15
|
}
|
|
16
16
|
];
|
|
17
17
|
var vouchers = [
|
|
@@ -39,7 +39,7 @@ var strategyConfigs = [
|
|
|
39
39
|
{
|
|
40
40
|
metadata: {
|
|
41
41
|
id: "STRATEGY_001",
|
|
42
|
-
name: "
|
|
42
|
+
name: "\u6EE1100\u51CF10",
|
|
43
43
|
type: "wallet_pass",
|
|
44
44
|
custom: {
|
|
45
45
|
maxDeductionAmount: 10,
|
|
@@ -86,7 +86,7 @@ var strategyConfigs = [
|
|
|
86
86
|
{
|
|
87
87
|
metadata: {
|
|
88
88
|
id: "STRATEGY_002",
|
|
89
|
-
name: "
|
|
89
|
+
name: "\u6EE1150\u51CF20",
|
|
90
90
|
type: "wallet_pass",
|
|
91
91
|
custom: {
|
|
92
92
|
maxDeductionAmount: 20,
|
|
@@ -127,7 +127,7 @@ var strategyConfigs = [
|
|
|
127
127
|
{
|
|
128
128
|
metadata: {
|
|
129
129
|
id: "STRATEGY_003",
|
|
130
|
-
name: "
|
|
130
|
+
name: "\u6EE1200\u51CF50",
|
|
131
131
|
type: "wallet_pass",
|
|
132
132
|
custom: {
|
|
133
133
|
maxDeductionAmount: 50,
|
|
@@ -166,7 +166,7 @@ var strategyConfigs = [
|
|
|
166
166
|
}
|
|
167
167
|
];
|
|
168
168
|
function runExample() {
|
|
169
|
-
console.log("========== WalletPass
|
|
169
|
+
console.log("========== WalletPass \u8BC4\u4F30\u5668\u793A\u4F8B ==========\n");
|
|
170
170
|
const evaluator = new import_evaluator.WalletPassEvaluator();
|
|
171
171
|
const results = evaluator.evaluate({
|
|
172
172
|
orderTotalAmount: 180,
|
|
@@ -174,33 +174,33 @@ function runExample() {
|
|
|
174
174
|
vouchers,
|
|
175
175
|
strategyConfigs
|
|
176
176
|
});
|
|
177
|
-
console.log("
|
|
178
|
-
console.log(`-
|
|
179
|
-
console.log(`-
|
|
177
|
+
console.log("\u8BA2\u5355\u4FE1\u606F\uFF1A");
|
|
178
|
+
console.log(`- \u603B\u91D1\u989D: ${180} \u5143`);
|
|
179
|
+
console.log(`- \u5546\u54C1: ${products.map((p) => `${p.name}(${p.quantity}\u4EF6)`).join(", ")}
|
|
180
180
|
`);
|
|
181
|
-
console.log("
|
|
181
|
+
console.log("\u8BC4\u4F30\u7ED3\u679C\uFF1A\n");
|
|
182
182
|
results.forEach((result, index) => {
|
|
183
183
|
console.log(`Voucher ${index + 1}: ${result.voucher.id}`);
|
|
184
|
-
console.log(`
|
|
185
|
-
console.log(`
|
|
184
|
+
console.log(` \u9762\u989D: ${result.voucher.amount} \u5143`);
|
|
185
|
+
console.log(` \u53EF\u7528: ${result.isApplicable ? "\u2705 \u662F" : "\u274C \u5426"}`);
|
|
186
186
|
if (result.isApplicable) {
|
|
187
|
-
console.log(`
|
|
188
|
-
console.log(`
|
|
189
|
-
console.log(`
|
|
190
|
-
console.log(`
|
|
187
|
+
console.log(` \u6700\u5927\u62B5\u6263: ${result.maxDeduction} \u5143`);
|
|
188
|
+
console.log(` \u6BCF\u5355\u53EF\u7528: ${result.canUseCount} \u5F20`);
|
|
189
|
+
console.log(` \u62B5\u6263\u7A0E\u8D39: ${result.deductTaxAndFee ? "\u662F" : "\u5426"}`);
|
|
190
|
+
console.log(` \u9002\u7528\u5546\u54C1: ${result.applicableProductIds.join(", ")}`);
|
|
191
191
|
} else {
|
|
192
|
-
console.log(`
|
|
193
|
-
console.log(`
|
|
192
|
+
console.log(` \u539F\u56E0: ${result.reason}`);
|
|
193
|
+
console.log(` \u539F\u56E0\u7801: ${result.reasonCode}`);
|
|
194
194
|
}
|
|
195
195
|
console.log("");
|
|
196
196
|
});
|
|
197
197
|
const availableVouchers = results.filter((r) => r.isApplicable);
|
|
198
198
|
console.log(`
|
|
199
|
-
|
|
199
|
+
\u5171 ${availableVouchers.length} \u5F20\u53EF\u7528`);
|
|
200
200
|
if (availableVouchers.length > 0) {
|
|
201
|
-
console.log("
|
|
201
|
+
console.log("\u53EF\u7528 voucher ID:");
|
|
202
202
|
availableVouchers.forEach((v) => {
|
|
203
|
-
console.log(` - ${v.voucher.id}:
|
|
203
|
+
console.log(` - ${v.voucher.id}: \u6700\u591A\u62B5\u6263 ${v.maxDeduction} \u5143`);
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
}
|