@libreapps/checkout 2.0.1
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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +24 -0
- package/LICENSE.md +21 -0
- package/README.md +211 -0
- package/client.ts +318 -0
- package/dist/client.d.ts +80 -0
- package/dist/client.js +229 -0
- package/dist/client.js.map +1 -0
- package/dist/elements/checkout-form.d.ts +14 -0
- package/dist/elements/checkout-form.js +112 -0
- package/dist/elements/checkout-form.js.map +1 -0
- package/dist/elements/index.d.ts +7 -0
- package/dist/elements/index.js +7 -0
- package/dist/elements/index.js.map +1 -0
- package/dist/embed/index.d.ts +6 -0
- package/dist/embed/index.js +7 -0
- package/dist/embed/index.js.map +1 -0
- package/dist/embed/libreapps-checkout.d.ts +32 -0
- package/dist/embed/libreapps-checkout.js +131 -0
- package/dist/embed/libreapps-checkout.js.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-checkout.d.ts +42 -0
- package/dist/hooks/use-checkout.js +168 -0
- package/dist/hooks/use-checkout.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +219 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/elements/checkout-form.tsx +543 -0
- package/elements/index.ts +8 -0
- package/embed/index.ts +7 -0
- package/embed/libreapps-checkout.ts +172 -0
- package/hooks/index.ts +6 -0
- package/hooks/use-checkout.tsx +244 -0
- package/index.ts +70 -0
- package/package.json +57 -0
- package/tsconfig.json +15 -0
- package/types.ts +301 -0
package/types.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @libreapps/checkout - Type definitions
|
|
3
|
+
*
|
|
4
|
+
* Stripe-like checkout widget for LibreApps Commerce
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface CheckoutOptions {
|
|
8
|
+
/** LibreApps API key (publishable key) */
|
|
9
|
+
apiKey: string
|
|
10
|
+
|
|
11
|
+
/** Environment: 'production' | 'sandbox' */
|
|
12
|
+
mode?: 'production' | 'sandbox'
|
|
13
|
+
|
|
14
|
+
/** Custom API endpoint */
|
|
15
|
+
apiEndpoint?: string
|
|
16
|
+
|
|
17
|
+
/** Locale for i18n */
|
|
18
|
+
locale?: string
|
|
19
|
+
|
|
20
|
+
/** Theme configuration */
|
|
21
|
+
appearance?: CheckoutAppearance
|
|
22
|
+
|
|
23
|
+
/** Callbacks */
|
|
24
|
+
onSuccess?: (result: CheckoutResult) => void
|
|
25
|
+
onError?: (error: CheckoutError) => void
|
|
26
|
+
onCancel?: () => void
|
|
27
|
+
|
|
28
|
+
/** Enable test mode */
|
|
29
|
+
testMode?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CheckoutAppearance {
|
|
33
|
+
/** Theme: 'light' | 'dark' | 'auto' */
|
|
34
|
+
theme?: 'light' | 'dark' | 'auto'
|
|
35
|
+
|
|
36
|
+
/** Primary brand color */
|
|
37
|
+
primaryColor?: string
|
|
38
|
+
|
|
39
|
+
/** Background color */
|
|
40
|
+
backgroundColor?: string
|
|
41
|
+
|
|
42
|
+
/** Border radius */
|
|
43
|
+
borderRadius?: string
|
|
44
|
+
|
|
45
|
+
/** Font family */
|
|
46
|
+
fontFamily?: string
|
|
47
|
+
|
|
48
|
+
/** Custom CSS variables */
|
|
49
|
+
variables?: Record<string, string>
|
|
50
|
+
|
|
51
|
+
/** Custom CSS rules */
|
|
52
|
+
rules?: Record<string, Record<string, string>>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface CheckoutSession {
|
|
56
|
+
/** Session ID */
|
|
57
|
+
id: string
|
|
58
|
+
|
|
59
|
+
/** Session status */
|
|
60
|
+
status: 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled'
|
|
61
|
+
|
|
62
|
+
/** Line items */
|
|
63
|
+
lineItems: CheckoutLineItem[]
|
|
64
|
+
|
|
65
|
+
/** Subtotal in cents */
|
|
66
|
+
subtotal: number
|
|
67
|
+
|
|
68
|
+
/** Tax amount in cents */
|
|
69
|
+
tax: number
|
|
70
|
+
|
|
71
|
+
/** Shipping cost in cents */
|
|
72
|
+
shipping: number
|
|
73
|
+
|
|
74
|
+
/** Total in cents */
|
|
75
|
+
total: number
|
|
76
|
+
|
|
77
|
+
/** Currency code */
|
|
78
|
+
currency: string
|
|
79
|
+
|
|
80
|
+
/** Customer info */
|
|
81
|
+
customer?: CheckoutCustomer
|
|
82
|
+
|
|
83
|
+
/** Shipping address */
|
|
84
|
+
shippingAddress?: CheckoutAddress
|
|
85
|
+
|
|
86
|
+
/** Billing address */
|
|
87
|
+
billingAddress?: CheckoutAddress
|
|
88
|
+
|
|
89
|
+
/** Payment method */
|
|
90
|
+
paymentMethod?: CheckoutPaymentMethod
|
|
91
|
+
|
|
92
|
+
/** Metadata */
|
|
93
|
+
metadata?: Record<string, string>
|
|
94
|
+
|
|
95
|
+
/** URLs */
|
|
96
|
+
successUrl?: string
|
|
97
|
+
cancelUrl?: string
|
|
98
|
+
|
|
99
|
+
/** Expiration */
|
|
100
|
+
expiresAt?: string
|
|
101
|
+
|
|
102
|
+
/** Timestamps */
|
|
103
|
+
createdAt: string
|
|
104
|
+
updatedAt: string
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface CheckoutLineItem {
|
|
108
|
+
/** Item ID */
|
|
109
|
+
id: string
|
|
110
|
+
|
|
111
|
+
/** Product ID */
|
|
112
|
+
productId: string
|
|
113
|
+
|
|
114
|
+
/** SKU */
|
|
115
|
+
sku?: string
|
|
116
|
+
|
|
117
|
+
/** Name */
|
|
118
|
+
name: string
|
|
119
|
+
|
|
120
|
+
/** Description */
|
|
121
|
+
description?: string
|
|
122
|
+
|
|
123
|
+
/** Image URL */
|
|
124
|
+
imageUrl?: string
|
|
125
|
+
|
|
126
|
+
/** Quantity */
|
|
127
|
+
quantity: number
|
|
128
|
+
|
|
129
|
+
/** Unit price in cents */
|
|
130
|
+
unitPrice: number
|
|
131
|
+
|
|
132
|
+
/** Total price in cents */
|
|
133
|
+
totalPrice: number
|
|
134
|
+
|
|
135
|
+
/** Currency */
|
|
136
|
+
currency: string
|
|
137
|
+
|
|
138
|
+
/** Metadata */
|
|
139
|
+
metadata?: Record<string, string>
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface CheckoutCustomer {
|
|
143
|
+
/** Customer ID */
|
|
144
|
+
id?: string
|
|
145
|
+
|
|
146
|
+
/** Email */
|
|
147
|
+
email: string
|
|
148
|
+
|
|
149
|
+
/** Name */
|
|
150
|
+
name?: string
|
|
151
|
+
|
|
152
|
+
/** Phone */
|
|
153
|
+
phone?: string
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface CheckoutAddress {
|
|
157
|
+
/** Address line 1 */
|
|
158
|
+
line1: string
|
|
159
|
+
|
|
160
|
+
/** Address line 2 */
|
|
161
|
+
line2?: string
|
|
162
|
+
|
|
163
|
+
/** City */
|
|
164
|
+
city: string
|
|
165
|
+
|
|
166
|
+
/** State/Province */
|
|
167
|
+
state?: string
|
|
168
|
+
|
|
169
|
+
/** Postal code */
|
|
170
|
+
postalCode: string
|
|
171
|
+
|
|
172
|
+
/** Country code (ISO 3166-1 alpha-2) */
|
|
173
|
+
country: string
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface CheckoutPaymentMethod {
|
|
177
|
+
/** Payment method type */
|
|
178
|
+
type: 'card' | 'crypto' | 'apple_pay' | 'google_pay' | 'bank_transfer'
|
|
179
|
+
|
|
180
|
+
/** Card details (if type is 'card') */
|
|
181
|
+
card?: {
|
|
182
|
+
brand: string
|
|
183
|
+
last4: string
|
|
184
|
+
expMonth: number
|
|
185
|
+
expYear: number
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Crypto details (if type is 'crypto') */
|
|
189
|
+
crypto?: {
|
|
190
|
+
currency: string
|
|
191
|
+
network: string
|
|
192
|
+
address: string
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface CheckoutResult {
|
|
197
|
+
/** Session ID */
|
|
198
|
+
sessionId: string
|
|
199
|
+
|
|
200
|
+
/** Order ID */
|
|
201
|
+
orderId: string
|
|
202
|
+
|
|
203
|
+
/** Status */
|
|
204
|
+
status: 'success' | 'pending'
|
|
205
|
+
|
|
206
|
+
/** Payment intent ID */
|
|
207
|
+
paymentIntentId?: string
|
|
208
|
+
|
|
209
|
+
/** Customer ID */
|
|
210
|
+
customerId?: string
|
|
211
|
+
|
|
212
|
+
/** Receipt URL */
|
|
213
|
+
receiptUrl?: string
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface CheckoutError {
|
|
217
|
+
/** Error code */
|
|
218
|
+
code: string
|
|
219
|
+
|
|
220
|
+
/** Error message */
|
|
221
|
+
message: string
|
|
222
|
+
|
|
223
|
+
/** Additional details */
|
|
224
|
+
details?: Record<string, unknown>
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface CreateSessionParams {
|
|
228
|
+
/** Line items */
|
|
229
|
+
lineItems: Array<{
|
|
230
|
+
productId?: string
|
|
231
|
+
sku?: string
|
|
232
|
+
name: string
|
|
233
|
+
description?: string
|
|
234
|
+
imageUrl?: string
|
|
235
|
+
quantity: number
|
|
236
|
+
unitPrice: number
|
|
237
|
+
currency?: string
|
|
238
|
+
metadata?: Record<string, string>
|
|
239
|
+
}>
|
|
240
|
+
|
|
241
|
+
/** Customer info */
|
|
242
|
+
customer?: {
|
|
243
|
+
email: string
|
|
244
|
+
name?: string
|
|
245
|
+
phone?: string
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Success URL */
|
|
249
|
+
successUrl?: string
|
|
250
|
+
|
|
251
|
+
/** Cancel URL */
|
|
252
|
+
cancelUrl?: string
|
|
253
|
+
|
|
254
|
+
/** Currency code */
|
|
255
|
+
currency?: string
|
|
256
|
+
|
|
257
|
+
/** Metadata */
|
|
258
|
+
metadata?: Record<string, string>
|
|
259
|
+
|
|
260
|
+
/** Enable shipping */
|
|
261
|
+
shipping?: boolean
|
|
262
|
+
|
|
263
|
+
/** Collect phone */
|
|
264
|
+
collectPhone?: boolean
|
|
265
|
+
|
|
266
|
+
/** Allowed payment methods */
|
|
267
|
+
paymentMethods?: Array<'card' | 'crypto' | 'apple_pay' | 'google_pay'>
|
|
268
|
+
|
|
269
|
+
/** Promo code */
|
|
270
|
+
promoCode?: string
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface ElementsOptions {
|
|
274
|
+
/** Checkout session or session ID */
|
|
275
|
+
session: CheckoutSession | string
|
|
276
|
+
|
|
277
|
+
/** Appearance options */
|
|
278
|
+
appearance?: CheckoutAppearance
|
|
279
|
+
|
|
280
|
+
/** Locale */
|
|
281
|
+
locale?: string
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type CheckoutStep = 'cart' | 'shipping' | 'payment' | 'confirmation'
|
|
285
|
+
|
|
286
|
+
export interface CheckoutState {
|
|
287
|
+
/** Current step */
|
|
288
|
+
step: CheckoutStep
|
|
289
|
+
|
|
290
|
+
/** Session data */
|
|
291
|
+
session: CheckoutSession | null
|
|
292
|
+
|
|
293
|
+
/** Loading state */
|
|
294
|
+
isLoading: boolean
|
|
295
|
+
|
|
296
|
+
/** Error state */
|
|
297
|
+
error: CheckoutError | null
|
|
298
|
+
|
|
299
|
+
/** Processing payment */
|
|
300
|
+
isProcessing: boolean
|
|
301
|
+
}
|