@clickaroo/checkout-ui 0.1.6-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,22 +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
39
  }
17
- declare const CheckoutPage: (props: CheckoutProps) => react_jsx_runtime.JSX.Element;
40
+ declare const CheckoutPage: (props: CheckoutPageProps) => react_jsx_runtime.JSX.Element;
18
41
 
19
- declare const SubmitButton: React.FC;
42
+ interface SubmitButtonProps {
43
+ onOrderSubmit?: OnOrderSubmitCallback;
44
+ onOrderSuccess?: OnOrderSuccessCallback;
45
+ }
46
+ declare const SubmitButton: React.FC<SubmitButtonProps>;
20
47
 
21
48
  interface CustomInfoProps {
22
49
  showTitle?: boolean;
@@ -25,78 +52,40 @@ declare const CustomInfo: React.FC<CustomInfoProps>;
25
52
 
26
53
  interface DeliveryAddressProps {
27
54
  showTitle?: boolean;
55
+ googleApiKey?: string;
28
56
  }
29
57
  declare const DeliveryAddress$1: React.FC<DeliveryAddressProps>;
30
58
 
31
59
  interface PaymentMethodsProps {
32
60
  showText?: boolean;
33
- }
34
- declare const PaymentMethods: React.FC<PaymentMethodsProps>;
35
-
36
- declare const CustomerInfoSchema: z.ZodObject<{
37
- firstName: z.ZodString;
38
- lastName: z.ZodString;
39
- email: z.ZodString;
40
- phone: z.ZodString;
41
- }, z.core.$strip>;
42
- type CustomerInfo = z.infer<typeof CustomerInfoSchema>;
43
- declare const AddressSchema: z.ZodObject<{
44
- country: z.ZodString;
45
- address: z.ZodString;
46
- address2: z.ZodOptional<z.ZodString>;
47
- city: z.ZodString;
48
- state: z.ZodString;
49
- zipCode: z.ZodString;
50
- }, z.core.$strip>;
51
- type DeliveryAddress = z.infer<typeof AddressSchema>;
52
- interface CheckoutProviderProps {
53
- children: ReactNode;
54
- cart: CartItem$1[];
55
- onCheckoutInit?: OnCheckoutInitCallback;
56
61
  onPaymentInfoComplete?: OnPaymentInfoCompleteCallback;
57
- onOrderSubmit?: OnOrderSubmitCallback;
58
- onOrderSuccess?: OnOrderSuccessCallback;
59
- googleApiKey?: string;
60
62
  }
61
- declare const CheckoutProvider: React.FC<CheckoutProviderProps>;
62
-
63
- declare const configureAPIUrl: (url: string) => void;
64
-
65
- interface CartItem {
66
- sku: string;
67
- offerPricePoint: string;
68
- [key: string]: unknown;
69
- }
70
-
71
- interface UseCheckoutContextPublic {
72
- isFormValid: () => boolean;
73
- customerInfo: CustomerInfo$1;
74
- deliveryAddress: DeliveryAddress$2;
75
- isPaymentComplete: boolean;
76
- cart: CartItem$1[];
77
- updateCustomerInfo: (info: Partial<CustomerInfo$1>) => void;
78
- updateDeliveryAddress: (address: Partial<DeliveryAddress$2>) => void;
79
- }
80
- declare const useCheckoutContextPublic: () => UseCheckoutContextPublic;
63
+ declare const PaymentMethods: React.FC<PaymentMethodsProps>;
81
64
 
82
- interface OrderSubmissionResult {
83
- success: boolean;
84
- message: string;
85
- orderCode?: string;
86
- 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
+ };
87
84
  }
88
- declare const useOrderSubmission: () => {
89
- isSubmitting: boolean;
90
- submitOrder: () => Promise<OrderSubmissionResult>;
91
- };
92
-
93
- interface UseOrderDetailReturn {
94
- orderDetail: OrderDetail$1 | null;
95
- loading: boolean;
96
- error: string | null;
97
- refetch: () => void;
85
+ interface ClickarooPaymentStripe {
86
+ publishable_key: string;
87
+ account_id: string;
98
88
  }
99
- declare const useOrderDetail: (orderCode: string | null) => UseOrderDetailReturn;
100
89
 
101
90
  declare enum OrderPaymentStatus {
102
91
  PENDING = "pending",
@@ -218,52 +207,182 @@ interface OrderDetail {
218
207
  updated_at: string;
219
208
  }
220
209
 
221
- 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<{
222
366
  success: boolean;
223
367
  data?: CreateOrderResponse;
224
368
  error?: OrderApiError;
225
369
  }>;
226
- declare const getOrderDetail: (orderCode: string) => Promise<{
370
+ declare const getOrderDetail: (baseUrl: string, orderCode: string) => Promise<{
227
371
  success: boolean;
228
372
  data?: OrderDetail;
229
373
  error?: OrderApiError;
230
374
  }>;
231
375
 
232
- interface ClickarooInfo {
233
- offer_code: string;
234
- type: "one_off" | "subscription_schedules";
235
- payment: {
236
- type: "stripe";
237
- data: ClickarooPaymentStripe;
238
- };
239
- subscription_schedules?: {
240
- phase: number;
241
- price_in_cents: number;
242
- currency: string;
243
- quantity: number;
244
- period: string;
245
- }[];
246
- one_off?: {
247
- price_in_cents: number;
248
- currency: string;
249
- quantity: number;
250
- };
251
- }
252
- interface ClickarooPaymentStripe {
253
- publishable_key: string;
254
- account_id: string;
255
- }
256
-
257
376
  interface PricePointApiError {
258
377
  message: string;
259
378
  code?: string;
260
379
  details?: unknown;
261
380
  }
262
- declare const getPricePointInfo: (offerPricePoints: string | string[]) => Promise<{
381
+ declare const getPricePointInfo: (baseUrl: string, offerPricePoints: string | string[]) => Promise<{
263
382
  success: boolean;
264
383
  data?: ClickarooInfo | Record<string, ClickarooInfo>;
265
384
  error?: PricePointApiError;
266
385
  }>;
267
386
 
268
- 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 };
269
- 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 };