@jarwizz/create-jarshop 0.1.8 → 0.3.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/README.md +15 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/generator.d.ts +11 -1
- package/dist/generator.js +45 -11
- package/dist/generator.js.map +1 -1
- package/dist/presets.d.ts +26 -0
- package/dist/presets.js +94 -0
- package/dist/presets.js.map +1 -0
- package/dist/template/CONTEXT.md +4 -2
- package/dist/template/README.md +255 -3
- package/dist/template/env.example.template +19 -0
- package/dist/template/gitignore.template +1 -0
- package/dist/template/jarshop.config.ts +31 -0
- package/dist/template/package.json +5 -0
- package/dist/template/pnpm-lock.yaml +3291 -1809
- package/dist/template/pnpm-workspace.yaml +6 -1
- package/dist/template/src/client/features.ts +41 -0
- package/dist/template/src/client/invoicing.ts +29 -0
- package/dist/template/src/dev-storefront-environment.test.ts +45 -0
- package/dist/template/src/dev-storefront-environment.ts +32 -0
- package/dist/template/src/dev-storefront.ts +3 -12
- package/dist/template/src/environment.d.ts +8 -0
- package/dist/template/src/invoice-email-recover.ts +59 -0
- package/dist/template/src/jarshop-config-loader.ts +118 -0
- package/dist/template/src/jarshop-config.test.ts +335 -0
- package/dist/template/src/jarshop-config.ts +439 -0
- package/dist/template/src/jarshop-features.test.ts +222 -0
- package/dist/template/src/jarshop-features.ts +112 -0
- package/dist/template/src/operation-codes.ts +34 -0
- package/dist/template/src/packeta-config.test.ts +95 -0
- package/dist/template/src/packeta-countries.test.ts +161 -0
- package/dist/template/src/packeta-countries.ts +120 -0
- package/dist/template/src/packeta-validation.test.ts +35 -0
- package/dist/template/src/packeta-validation.ts +52 -0
- package/dist/template/src/payment-return-url.test.ts +57 -0
- package/dist/template/src/payment-return-url.ts +34 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation-view.test.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +51 -0
- package/dist/template/src/plugins/jarshop-checkout/dashboard/index.tsx +1 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-delivery.plugin.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-events.ts +35 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-lifecycle.ts +235 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-worker.test.ts +426 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email.test.ts +107 -0
- package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +161 -57
- package/dist/template/src/plugins/jarshop-checkout/market-channels.test.ts +58 -0
- package/dist/template/src/plugins/jarshop-checkout/market-channels.ts +87 -0
- package/dist/template/src/plugins/jarshop-checkout/operation-code-check.ts +36 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.entity.ts +1 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +94 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery.entity.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-outbox.ts +83 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-worker.ts +136 -1
- package/dist/template/src/plugins/jarshop-checkout/shipping-tax.test.ts +109 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.test.ts +156 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.ts +75 -11
- package/dist/template/src/seed.ts +427 -184
- package/dist/template/src/vendure-config.ts +258 -113
- package/dist/template/storefront/README.md +7 -0
- package/dist/template/storefront/app/[locale]/[slug]/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/login/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/page.tsx +10 -4
- package/dist/template/storefront/app/[locale]/account/password-reset/callback/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/complete/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/register/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/verify/complete/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/verify/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/cart/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/checkout/actions.ts +43 -0
- package/dist/template/storefront/app/[locale]/checkout/checkout-form.tsx +188 -36
- package/dist/template/storefront/app/[locale]/checkout/confirmation/route.ts +2 -2
- package/dist/template/storefront/app/[locale]/checkout/packeta-chooser.tsx +96 -0
- package/dist/template/storefront/app/[locale]/checkout/page.tsx +60 -2
- package/dist/template/storefront/app/[locale]/checkout/payment-return/actions.ts +55 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/page.tsx +32 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/payment-return.tsx +84 -0
- package/dist/template/storefront/app/[locale]/checkout/success/page.tsx +32 -2
- package/dist/template/storefront/app/[locale]/layout.tsx +3 -2
- package/dist/template/storefront/app/[locale]/page.tsx +3 -2
- package/dist/template/storefront/app/globals.css +16 -0
- package/dist/template/storefront/app/layout.tsx +6 -2
- package/dist/template/storefront/lib/cart.ts +2 -4
- package/dist/template/storefront/lib/checkout-contract.test.ts +18 -1
- package/dist/template/storefront/lib/checkout-contract.ts +8 -0
- package/dist/template/storefront/lib/checkout-countries.test.ts +61 -0
- package/dist/template/storefront/lib/checkout-countries.ts +67 -0
- package/dist/template/storefront/lib/checkout.ts +22 -11
- package/dist/template/storefront/lib/commerce.ts +262 -2
- package/dist/template/storefront/lib/confirmation.test.ts +116 -0
- package/dist/template/storefront/lib/confirmation.ts +13 -7
- package/dist/template/storefront/lib/i18n.test.ts +32 -12
- package/dist/template/storefront/lib/i18n.ts +29 -8
- package/dist/template/storefront/lib/market-config.ts +40 -0
- package/dist/template/storefront/lib/market-routing.test.ts +107 -0
- package/dist/template/storefront/lib/market-routing.ts +57 -0
- package/dist/template/storefront/lib/market.ts +51 -0
- package/dist/template/storefront/lib/packeta-selection.test.ts +141 -0
- package/dist/template/storefront/lib/packeta-selection.ts +98 -0
- package/dist/template/storefront/lib/payment-return-actions.test.ts +61 -0
- package/dist/template/storefront/lib/payment-return-page.test.ts +30 -0
- package/dist/template/storefront/lib/payment-return-polling.test.ts +37 -0
- package/dist/template/storefront/lib/payment-return-polling.ts +58 -0
- package/dist/template/storefront/messages/en.json +13 -1
- package/dist/template/storefront/messages/sk.json +13 -1
- package/dist/template/storefront/package.json +2 -1
- package/dist/template/storefront/proxy.ts +35 -0
- package/dist/template/turbo.json +5 -1
- package/dist/template/vite.config.mts +13 -2
- package/dist/template-manifest.json +1 -1
- package/dist/template.js +1 -0
- package/dist/template.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,9 +2,165 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
compareCheckoutSnapshot,
|
|
5
|
+
mapPaymentTransitionFailure,
|
|
5
6
|
resolveLocalizedShippingMethodName,
|
|
7
|
+
shouldUnsetShippingAddress,
|
|
8
|
+
validateCheckoutMarket,
|
|
9
|
+
validateShippingSelection,
|
|
6
10
|
} from "./shipping.js";
|
|
7
11
|
|
|
12
|
+
describe("validateCheckoutMarket", () => {
|
|
13
|
+
const czechia = { code: "cz", currency: "CZK" };
|
|
14
|
+
|
|
15
|
+
it("accepts the market and currency of the request Channel", () => {
|
|
16
|
+
expect(
|
|
17
|
+
validateCheckoutMarket(
|
|
18
|
+
{ marketCode: "cz", currencyCode: "CZK" },
|
|
19
|
+
czechia,
|
|
20
|
+
),
|
|
21
|
+
).toEqual({ ok: true });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("refuses another market or currency with a stable error code", () => {
|
|
25
|
+
for (const input of [
|
|
26
|
+
{ marketCode: "sk", currencyCode: "CZK" },
|
|
27
|
+
{ marketCode: "cz", currencyCode: "EUR" },
|
|
28
|
+
]) {
|
|
29
|
+
expect(validateCheckoutMarket(input, czechia)).toEqual({
|
|
30
|
+
ok: false,
|
|
31
|
+
errorCode: "VALIDATION_ERROR",
|
|
32
|
+
message: `Checkout market ${input.marketCode}/${input.currencyCode} does not match this Channel's market cz/CZK`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("mapPaymentTransitionFailure", () => {
|
|
39
|
+
it("maps the kit's shipping selection refusal to the shipping vocabulary", () => {
|
|
40
|
+
expect(
|
|
41
|
+
mapPaymentTransitionFailure("Shipping selection required before payment"),
|
|
42
|
+
).toEqual({
|
|
43
|
+
errorCode: "SHIPPING_METHOD_INELIGIBLE",
|
|
44
|
+
message: "Choose a pickup point for the selected shipping method first",
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("keeps every other transition failure as a generic order state error", () => {
|
|
49
|
+
expect(
|
|
50
|
+
mapPaymentTransitionFailure(
|
|
51
|
+
'Cannot transition Order from "AddingItems" to "ArrangingPayment"',
|
|
52
|
+
),
|
|
53
|
+
).toEqual({
|
|
54
|
+
errorCode: "ORDER_STATE_INVALID",
|
|
55
|
+
message: "Order is not ready for payment",
|
|
56
|
+
});
|
|
57
|
+
expect(mapPaymentTransitionFailure(undefined)).toEqual({
|
|
58
|
+
errorCode: "ORDER_STATE_INVALID",
|
|
59
|
+
message: "Order is not ready for payment",
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("validateShippingSelection", () => {
|
|
65
|
+
it("clears a provider-derived address only when returning to native pickup", () => {
|
|
66
|
+
expect(shouldUnsetShippingAddress({ shippingMethodCode: "pickup" })).toBe(
|
|
67
|
+
true,
|
|
68
|
+
);
|
|
69
|
+
expect(
|
|
70
|
+
shouldUnsetShippingAddress({
|
|
71
|
+
shippingMethodCode: "packeta-pickup-point",
|
|
72
|
+
}),
|
|
73
|
+
).toBe(false);
|
|
74
|
+
expect(
|
|
75
|
+
shouldUnsetShippingAddress({
|
|
76
|
+
shippingMethodCode: "courier",
|
|
77
|
+
shippingAddress: {
|
|
78
|
+
streetLine1: "Hlavná 1",
|
|
79
|
+
city: "Bratislava",
|
|
80
|
+
postalCode: "811 01",
|
|
81
|
+
countryCode: "SK",
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("accepts a method code it does not know, leaving eligibility to Vendure", () => {
|
|
88
|
+
expect(
|
|
89
|
+
validateShippingSelection(
|
|
90
|
+
{ shippingMethodCode: "packeta-pickup-point" },
|
|
91
|
+
["SK"],
|
|
92
|
+
),
|
|
93
|
+
).toEqual({ ok: true });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("keeps accepting pickup without an address", () => {
|
|
97
|
+
expect(
|
|
98
|
+
validateShippingSelection({ shippingMethodCode: "pickup" }, ["SK"]),
|
|
99
|
+
).toEqual({ ok: true });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("keeps requiring an address for courier", () => {
|
|
103
|
+
expect(
|
|
104
|
+
validateShippingSelection({ shippingMethodCode: "courier" }, ["SK"]),
|
|
105
|
+
).toEqual({
|
|
106
|
+
ok: false,
|
|
107
|
+
errorCode: "VALIDATION_ERROR",
|
|
108
|
+
message: "A shipping address is required for courier delivery",
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("keeps requiring an address in a country the market serves", () => {
|
|
113
|
+
expect(
|
|
114
|
+
validateShippingSelection(
|
|
115
|
+
{
|
|
116
|
+
shippingMethodCode: "courier",
|
|
117
|
+
shippingAddress: {
|
|
118
|
+
streetLine1: "Kaerntner Strasse 1",
|
|
119
|
+
city: "Vienna",
|
|
120
|
+
postalCode: "1010",
|
|
121
|
+
countryCode: "AT",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
["SK"],
|
|
125
|
+
),
|
|
126
|
+
).toEqual({
|
|
127
|
+
ok: false,
|
|
128
|
+
errorCode: "VALIDATION_ERROR",
|
|
129
|
+
message: "Courier delivery requires a valid shipping address in SK",
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("reads courier countries from the market instead of assuming Slovakia", () => {
|
|
134
|
+
const czechAddress = {
|
|
135
|
+
streetLine1: "Vaclavske namesti 1",
|
|
136
|
+
city: "Praha",
|
|
137
|
+
postalCode: "110 00",
|
|
138
|
+
countryCode: "CZ",
|
|
139
|
+
};
|
|
140
|
+
expect(
|
|
141
|
+
validateShippingSelection(
|
|
142
|
+
{ shippingMethodCode: "courier", shippingAddress: czechAddress },
|
|
143
|
+
["CZ"],
|
|
144
|
+
),
|
|
145
|
+
).toEqual({ ok: true });
|
|
146
|
+
expect(
|
|
147
|
+
validateShippingSelection(
|
|
148
|
+
{ shippingMethodCode: "courier", shippingAddress: czechAddress },
|
|
149
|
+
["SK"],
|
|
150
|
+
),
|
|
151
|
+
).toMatchObject({ ok: false, errorCode: "VALIDATION_ERROR" });
|
|
152
|
+
expect(
|
|
153
|
+
validateShippingSelection(
|
|
154
|
+
{
|
|
155
|
+
shippingMethodCode: "courier",
|
|
156
|
+
shippingAddress: { ...czechAddress, countryCode: "SK" },
|
|
157
|
+
},
|
|
158
|
+
["CZ"],
|
|
159
|
+
),
|
|
160
|
+
).toMatchObject({ ok: false, errorCode: "VALIDATION_ERROR" });
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
8
164
|
describe("compareCheckoutSnapshot", () => {
|
|
9
165
|
it("accepts equivalent GraphQL ID string and number representations", () => {
|
|
10
166
|
expect(
|
|
@@ -119,22 +119,55 @@ export type ShippingValidationResult =
|
|
|
119
119
|
readonly message: string;
|
|
120
120
|
};
|
|
121
121
|
|
|
122
|
-
export
|
|
122
|
+
export interface PaymentTransitionFailure {
|
|
123
|
+
readonly errorCode: "SHIPPING_METHOD_INELIGIBLE" | "ORDER_STATE_INVALID";
|
|
124
|
+
readonly message: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function shouldUnsetShippingAddress(input: {
|
|
123
128
|
shippingMethodCode: string;
|
|
124
129
|
shippingAddress?: ShippingAddressInput;
|
|
125
|
-
}):
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
}): boolean {
|
|
131
|
+
return input.shippingMethodCode === "pickup" && !input.shippingAddress;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The kit refuses ArrangingPayment with this exact text when a pickup point method has
|
|
136
|
+
* no current selection. Matched literally: the starter imports nothing from the kit,
|
|
137
|
+
* and the text carries no colon or braces so Vendure's translation leaves it intact.
|
|
138
|
+
*/
|
|
139
|
+
const SHIPPING_SELECTION_REQUIRED =
|
|
140
|
+
"Shipping selection required before payment";
|
|
141
|
+
|
|
142
|
+
export function mapPaymentTransitionFailure(
|
|
143
|
+
transitionError: string | undefined,
|
|
144
|
+
): PaymentTransitionFailure {
|
|
145
|
+
if (transitionError === SHIPPING_SELECTION_REQUIRED) {
|
|
130
146
|
return {
|
|
131
|
-
ok: false,
|
|
132
147
|
errorCode: "SHIPPING_METHOD_INELIGIBLE",
|
|
133
|
-
message: "
|
|
148
|
+
message: "Choose a pickup point for the selected shipping method first",
|
|
134
149
|
};
|
|
135
150
|
}
|
|
151
|
+
return {
|
|
152
|
+
errorCode: "ORDER_STATE_INVALID",
|
|
153
|
+
message: "Order is not ready for payment",
|
|
154
|
+
};
|
|
155
|
+
}
|
|
136
156
|
|
|
137
|
-
|
|
157
|
+
/**
|
|
158
|
+
* `servedCountries` are the courier destinations of the order's market, read
|
|
159
|
+
* from `jarshop.config.ts`; the starter never assumes a country of its own.
|
|
160
|
+
*/
|
|
161
|
+
export function validateShippingSelection(
|
|
162
|
+
input: {
|
|
163
|
+
shippingMethodCode: string;
|
|
164
|
+
shippingAddress?: ShippingAddressInput;
|
|
165
|
+
},
|
|
166
|
+
servedCountries: readonly string[],
|
|
167
|
+
): ShippingValidationResult {
|
|
168
|
+
// Only courier has address rules of its own; any other code, including one a
|
|
169
|
+
// Feature contributed, is left to Vendure's eligibility check.
|
|
170
|
+
if (input.shippingMethodCode !== "courier") return { ok: true };
|
|
138
171
|
|
|
139
172
|
const address = input.shippingAddress;
|
|
140
173
|
if (!address) {
|
|
@@ -149,14 +182,45 @@ export function validateShippingSelection(input: {
|
|
|
149
182
|
!address.streetLine1.trim() ||
|
|
150
183
|
!address.city.trim() ||
|
|
151
184
|
!address.postalCode.trim() ||
|
|
152
|
-
address.countryCode
|
|
185
|
+
!servedCountries.includes(address.countryCode)
|
|
153
186
|
) {
|
|
154
187
|
return {
|
|
155
188
|
ok: false,
|
|
156
189
|
errorCode: "VALIDATION_ERROR",
|
|
157
|
-
message:
|
|
190
|
+
message: `Courier delivery requires a valid shipping address in ${servedCountries.join(", ")}`,
|
|
158
191
|
};
|
|
159
192
|
}
|
|
160
193
|
|
|
161
194
|
return { ok: true };
|
|
162
195
|
}
|
|
196
|
+
|
|
197
|
+
export type CheckoutMarketValidationResult =
|
|
198
|
+
| { readonly ok: true }
|
|
199
|
+
| {
|
|
200
|
+
readonly ok: false;
|
|
201
|
+
readonly errorCode: "VALIDATION_ERROR";
|
|
202
|
+
readonly message: string;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The Channel of the request decides the market; the storefront's
|
|
207
|
+
* `marketCode` and `currencyCode` only restate it. A mismatch means the client
|
|
208
|
+
* addressed one market's Channel while believing it was in another, so the
|
|
209
|
+
* order is refused before any customer, address or payment state changes.
|
|
210
|
+
*/
|
|
211
|
+
export function validateCheckoutMarket(
|
|
212
|
+
input: { readonly marketCode: string; readonly currencyCode: string },
|
|
213
|
+
market: { readonly code: string; readonly currency: string },
|
|
214
|
+
): CheckoutMarketValidationResult {
|
|
215
|
+
if (
|
|
216
|
+
input.marketCode === market.code &&
|
|
217
|
+
input.currencyCode === market.currency
|
|
218
|
+
) {
|
|
219
|
+
return { ok: true };
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
ok: false,
|
|
223
|
+
errorCode: "VALIDATION_ERROR",
|
|
224
|
+
message: `Checkout market ${input.marketCode}/${input.currencyCode} does not match this Channel's market ${market.code}/${market.currency}`,
|
|
225
|
+
};
|
|
226
|
+
}
|