@intercartx/booster-core 0.0.1-beta.5 → 0.0.1-beta.6

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/README.md CHANGED
@@ -1,2 +1,380 @@
1
+ # @intercartx/booster-core
1
2
 
2
- @intercartx/booster-core
3
+ 核心功能库,提供结账系统的业务逻辑、数据模型、验证工具、API 接口和样式文件。这是一个框架无关的核心包,为上层 UI 组件库提供基础能力。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @intercartx/booster-core
9
+ # 或
10
+ pnpm add @intercartx/booster-core
11
+ # 或
12
+ yarn add @intercartx/booster-core
13
+ ```
14
+
15
+ ## 功能特性
16
+
17
+ ### 🎯 核心功能
18
+
19
+ - **业务模型 (Models)**: 提供完整的结账业务逻辑模型
20
+ - 地址管理 (Address)
21
+ - 支付处理 (Payment)
22
+ - 订单摘要 (OrderSummary)
23
+ - 费用管理 (Fees Manager)
24
+ - 小费管理 (Tips)
25
+ - 运费管理 (Shipping Methods)
26
+ - 自定义信息 (Custom Info)
27
+ - 购买按钮 (Buy Now)
28
+ - PayPal 模态框 (PayPal Modal)
29
+ - 电话输入 (Phone)
30
+
31
+ - **数据验证 (Validation)**: 提供完整的表单验证功能
32
+ - 邮箱验证
33
+ - 电话验证
34
+ - 必填字段验证
35
+ - 国家/地区验证
36
+ - 邮政编码验证(支持多个国家)
37
+ - 州/省验证
38
+
39
+ - **工具函数 (Utils)**: 提供常用工具函数
40
+ - 货币格式化
41
+ - 电话号码处理
42
+ - Google Places API 集成
43
+ - 加密工具
44
+ - 防抖函数
45
+ - 重试机制
46
+ - 浏览器信息检测
47
+ - 追踪工具 (Tracksity)
48
+
49
+ - **API 接口**: 提供与后端交互的 API
50
+ - 配置获取
51
+ - 订单处理
52
+ - 支付处理(信用卡、ACH、PayPal)
53
+ - 订单确认
54
+
55
+ - **样式文件**: 提供完整的样式系统
56
+ - 全局样式
57
+ - 组件样式
58
+ - 主题配置
59
+ - 响应式设计
60
+
61
+ ## 使用方式
62
+
63
+ ### 基础导入
64
+
65
+ ```typescript
66
+ import {
67
+ setGlobalConfig,
68
+ getGlobalConfig,
69
+ globalState,
70
+ CheckoutConfig
71
+ } from '@intercartx/booster-core'
72
+ ```
73
+
74
+ ### 配置管理
75
+
76
+ ```typescript
77
+ import { setGlobalConfig, CheckoutConfig } from '@intercartx/booster-core'
78
+
79
+ const config: CheckoutConfig = {
80
+ token: 'your-token',
81
+ googleApiKey: 'your-google-api-key',
82
+ website: {
83
+ name: 'Your Website',
84
+ setting: {
85
+ trackings: {}
86
+ }
87
+ },
88
+ currency: 'USD',
89
+ language: 'en',
90
+ region: 'US',
91
+ feeSetting: {
92
+ tip: true,
93
+ coupon: true,
94
+ shipping: true
95
+ },
96
+ processorData: {
97
+ productInfo: {
98
+ // 产品信息
99
+ }
100
+ },
101
+ paymentMethods: {
102
+ // 支付方式配置
103
+ },
104
+ publicKey: 'your-public-key'
105
+ }
106
+
107
+ setGlobalConfig(config)
108
+ ```
109
+
110
+ ### 使用验证函数
111
+
112
+ ```typescript
113
+ import {
114
+ validateEmail,
115
+ validatePhone,
116
+ validateRequired,
117
+ validateCountry
118
+ } from '@intercartx/booster-core'
119
+
120
+ // 验证邮箱
121
+ const isValidEmail = validateEmail('user@example.com')
122
+
123
+ // 验证电话
124
+ const isValidPhone = validatePhone('+1234567890', 'US')
125
+
126
+ // 验证必填字段
127
+ const isValid = validateRequired('value')
128
+
129
+ // 验证国家
130
+ const isValidCountry = validateCountry('US')
131
+ ```
132
+
133
+ ### 使用工具函数
134
+
135
+ ```typescript
136
+ import {
137
+ formatCurrency,
138
+ formatPhoneNumber,
139
+ debounce
140
+ } from '@intercartx/booster-core'
141
+
142
+ // 格式化货币
143
+ const formatted = formatCurrency(1000, 'USD') // $10.00
144
+
145
+ // 格式化电话号码
146
+ const phone = formatPhoneNumber('1234567890', 'US')
147
+
148
+ // 防抖函数
149
+ const debouncedFn = debounce(() => {
150
+ console.log('Debounced!')
151
+ }, 300)
152
+ ```
153
+
154
+ ### 使用 API
155
+
156
+ ```typescript
157
+ import { apiGetConfig, apiProcessor } from '@intercartx/booster-core/api'
158
+
159
+ // 获取配置
160
+ const config = await apiGetConfig('your-token')
161
+
162
+ // 处理订单
163
+ const result = await apiProcessor({
164
+ website: 'Your Website',
165
+ region: 'US',
166
+ processorData: {
167
+ productInfo: {
168
+ // 产品信息
169
+ }
170
+ }
171
+ })
172
+ ```
173
+
174
+ ### 使用样式
175
+
176
+ ```typescript
177
+ // 导入全局样式
178
+ import '@intercartx/booster-core/styles/global.css'
179
+
180
+ // 导入特定组件样式
181
+ import '@intercartx/booster-core/styles/button.css'
182
+ import '@intercartx/booster-core/styles/input.css'
183
+ import '@intercartx/booster-core/styles/payment.css'
184
+ ```
185
+
186
+ ### 使用业务模型
187
+
188
+ ```typescript
189
+ import {
190
+ AddressModel,
191
+ PaymentModel,
192
+ OrderSummaryModel,
193
+ TipsModel,
194
+ ShippingMethodsModel
195
+ } from '@intercartx/booster-core'
196
+
197
+ // 创建地址模型实例
198
+ const addressModel = new AddressModel({
199
+ // 地址配置
200
+ })
201
+
202
+ // 创建支付模型实例
203
+ const paymentModel = new PaymentModel({
204
+ // 支付配置
205
+ })
206
+ ```
207
+
208
+ ## API 参考
209
+
210
+ ### 主要导出
211
+
212
+ #### 配置管理
213
+ - `setGlobalConfig(config: CheckoutConfig)`: 设置全局配置
214
+ - `getGlobalConfig(): CheckoutConfig`: 获取全局配置
215
+ - `globalState`: 全局状态对象
216
+
217
+ #### 验证函数
218
+ - `validateEmail(email: string): boolean`
219
+ - `validatePhone(phone: string, country?: string): boolean`
220
+ - `validateRequired(value: any): boolean`
221
+ - `validateCountry(country: string): boolean`
222
+ - `validateUSZipCode(zipCode: string): boolean`
223
+ - `validateUSStateCode(stateCode: string): boolean`
224
+ - `validateCAPostcode(postcode: string): boolean`
225
+ - `validateCAProvince(province: string): boolean`
226
+ - `validateGBPostcode(postcode: string): boolean`
227
+ - `validateAUPostcode(postcode: string): boolean`
228
+ - `validateAUStateOrTerritory(state: string): boolean`
229
+ - `validateNZPostalCode(postcode: string): boolean`
230
+ - `validateNZRegion(region: string): boolean`
231
+
232
+ #### 工具函数
233
+ - `formatCurrency(amount: number, currency: string): string`
234
+ - `formatPhoneNumber(phone: string, country: string): string`
235
+ - `debounce<T extends (...args: any[]) => any>(fn: T, delay: number): T`
236
+ - `retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>`
237
+ - `encrypt(data: string, key: string): string`
238
+ - `getBrowserInfo(): BrowserInfo`
239
+
240
+ #### API 函数
241
+ - `apiGetConfig(token: string): Promise<CheckoutConfig>`
242
+ - `apiProcessor(data: ProcessorData): Promise<ProcessorResult>`
243
+ - `apiPreOrder(data: PreOrderData): Promise<PreOrderResult>`
244
+ - `apiOrderConfirm(data: OrderConfirmData): Promise<OrderConfirmResult>`
245
+ - `apiCCPayment(data: CCPaymentData): Promise<CCPaymentResult>`
246
+ - `apiACHPayment(data: ACHPaymentData): Promise<ACHPaymentResult>`
247
+ - `apiPPPayment(data: PPPaymentData): Promise<PPPaymentResult>`
248
+
249
+ #### 业务模型
250
+ - `AddressModel`: 地址管理模型
251
+ - `AddressSuggestModel`: 地址建议模型
252
+ - `MultiRegionsModel`: 多地区模型
253
+ - `PaymentModel`: 支付模型
254
+ - `CCPaymentModel`: 信用卡支付模型
255
+ - `ACHPaymentModel`: ACH 支付模型
256
+ - `PPPaymentModel`: PayPal 支付模型
257
+ - `StripePaymentModel`: Stripe 支付模型
258
+ - `FxpPaymentModel`: FXP 支付模型
259
+ - `OrderSummaryModel`: 订单摘要模型
260
+ - `TipsModel`: 小费模型
261
+ - `ShippingMethodsModel`: 运费方法模型
262
+ - `CustomInfoModel`: 自定义信息模型
263
+ - `BuyNowModel`: 购买按钮模型
264
+ - `PaypalModalModel`: PayPal 模态框模型
265
+ - `PhoneModel`: 电话输入模型
266
+ - `PayButtonModel`: 支付按钮模型
267
+
268
+ ## 类型定义
269
+
270
+ ### CheckoutConfig
271
+
272
+ ```typescript
273
+ interface CheckoutConfig {
274
+ token: string
275
+ googleApiKey?: string
276
+ website: {
277
+ name: string
278
+ setting: {
279
+ trackings: any
280
+ }
281
+ }
282
+ currency: string
283
+ language: string
284
+ region: string
285
+ feeSetting: {
286
+ tip: boolean
287
+ coupon: boolean
288
+ shipping: boolean
289
+ }
290
+ processorData: {
291
+ productInfo: OrderProduct
292
+ }
293
+ paymentMethods: PaymentConfig
294
+ publicKey: string
295
+ }
296
+ ```
297
+
298
+ ### PaymentConfig
299
+
300
+ ```typescript
301
+ interface PaymentConfig {
302
+ CC?: ccPaymentConfig
303
+ PP?: ppPaymentConfig
304
+ ACH?: achPaymentConfig
305
+ }
306
+ ```
307
+
308
+ ## 样式系统
309
+
310
+ 本包提供了完整的样式系统,包括:
311
+
312
+ - **全局样式**: `styles/global.css`
313
+ - **组件样式**:
314
+ - `styles/button.css`
315
+ - `styles/input.css`
316
+ - `styles/select.css`
317
+ - `styles/payment.css`
318
+ - `styles/address.css`
319
+ - `styles/order-summary.css`
320
+ - `styles/custom-info.css`
321
+ - `styles/paypal-modal.css`
322
+ - `styles/phone-input.css`
323
+ - `styles/fee.css`
324
+ - `styles/loading.css`
325
+ - `styles/checkout-page.css`
326
+ - `styles/stripe-payment.css`
327
+ - `styles/fxp-payment.css`
328
+ - `styles/select-list.css`
329
+ - `styles/theme.css`
330
+
331
+ ## 依赖项
332
+
333
+ ### 核心依赖
334
+ - `@stripe/stripe-js`: Stripe 支付集成
335
+ - `currency-symbol-map`: 货币符号映射
336
+ - `decimal.js`: 精确的十进制运算
337
+ - `libphonenumber-js`: 电话号码处理
338
+ - `node-forge`: 加密工具
339
+ - `payment`: 支付处理
340
+ - `uuid`: UUID 生成
341
+ - `zod`: 数据验证
342
+
343
+ ### 开发依赖
344
+ - `typescript`: TypeScript 支持
345
+ - `sass`: SCSS 编译
346
+ - `tailwindcss`: Tailwind CSS
347
+ - `postcss`: PostCSS 处理
348
+ - `autoprefixer`: CSS 自动前缀
349
+
350
+ ## 构建
351
+
352
+ ```bash
353
+ # 构建 TypeScript
354
+ pnpm run build:ts
355
+
356
+ # 构建 SCSS
357
+ pnpm run build:scss
358
+
359
+ # 构建样式文件
360
+ pnpm run build:styles
361
+
362
+ # 完整构建
363
+ pnpm run build
364
+
365
+ # 开发模式(监听 SCSS 变化)
366
+ pnpm run dev
367
+
368
+ # 类型检查
369
+ pnpm run typecheck
370
+ ```
371
+
372
+ ## 许可证
373
+
374
+ GPL-3.0-only
375
+
376
+ ## 相关包
377
+
378
+ - `@intercartx/booster-react`: React 组件库
379
+ - `@intercartx/booster-solid`: SolidJS 组件库
380
+ - `@intercartx/booster-elements`: Web Components 库