@clickaroo/checkout-ui 0.1.7-beta → 1.0.0-beta

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/CHANGELOG.md CHANGED
@@ -4,40 +4,40 @@
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - 配置 storybook、支持多产品下单、添加谷歌地址建议支持
7
+ - Configure storybook, support multi-product checkout, add Google address suggestions support
8
8
 
9
9
  ## 1.0.4
10
10
 
11
11
  ### Patch Changes
12
12
 
13
- - 修改.gitlab-ci.yml
13
+ - Update .gitlab-ci.yml
14
14
 
15
15
  ## 1.0.3
16
16
 
17
17
  ### Patch Changes
18
18
 
19
- - 添加 Changesets 支持,用于自动管理版本和 changelog
19
+ - Add Changesets support for automatic version and changelog management
20
20
 
21
21
  ## 1.0.2
22
22
 
23
23
  ### Patch Changes
24
24
 
25
- - 添加 Terser 压缩混淆生产环境代码
25
+ - Add Terser compression and obfuscation for production code
26
26
 
27
27
  ## 1.0.1
28
28
 
29
29
  ### Patch Changes
30
30
 
31
- - 关闭 source map 文件生成
31
+ - Disable source map file generation
32
32
 
33
33
  ## 1.0.0
34
34
 
35
- ### 首次发布
35
+ ### Initial Release
36
36
 
37
- - ✨ 完整的结账流程组件
38
- - ✨ CheckoutProvider 上下文提供者
39
- - ✨ CustomerInfo 客户信息组件
40
- - ✨ DeliveryAddress 收货地址组件
41
- - ✨ PaymentMethods 支付方式组件
42
- - ✨ ButtonGroup 订单提交按钮组
43
- - ✨ Stripe 支付集成
37
+ - ✨ Complete checkout flow components
38
+ - ✨ CheckoutProvider context provider
39
+ - ✨ CustomerInfo customer information component
40
+ - ✨ DeliveryAddress delivery address component
41
+ - ✨ PaymentMethods payment methods component
42
+ - ✨ ButtonGroup order submission button group
43
+ - ✨ Stripe payment integration
package/README.md CHANGED
@@ -17,18 +17,30 @@ yarn add @clickaroo/checkout-ui
17
17
  #### Use CheckoutPage
18
18
 
19
19
  ```tsx
20
- import { CheckoutPage } from '@clickaroo/checkout-ui';
20
+ import { CheckoutPage, CheckoutProvider, ClickarooProvider } from '@clickaroo/checkout-ui';
21
21
 
22
22
  function App() {
23
- const carts = [{
23
+ const cart = [{
24
24
  sku: "TEST001",
25
25
  offerPricePoint: "OPP-TEST001",
26
- }]
26
+ }];
27
27
 
28
28
  return (
29
- <CheckoutPage
30
- cart={carts}
31
- />
29
+ <ClickarooProvider>
30
+ <CheckoutProvider
31
+ baseUrl="https://api.clickaroo.io"
32
+ cart={cart}
33
+ >
34
+ <CheckoutPage />
35
+ </CheckoutProvider>
36
+ </ClickarooProvider>
32
37
  );
33
38
  }
34
39
  ```
