@jarwizz/create-jarshop 0.1.6 → 0.1.8
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 +6 -1
- package/dist/cli.d.ts +14 -0
- package/dist/cli.js +27 -3
- package/dist/cli.js.map +1 -1
- package/dist/template/README.md +1 -1
- package/dist/template/i18n/dashboard/sk.po +6018 -0
- package/dist/template/package.json +6 -2
- package/dist/template/patches/@vendure__dashboard@3.7.1.patch +6535 -0
- package/dist/template/pnpm-lock.yaml +388 -2
- package/dist/template/pnpm-workspace.yaml +2 -0
- package/dist/template/src/plugins/jarshop-checkout/cod-payment-core.ts +102 -0
- package/dist/template/src/plugins/jarshop-checkout/cod-payment.test.ts +71 -1
- package/dist/template/src/plugins/jarshop-checkout/cod-payment.ts +13 -8
- package/dist/template/src/plugins/jarshop-checkout/dashboard/index.tsx +4 -0
- package/dist/template/src/plugins/jarshop-checkout/dashboard/login-branding.tsx +49 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping-rates.ts +13 -0
- package/dist/template/src/seed.ts +34 -3
- package/dist/template/src/vendure-config.ts +9 -1
- package/dist/template/static/email/templates/partials/footer.hbs +1 -1
- package/dist/template/static/email/templates/partials/header.hbs +3 -1
- package/dist/template/turbo.json +1 -0
- package/dist/template/vite.config.mts +28 -1
- package/dist/template/vitest.config.ts +11 -0
- package/dist/template-manifest.json +1 -1
- package/package.json +1 -1
|
@@ -34,11 +34,81 @@ describe("jarShopCodPaymentHandler", () => {
|
|
|
34
34
|
const result = await jarShopCodPaymentHandler.settlePayment(
|
|
35
35
|
context,
|
|
36
36
|
order,
|
|
37
|
-
{} as Payment,
|
|
37
|
+
{ transactionId: "cod:ORDER-123" } as Payment,
|
|
38
38
|
[],
|
|
39
39
|
method,
|
|
40
40
|
);
|
|
41
41
|
|
|
42
42
|
expect(result).toEqual({ success: true });
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
it("refuses to authorize collection a second time once the cash arrived", async () => {
|
|
46
|
+
const collected = { code: "ORDER-456" } as Order;
|
|
47
|
+
|
|
48
|
+
await jarShopCodPaymentHandler.createPayment(
|
|
49
|
+
context,
|
|
50
|
+
collected,
|
|
51
|
+
500,
|
|
52
|
+
[],
|
|
53
|
+
{},
|
|
54
|
+
method,
|
|
55
|
+
);
|
|
56
|
+
await jarShopCodPaymentHandler.settlePayment(
|
|
57
|
+
context,
|
|
58
|
+
collected,
|
|
59
|
+
{ transactionId: "cod:ORDER-456" } as Payment,
|
|
60
|
+
[],
|
|
61
|
+
method,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const again = await jarShopCodPaymentHandler.createPayment(
|
|
65
|
+
context,
|
|
66
|
+
collected,
|
|
67
|
+
500,
|
|
68
|
+
[],
|
|
69
|
+
{},
|
|
70
|
+
method,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(again).toMatchObject({ state: "Declined" });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("lets the shop start again once a collection is cancelled", async () => {
|
|
77
|
+
const mistaken = { code: "ORDER-789" } as Order;
|
|
78
|
+
const payment = { transactionId: "cod:ORDER-789" } as Payment;
|
|
79
|
+
|
|
80
|
+
await jarShopCodPaymentHandler.createPayment(
|
|
81
|
+
context,
|
|
82
|
+
mistaken,
|
|
83
|
+
500,
|
|
84
|
+
[],
|
|
85
|
+
{},
|
|
86
|
+
method,
|
|
87
|
+
);
|
|
88
|
+
await jarShopCodPaymentHandler.settlePayment(
|
|
89
|
+
context,
|
|
90
|
+
mistaken,
|
|
91
|
+
payment,
|
|
92
|
+
[],
|
|
93
|
+
method,
|
|
94
|
+
);
|
|
95
|
+
await jarShopCodPaymentHandler.cancelPayment!(
|
|
96
|
+
context,
|
|
97
|
+
mistaken,
|
|
98
|
+
payment,
|
|
99
|
+
[],
|
|
100
|
+
method,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const again = await jarShopCodPaymentHandler.createPayment(
|
|
104
|
+
context,
|
|
105
|
+
mistaken,
|
|
106
|
+
500,
|
|
107
|
+
[],
|
|
108
|
+
{},
|
|
109
|
+
method,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(again).toMatchObject({ state: "Authorized" });
|
|
113
|
+
});
|
|
44
114
|
});
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { LanguageCode, PaymentMethodHandler } from "@vendure/core";
|
|
2
|
+
import { createCashOnDeliveryLedger } from "./cod-payment-core.js";
|
|
3
|
+
|
|
4
|
+
/** One ledger for the shop, so what it has already collected stays remembered. */
|
|
5
|
+
const ledger = createCashOnDeliveryLedger();
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* Cash on delivery is a two-step payment: checkout authorizes collection, and
|
|
5
9
|
* an authenticated operator settles it only after money is actually received.
|
|
10
|
+
*
|
|
11
|
+
* The decisions are made in `cod-payment-core.ts`; this handler is the Vendure
|
|
12
|
+
* face of them and adds nothing of its own.
|
|
6
13
|
*/
|
|
7
14
|
export const jarShopCodPaymentHandler = new PaymentMethodHandler({
|
|
8
15
|
code: "jarshop-cod-handler",
|
|
@@ -17,12 +24,10 @@ export const jarShopCodPaymentHandler = new PaymentMethodHandler({
|
|
|
17
24
|
},
|
|
18
25
|
],
|
|
19
26
|
args: {},
|
|
20
|
-
createPayment: async (_ctx, order, amount, _args, metadata) =>
|
|
21
|
-
amount,
|
|
22
|
-
|
|
23
|
-
transactionId
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
settlePayment: async () => ({ success: true }),
|
|
27
|
-
cancelPayment: async () => ({ success: true }),
|
|
27
|
+
createPayment: async (_ctx, order, amount, _args, metadata) =>
|
|
28
|
+
ledger.authorize({ orderCode: order.code, amount, metadata }),
|
|
29
|
+
settlePayment: async (_ctx, _order, payment) =>
|
|
30
|
+
ledger.settle(payment.transactionId),
|
|
31
|
+
cancelPayment: async (_ctx, _order, payment) =>
|
|
32
|
+
ledger.cancel(payment.transactionId),
|
|
28
33
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { api, defineDashboardExtension, useQuery } from "@vendure/dashboard";
|
|
2
|
+
import { JarShopLoginLogo } from "./login-branding.js";
|
|
2
3
|
import { graphql } from "@/gql";
|
|
3
4
|
import { useState, type FormEvent } from "react";
|
|
4
5
|
import {
|
|
@@ -261,6 +262,9 @@ function EmailBrandConfigurationBlock() {
|
|
|
261
262
|
}
|
|
262
263
|
|
|
263
264
|
defineDashboardExtension({
|
|
265
|
+
login: {
|
|
266
|
+
logo: { component: JarShopLoginLogo },
|
|
267
|
+
},
|
|
264
268
|
pageBlocks: [
|
|
265
269
|
{
|
|
266
270
|
id: "jarshop-order-email-delivery-status",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Replaces the default Vendure wordmark on the Dashboard login page via the
|
|
2
|
+
// login.logo extension point (see defineDashboardExtension in ./index.tsx).
|
|
3
|
+
//
|
|
4
|
+
// The brand ships two tile variants that differ only in their three fill
|
|
5
|
+
// colours: a blue tile for light surfaces and a light tile for the dark
|
|
6
|
+
// Dashboard. Rather than render both and hide one, the single mark below swaps
|
|
7
|
+
// those fills on the `dark` class that the Dashboard's theme provider puts on
|
|
8
|
+
// the root element, so the login logo stays legible in light, dark and system
|
|
9
|
+
// themes without any script. The favicon is the blue tile in every theme,
|
|
10
|
+
// because a browser tab has no way to ask the page which theme is active.
|
|
11
|
+
export function JarShopLoginLogo() {
|
|
12
|
+
return (
|
|
13
|
+
<svg
|
|
14
|
+
viewBox="0 0 1200 1200"
|
|
15
|
+
className="h-16 w-auto"
|
|
16
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
17
|
+
role="img"
|
|
18
|
+
aria-label="JarShop"
|
|
19
|
+
>
|
|
20
|
+
<title>JarShop</title>
|
|
21
|
+
<rect
|
|
22
|
+
x="440"
|
|
23
|
+
y="60"
|
|
24
|
+
width="320"
|
|
25
|
+
height="84"
|
|
26
|
+
rx="42"
|
|
27
|
+
className="fill-[#243A52] dark:fill-[#E9F0F7]"
|
|
28
|
+
/>
|
|
29
|
+
<rect
|
|
30
|
+
x="100"
|
|
31
|
+
y="200"
|
|
32
|
+
width="1000"
|
|
33
|
+
height="900"
|
|
34
|
+
rx="220"
|
|
35
|
+
className="fill-[#243A52] dark:fill-[#E9F0F7]"
|
|
36
|
+
/>
|
|
37
|
+
<g transform="translate(225,368) scale(0.5)">
|
|
38
|
+
<path
|
|
39
|
+
className="fill-[#A8C0DA] dark:fill-[#4C6C91]"
|
|
40
|
+
d="M 431.1 225.3 L 431.1 259.6 590.5 419 L 750 578.4 750 543.5 L 750 508.5 591.2 349.8 C 503.9 262.4, 432.2 191, 431.8 191 C 431.4 191, 431.1 206.4, 431.1 225.3 M 78 578.5 L 78 613.5 237 772.5 L 396 931.5 396 896.5 L 396 861.5 237 702.5 L 78 543.5 78 578.5 M 799.1 599.3 L 799.1 633.6 951 785.5 L 1103 937.5 1103 902.5 L 1103 867.5 951.7 716.2 C 868.6 633.1, 800.2 565, 799.8 565 C 799.4 565, 799.1 580.4, 799.1 599.3"
|
|
41
|
+
/>
|
|
42
|
+
<path
|
|
43
|
+
className="fill-[#4C6C91] dark:fill-[#243A52]"
|
|
44
|
+
d="M 555.2 702.3 L 396 861.5 396.2 896.3 L 396.5 931 573 754.5 L 749.5 578 732 560.5 L 714.5 543 555.2 702.3 M 1261.7 708.8 L 1103 867.5 1103 902.3 C 1103 921.4, 1103.3 937, 1103.8 937 C 1104.2 937, 1176 865.5, 1263.3 778.2 L 1422 619.4 1422 584.7 C 1421.9 565.6, 1421.6 550, 1421.2 550 C 1420.8 550, 1349.1 621.4, 1261.7 708.8"
|
|
45
|
+
/>
|
|
46
|
+
</g>
|
|
47
|
+
</svg>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shipping rates the seed configures on the starter's own methods, in minor
|
|
3
|
+
* units of the Channel currency, tax included.
|
|
4
|
+
*
|
|
5
|
+
* The seed reads them to configure `default-shipping-calculator`, and the platform's
|
|
6
|
+
* contract matrix reads them to know what the native methods must quote. One module
|
|
7
|
+
* for both is what keeps the matrix from proving a price the shop no longer charges.
|
|
8
|
+
* It imports nothing, so the root matrix can load it without pulling Vendure in.
|
|
9
|
+
*/
|
|
10
|
+
export const seededShippingRates = Object.freeze({
|
|
11
|
+
pickup: 0,
|
|
12
|
+
courier: 490,
|
|
13
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CurrencyCode,
|
|
3
|
+
GlobalSettingsService,
|
|
3
4
|
LanguageCode,
|
|
4
5
|
ProductService,
|
|
5
6
|
ProductVariantService,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
import { GlobalFlag } from "@vendure/common/lib/generated-types";
|
|
21
22
|
import { config } from "./vendure-config";
|
|
22
23
|
import { JarShopLegalConfiguration } from "./plugins/jarshop-checkout/legal.entity.js";
|
|
24
|
+
import { seededShippingRates } from "./plugins/jarshop-checkout/shipping-rates.js";
|
|
23
25
|
|
|
24
26
|
const productSlug = "jarshop-demo-product";
|
|
25
27
|
|
|
@@ -42,6 +44,7 @@ async function seed(): Promise<void> {
|
|
|
42
44
|
const taxCategoryService = app.get(TaxCategoryService);
|
|
43
45
|
const taxRateService = app.get(TaxRateService);
|
|
44
46
|
const channelService = app.get(ChannelService);
|
|
47
|
+
const globalSettingsService = app.get(GlobalSettingsService);
|
|
45
48
|
const paymentMethodService = app.get(PaymentMethodService);
|
|
46
49
|
const shippingMethodService = app.get(ShippingMethodService);
|
|
47
50
|
const connection = app.get(TransactionalConnection);
|
|
@@ -70,15 +73,43 @@ async function seed(): Promise<void> {
|
|
|
70
73
|
memberIds: [slovakia.id],
|
|
71
74
|
});
|
|
72
75
|
}
|
|
76
|
+
// The Dashboard offers a translation tab per language listed in the global
|
|
77
|
+
// settings, and the Shop API falls back to the channel default language.
|
|
78
|
+
// Both are database state, so an installation created before JarShop chose
|
|
79
|
+
// Slovak still has to be corrected here rather than in the config alone.
|
|
80
|
+
const storeLanguages = [LanguageCode.sk, LanguageCode.en];
|
|
81
|
+
const globalSettings = await globalSettingsService.getSettings(ctx);
|
|
82
|
+
const missingGlobalLanguages = storeLanguages.filter(
|
|
83
|
+
(languageCode) =>
|
|
84
|
+
!globalSettings.availableLanguages.includes(languageCode),
|
|
85
|
+
);
|
|
86
|
+
if (missingGlobalLanguages.length > 0) {
|
|
87
|
+
await globalSettingsService.updateSettings(ctx, {
|
|
88
|
+
availableLanguages: [
|
|
89
|
+
...globalSettings.availableLanguages,
|
|
90
|
+
...missingGlobalLanguages,
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const channelLanguagesMissing =
|
|
96
|
+
channel.defaultLanguageCode !== LanguageCode.sk ||
|
|
97
|
+
storeLanguages.some(
|
|
98
|
+
(languageCode) =>
|
|
99
|
+
!(channel.availableLanguageCodes ?? []).includes(languageCode),
|
|
100
|
+
);
|
|
73
101
|
if (
|
|
74
102
|
!channel.defaultTaxZone ||
|
|
75
|
-
channel.defaultCurrencyCode !== CurrencyCode.EUR
|
|
103
|
+
channel.defaultCurrencyCode !== CurrencyCode.EUR ||
|
|
104
|
+
channelLanguagesMissing
|
|
76
105
|
) {
|
|
77
106
|
await channelService.update(ctx, {
|
|
78
107
|
id: channel.id,
|
|
79
108
|
defaultTaxZoneId: taxZone.id,
|
|
80
109
|
defaultCurrencyCode: CurrencyCode.EUR,
|
|
81
110
|
availableCurrencyCodes: [CurrencyCode.EUR],
|
|
111
|
+
defaultLanguageCode: LanguageCode.sk,
|
|
112
|
+
availableLanguageCodes: storeLanguages,
|
|
82
113
|
});
|
|
83
114
|
channel = await channelService.getDefaultChannel(ctx);
|
|
84
115
|
ctx = await requestContextService.create({
|
|
@@ -101,7 +132,7 @@ async function seed(): Promise<void> {
|
|
|
101
132
|
calculator: {
|
|
102
133
|
code: "default-shipping-calculator",
|
|
103
134
|
arguments: [
|
|
104
|
-
{ name: "rate", value:
|
|
135
|
+
{ name: "rate", value: String(seededShippingRates.pickup) },
|
|
105
136
|
{ name: "taxRate", value: "0" },
|
|
106
137
|
{ name: "includesTax", value: "auto" },
|
|
107
138
|
],
|
|
@@ -134,7 +165,7 @@ async function seed(): Promise<void> {
|
|
|
134
165
|
calculator: {
|
|
135
166
|
code: "default-shipping-calculator",
|
|
136
167
|
arguments: [
|
|
137
|
-
{ name: "rate", value:
|
|
168
|
+
{ name: "rate", value: String(seededShippingRates.courier) },
|
|
138
169
|
{ name: "taxRate", value: "0" },
|
|
139
170
|
{ name: "includesTax", value: "auto" },
|
|
140
171
|
],
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
DefaultJobQueuePlugin,
|
|
3
3
|
DefaultSchedulerPlugin,
|
|
4
4
|
DefaultSearchPlugin,
|
|
5
|
+
LanguageCode,
|
|
5
6
|
VendureConfig,
|
|
6
7
|
} from "@vendure/core";
|
|
7
8
|
import { AssetServerPlugin } from "@vendure/asset-server-plugin";
|
|
@@ -39,6 +40,10 @@ function storefrontAccountUrl(locale: string, path: string): string {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export const config: VendureConfig = {
|
|
43
|
+
// JarShop sells in Slovakia first. This is read when a new installation
|
|
44
|
+
// populates its default channel and global settings, so it decides which
|
|
45
|
+
// translation the Dashboard and Shop API fall back to.
|
|
46
|
+
defaultLanguageCode: LanguageCode.sk,
|
|
42
47
|
apiOptions: {
|
|
43
48
|
port: Number(process.env.PORT ?? 3000),
|
|
44
49
|
adminApiPath: "admin-api",
|
|
@@ -81,7 +86,10 @@ export const config: VendureConfig = {
|
|
|
81
86
|
paymentOptions: { paymentMethodHandlers: [jarShopCodPaymentHandler] },
|
|
82
87
|
plugins: [
|
|
83
88
|
JarShopCheckoutPlugin,
|
|
84
|
-
|
|
89
|
+
// A GraphQL IDE is a development convenience, not something a live
|
|
90
|
+
// storefront's admin needs exposed - and its own page is titled
|
|
91
|
+
// "Vendure GraphiQL", which JarShop has no override for.
|
|
92
|
+
...(isDev ? [GraphiqlPlugin.init()] : []),
|
|
85
93
|
AssetServerPlugin.init({
|
|
86
94
|
route: "assets",
|
|
87
95
|
assetUploadDir: path.join(__dirname, "../static/assets"),
|
package/dist/template/turbo.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { vendureDashboardPlugin } from "@vendure/dashboard/vite";
|
|
2
|
+
import { LanguageCode } from "@vendure/core";
|
|
2
3
|
import { join, resolve } from "node:path";
|
|
3
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
5
|
import { defineConfig } from "vite";
|
|
@@ -7,7 +8,15 @@ const projectRoot = fileURLToPath(new URL(".", import.meta.url));
|
|
|
7
8
|
|
|
8
9
|
export default defineConfig({
|
|
9
10
|
base: "/dashboard",
|
|
10
|
-
build: {
|
|
11
|
+
build: {
|
|
12
|
+
outDir: join(projectRoot, "dist/dashboard"),
|
|
13
|
+
// The output directory is named by an absolute path, which is outside the
|
|
14
|
+
// Vite root, and Vite will not empty such a directory unless asked. Without
|
|
15
|
+
// this, every dashboard build layers its hashed assets on top of the last
|
|
16
|
+
// one: the directory grows without bound and the served chunk graph can mix
|
|
17
|
+
// two builds, which fails at runtime as a null React dispatcher.
|
|
18
|
+
emptyOutDir: true,
|
|
19
|
+
},
|
|
11
20
|
plugins: [
|
|
12
21
|
vendureDashboardPlugin({
|
|
13
22
|
vendureConfigPath: pathToFileURL(
|
|
@@ -20,7 +29,25 @@ export default defineConfig({
|
|
|
20
29
|
host: "http://localhost",
|
|
21
30
|
port: Number(process.env.PORT ?? 3000),
|
|
22
31
|
},
|
|
32
|
+
// JarShop ships its own Slovak catalogue through a patch on
|
|
33
|
+
// @vendure/dashboard. Vendure's own default language list has no Slovak
|
|
34
|
+
// in it, so the display-language dialog has to be told about it here.
|
|
35
|
+
i18n: {
|
|
36
|
+
defaultLanguage: LanguageCode.sk,
|
|
37
|
+
defaultLocale: "SK",
|
|
38
|
+
availableLanguages: [LanguageCode.sk, LanguageCode.en],
|
|
39
|
+
availableLocales: ["SK", "CZ", "AT", "GB", "US"],
|
|
40
|
+
},
|
|
23
41
|
gqlOutputPath: "./src/gql",
|
|
42
|
+
// Dashboard extensions shipped by an installed Feature Package are found by
|
|
43
|
+
// scanning node_modules. The default guess is derived from wherever
|
|
44
|
+
// `@vendure/core` resolves, which under pnpm is a directory inside
|
|
45
|
+
// `node_modules/.pnpm` that holds Vendure alone — every other installed
|
|
46
|
+
// package is invisible from there. Point the scanner at this project's own
|
|
47
|
+
// `node_modules` so package-provided extensions are discovered.
|
|
48
|
+
pluginPackageScanner: {
|
|
49
|
+
nodeModulesRoot: resolve(projectRoot, "node_modules"),
|
|
50
|
+
},
|
|
24
51
|
}),
|
|
25
52
|
],
|
|
26
53
|
resolve: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
// A bare `vitest run` would pick up `vite.config.mts`, which loads the
|
|
4
|
+
// Dashboard build plugin and the whole Vendure config just to run unit tests.
|
|
5
|
+
// This file keeps the Vendure-side plugin tests on a plain Node runner.
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
test: {
|
|
8
|
+
environment: "node",
|
|
9
|
+
include: ["src/**/*.test.ts"],
|
|
10
|
+
},
|
|
11
|
+
});
|