@anpayeras/agnostic-checkout 0.1.0 → 0.1.2

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.
Files changed (77) hide show
  1. package/dist/components/Checkout.d.ts +4 -0
  2. package/dist/components/Checkout.d.ts.map +1 -0
  3. package/dist/components/CheckoutLayout.d.ts +3 -0
  4. package/dist/components/CheckoutLayout.d.ts.map +1 -0
  5. package/dist/components/FeedbackScreen.d.ts +3 -0
  6. package/dist/components/FeedbackScreen.d.ts.map +1 -0
  7. package/dist/components/MobileOrderBar.d.ts +10 -0
  8. package/dist/components/MobileOrderBar.d.ts.map +1 -0
  9. package/dist/components/OrderSidebarSummary.d.ts +3 -0
  10. package/dist/components/OrderSidebarSummary.d.ts.map +1 -0
  11. package/dist/components/OrderSummary.d.ts +2 -0
  12. package/dist/components/OrderSummary.d.ts.map +1 -0
  13. package/dist/components/PaymentForm.d.ts +2 -0
  14. package/dist/components/PaymentForm.d.ts.map +1 -0
  15. package/dist/components/PaymentMethods.d.ts +2 -0
  16. package/dist/components/PaymentMethods.d.ts.map +1 -0
  17. package/dist/components/button.d.ts +3 -0
  18. package/dist/components/button.d.ts.map +1 -0
  19. package/dist/components/checkout-content.d.ts +4 -0
  20. package/dist/components/checkout-content.d.ts.map +1 -0
  21. package/dist/components/dev-tools.d.ts +3 -0
  22. package/dist/components/dev-tools.d.ts.map +1 -0
  23. package/dist/components/mobile-bar.d.ts +4 -0
  24. package/dist/components/mobile-bar.d.ts.map +1 -0
  25. package/dist/components/types.d.ts +57 -0
  26. package/dist/components/types.d.ts.map +1 -0
  27. package/dist/core/checkout-context.d.ts +56 -0
  28. package/dist/core/checkout-context.d.ts.map +1 -0
  29. package/dist/core/checkout-machine.d.ts +3 -0
  30. package/dist/core/checkout-machine.d.ts.map +1 -0
  31. package/dist/core/event-system.d.ts +32 -0
  32. package/dist/core/event-system.d.ts.map +1 -0
  33. package/dist/core/i18n-context.d.ts +17 -0
  34. package/dist/core/i18n-context.d.ts.map +1 -0
  35. package/dist/core/provider.interface.d.ts +7 -0
  36. package/dist/core/provider.interface.d.ts.map +1 -0
  37. package/dist/core/types.d.ts +74 -0
  38. package/dist/core/types.d.ts.map +1 -0
  39. package/dist/hooks/useCheckout.d.ts +26 -0
  40. package/dist/hooks/useCheckout.d.ts.map +1 -0
  41. package/dist/index.cjs +157 -1622
  42. package/dist/index.d.ts +16 -321
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +4291 -1025
  45. package/dist/locales/en.d.ts +3 -0
  46. package/dist/locales/en.d.ts.map +1 -0
  47. package/dist/locales/es.d.ts +3 -0
  48. package/dist/locales/es.d.ts.map +1 -0
  49. package/dist/locales/index.d.ts +14 -0
  50. package/dist/locales/index.d.ts.map +1 -0
  51. package/dist/locales/pt-BR.d.ts +3 -0
  52. package/dist/locales/pt-BR.d.ts.map +1 -0
  53. package/dist/locales/types.d.ts +41 -0
  54. package/dist/locales/types.d.ts.map +1 -0
  55. package/dist/plugins/cart-edit-plugin.d.ts +10 -0
  56. package/dist/plugins/cart-edit-plugin.d.ts.map +1 -0
  57. package/dist/plugins/discount-plugin.d.ts +4 -0
  58. package/dist/plugins/discount-plugin.d.ts.map +1 -0
  59. package/dist/plugins/index.d.ts +6 -0
  60. package/dist/plugins/index.d.ts.map +1 -0
  61. package/dist/plugins/plugin-context.d.ts +10 -0
  62. package/dist/plugins/plugin-context.d.ts.map +1 -0
  63. package/dist/plugins/types.d.ts +32 -0
  64. package/dist/plugins/types.d.ts.map +1 -0
  65. package/dist/style.css +1 -0
  66. package/dist/theme/color-utils.d.ts +39 -0
  67. package/dist/theme/color-utils.d.ts.map +1 -0
  68. package/dist/theme/theme-provider.d.ts +11 -0
  69. package/dist/theme/theme-provider.d.ts.map +1 -0
  70. package/dist/theme/tokens.d.ts +30 -0
  71. package/dist/theme/tokens.d.ts.map +1 -0
  72. package/dist/utils/utils.d.ts +6 -0
  73. package/dist/utils/utils.d.ts.map +1 -0
  74. package/package.json +17 -9
  75. package/dist/index.cjs.map +0 -1
  76. package/dist/index.d.cts +0 -321
  77. package/dist/index.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,321 +1,16 @@
