@jarwizz/create-jarshop 0.1.2 → 0.1.4
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/README.md +2 -2
- package/dist/generator.js +4 -1
- package/dist/generator.js.map +1 -1
- package/dist/template/AGENTS.md +3 -3
- package/dist/template/CONTEXT.md +4 -0
- package/dist/template/README.md +5 -0
- package/dist/template/package.json +6 -1
- package/dist/template/pnpm-lock.yaml +2339 -79
- package/dist/template/pnpm-workspace.yaml +12 -1
- package/dist/template/src/plugins/jarshop-checkout/cod-payment.test.ts +44 -0
- package/dist/template/src/plugins/jarshop-checkout/cod-payment.ts +28 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +50 -4
- package/dist/template/src/plugins/jarshop-checkout/index.ts +5 -1
- package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +95 -31
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +1 -1
- package/dist/template/src/seed.ts +41 -19
- package/dist/template/src/vendure-config.ts +5 -3
- package/dist/template/storefront/app/[locale]/checkout/confirmation/route.ts +21 -0
- package/dist/template/storefront/app/[locale]/checkout/success/page.tsx +6 -1
- package/dist/template/storefront/app/[locale]/page.tsx +2 -2
- package/dist/template/storefront/eslint.config.mjs +8 -1
- package/dist/template/storefront/lib/checkout.ts +14 -8
- package/dist/template/storefront/lib/commerce.ts +7 -3
- package/dist/template/storefront/lib/confirmation.ts +66 -18
- package/dist/template/storefront/package.json +7 -3
- package/dist/template/storefront/vitest.config.ts +8 -0
- package/dist/template/turbo.json +7 -0
- package/dist/template-manifest.json +1 -1
- package/package.json +1 -1
- package/dist/template/storefront/pnpm-lock.yaml +0 -4316
- package/dist/template/storefront/pnpm-workspace.yaml +0 -26
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import { cookies } from "next/headers";
|
|
4
4
|
|
|
5
5
|
import type { CommerceLocale } from "./commerce";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
confirmationCookieOptions,
|
|
8
|
+
CONFIRMATION_COOKIE_NAME,
|
|
9
|
+
} from "./confirmation-cookie";
|
|
7
10
|
|
|
8
11
|
export interface OrderConfirmationView {
|
|
9
12
|
orderId: string;
|
|
@@ -13,35 +16,80 @@ export interface OrderConfirmationView {
|
|
|
13
16
|
currencyCode: string;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
interface ConfirmationExchange {
|
|
20
|
+
credential: string;
|
|
21
|
+
confirmation: OrderConfirmationView;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function endpointFor(locale: CommerceLocale): string {
|
|
22
25
|
const endpoint = new URL(
|
|
23
26
|
process.env.JARSHOP_COMMERCE_ENDPOINT ?? "http://localhost:3000/shop-api",
|
|
24
27
|
);
|
|
25
28
|
endpoint.searchParams.set("languageCode", locale);
|
|
26
|
-
|
|
29
|
+
return endpoint.toString();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function commerceHeaders(cookie?: string): HeadersInit {
|
|
33
|
+
return {
|
|
34
|
+
"content-type": "application/json",
|
|
35
|
+
...(process.env.JARSHOP_CHANNEL_TOKEN
|
|
36
|
+
? { "vendure-token": process.env.JARSHOP_CHANNEL_TOKEN }
|
|
37
|
+
: {}),
|
|
38
|
+
...(cookie ? { cookie } : {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function exchangeOrderConfirmation(
|
|
43
|
+
locale: CommerceLocale,
|
|
44
|
+
token: string,
|
|
45
|
+
): Promise<OrderConfirmationView | null> {
|
|
46
|
+
const store = await cookies();
|
|
47
|
+
const response = await fetch(endpointFor(locale), {
|
|
27
48
|
method: "POST",
|
|
28
|
-
headers:
|
|
29
|
-
"content-type": "application/json",
|
|
30
|
-
...(process.env.JARSHOP_CHANNEL_TOKEN
|
|
31
|
-
? { "vendure-token": process.env.JARSHOP_CHANNEL_TOKEN }
|
|
32
|
-
: {}),
|
|
33
|
-
cookie: `${CONFIRMATION_COOKIE_NAME}=${token}`,
|
|
34
|
-
},
|
|
49
|
+
headers: commerceHeaders(),
|
|
35
50
|
body: JSON.stringify({
|
|
36
|
-
query: `
|
|
51
|
+
query: `mutation ExchangeConfirmation($token: String!) { exchangeJarShopOrderConfirmation(token: $token) { credential confirmation { orderId orderCode state totalWithTax currencyCode } } }`,
|
|
37
52
|
variables: { token },
|
|
38
53
|
}),
|
|
39
54
|
cache: "no-store",
|
|
40
55
|
});
|
|
41
56
|
if (!response.ok) return null;
|
|
42
57
|
const body = (await response.json()) as {
|
|
43
|
-
data?: {
|
|
58
|
+
data?: { exchangeJarShopOrderConfirmation: ConfirmationExchange | null };
|
|
59
|
+
errors?: Array<{ message: string }>;
|
|
60
|
+
};
|
|
61
|
+
const exchange = body.data?.exchangeJarShopOrderConfirmation;
|
|
62
|
+
if (!exchange) return null;
|
|
63
|
+
store.set(
|
|
64
|
+
CONFIRMATION_COOKIE_NAME,
|
|
65
|
+
exchange.credential,
|
|
66
|
+
confirmationCookieOptions,
|
|
67
|
+
);
|
|
68
|
+
return exchange.confirmation;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function getOrderConfirmation(
|
|
72
|
+
locale: CommerceLocale,
|
|
73
|
+
orderCode: string,
|
|
74
|
+
): Promise<OrderConfirmationView | null> {
|
|
75
|
+
const store = await cookies();
|
|
76
|
+
const credential = store.get(CONFIRMATION_COOKIE_NAME)?.value;
|
|
77
|
+
if (!credential) return null;
|
|
78
|
+
const response = await fetch(endpointFor(locale), {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: commerceHeaders(
|
|
81
|
+
`${CONFIRMATION_COOKIE_NAME}=${encodeURIComponent(credential)}`,
|
|
82
|
+
),
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
query: `query ProtectedConfirmation($orderCode: String!) { jarShopProtectedOrderConfirmation(orderCode: $orderCode) { orderId orderCode state totalWithTax currencyCode } }`,
|
|
85
|
+
variables: { orderCode },
|
|
86
|
+
}),
|
|
87
|
+
cache: "no-store",
|
|
88
|
+
});
|
|
89
|
+
if (!response.ok) return null;
|
|
90
|
+
const body = (await response.json()) as {
|
|
91
|
+
data?: { jarShopProtectedOrderConfirmation: OrderConfirmationView | null };
|
|
44
92
|
errors?: Array<{ message: string }>;
|
|
45
93
|
};
|
|
46
|
-
return body.data?.
|
|
94
|
+
return body.data?.jarShopProtectedOrderConfirmation ?? null;
|
|
47
95
|
}
|
|
@@ -6,16 +6,20 @@
|
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.18.0 <25"
|
|
8
8
|
},
|
|
9
|
-
"packageManager": "pnpm@11.18.0",
|
|
10
9
|
"scripts": {
|
|
11
10
|
"dev": "next dev",
|
|
12
11
|
"build": "next build",
|
|
12
|
+
"build:storefront": "next build",
|
|
13
13
|
"start": "next start",
|
|
14
14
|
"lint": "eslint .",
|
|
15
|
-
"
|
|
15
|
+
"lint:storefront": "eslint .",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"typecheck:storefront": "tsc --noEmit",
|
|
18
|
+
"test": "vitest run --config vitest.config.ts",
|
|
19
|
+
"test:storefront": "vitest run --config vitest.config.ts"
|
|
16
20
|
},
|
|
17
21
|
"dependencies": {
|
|
18
|
-
"@jarwizz/commerce-sdk": "0.
|
|
22
|
+
"@jarwizz/commerce-sdk": "0.3.0",
|
|
19
23
|
"@swc/helpers": "0.5.15",
|
|
20
24
|
"@valkey/valkey-glide": "2.5.1",
|
|
21
25
|
"next": "16.2.12",
|
package/dist/template/turbo.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://turbo.build/schema.json",
|
|
3
3
|
"tasks": {
|
|
4
|
+
"build:vendure": { "outputs": ["dist/**"] },
|
|
5
|
+
"build:storefront": {
|
|
6
|
+
"outputs": [".next/**", "!.next/cache/**"]
|
|
7
|
+
},
|
|
8
|
+
"lint:storefront": {},
|
|
9
|
+
"typecheck:storefront": {},
|
|
10
|
+
"test:storefront": {},
|
|
4
11
|
"dev:server": { "cache": false, "persistent": true },
|
|
5
12
|
"dev:worker": { "cache": false, "persistent": true },
|
|
6
13
|
"dev:dashboard": { "cache": false, "persistent": true },
|