create-brainerce-store 1.0.0

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 (53) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +502 -0
  3. package/package.json +44 -0
  4. package/templates/nextjs/base/.env.local.ejs +3 -0
  5. package/templates/nextjs/base/.eslintrc.json +3 -0
  6. package/templates/nextjs/base/gitignore +30 -0
  7. package/templates/nextjs/base/next.config.ts +9 -0
  8. package/templates/nextjs/base/package.json.ejs +30 -0
  9. package/templates/nextjs/base/postcss.config.mjs +9 -0
  10. package/templates/nextjs/base/src/app/account/page.tsx +105 -0
  11. package/templates/nextjs/base/src/app/auth/callback/page.tsx +99 -0
  12. package/templates/nextjs/base/src/app/cart/page.tsx +263 -0
  13. package/templates/nextjs/base/src/app/checkout/page.tsx +463 -0
  14. package/templates/nextjs/base/src/app/globals.css +30 -0
  15. package/templates/nextjs/base/src/app/layout.tsx.ejs +33 -0
  16. package/templates/nextjs/base/src/app/login/page.tsx +56 -0
  17. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +191 -0
  18. package/templates/nextjs/base/src/app/page.tsx +95 -0
  19. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +346 -0
  20. package/templates/nextjs/base/src/app/products/page.tsx +243 -0
  21. package/templates/nextjs/base/src/app/register/page.tsx +66 -0
  22. package/templates/nextjs/base/src/app/verify-email/page.tsx +291 -0
  23. package/templates/nextjs/base/src/components/account/order-history.tsx +184 -0
  24. package/templates/nextjs/base/src/components/account/profile-section.tsx +73 -0
  25. package/templates/nextjs/base/src/components/auth/login-form.tsx +92 -0
  26. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +134 -0
  27. package/templates/nextjs/base/src/components/auth/register-form.tsx +177 -0
  28. package/templates/nextjs/base/src/components/cart/cart-item.tsx +150 -0
  29. package/templates/nextjs/base/src/components/cart/cart-nudges.tsx +39 -0
  30. package/templates/nextjs/base/src/components/cart/cart-summary.tsx +67 -0
  31. package/templates/nextjs/base/src/components/cart/coupon-input.tsx +131 -0
  32. package/templates/nextjs/base/src/components/cart/reservation-countdown.tsx +100 -0
  33. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +273 -0
  34. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +124 -0
  35. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +111 -0
  36. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +62 -0
  37. package/templates/nextjs/base/src/components/layout/footer.tsx +35 -0
  38. package/templates/nextjs/base/src/components/layout/header.tsx +329 -0
  39. package/templates/nextjs/base/src/components/products/discount-badge.tsx +36 -0
  40. package/templates/nextjs/base/src/components/products/product-card.tsx +94 -0
  41. package/templates/nextjs/base/src/components/products/product-grid.tsx +33 -0
  42. package/templates/nextjs/base/src/components/products/stock-badge.tsx +34 -0
  43. package/templates/nextjs/base/src/components/products/variant-selector.tsx +147 -0
  44. package/templates/nextjs/base/src/components/shared/loading-spinner.tsx +30 -0
  45. package/templates/nextjs/base/src/components/shared/price-display.tsx +62 -0
  46. package/templates/nextjs/base/src/hooks/use-search.ts +77 -0
  47. package/templates/nextjs/base/src/lib/brainerce.ts.ejs +59 -0
  48. package/templates/nextjs/base/src/lib/utils.ts +6 -0
  49. package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +168 -0
  50. package/templates/nextjs/base/tailwind.config.ts +30 -0
  51. package/templates/nextjs/base/tsconfig.json +23 -0
  52. package/templates/nextjs/themes/minimal/globals.css +30 -0
  53. package/templates/nextjs/themes/minimal/theme.json +23 -0