1
- import React, { CSSProperties, ReactNode } from 'react';
2
- import { ClassValue } from 'clsx';
3
-
4
- type CheckoutState = "review" | "payment_method" | "payment_details" | "processing" | "pending" | "redirect" | "success" | "error";
5
-
6
- type CheckoutEvent = {
7
- type: "CHECKOUT_VIEWED";
8
- } | {
9
- type: "STEP_CHANGED";
10
- step: CheckoutState;
11
- } | {
12
- type: "PAYMENT_METHOD_SELECTED";
13
- methodId: string;
14
- } | {
15
- type: "PAYMENT_SUBMITTED";
16
- } | {
17
- type: "PAYMENT_SUCCESS";
18
- transactionId: string;
19
- } | {
20
- type: "PAYMENT_ERROR";
21
- error: string;
22
- } | {
23
- type: "COUPON_APPLY_REQUESTED";
24
- code: string;
25
- } | {
26
- type: "COUPON_REMOVE_REQUESTED";
27
- } | {
28
- type: "ITEM_QUANTITY_UPDATE_REQUESTED";
29
- itemId: string;
30
- quantity: number;
31
- } | {
32
- type: "ITEM_REMOVE_REQUESTED";
33
- itemId: string;
34
- };
35
- type EventHandler = (event: CheckoutEvent) => void;
36
-
37
- interface PaymentProvider {
38
- initialize?(config: unknown): Promise<void>;
39
- createPayment(data: PaymentPayload): Promise<PaymentResult>;
40
- confirmPayment?(data: unknown): Promise<PaymentResult>;
41
- }
42
-
43
- interface CheckoutThemeColors {
44
- primary: string;
45
- background: string;
46
- surface: string;
47
- text: string;
48
- border: string;
49
- success: string;
50
- error: string;
51
- }
52
- interface CheckoutTheme {
53
- colors: Partial<CheckoutThemeColors>;
54
- radius: string;
55
- fontFamily: string;
56
- }
57
- type CheckoutThemeName = "light" | "dark" | "minimal" | "corporate" | "neon";
58
- declare const checkoutThemes: Record<CheckoutThemeName, CheckoutTheme>;
59
- declare const defaultTheme: CheckoutTheme;
60
- declare function mergeTheme(base: CheckoutTheme, overrides?: Partial<CheckoutTheme>): CheckoutTheme;
61
- declare function createCssVars(theme: CheckoutTheme): CSSProperties;
62
- /**
63
- * Generates a complete CheckoutTheme from a single brand color.
64
- * Uses the brand color as `primary` and auto-generates all other tokens.
65
- */
66
- declare function generateBrandTheme(brandColor: string): CheckoutTheme;
67
- /**
68
- * Priority chain: customTheme overrides → brandColor theme → preset theme
69
- */
70
- declare function resolveTheme(theme?: CheckoutThemeName | Partial<CheckoutTheme>, brandColor?: string, customTheme?: Partial<CheckoutTheme>): CheckoutTheme;
71
-
72
- interface CheckoutMessages {
73
- orderSummary: string;
74
- quantity: string;
75
- quantityShort: string;
76
- removeItem: string;
77
- subtotal: string;
78
- discount: string;
79
- shipping: string;
80
- shippingFree: string;
81
- taxes: string;
82
- total: string;
83
- couponPlaceholder: string;
84
- couponApply: string;
85
- couponApplied: string;
86
- couponInvalid: string;
87
- couponRemove: string;
88
- orderSummaryTitle: string;
89
- securePayment: string;
90
- continueToPay: string;
91
- payNow: string;
92
- pay: string;
93
- processing: string;
94
- continueNow: string;
95
- paymentMethod: string;
96
- back: string;
97
- completeDetails: string;
98
- selectMethod: string;
99
- processingPayment: string;
100
- processingDescription: string;
101
- redirecting: string;
102
- redirectDescription: string;
103
- showOrderDetails: string;
104
- hideOrderDetails: string;
105
- continue: string;
106
- }
107
- type CheckoutLocale = "es" | "en" | "pt-BR" | "auto";
108
- type SupportedCurrency = "USD" | "EUR" | "GBP" | "BRL" | "ARS" | "MXN" | "CLP" | "COP" | "PEN" | "UYU" | "PYG" | "BOB" | "VES" | "DOP" | "CRC" | "GTQ" | "HNL" | "NIO" | "PAB" | "CAD" | "JPY" | "CNY" | "KRW" | "INR" | "AUD" | (string & {});
109
- interface CheckoutFormatters {
110
- currency?: (amount: number) => string;
111
- }
112
-
113
- interface PluginSlotProps {
114
- items: CheckoutItem[];
115
- totals: CheckoutTotals;
116
- step: string;
117
- t: CheckoutMessages;
118
- fmt: (amount: number) => string;
119
- }
120
- interface PluginItemSlotProps extends PluginSlotProps {
121
- item: CheckoutItem;
122
- }
123
- interface PluginSlots {
124
- orderItemActions?: (props: PluginItemSlotProps) => ReactNode;
125
- /** Renders at the end of item row in OrderSummary (e.g. remove icon) */
126
- orderItemEnd?: (props: PluginItemSlotProps) => ReactNode;
127
- /** Renders before totals in sidebar (desktop) — e.g. coupon input */
128
- sidebarBeforeTotals?: (props: PluginSlotProps) => ReactNode;
129
- /** Renders next to discount line in totals — e.g. remove coupon */
130
- totalsDiscountAction?: (props: PluginSlotProps) => ReactNode;
131
- /** Renders inside mobile bar expandable section — e.g. coupon input */
132
- mobileBarExpanded?: (props: PluginSlotProps) => ReactNode;
133
- }
134
- interface CheckoutPlugin {
135
- id: string;
136
- slots: PluginSlots;
137
- }
138
-
139
- interface CheckoutProps {
140
- items: CheckoutItem[];
141
- totals: CheckoutTotals;
142
- paymentMethods: PaymentMethod[];
143
- provider: PaymentProvider;
144
- currency: SupportedCurrency;
145
- locale?: CheckoutLocale;
146
- theme?: CheckoutThemeName | Partial<CheckoutTheme>;
147
- brandColor?: string;
148
- customTheme?: Partial<CheckoutTheme>;
149
- onEvent?: EventHandler;
150
- cartController?: CartController;
151
- initialState?: Extract<PaymentResult, {
152
- status: "success" | "error" | "pending";
153
- }>;
154
- devTools?: boolean;
155
- messages?: Partial<CheckoutMessages>;
156
- formatters?: CheckoutFormatters;
157
- plugins?: CheckoutPlugin[];
158
- }
159
- interface ButtonProps {
160
- label: string;
161
- onPress: () => void;
162
- variant?: FractalButtonVariant;
163
- icon?: ReactNode;
164
- disabled?: boolean;
165
- className?: string;
166
- type?: "button" | "submit";
167
- }
168
-
169
- interface CheckoutItem {
170
- id: string;
171
- name: string;
172
- quantity: number;
173
- unitPrice: number;
174
- discount?: {
175
- type: "percentage" | "fixed";
176
- value: number;
177
- label?: string;
178
- };
179
- total: number;
180
- image?: string;
181
- }
182
- interface CheckoutTotals {
183
- subtotal: number;
184
- discount?: number;
185
- taxes?: number;
186
- shipping?: number;
187
- total: number;
188
- }
189
- interface CartState {
190
- items: CheckoutItem[];
191
- totals: CheckoutTotals;
192
- }
193
- interface CartController {
194
- updateQuantity: (id: string, qty: number) => Promise<CartState>;
195
- removeItem: (id: string) => Promise<CartState>;
196
- applyCoupon: (code: string) => Promise<CartState>;
197
- removeCoupon?: () => Promise<CartState>;
198
- }
199
- interface PaymentMethodComponentProps {
200
- /** Call this to enable or disable the Pay button while the user fills in the form */
201
- onReadyChange: (ready: boolean) => void;
202
- }
203
- interface PaymentMethod {
204
- id: string;
205
- label: string;
206
- type: string;
207
- icon?: string;
208
- /**
209
- * Optional renderer for inline payment UI (card form, wallet picker, etc.).
210
- * If provided, the Pay button starts disabled until `onReadyChange(true)` is called.
211
- */
212
- renderComponent?: (props: PaymentMethodComponentProps) => ReactNode;
213
- }
214
- /**
215
- * Props the integrator can return from createPayment to control
216
- * what the FeedbackScreen displays after a payment attempt.
217
- * `variant` and `children` are always derived by the framework.
218
- */
219
- interface FeedbackProps {
220
- title: string;
221
- description?: string;
222
- actions?: ButtonProps[];
223
- }
224
- type PaymentResult = {
225
- status: "success";
226
- feedback?: FeedbackProps;
227
- } | {
228
- status: "pending";
229
- feedback?: FeedbackProps;
230
- } | {
231
- status: "error";
232
- feedback?: FeedbackProps;
233
- } | {
234
- status: "redirect";
235
- url: string;
236
- feedback?: FeedbackProps;
237
- };
238
- type FractalButtonVariant = "solid" | "outline" | "ghost";
239
- type PaymentPayload = unknown;
240
-
241
- /**
242
- * Color manipulation utilities for the Brand Auto Theme system.
243
- * All functions work with hex color strings (#RRGGBB or #RGB).
244
- */
245
- interface RGB {
246
- r: number;
247
- g: number;
248
- b: number;
249
- }
250
- declare function hexToRgb(hex: string): RGB;
251
- declare function rgbToHex({ r, g, b }: RGB): string;
252
- /**
253
- * Calculates relative luminance using sRGB coefficients (W3C formula).
254
- * Returns a value between 0 (black) and 1 (white).
255
- */
256
- declare function getLuminance(hex: string): number;
257
- /**
258
- * Returns #000000 or #FFFFFF based on which provides better contrast
259
- * against the given background color.
260
- */
261
- declare function getContrastColor(hex: string): string;
262
- /**
263
- * Returns true if the color is considered "dark" (luminance < 0.5).
264
- */
265
- declare function isDark(hex: string): boolean;
266
- /**
267
- * Darkens a hex color by a given amount (0–100).
268
- */
269
- declare function darken(hex: string, amount: number): string;
270
- /**
271
- * Lightens a hex color by a given amount (0–100).
272
- */
273
- declare function lighten(hex: string, amount: number): string;
274
- /**
275
- * Mixes two hex colors by a given ratio (0 = first color, 1 = second color).
276
- */
277
- declare function mix(hex1: string, hex2: string, ratio: number): string;
278
-
279
- interface CartEditPluginOptions {
280
- allowRemove?: boolean;
281
- allowQuantityEdit?: boolean;
282
- minQuantity?: number;
283
- maxQuantity?: number;
284
- }
285
- declare function createCartEditPlugin(emit: EventHandler, options?: CartEditPluginOptions): CheckoutPlugin;
286
-
287
- declare function createDiscountPlugin(emit: EventHandler): CheckoutPlugin;
288
-
289
- declare const useCheckout: () => {
290
- setStep: (step: CheckoutState) => void;
291
- selectMethod: (methodId: string) => void;
292
- submitPayment: (data: unknown) => Promise<void>;
293
- setError: (error: string) => void;
294
- updateQuantity: (id: string, qty: number) => Promise<void>;
295
- removeItem: (id: string) => Promise<void>;
296
- applyCoupon: (code: string) => Promise<boolean>;
297
- removeCoupon: () => Promise<boolean>;
298
- hasCartController: boolean;
299
- hasRemoveCoupon: boolean;
300
- items: CheckoutItem[];
301
- paymentMethods: PaymentMethod[];
302
- provider: PaymentProvider;
303
- currency: string;
304
- locale: string;
305
- step: CheckoutState;
306
- selectedMethodId: string | null;
307
- totals: CheckoutTotals;
308
- cartController?: CartController;
309
- theme?: CheckoutTheme;
310
- error: string | null;
311
- paymentResult?: PaymentResult;
312
- };
313
-
314
- declare function cn(...inputs: ClassValue[]): string;
315
- declare const isPaymentStep: (step: string) => step is "payment_method" | "payment_details";
316
- declare const isReviewStep: (step: string) => step is "review";
317
- declare const formatNumber: (n: number, currency: string) => string;
318
-
319
- declare const Checkout: React.FC<CheckoutProps>;
320
-
321
- export { type CartController, type CartEditPluginOptions, type CartState, Checkout, type CheckoutEvent, type CheckoutFormatters, type CheckoutItem, type CheckoutLocale, type CheckoutMessages, type CheckoutPlugin, type CheckoutState, type CheckoutTheme, type CheckoutThemeColors, type CheckoutThemeName, type CheckoutTotals, type EventHandler, type FeedbackProps, type FractalButtonVariant, type PaymentMethod, type PaymentMethodComponentProps, type PaymentPayload, type PaymentProvider, type PaymentResult, type PluginItemSlotProps, type PluginSlotProps, type PluginSlots, type SupportedCurrency, checkoutThemes, cn, createCartEditPlugin, createCssVars, createDiscountPlugin, darken, defaultTheme, formatNumber, generateBrandTheme, getContrastColor, getLuminance, hexToRgb, isDark, isPaymentStep, isReviewStep, lighten, mergeTheme, mix, resolveTheme, rgbToHex, useCheckout };
1
+ export type { CheckoutItem, CheckoutTotals, CartState, CartController, PaymentMethod, PaymentMethodComponentProps, PaymentResult, FeedbackProps, PaymentPayload, FractalButtonVariant } from './core/types';
2
+ export type { PaymentProvider } from './core/provider.interface';
3
+ export type { CheckoutEvent, EventHandler } from './core/event-system';
4
+ export type { CheckoutState } from './core/checkout-machine';
5
+ export type { CheckoutTheme, CheckoutThemeColors, CheckoutThemeName } from './theme/tokens';
6
+ export { checkoutThemes, defaultTheme, mergeTheme, createCssVars, generateBrandTheme, resolveTheme } from './theme/tokens';
7
+ export { hexToRgb, rgbToHex, getLuminance, getContrastColor, isDark, darken, lighten, mix } from './theme/color-utils';
8
+ export type { CheckoutMessages, CheckoutFormatters, CheckoutLocale, SupportedCurrency } from './locales/types';
9
+ export type { CheckoutPlugin, PluginSlots, PluginSlotProps, PluginItemSlotProps } from './plugins/types';
10
+ export type { CartEditPluginOptions } from './plugins/cart-edit-plugin';
11
+ export { createDiscountPlugin } from './plugins/discount-plugin';
12
+ export { createCartEditPlugin } from './plugins/cart-edit-plugin';
13
+ export { useCheckout } from './hooks/useCheckout';
14
+ export { cn, formatNumber, isPaymentStep, isReviewStep } from './utils/utils';
15
+ export { Checkout } from './components/Checkout';
16
+ //# sourceMappingURL=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