40
+
41
+ > **Note**:
42
+ > - `ClickarooProvider` must wrap your application at the root level to manage Clickaroo parameters
43
+ > - `CheckoutProvider` requires a `baseUrl` prop (the API base URL)
44
+ > - `CheckoutPage` must be wrapped with both providers
45
+
46
+ For more detailed documentation, see the [Storybook documentation](https://your-storybook-url).
package/dist/index.d.ts CHANGED
@@ -1,23 +1,49 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { OnCheckoutInitCallback, OnPaymentInfoCompleteCallback, OnOrderSubmitCallback, OnOrderSuccessCallback } from '@/types/callback';
3
- import { CartItem as CartItem$1 } from '@/types/cartItem';
4
2
  import React, { ReactNode } from 'react';
5
- import z from 'zod/v4';
6
- import { CustomerInfo as CustomerInfo$1, DeliveryAddress as DeliveryAddress$2 } from '@/contexts/CheckoutContext';
7
- import { OrderDetail as OrderDetail$1 } from '@/types/order';
3
+ import { z } from 'zod';
8
4
 
9
- interface CheckoutProps {
10
- cart: CartItem$1[];
11
- onCheckoutInit?: OnCheckoutInitCallback;
5
+ interface CartItem {
6
+ sku: string;
7
+ offerPricePoint: string;
8
+ [key: string]: unknown;
9
+ }
10
+
11
+ declare enum PaymentType {
12
+ OneTime = "one-time",
13
+ Subscription = "subscription"
14
+ }
15
+ interface CheckoutCartItem extends CartItem {
16
+ priceInCents: number;
17
+ currency: string;
18
+ quantity: number;
19
+ paymentType: PaymentType;
20
+ }
21
+ interface OnCheckoutInitCallback {
22
+ (): void;
23
+ }
24
+ interface OnPaymentInfoCompleteCallback {
25
+ (products: CheckoutCartItem[], totalAmount: number): void;
26
+ }
27
+ interface OnOrderSubmitCallback {
28
+ (products: CheckoutCartItem[], totalAmount: number, setMetadata: (metadata: Record<string, string>) => void): void;
29
+ }
30
+ interface OnOrderSuccessCallback {
31
+ (orderCode: string, tradeCode?: string): void;
32
+ }
33
+
34
+ interface CheckoutPageProps {
35
+ googleApiKey?: string;
12
36
  onPaymentInfoComplete?: OnPaymentInfoCompleteCallback;
13
37
  onOrderSubmit?: OnOrderSubmitCallback;
14
38
  onOrderSuccess?: OnOrderSuccessCallback;
15
- googleApiKey?: string;
16
- metadata?: Record<string, string>;
17
39
  }
18
- declare const CheckoutPage: (props: CheckoutProps) => react_jsx_runtime.JSX.Element;
40
+ declare const CheckoutPage: (props: CheckoutPageProps) => react_jsx_runtime.JSX.Element;
19
41
 
20
- declare const SubmitButton: React.FC;
42
+ interface SubmitButtonProps {
43
+ onOrderSubmit?: OnOrderSubmitCallback;
44
+ onOrderSuccess?: OnOrderSuccessCallback;
45
+ }
46
+ declare const SubmitButton: React.FC<SubmitButtonProps>;
21
47
 
22
48
  interface CustomInfoProps {
23
49
  showTitle?: boolean;
@@ -26,79 +52,40 @@ declare const CustomInfo: React.FC<CustomInfoProps>;
26
52
 
27
53
  interface DeliveryAddressProps {
28
54
  showTitle?: boolean;
55
+ googleApiKey?: string;
29
56
  }
30
57
  declare const DeliveryAddress$1: React.FC<DeliveryAddressProps>;
31
58
 
32
59
  interface PaymentMethodsProps {
33
60
  showText?: boolean;
34
- }
35
- declare const PaymentMethods: React.FC<PaymentMethodsProps>;
36
-
37
- declare const CustomerInfoSchema: z.ZodObject<{
38
- firstName: z.ZodString;
39
- lastName: z.ZodString;
40
- email: z.ZodString;
41
- phone: z.ZodString;
42
- }, z.core.$strip>;
43
- type CustomerInfo = z.infer<typeof CustomerInfoSchema>;
44
- declare const AddressSchema: z.ZodObject<{
45
- country: z.ZodString;
46
- address: z.ZodString;
47
- address2: z.ZodOptional<z.ZodString>;
48
- city: z.ZodString;
49
- state: z.ZodString;
50
- zipCode: z.ZodString;
51
- }, z.core.$strip>;
52
- type DeliveryAddress = z.infer<typeof AddressSchema>;
53
- interface CheckoutProviderProps {
54
- children: ReactNode;
55
- cart: CartItem$1[];
56
- onCheckoutInit?: OnCheckoutInitCallback;
57
61
  onPaymentInfoComplete?: OnPaymentInfoCompleteCallback;
58
- onOrderSubmit?: OnOrderSubmitCallback;
59
- onOrderSuccess?: OnOrderSuccessCallback;
60
- googleApiKey?: string;
61
- metadata?: Record<string, string>;
62
- }
63
- declare const CheckoutProvider: React.FC<CheckoutProviderProps>;
64
-
65
- declare const configureAPIUrl: (url: string) => void;
66
-
67
- interface CartItem {
68
- sku: string;
69
- offerPricePoint: string;
70
- [key: string]: unknown;
71
- }
72
-
73
- interface UseCheckoutContextPublic {
74
- isFormValid: () => boolean;
75
- customerInfo: CustomerInfo$1;
76
- deliveryAddress: DeliveryAddress$2;
77
- isPaymentComplete: boolean;
78
- cart: CartItem$1[];
79
- updateCustomerInfo: (info: Partial<CustomerInfo$1>) => void;
80
- updateDeliveryAddress: (address: Partial<DeliveryAddress$2>) => void;
81
62
  }
82
- declare const useCheckoutContextPublic: () => UseCheckoutContextPublic;
63
+ declare const PaymentMethods: React.FC<PaymentMethodsProps>;
83
64
 
84
- interface OrderSubmissionResult {
85
- success: boolean;
86
- message: string;
87
- orderCode?: string;
88
- tradeCode?: string;
65
+ interface ClickarooInfo {
66
+ offer_code: string;
67
+ type: "one_off" | "subscription_schedules";
68
+ payment: {
69
+ type: "stripe";
70
+ data: ClickarooPaymentStripe;
71
+ };
72
+ subscription_schedules?: {
73
+ phase: number;
74
+ price_in_cents: number;
75
+ currency: string;
76
+ quantity: number;
77
+ period: string;
78
+ }[];
79
+ one_off?: {
80
+ price_in_cents: number;
81
+ currency: string;
82
+ quantity: number;
83
+ };
89
84
  }
90
- declare const useOrderSubmission: () => {
91
- isSubmitting: boolean;
92
- submitOrder: () => Promise<OrderSubmissionResult>;
93
- };
94
-
95
- interface UseOrderDetailReturn {
96
- orderDetail: OrderDetail$1 | null;
97
- loading: boolean;
98
- error: string | null;
99
- refetch: () => void;
85
+ interface ClickarooPaymentStripe {
86
+ publishable_key: string;
87
+ account_id: string;
100
88
  }
101
- declare const useOrderDetail: (orderCode: string | null) => UseOrderDetailReturn;
102
89
 
103
90
  declare enum OrderPaymentStatus {
104
91
  PENDING = "pending",
@@ -220,52 +207,182 @@ interface OrderDetail {
220
207
  updated_at: string;
221
208
  }
222
209
 
223
- declare const createOrderWithToken: (orderData: Omit<CreateOrderRequest, "clickaroo_token">) => Promise<{
210
+ interface ApiClientConfig {
211
+ baseUrl: string;
212
+ }
213
+ interface ApiResponse<T> {
214
+ success: boolean;
215
+ data?: T;
216
+ error?: {
217
+ message: string;
218
+ code?: string;
219
+ details?: unknown;
220
+ };
221
+ }
222
+ /**
223
+ * SDK-style API client for Clickaroo backend.
224
+ */
225
+ declare class ApiClient {
226
+ private baseUrl;
227
+ constructor(config: ApiClientConfig);
228
+ getBaseUrl(): string;
229
+ setBaseUrl(baseUrl: string): void;
230
+ createOrder(orderData: CreateOrderRequest): Promise<ApiResponse<CreateOrderResponse>>;
231
+ createOrderWithToken(orderData: Omit<CreateOrderRequest, "clickaroo_token">): Promise<ApiResponse<CreateOrderResponse>>;
232
+ getOrderDetail(orderCode: string): Promise<ApiResponse<OrderDetail>>;
233
+ getPricePointInfo(offerPricePoints: string | string[]): Promise<ApiResponse<ClickarooInfo | Record<string, ClickarooInfo>>>;
234
+ }
235
+
236
+ declare global {
237
+ interface Window {
238
+ dataLayer: unknown[];
239
+ gtag: (...args: unknown[]) => void;
240
+ }
241
+ }
242
+
243
+ declare const CustomerInfoSchema: z.ZodObject<{
244
+ firstName: z.ZodString;
245
+ lastName: z.ZodString;
246
+ email: z.ZodString;
247
+ phone: z.ZodString;
248
+ }, z.core.$strip>;
249
+ type CustomerInfo = z.infer<typeof CustomerInfoSchema>;
250
+ declare const AddressSchema: z.ZodObject<{
251
+ country: z.ZodString;
252
+ address: z.ZodString;
253
+ address2: z.ZodOptional<z.ZodString>;
254
+ city: z.ZodString;
255
+ state: z.ZodString;
256
+ zipCode: z.ZodString;
257
+ }, z.core.$strip>;
258
+ type DeliveryAddress = z.infer<typeof AddressSchema>;
259
+ interface CheckoutProviderProps {
260
+ children: ReactNode;
261
+ cart: CartItem[];
262
+ baseUrl: string;
263
+ onCheckoutInit?: OnCheckoutInitCallback;
264
+ metadata?: Record<string, string>;
265
+ }
266
+ declare const CheckoutProvider: React.FC<CheckoutProviderProps>;
267
+
268
+ /**
269
+ * Storage utility functions
270
+ * Provides unified interface for Cookie, LocalStorage, SessionStorage operations
271
+ */
272
+ interface CookieOptions {
273
+ expires?: number;
274
+ path?: string;
275
+ domain?: string;
276
+ secure?: boolean;
277
+ sameSite?: 'strict' | 'lax' | 'none';
278
+ }
279
+
280
+ /**
281
+ * ClickarooProvider configuration options
282
+ */
283
+ interface ClickarooProviderConfig {
284
+ /** Storage key prefix, if not provided, no prefix is added when storing */
285
+ keyPrefix?: string;
286
+ /** List of parameters to manage, if not provided, all parameters from URL are stored */
287
+ params?: string[];
288
+ /** Cookie configuration options */
289
+ cookieOptions?: CookieOptions;
290
+ /** Whether to output debug information to console */
291
+ debug?: boolean;
292
+ }
293
+ /**
294
+ * Clickaroo Context type
295
+ */
296
+ interface ClickarooContextType {
297
+ /** Get parameter value */
298
+ getParam: (paramName: string) => string | null;
299
+ /** Set parameter value (saved according to storage priority) */
300
+ setParam: (paramName: string, value: string) => void;
301
+ /** Get all parameters */
302
+ getAllParams: () => Record<string, string>;
303
+ /** Clear parameter */
304
+ clearParam: (paramName: string) => void;
305
+ /** Clear all parameters */
306
+ clearAllParams: () => void;
307
+ /** Current parameter values (read-only) */
308
+ params: Record<string, string>;
309
+ }
310
+ /**
311
+ * ClickarooProvider Props
312
+ */
313
+ interface ClickarooProviderProps {
314
+ children: ReactNode;
315
+ config?: ClickarooProviderConfig;
316
+ }
317
+ /**
318
+ * ClickarooProvider component
319
+ * Used to manage Clickaroo-related parameters at the outermost level of the application
320
+ */
321
+ declare const ClickarooProvider: React.FC<ClickarooProviderProps>;
322
+
323
+ interface UseCheckoutContextPublic {
324
+ isFormValid: () => boolean;
325
+ customerInfo: CustomerInfo;
326
+ deliveryAddress: DeliveryAddress;
327
+ isPaymentComplete: boolean;
328
+ cart: CartItem[];
329
+ updateCustomerInfo: (info: Partial<CustomerInfo>) => void;
330
+ updateDeliveryAddress: (address: Partial<DeliveryAddress>) => void;
331
+ }
332
+ declare const useCheckoutContextPublic: () => UseCheckoutContextPublic;
333
+
334
+ interface OrderSubmissionResult {
335
+ success: boolean;
336
+ message: string;
337
+ orderCode?: string;
338
+ tradeCode?: string;
339
+ }
340
+ declare const useOrderSubmission: () => {
341
+ isSubmitting: boolean;
342
+ submitOrder: () => Promise<OrderSubmissionResult>;
343
+ };
344
+
345
+ interface UseOrderDetailReturn {
346
+ orderDetail: OrderDetail | null;
347
+ loading: boolean;
348
+ error: string | null;
349
+ refetch: () => void;
350
+ }
351
+ declare const useOrderDetail: (orderCode: string | null) => UseOrderDetailReturn;
352
+
353
+ /**
354
+ * Hook for using Clickaroo parameters
355
+ *
356
+ * @example
357
+ * ```tsx
358
+ * const { getParam, params } = useClickarooParams();
359
+ * const token = getParam('token');
360
+ * const sub4 = getParam('sub4');
361
+ * ```
362
+ */
363
+ declare const useClickarooParams: () => ClickarooContextType;
364
+
365
+ declare const createOrderWithToken: (baseUrl: string, orderData: Omit<CreateOrderRequest, "clickaroo_token">) => Promise<{
224
366
  success: boolean;
225
367
  data?: CreateOrderResponse;
226
368
  error?: OrderApiError;
227
369
  }>;
228
- declare const getOrderDetail: (orderCode: string) => Promise<{
370
+ declare const getOrderDetail: (baseUrl: string, orderCode: string) => Promise<{
229
371
  success: boolean;
230
372
  data?: OrderDetail;
231
373
  error?: OrderApiError;
232
374
  }>;
233
375
 
234
- interface ClickarooInfo {
235
- offer_code: string;
236
- type: "one_off" | "subscription_schedules";
237
- payment: {
238
- type: "stripe";
239
- data: ClickarooPaymentStripe;
240
- };
241
- subscription_schedules?: {
242
- phase: number;
243
- price_in_cents: number;
244
- currency: string;
245
- quantity: number;
246
- period: string;
247
- }[];
248
- one_off?: {
249
- price_in_cents: number;
250
- currency: string;
251
- quantity: number;
252
- };
253
- }
254
- interface ClickarooPaymentStripe {
255
- publishable_key: string;
256
- account_id: string;
257
- }
258
-
259
376
  interface PricePointApiError {
260
377
  message: string;
261
378
  code?: string;
262
379
  details?: unknown;
263
380
  }
264
- declare const getPricePointInfo: (offerPricePoints: string | string[]) => Promise<{
381
+ declare const getPricePointInfo: (baseUrl: string, offerPricePoints: string | string[]) => Promise<{
265
382
  success: boolean;
266
383
  data?: ClickarooInfo | Record<string, ClickarooInfo>;
267
384
  error?: PricePointApiError;
268
385
  }>;
269
386
 
270
- export { SubmitButton as ButtonGroup, CheckoutPage, CheckoutProvider, CustomInfo as CustomerInfo, DeliveryAddress$1 as DeliveryAddress, PaymentMethods, configureAPIUrl, createOrderWithToken as createOrder, getOrderDetail, getPricePointInfo, useCheckoutContextPublic as useCheckoutContext, useOrderDetail, useOrderSubmission };
271
- export type { CartItem, CustomerInfo as CustomerInfoType, DeliveryAddress as DeliveryAddressType, UseCheckoutContextPublic as UseCheckoutContext };
387
+ export { ApiClient, SubmitButton as ButtonGroup, CheckoutPage, CheckoutProvider, ClickarooProvider, CustomInfo as CustomerInfo, DeliveryAddress$1 as DeliveryAddress, PaymentMethods, createOrderWithToken as createOrder, getOrderDetail, getPricePointInfo, useCheckoutContextPublic as useCheckoutContext, useClickarooParams, useOrderDetail, useOrderSubmission };
388
+ export type { ApiClientConfig, ApiResponse, CartItem, ClickarooContextType, ClickarooProviderConfig, CustomerInfo as CustomerInfoType, DeliveryAddress as DeliveryAddressType, UseCheckoutContextPublic as UseCheckoutContext };