create-brainerce-store 1.19.0 → 1.20.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.
package/LICENSE ADDED
File without changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var require_package = __commonJS({
31
31
  "package.json"(exports2, module2) {
32
32
  module2.exports = {
33
33
  name: "create-brainerce-store",
34
- version: "1.19.0",
34
+ version: "1.20.0",
35
35
  description: "Scaffold a production-ready e-commerce storefront connected to Brainerce",
36
36
  bin: {
37
37
  "create-brainerce-store": "dist/index.js"
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "create-brainerce-store",
3
- "version": "1.19.0",
4
- "description": "Scaffold a production-ready e-commerce storefront connected to Brainerce",
5
- "bin": {
6
- "create-brainerce-store": "dist/index.js"
7
- },
8
- "files": [
9
- "dist",
10
- "templates",
11
- "messages"
12
- ],
13
- "scripts": {
14
- "build": "tsup src/index.ts --format cjs --dts --clean",
15
- "dev": "tsup src/index.ts --format cjs --dts --watch",
16
- "clean": "rimraf dist"
17
- },
18
- "dependencies": {
19
- "chalk": "^4.1.2",
20
- "commander": "^12.1.0",
21
- "ejs": "^3.1.10",
22
- "fs-extra": "^11.2.0",
23
- "ora": "^5.4.1",
24
- "prompts": "^2.4.2"
25
- },
26
- "devDependencies": {
27
- "@types/ejs": "^3.1.5",
28
- "@types/fs-extra": "^11.0.4",
29
- "@types/prompts": "^2.4.9",
30
- "tsup": "^8.0.0",
31
- "typescript": "^5.4.0"
32
- },
33
- "engines": {
34
- "node": ">=18"
35
- },
36
- "keywords": [
37
- "brainerce",
38
- "ecommerce",
39
- "storefront",
40
- "scaffold",
41
- "create",
42
- "nextjs"
43
- ],
44
- "license": "MIT"
45
- }
1
+ {
2
+ "name": "create-brainerce-store",
3
+ "version": "1.20.0",
4
+ "description": "Scaffold a production-ready e-commerce storefront connected to Brainerce",
5
+ "bin": {
6
+ "create-brainerce-store": "dist/index.js"
7
+ },
8
+ "files": [
9
+ "dist",
10
+ "templates",
11
+ "messages"
12
+ ],
13
+ "dependencies": {
14
+ "chalk": "^4.1.2",
15
+ "commander": "^12.1.0",
16
+ "ejs": "^3.1.10",
17
+ "fs-extra": "^11.2.0",
18
+ "ora": "^5.4.1",
19
+ "prompts": "^2.4.2"
20
+ },
21
+ "devDependencies": {
22
+ "@types/ejs": "^3.1.5",
23
+ "@types/fs-extra": "^11.0.4",
24
+ "@types/prompts": "^2.4.9",
25
+ "tsup": "^8.0.0",
26
+ "typescript": "^5.4.0"
27
+ },
28
+ "engines": {
29
+ "node": ">=18"
30
+ },
31
+ "keywords": [
32
+ "brainerce",
33
+ "ecommerce",
34
+ "storefront",
35
+ "scaffold",
36
+ "create",
37
+ "nextjs"
38
+ ],
39
+ "license": "MIT",
40
+ "scripts": {
41
+ "build": "tsup src/index.ts --format cjs --dts --clean",
42
+ "dev": "tsup src/index.ts --format cjs --dts --watch",
43
+ "clean": "rimraf dist"
44
+ }
45
+ }
@@ -1,254 +1,271 @@
1
- 'use client';
2
-
3
- import { Suspense, useEffect, useState } from 'react';
4
- import { useSearchParams } from 'next/navigation';
5
- import Link from 'next/link';
6
- import type { WaitForOrderResult, OrderDownloadLink } from 'brainerce';
7
- import { getClient } from '@/lib/brainerce';
8
- import { useCart } from '@/providers/store-provider';
9
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
10
- import { useTranslations } from '@/lib/translations';
11
-
12
- function OrderConfirmationContent() {
13
- const searchParams = useSearchParams();
14
- const checkoutId = searchParams.get('checkout_id');
15
-
16
- const { refreshCart } = useCart();
17
- const t = useTranslations('orderConfirmation');
18
- const tc = useTranslations('common');
19
- const [result, setResult] = useState<WaitForOrderResult | null>(null);
20
- const [loading, setLoading] = useState(true);
21
- const [error, setError] = useState<string | null>(null);
22
-
23
- useEffect(() => {
24
- if (!checkoutId) {
25
- setError(t('missingCheckoutInfo'));
26
- setLoading(false);
27
- return;
28
- }
29
-
30
- async function waitForOrder() {
31
- try {
32
- const client = getClient();
33
-
34
- // Clear cart state after successful payment
35
- client.handlePaymentSuccess(checkoutId!);
36
- await refreshCart();
37
-
38
- const orderResult = await client.waitForOrder(checkoutId!, {
39
- maxWaitMs: 30000,
40
- });
41
- setResult(orderResult);
42
- } catch (err) {
43
- const message = err instanceof Error ? err.message : 'Failed to confirm order';
44
- setError(message);
45
- } finally {
46
- setLoading(false);
47
- }
48
- }
49
-
50
- waitForOrder();
51
- }, [checkoutId, refreshCart]);
52
-
53
- if (loading) {
54
- return (
55
- <div className="flex min-h-[60vh] flex-col items-center justify-center">
56
- <LoadingSpinner size="lg" />
57
- <p className="text-muted-foreground mt-4">{t('confirming')}</p>
58
- <p className="text-muted-foreground mt-1 text-xs">{t('confirmingHint')}</p>
59
- </div>
60
- );
61
- }
62
-
63
- if (error) {
64
- return (
65
- <div className="mx-auto max-w-2xl px-4 py-16 text-center sm:px-6 lg:px-8">
66
- <svg
67
- className="text-destructive mx-auto mb-4 h-16 w-16"
68
- fill="none"
69
- viewBox="0 0 24 24"
70
- stroke="currentColor"
71
- >
72
- <path
73
- strokeLinecap="round"
74
- strokeLinejoin="round"
75
- strokeWidth={1.5}
76
- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.834-2.694-.834-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z"
77
- />
78
- </svg>
79
- <h1 className="text-foreground text-2xl font-bold">{t('errorTitle')}</h1>
80
- <p className="text-muted-foreground mt-2">{error}</p>
81
- <p className="text-muted-foreground mt-1 text-sm">{t('errorChargedHint')}</p>
82
- <Link
83
- href="/"
84
- className="bg-primary text-primary-foreground mt-6 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
85
- >
86
- {t('returnHome')}
87
- </Link>
88
- </div>
89
- );
90
- }
91
-
92
- // Order was created successfully
93
- if (result?.success) {
94
- const orderNumber = result.status.orderNumber;
95
-
96
- return (
97
- <div className="mx-auto max-w-2xl px-4 py-16 text-center sm:px-6 lg:px-8">
98
- <svg
99
- className="text-primary mx-auto mb-4 h-16 w-16"
100
- fill="none"
101
- viewBox="0 0 24 24"
102
- stroke="currentColor"
103
- >
104
- <path
105
- strokeLinecap="round"
106
- strokeLinejoin="round"
107
- strokeWidth={1.5}
108
- d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
109
- />
110
- </svg>
111
-
112
- <h1 className="text-foreground text-2xl font-bold">{t('thankYou')}</h1>
113
-
114
- {orderNumber && (
115
- <p className="text-foreground mt-3 text-lg">
116
- {t('orderNumber')} <span className="font-semibold">{orderNumber}</span>
117
- </p>
118
- )}
119
-
120
- <p className="text-muted-foreground mt-2">{t('confirmationEmail')}</p>
121
-
122
- {result.status.orderId && (
123
- <ConfirmationDownloads orderId={result.status.orderId} checkoutId={checkoutId!} />
124
- )}
125
-
126
- <div className="mt-8 flex flex-col items-center justify-center gap-3 sm:flex-row">
127
- <Link
128
- href="/products"
129
- className="bg-primary text-primary-foreground inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
130
- >
131
- {tc('continueShopping')}
132
- </Link>
133
-
134
- <Link
135
- href="/account"
136
- className="border-border text-foreground hover:bg-muted inline-flex items-center rounded border px-6 py-3 font-medium transition-colors"
137
- >
138
- {t('viewOrders')}
139
- </Link>
140
- </div>
141
- </div>
142
- );
143
- }
144
-
145
- // Order not yet confirmed (polling timed out) - still show success
146
- return (
147
- <div className="mx-auto max-w-2xl px-4 py-16 text-center sm:px-6 lg:px-8">
148
- <svg
149
- className="text-primary mx-auto mb-4 h-16 w-16"
150
- fill="none"
151
- viewBox="0 0 24 24"
152
- stroke="currentColor"
153
- >
154
- <path
155
- strokeLinecap="round"
156
- strokeLinejoin="round"
157
- strokeWidth={1.5}
158
- d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
159
- />
160
- </svg>
161
-
162
- <h1 className="text-foreground text-2xl font-bold">{t('paymentReceived')}</h1>
163
-
164
- <p className="text-muted-foreground mt-2">{t('orderProcessing')}</p>
165
-
166
- <div className="mt-8 flex flex-col items-center justify-center gap-3 sm:flex-row">
167
- <Link
168
- href="/products"
169
- className="bg-primary text-primary-foreground inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
170
- >
171
- {tc('continueShopping')}
172
- </Link>
173
-
174
- <Link
175
- href="/account"
176
- className="border-border text-foreground hover:bg-muted inline-flex items-center rounded border px-6 py-3 font-medium transition-colors"
177
- >
178
- {t('viewOrders')}
179
- </Link>
180
- </div>
181
- </div>
182
- );
183
- }
184
-
185
- function ConfirmationDownloads({ orderId, checkoutId }: { orderId: string; checkoutId: string }) {
186
- const t = useTranslations('orderConfirmation');
187
- const [downloads, setDownloads] = useState<OrderDownloadLink[] | null>(null);
188
-
189
- useEffect(() => {
190
- let cancelled = false;
191
- async function fetchDownloads() {
192
- const client = getClient();
193
- // Retry a few times the worker may still be writing downloadMeta
194
- for (let attempt = 0; attempt < 3; attempt++) {
195
- try {
196
- const links = await client.getOrderDownloads(orderId, { checkoutId });
197
- if (!cancelled && links.length > 0) {
198
- setDownloads(links);
199
- return;
200
- }
201
- } catch {
202
- // Not all orders have downloads
203
- }
204
- if (attempt < 2 && !cancelled) {
205
- await new Promise((r) => setTimeout(r, 1500));
206
- }
207
- }
208
- }
209
- fetchDownloads();
210
- return () => {
211
- cancelled = true;
212
- };
213
- }, [orderId, checkoutId]);
214
-
215
- if (!downloads || downloads.length === 0) return null;
216
-
217
- return (
218
- <div className="border-border bg-muted/30 mx-auto mt-8 max-w-md rounded-lg border p-6 text-start">
219
- <h3 className="text-foreground mb-3 text-sm font-semibold">{t('yourDownloads')}</h3>
220
- <div className="space-y-2">
221
- {downloads.map((link, idx) => (
222
- <div key={idx} className="flex items-center justify-between gap-3">
223
- <div className="min-w-0 flex-1">
224
- <p className="text-foreground truncate text-sm">{link.fileName}</p>
225
- <p className="text-muted-foreground truncate text-xs">{link.productName}</p>
226
- </div>
227
- <a
228
- href={link.downloadUrl}
229
- target="_blank"
230
- rel="noopener noreferrer"
231
- className="bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1.5 text-xs font-medium hover:opacity-90"
232
- >
233
- {t('download')}
234
- </a>
235
- </div>
236
- ))}
237
- </div>
238
- </div>
239
- );
240
- }
241
-
242
- export default function OrderConfirmationPage() {
243
- return (
244
- <Suspense
245
- fallback={
246
- <div className="flex min-h-[60vh] items-center justify-center">
247
- <LoadingSpinner size="lg" />
248
- </div>
249
- }
250
- >
251
- <OrderConfirmationContent />
252
- </Suspense>
253
- );
254
- }
1
+ 'use client';
2
+
3
+ import { Suspense, useEffect, useState } from 'react';
4
+ import { useSearchParams } from 'next/navigation';
5
+ import Link from 'next/link';
6
+ import type { WaitForOrderResult, OrderDownloadLink } from 'brainerce';
7
+ import { getClient } from '@/lib/brainerce';
8
+ import { useCart } from '@/providers/store-provider';
9
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
10
+ import { useTranslations } from '@/lib/translations';
11
+
12
+ function OrderConfirmationContent() {
13
+ const searchParams = useSearchParams();
14
+ const checkoutId = searchParams.get('checkout_id');
15
+
16
+ const { refreshCart } = useCart();
17
+ const t = useTranslations('orderConfirmation');
18
+ const tc = useTranslations('common');
19
+ const [result, setResult] = useState<WaitForOrderResult | null>(null);
20
+ const [loading, setLoading] = useState(true);
21
+ const [error, setError] = useState<string | null>(null);
22
+
23
+ useEffect(() => {
24
+ if (!checkoutId) {
25
+ setError(t('missingCheckoutInfo'));
26
+ setLoading(false);
27
+ return;
28
+ }
29
+
30
+ async function waitForOrder() {
31
+ try {
32
+ const client = getClient();
33
+
34
+ // Clear cart state after successful payment
35
+ client.handlePaymentSuccess(checkoutId!);
36
+ await refreshCart();
37
+
38
+ // For redirect-based payment providers (e.g. CardCom), the customer
39
+ // returns with provider params in the URL (lowprofilecode, etc.).
40
+ // Send these to the backend for server-side verification via the
41
+ // provider's API (e.g. GetLpResult) — never trust URL params alone.
42
+ const lowProfileCode =
43
+ searchParams.get('lowprofilecode') || searchParams.get('LowProfileCode');
44
+ if (lowProfileCode) {
45
+ try {
46
+ await client.confirmSdkPayment(checkoutId!, {
47
+ paymentIntentId: lowProfileCode,
48
+ });
49
+ } catch (err) {
50
+ console.warn('Redirect payment confirmation failed:', err);
51
+ // Don't block — webhook may still process the payment
52
+ }
53
+ }
54
+
55
+ const orderResult = await client.waitForOrder(checkoutId!, {
56
+ maxWaitMs: 30000,
57
+ });
58
+ setResult(orderResult);
59
+ } catch (err) {
60
+ const message = err instanceof Error ? err.message : 'Failed to confirm order';
61
+ setError(message);
62
+ } finally {
63
+ setLoading(false);
64
+ }
65
+ }
66
+
67
+ waitForOrder();
68
+ }, [checkoutId, refreshCart]);
69
+
70
+ if (loading) {
71
+ return (
72
+ <div className="flex min-h-[60vh] flex-col items-center justify-center">
73
+ <LoadingSpinner size="lg" />
74
+ <p className="text-muted-foreground mt-4">{t('confirming')}</p>
75
+ <p className="text-muted-foreground mt-1 text-xs">{t('confirmingHint')}</p>
76
+ </div>
77
+ );
78
+ }
79
+
80
+ if (error) {
81
+ return (
82
+ <div className="mx-auto max-w-2xl px-4 py-16 text-center sm:px-6 lg:px-8">
83
+ <svg
84
+ className="text-destructive mx-auto mb-4 h-16 w-16"
85
+ fill="none"
86
+ viewBox="0 0 24 24"
87
+ stroke="currentColor"
88
+ >
89
+ <path
90
+ strokeLinecap="round"
91
+ strokeLinejoin="round"
92
+ strokeWidth={1.5}
93
+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.834-2.694-.834-3.464 0L3.34 16.5c-.77.833.192 2.5 1.732 2.5z"
94
+ />
95
+ </svg>
96
+ <h1 className="text-foreground text-2xl font-bold">{t('errorTitle')}</h1>
97
+ <p className="text-muted-foreground mt-2">{error}</p>
98
+ <p className="text-muted-foreground mt-1 text-sm">{t('errorChargedHint')}</p>
99
+ <Link
100
+ href="/"
101
+ className="bg-primary text-primary-foreground mt-6 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
102
+ >
103
+ {t('returnHome')}
104
+ </Link>
105
+ </div>
106
+ );
107
+ }
108
+
109
+ // Order was created successfully
110
+ if (result?.success) {
111
+ const orderNumber = result.status.orderNumber;
112
+
113
+ return (
114
+ <div className="mx-auto max-w-2xl px-4 py-16 text-center sm:px-6 lg:px-8">
115
+ <svg
116
+ className="text-primary mx-auto mb-4 h-16 w-16"
117
+ fill="none"
118
+ viewBox="0 0 24 24"
119
+ stroke="currentColor"
120
+ >
121
+ <path
122
+ strokeLinecap="round"
123
+ strokeLinejoin="round"
124
+ strokeWidth={1.5}
125
+ d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
126
+ />
127
+ </svg>
128
+
129
+ <h1 className="text-foreground text-2xl font-bold">{t('thankYou')}</h1>
130
+
131
+ {orderNumber && (
132
+ <p className="text-foreground mt-3 text-lg">
133
+ {t('orderNumber')} <span className="font-semibold">{orderNumber}</span>
134
+ </p>
135
+ )}
136
+
137
+ <p className="text-muted-foreground mt-2">{t('confirmationEmail')}</p>
138
+
139
+ {result.status.orderId && (
140
+ <ConfirmationDownloads orderId={result.status.orderId} checkoutId={checkoutId!} />
141
+ )}
142
+
143
+ <div className="mt-8 flex flex-col items-center justify-center gap-3 sm:flex-row">
144
+ <Link
145
+ href="/products"
146
+ className="bg-primary text-primary-foreground inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
147
+ >
148
+ {tc('continueShopping')}
149
+ </Link>
150
+
151
+ <Link
152
+ href="/account"
153
+ className="border-border text-foreground hover:bg-muted inline-flex items-center rounded border px-6 py-3 font-medium transition-colors"
154
+ >
155
+ {t('viewOrders')}
156
+ </Link>
157
+ </div>
158
+ </div>
159
+ );
160
+ }
161
+
162
+ // Order not yet confirmed (polling timed out) - still show success
163
+ return (
164
+ <div className="mx-auto max-w-2xl px-4 py-16 text-center sm:px-6 lg:px-8">
165
+ <svg
166
+ className="text-primary mx-auto mb-4 h-16 w-16"
167
+ fill="none"
168
+ viewBox="0 0 24 24"
169
+ stroke="currentColor"
170
+ >
171
+ <path
172
+ strokeLinecap="round"
173
+ strokeLinejoin="round"
174
+ strokeWidth={1.5}
175
+ d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
176
+ />
177
+ </svg>
178
+
179
+ <h1 className="text-foreground text-2xl font-bold">{t('paymentReceived')}</h1>
180
+
181
+ <p className="text-muted-foreground mt-2">{t('orderProcessing')}</p>
182
+
183
+ <div className="mt-8 flex flex-col items-center justify-center gap-3 sm:flex-row">
184
+ <Link
185
+ href="/products"
186
+ className="bg-primary text-primary-foreground inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
187
+ >
188
+ {tc('continueShopping')}
189
+ </Link>
190
+
191
+ <Link
192
+ href="/account"
193
+ className="border-border text-foreground hover:bg-muted inline-flex items-center rounded border px-6 py-3 font-medium transition-colors"
194
+ >
195
+ {t('viewOrders')}
196
+ </Link>
197
+ </div>
198
+ </div>
199
+ );
200
+ }
201
+
202
+ function ConfirmationDownloads({ orderId, checkoutId }: { orderId: string; checkoutId: string }) {
203
+ const t = useTranslations('orderConfirmation');
204
+ const [downloads, setDownloads] = useState<OrderDownloadLink[] | null>(null);
205
+
206
+ useEffect(() => {
207
+ let cancelled = false;
208
+ async function fetchDownloads() {
209
+ const client = getClient();
210
+ // Retry a few times — the worker may still be writing downloadMeta
211
+ for (let attempt = 0; attempt < 3; attempt++) {
212
+ try {
213
+ const links = await client.getOrderDownloads(orderId, { checkoutId });
214
+ if (!cancelled && links.length > 0) {
215
+ setDownloads(links);
216
+ return;
217
+ }
218
+ } catch {
219
+ // Not all orders have downloads
220
+ }
221
+ if (attempt < 2 && !cancelled) {
222
+ await new Promise((r) => setTimeout(r, 1500));
223
+ }
224
+ }
225
+ }
226
+ fetchDownloads();
227
+ return () => {
228
+ cancelled = true;
229
+ };
230
+ }, [orderId, checkoutId]);
231
+
232
+ if (!downloads || downloads.length === 0) return null;
233
+
234
+ return (
235
+ <div className="border-border bg-muted/30 mx-auto mt-8 max-w-md rounded-lg border p-6 text-start">
236
+ <h3 className="text-foreground mb-3 text-sm font-semibold">{t('yourDownloads')}</h3>
237
+ <div className="space-y-2">
238
+ {downloads.map((link, idx) => (
239
+ <div key={idx} className="flex items-center justify-between gap-3">
240
+ <div className="min-w-0 flex-1">
241
+ <p className="text-foreground truncate text-sm">{link.fileName}</p>
242
+ <p className="text-muted-foreground truncate text-xs">{link.productName}</p>
243
+ </div>
244
+ <a
245
+ href={link.downloadUrl}
246
+ target="_blank"
247
+ rel="noopener noreferrer"
248
+ className="bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1.5 text-xs font-medium hover:opacity-90"
249
+ >
250
+ {t('download')}
251
+ </a>
252
+ </div>
253
+ ))}
254
+ </div>
255
+ </div>
256
+ );
257
+ }
258
+
259
+ export default function OrderConfirmationPage() {
260
+ return (
261
+ <Suspense
262
+ fallback={
263
+ <div className="flex min-h-[60vh] items-center justify-center">
264
+ <LoadingSpinner size="lg" />
265
+ </div>
266
+ }
267
+ >
268
+ <OrderConfirmationContent />
269
+ </Suspense>
270
+ );
271
+ }