@intercartx/booster-core 0.0.1-beta.27 → 0.0.1-beta.29

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.
@@ -5,3 +5,4 @@ export * from './cc';
5
5
  export * from './pp';
6
6
  export * from './ach';
7
7
  export * from './types';
8
+ export * from './quick';
@@ -5,3 +5,4 @@ export * from './cc';
5
5
  export * from './pp';
6
6
  export * from './ach';
7
7
  export * from './types';
8
+ export * from './quick';
@@ -0,0 +1,12 @@
1
+ import { OrderProduct } from "../types";
2
+ export interface QuickOrderRequest {
3
+ products: OrderProduct;
4
+ confirmUrl: string;
5
+ }
6
+ export interface QuickOrderResponse {
7
+ sourceToken: string;
8
+ newToken: string;
9
+ newOrderId: string;
10
+ newTradeId: string;
11
+ }
12
+ export declare function apiCreateQuickOrder(token: string, body: QuickOrderRequest): Promise<QuickOrderResponse>;
@@ -0,0 +1,4 @@
1
+ import { post } from "../helper";
2
+ export async function apiCreateQuickOrder(token, body) {
3
+ return post(`/order/quick/submission/${token}`, body);
4
+ }
@@ -25,6 +25,7 @@ interface BaseOrderProduct {
25
25
  originPrice: number | string;
26
26
  discount: number;
27
27
  productId?: string;
28
+ [key: string]: any;
28
29
  }[];
29
30
  }
30
31
  interface OneTimeOrderProduct extends BaseOrderProduct {
@@ -49,7 +49,7 @@ export class CustomInfoModel extends BusinessModel {
49
49
  inputMode: 'numeric',
50
50
  maxLength: 16,
51
51
  ...props.phone,
52
- validateFn: validatePhone,
52
+ validateFn: (e, m) => validatePhone(`${this.phone.prefix}${e}`, m),
53
53
  validateMessages: validateMessages.phone,
54
54
  region: 'US'
55
55
  });
@@ -23,6 +23,8 @@ export class AddressModel extends BusinessModel {
23
23
  province: addressData.province,
24
24
  zip: addressData.zip,
25
25
  });
26
+ // 关闭multiRegions的验证
27
+ this.multiRegions.clearErrorValues();
26
28
  };
27
29
  this.address1 = new AddressSuggestModel({
28
30
  label: 'Address',
@@ -50,6 +50,7 @@ export declare class MultiRegionsModel extends BusinessModel<MultiRegionsData> i
50
50
  getFieldModel(fieldName: string): InputModel<import("../../types").FieldProps> | SelectModel<import("../../types").FieldProps> | undefined;
51
51
  getValue(): MultiRegionsData;
52
52
  setValue(value: MultiRegionsData): void;
53
+ clearErrorValues(): void;
53
54
  validate(): boolean;
54
55
  clearAllFields(): void;
55
56
  }
@@ -70,6 +70,11 @@ export class MultiRegionsModel extends BusinessModel {
70
70
  this.province.setValue(value.province);
71
71
  this.zip.setValue(value.zip);
72
72
  }
73
+ clearErrorValues() {
74
+ this.city.setError('');
75
+ this.province.setError('');
76
+ this.zip.setError('');
77
+ }
73
78
  validate() {
74
79
  return [
75
80
  this.city.validate(),
@@ -1,12 +1,21 @@
1
- import { z } from 'zod';
1
+ import { parsePhoneNumber } from 'libphonenumber-js';
2
2
  export function validatePhone(phone, validateMessages) {
3
3
  var _a, _b;
4
+ console.log('phone', phone);
4
5
  if (!phone) {
5
6
  return (_a = validateMessages === null || validateMessages === void 0 ? void 0 : validateMessages.required) !== null && _a !== void 0 ? _a : 'Required!';
6
7
  }
7
- const result = z.string().regex(/^1[3-9]\d{9}$/, { message: 'Invalid phone number' }).safeParse(phone);
8
- if (!result.success) {
9
- return (_b = validateMessages === null || validateMessages === void 0 ? void 0 : validateMessages.invalid) !== null && _b !== void 0 ? _b : result.error.issues[0].message;
8
+ try {
9
+ // parsePhoneNumber 可以解析 E.164 格式(以 + 开头)的号码
10
+ // PhoneModel 会将号码格式化为 E.164 格式,所以这里可以直接验证
11
+ const phoneNumber = parsePhoneNumber(phone);
12
+ console.log('phoneNumber', phoneNumber);
13
+ if (phoneNumber && phoneNumber.isValid()) {
14
+ return '';
15
+ }
10
16
  }
11
- return '';
17
+ catch (error) {
18
+ // parsePhoneNumber 会抛出错误如果号码无效或格式不正确
19
+ }
20
+ return (_b = validateMessages === null || validateMessages === void 0 ? void 0 : validateMessages.invalid) !== null && _b !== void 0 ? _b : 'Invalid phone number';
12
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intercartx/booster-core",
3
- "version": "0.0.1-beta.27",
3
+ "version": "0.0.1-beta.29",
4
4
  "description": "核心功能库,提供结账系统的业务逻辑、数据模型、验证工具、API 接口和样式文件",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",