@jarwizz/create-jarshop 0.1.2 → 0.1.3

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 (31) hide show
  1. package/README.md +2 -2
  2. package/dist/generator.js +4 -1
  3. package/dist/generator.js.map +1 -1
  4. package/dist/template/AGENTS.md +3 -3
  5. package/dist/template/CONTEXT.md +4 -0
  6. package/dist/template/README.md +5 -0
  7. package/dist/template/package.json +6 -1
  8. package/dist/template/pnpm-lock.yaml +2339 -79
  9. package/dist/template/pnpm-workspace.yaml +12 -1
  10. package/dist/template/src/plugins/jarshop-checkout/cod-payment.test.ts +44 -0
  11. package/dist/template/src/plugins/jarshop-checkout/cod-payment.ts +28 -0
  12. package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +37 -4
  13. package/dist/template/src/plugins/jarshop-checkout/index.ts +5 -1
  14. package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +80 -23
  15. package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +1 -1
  16. package/dist/template/src/seed.ts +41 -19
  17. package/dist/template/src/vendure-config.ts +5 -3
  18. package/dist/template/storefront/app/[locale]/checkout/confirmation/route.ts +21 -0
  19. package/dist/template/storefront/app/[locale]/checkout/success/page.tsx +6 -1
  20. package/dist/template/storefront/app/[locale]/page.tsx +2 -2
  21. package/dist/template/storefront/eslint.config.mjs +8 -1
  22. package/dist/template/storefront/lib/checkout.ts +14 -8
  23. package/dist/template/storefront/lib/commerce.ts +7 -3
  24. package/dist/template/storefront/lib/confirmation.ts +66 -18
  25. package/dist/template/storefront/package.json +7 -3
  26. package/dist/template/storefront/vitest.config.ts +8 -0
  27. package/dist/template/turbo.json +7 -0
  28. package/dist/template-manifest.json +1 -1
  29. package/package.json +1 -1
  30. package/dist/template/storefront/pnpm-lock.yaml +0 -4316
  31. 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 { CONFIRMATION_COOKIE_NAME } from "./confirmation-cookie";
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
- export async function getOrderConfirmation(
17
- locale: CommerceLocale,
18
- ): Promise<OrderConfirmationView | null> {
19
- const store = await cookies();
20
- const token = store.get(CONFIRMATION_COOKIE_NAME)?.value;
21
- if (!token) return null;
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
- const response = await fetch(endpoint, {
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: `query Confirmation($token: String!) { jarShopOrderConfirmation(token: $token) { orderId orderCode state totalWithTax currencyCode } }`,
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?: { jarShopOrderConfirmation: OrderConfirmationView | null };
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?.jarShopOrderConfirmation ?? null;
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
- "typecheck": "tsc --noEmit"
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.1.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",
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: "node",
6
+ include: ["lib/**/*.test.ts"],
7
+ },
8
+ });
@@ -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 },
@@ -1,3 +1,3 @@
1
1
  {
2
- "digest": "sha256:99fa08eb5086de015a4b769a9d5e1739a3c734f6451b9ba027ed054c15014e30"
2
+ "digest": "sha256:16e696efe1452c2aeac287d87541d38e5254828686eae16084e1562c0e5a6bd1"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jarwizz/create-jarshop",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "description": "Generate an independent JarShop Client Project.",
6
6
  "license": "MIT",