@@ -0,0 +1,150 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import Image from 'next/image';
5
+ import type { CartItem as CartItemType } from 'brainerce';
6
+ import { getCartItemName, getCartItemImage, formatPrice } from 'brainerce';
7
+ import { getClient } from '@/lib/brainerce';
8
+ import { useStoreInfo } from '@/providers/store-provider';
9
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
10
+ import { cn } from '@/lib/utils';
11
+
12
+ interface CartItemProps {
13
+ item: CartItemType;
14
+ onUpdate: () => void;
15
+ className?: string;
16
+ }
17
+
18
+ export function CartItem({ item, onUpdate, className }: CartItemProps) {
19
+ const { storeInfo } = useStoreInfo();
20
+ const currency = storeInfo?.currency || 'USD';
21
+ const [updating, setUpdating] = useState(false);
22
+ const [removing, setRemoving] = useState(false);
23
+
24
+ const name = getCartItemName(item);
25
+ const imageUrl = getCartItemImage(item);
26
+ const variantName = item.variant?.name;
27
+ const unitPrice = parseFloat(item.unitPrice);
28
+ const lineTotal = unitPrice * item.quantity;
29
+
30
+ async function handleQuantityChange(newQuantity: number) {
31
+ if (newQuantity < 1 || updating) return;
32
+
33
+ try {
34
+ setUpdating(true);
35
+ const client = getClient();
36
+ await client.smartUpdateCartItem(item.productId, newQuantity, item.variantId || undefined);
37
+ onUpdate();
38
+ } catch (err) {
39
+ console.error('Failed to update quantity:', err);
40
+ } finally {
41
+ setUpdating(false);
42
+ }
43
+ }
44
+
45
+ async function handleRemove() {
46
+ if (removing) return;
47
+
48
+ try {
49
+ setRemoving(true);
50
+ const client = getClient();
51
+ await client.smartRemoveFromCart(item.productId, item.variantId || undefined);
52
+ onUpdate();
53
+ } catch (err) {
54
+ console.error('Failed to remove item:', err);
55
+ } finally {
56
+ setRemoving(false);
57
+ }
58
+ }
59
+
60
+ return (
61
+ <div
62
+ className={cn(
63
+ 'border-border flex gap-4 border-b py-4 last:border-0',
64
+ (updating || removing) && 'opacity-60',
65
+ className
66
+ )}
67
+ >
68
+ {/* Image */}
69
+ <div className="bg-muted relative h-20 w-20 flex-shrink-0 overflow-hidden rounded">
70
+ {imageUrl ? (
71
+ <Image src={imageUrl} alt={name} fill sizes="80px" className="object-cover" />
72
+ ) : (
73
+ <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
74
+ <svg className="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
75
+ <path
76
+ strokeLinecap="round"
77
+ strokeLinejoin="round"
78
+ strokeWidth={1.5}
79
+ d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
80
+ />
81
+ </svg>
82
+ </div>
83
+ )}
84
+ </div>
85
+
86
+ {/* Details */}
87
+ <div className="min-w-0 flex-1">
88
+ <h3 className="text-foreground truncate text-sm font-medium">{name}</h3>
89
+
90
+ {/* Variant name */}
91
+ {variantName && <p className="text-muted-foreground mt-1 text-xs">{variantName}</p>}
92
+
93
+ {/* Unit price */}
94
+ <p className="text-muted-foreground mt-1 text-sm">
95
+ {formatPrice(unitPrice, { currency }) as string}
96
+ </p>
97
+
98
+ {/* Quantity controls */}
99
+ <div className="mt-2 flex items-center gap-3">
100
+ <div className="border-border flex items-center rounded border">
101
+ <button
102
+ type="button"
103
+ onClick={() => handleQuantityChange(item.quantity - 1)}
104
+ disabled={updating || item.quantity <= 1}
105
+ className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
106
+ aria-label="Decrease quantity"
107
+ >
108
+ -
109
+ </button>
110
+ <span className="text-foreground min-w-[2.5rem] px-3 py-1 text-center text-sm font-medium">
111
+ {updating ? (
112
+ <LoadingSpinner
113
+ size="sm"
114
+ className="border-muted-foreground/30 border-t-foreground mx-auto"
115
+ />
116
+ ) : (
117
+ item.quantity
118
+ )}
119
+ </span>
120
+ <button
121
+ type="button"
122
+ onClick={() => handleQuantityChange(item.quantity + 1)}
123
+ disabled={updating}
124
+ className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
125
+ aria-label="Increase quantity"
126
+ >
127
+ +
128
+ </button>
129
+ </div>
130
+
131
+ <button
132
+ type="button"
133
+ onClick={handleRemove}
134
+ disabled={removing}
135
+ className="text-destructive hover:text-destructive/80 text-xs transition-colors disabled:opacity-40"
136
+ >
137
+ {removing ? 'Removing...' : 'Remove'}
138
+ </button>
139
+ </div>
140
+ </div>
141
+
142
+ {/* Line total */}
143
+ <div className="flex-shrink-0 text-end">
144
+ <span className="text-foreground text-sm font-medium">
145
+ {formatPrice(lineTotal, { currency }) as string}
146
+ </span>
147
+ </div>
148
+ </div>
149
+ );
150
+ }
@@ -0,0 +1,39 @@
1
+ 'use client';
2
+
3
+ import type { CartNudge } from 'brainerce';
4
+ import { cn } from '@/lib/utils';
5
+
6
+ interface CartNudgesProps {
7
+ nudges: CartNudge[];
8
+ className?: string;
9
+ }
10
+
11
+ export function CartNudges({ nudges, className }: CartNudgesProps) {
12
+ if (nudges.length === 0) return null;
13
+
14
+ return (
15
+ <div className={cn('space-y-2', className)}>
16
+ {nudges.map((nudge) => (
17
+ <div
18
+ key={nudge.ruleId}
19
+ className="bg-primary/5 border-primary/20 flex items-start gap-3 rounded-lg border px-4 py-3"
20
+ >
21
+ <svg
22
+ className="text-primary mt-0.5 h-5 w-5 flex-shrink-0"
23
+ fill="none"
24
+ viewBox="0 0 24 24"
25
+ stroke="currentColor"
26
+ >
27
+ <path
28
+ strokeLinecap="round"
29
+ strokeLinejoin="round"
30
+ strokeWidth={2}
31
+ d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
32
+ />
33
+ </svg>
34
+ <p className="text-foreground flex-1 text-sm">{nudge.text}</p>
35
+ </div>
36
+ ))}
37
+ </div>
38
+ );
39
+ }
@@ -0,0 +1,67 @@
1
+ 'use client';
2
+
3
+ import { formatPrice } from 'brainerce';
4
+ import { useStoreInfo, useCart } from '@/providers/store-provider';
5
+ import { cn } from '@/lib/utils';
6
+
7
+ interface CartSummaryProps {
8
+ className?: string;
9
+ }
10
+
11
+ export function CartSummary({ className }: CartSummaryProps) {
12
+ const { storeInfo } = useStoreInfo();
13
+ const { totals } = useCart();
14
+ const currency = storeInfo?.currency || 'USD';
15
+
16
+ return (
17
+ <div className={cn('space-y-3', className)}>
18
+ <h3 className="text-foreground text-lg font-semibold">Order Summary</h3>
19
+
20
+ <div className="space-y-2 text-sm">
21
+ {/* Subtotal */}
22
+ <div className="flex items-center justify-between">
23
+ <span className="text-muted-foreground">Subtotal</span>
24
+ <span className="text-foreground font-medium">
25
+ {formatPrice(totals.subtotal, { currency }) as string}
26
+ </span>
27
+ </div>
28
+
29
+ {/* Discount */}
30
+ {totals.discount > 0 && (
31
+ <div className="flex items-center justify-between">
32
+ <span className="text-muted-foreground">Discount</span>
33
+ <span className="text-destructive font-medium">
34
+ -{formatPrice(totals.discount, { currency }) as string}
35
+ </span>
36
+ </div>
37
+ )}
38
+
39
+ {/* Shipping */}
40
+ {totals.shipping > 0 && (
41
+ <div className="flex items-center justify-between">
42
+ <span className="text-muted-foreground">Shipping</span>
43
+ <span className="text-foreground font-medium">
44
+ {formatPrice(totals.shipping, { currency }) as string}
45
+ </span>
46
+ </div>
47
+ )}
48
+
49
+ {/* Tax */}
50
+ <div className="flex items-center justify-between">
51
+ <span className="text-muted-foreground">Tax</span>
52
+ <span className="text-muted-foreground text-xs">Calculated at checkout</span>
53
+ </div>
54
+
55
+ {/* Divider */}
56
+ <div className="border-border mt-2 border-t pt-2">
57
+ <div className="flex items-center justify-between">
58
+ <span className="text-foreground font-semibold">Total</span>
59
+ <span className="text-foreground text-base font-semibold">
60
+ {formatPrice(totals.total, { currency }) as string}
61
+ </span>
62
+ </div>
63
+ </div>
64
+ </div>
65
+ </div>
66
+ );
67
+ }
@@ -0,0 +1,131 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import type { Cart } from 'brainerce';
5
+ import { getClient } from '@/lib/brainerce';
6
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
+ import { cn } from '@/lib/utils';
8
+
9
+ interface CouponInputProps {
10
+ cart: Cart;
11
+ onUpdate: () => void;
12
+ className?: string;
13
+ }
14
+
15
+ export function CouponInput({ cart, onUpdate, className }: CouponInputProps) {
16
+ const [code, setCode] = useState('');
17
+ const [applying, setApplying] = useState(false);
18
+ const [removing, setRemoving] = useState(false);
19
+ const [error, setError] = useState<string | null>(null);
20
+
21
+ const appliedCoupon = cart.couponCode || null;
22
+
23
+ async function handleApply() {
24
+ const trimmed = code.trim();
25
+ if (!trimmed || applying) return;
26
+
27
+ try {
28
+ setApplying(true);
29
+ setError(null);
30
+ const client = getClient();
31
+ await client.applyCoupon(cart.id, trimmed);
32
+ setCode('');
33
+ onUpdate();
34
+ } catch (err) {
35
+ const message = err instanceof Error ? err.message : 'Invalid coupon code';
36
+ setError(message);
37
+ } finally {
38
+ setApplying(false);
39
+ }
40
+ }
41
+
42
+ async function handleRemove() {
43
+ if (removing) return;
44
+
45
+ try {
46
+ setRemoving(true);
47
+ setError(null);
48
+ const client = getClient();
49
+ await client.removeCoupon(cart.id);
50
+ onUpdate();
51
+ } catch (err) {
52
+ console.error('Failed to remove coupon:', err);
53
+ } finally {
54
+ setRemoving(false);
55
+ }
56
+ }
57
+
58
+ // Show applied coupon
59
+ if (appliedCoupon) {
60
+ return (
61
+ <div className={cn('space-y-2', className)}>
62
+ <div className="bg-muted flex items-center justify-between rounded px-3 py-2">
63
+ <div className="flex items-center gap-2">
64
+ <svg
65
+ className="text-primary h-4 w-4 flex-shrink-0"
66
+ fill="none"
67
+ viewBox="0 0 24 24"
68
+ stroke="currentColor"
69
+ >
70
+ <path
71
+ strokeLinecap="round"
72
+ strokeLinejoin="round"
73
+ strokeWidth={2}
74
+ d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"
75
+ />
76
+ </svg>
77
+ <span className="text-foreground text-sm font-medium">{appliedCoupon}</span>
78
+ </div>
79
+ <button
80
+ type="button"
81
+ onClick={handleRemove}
82
+ disabled={removing}
83
+ className="text-destructive hover:text-destructive/80 text-xs transition-colors disabled:opacity-40"
84
+ >
85
+ {removing ? 'Removing...' : 'Remove'}
86
+ </button>
87
+ </div>
88
+ </div>
89
+ );
90
+ }
91
+
92
+ return (
93
+ <div className={cn('space-y-2', className)}>
94
+ <div className="flex gap-2">
95
+ <input
96
+ type="text"
97
+ value={code}
98
+ onChange={(e) => {
99
+ setCode(e.target.value);
100
+ if (error) setError(null);
101
+ }}
102
+ onKeyDown={(e) => {
103
+ if (e.key === 'Enter') {
104
+ e.preventDefault();
105
+ handleApply();
106
+ }
107
+ }}
108
+ placeholder="Coupon code"
109
+ className={cn(
110
+ 'bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-9 flex-1 rounded border px-3 text-sm focus:outline-none focus:ring-2',
111
+ error ? 'border-destructive' : 'border-border'
112
+ )}
113
+ />
114
+ <button
115
+ type="button"
116
+ onClick={handleApply}
117
+ disabled={applying || !code.trim()}
118
+ className="border-border bg-background text-foreground hover:bg-muted h-9 rounded border px-4 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40"
119
+ >
120
+ {applying ? (
121
+ <LoadingSpinner size="sm" className="border-muted-foreground/30 border-t-foreground" />
122
+ ) : (
123
+ 'Apply'
124
+ )}
125
+ </button>
126
+ </div>
127
+
128
+ {error && <p className="text-destructive text-xs">{error}</p>}
129
+ </div>
130
+ );
131
+ }
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect, useCallback } from 'react';
4
+ import type { ReservationInfo } from 'brainerce';
5
+ import { cn } from '@/lib/utils';
6
+
7
+ interface ReservationCountdownProps {
8
+ reservation: ReservationInfo;
9
+ className?: string;
10
+ }
11
+
12
+ export function ReservationCountdown({ reservation, className }: ReservationCountdownProps) {
13
+ const [remainingSeconds, setRemainingSeconds] = useState<number>(0);
14
+
15
+ const calculateRemaining = useCallback(() => {
16
+ if (!reservation.expiresAt) return 0;
17
+ const expiresAtMs = new Date(reservation.expiresAt).getTime();
18
+ const nowMs = Date.now();
19
+ return Math.max(0, Math.floor((expiresAtMs - nowMs) / 1000));
20
+ }, [reservation.expiresAt]);
21
+
22
+ useEffect(() => {
23
+ setRemainingSeconds(calculateRemaining());
24
+
25
+ const interval = setInterval(() => {
26
+ const remaining = calculateRemaining();
27
+ setRemainingSeconds(remaining);
28
+
29
+ if (remaining <= 0) {
30
+ clearInterval(interval);
31
+ }
32
+ }, 1000);
33
+
34
+ return () => clearInterval(interval);
35
+ }, [calculateRemaining]);
36
+
37
+ if (!reservation.hasReservation) return null;
38
+
39
+ const minutes = Math.floor(remainingSeconds / 60);
40
+ const seconds = remainingSeconds % 60;
41
+ const isExpired = remainingSeconds <= 0;
42
+ const isUrgent = remainingSeconds > 0 && remainingSeconds < 120;
43
+
44
+ const displayMessage = reservation.countdownMessage
45
+ ? reservation.countdownMessage.replace(
46
+ '{time}',
47
+ `${minutes}:${seconds.toString().padStart(2, '0')}`
48
+ )
49
+ : null;
50
+
51
+ return (
52
+ <div
53
+ className={cn(
54
+ 'flex items-center gap-3 rounded-lg px-4 py-3 text-sm',
55
+ isExpired
56
+ ? 'bg-destructive/10 border-destructive/20 text-destructive border'
57
+ : isUrgent
58
+ ? 'border border-orange-200 bg-orange-50 text-orange-800 dark:border-orange-800 dark:bg-orange-950/30 dark:text-orange-300'
59
+ : 'bg-primary/5 border-primary/20 text-foreground border',
60
+ className
61
+ )}
62
+ >
63
+ <svg
64
+ className={cn(
65
+ 'h-5 w-5 flex-shrink-0',
66
+ isExpired
67
+ ? 'text-destructive'
68
+ : isUrgent
69
+ ? 'text-orange-600 dark:text-orange-400'
70
+ : 'text-primary'
71
+ )}
72
+ fill="none"
73
+ viewBox="0 0 24 24"
74
+ stroke="currentColor"
75
+ >
76
+ <path
77
+ strokeLinecap="round"
78
+ strokeLinejoin="round"
79
+ strokeWidth={2}
80
+ d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
81
+ />
82
+ </svg>
83
+
84
+ <div className="flex-1">
85
+ {isExpired ? (
86
+ <p className="font-medium">Reservation expired. Items may no longer be available.</p>
87
+ ) : displayMessage ? (
88
+ <p>{displayMessage}</p>
89
+ ) : (
90
+ <p>
91
+ {isUrgent ? 'Hurry! ' : ''}Items reserved for{' '}
92
+ <span className="font-semibold tabular-nums">
93
+ {minutes}:{seconds.toString().padStart(2, '0')}
94
+ </span>
95
+ </p>
96
+ )}
97
+ </div>
98
+ </div>
99
+ );
100
+ }