@jarwizz/create-jarshop 0.1.9 → 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 +4 -0
- package/dist/template/pnpm-lock.yaml +3284 -1815
- 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-manifest.json +1 -1
- package/dist/template.js +1 -0
- package/dist/template.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Channel,
|
|
2
3
|
CurrencyCode,
|
|
4
|
+
Injector,
|
|
3
5
|
GlobalSettingsService,
|
|
4
6
|
LanguageCode,
|
|
5
7
|
ProductService,
|
|
6
8
|
ProductVariantService,
|
|
9
|
+
RequestContext,
|
|
7
10
|
RequestContextService,
|
|
11
|
+
RoleService,
|
|
12
|
+
StockLocation,
|
|
8
13
|
StockLocationService,
|
|
9
14
|
TaxCategoryService,
|
|
10
15
|
TaxRateService,
|
|
16
|
+
UserService,
|
|
17
|
+
Zone,
|
|
11
18
|
ZoneService,
|
|
12
19
|
ChannelService,
|
|
13
20
|
CountryService,
|
|
@@ -19,11 +26,57 @@ import {
|
|
|
19
26
|
bootstrap,
|
|
20
27
|
} from "@vendure/core";
|
|
21
28
|
import { GlobalFlag } from "@vendure/common/lib/generated-types";
|
|
29
|
+
import { ModuleRef } from "@nestjs/core";
|
|
30
|
+
import {
|
|
31
|
+
JarShopInvoicingPlugin,
|
|
32
|
+
seedSlovakNonVatInvoiceTemplate,
|
|
33
|
+
} from "@jarwizz/jarshop-invoicing/server";
|
|
22
34
|
import { config } from "./vendure-config";
|
|
35
|
+
import {
|
|
36
|
+
configuredLanguages,
|
|
37
|
+
defaultMarket,
|
|
38
|
+
type JarShopMarket,
|
|
39
|
+
} from "./jarshop-config.js";
|
|
40
|
+
import { loadJarShopConfig } from "./jarshop-config-loader.js";
|
|
41
|
+
import { packetaCountriesForMarket } from "./packeta-countries.js";
|
|
23
42
|
import { JarShopLegalConfiguration } from "./plugins/jarshop-checkout/legal.entity.js";
|
|
24
43
|
import { seededShippingRates } from "./plugins/jarshop-checkout/shipping-rates.js";
|
|
25
44
|
|
|
26
45
|
const productSlug = "jarshop-demo-product";
|
|
46
|
+
const demoVariantPrice = 1990;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Demo prices are authored in EUR minor units. Another market currency gets a
|
|
50
|
+
* rounded, plausible amount instead of the same number in a different unit.
|
|
51
|
+
*/
|
|
52
|
+
const demoCurrencyFactors: Readonly<Record<string, number>> = {
|
|
53
|
+
EUR: 1,
|
|
54
|
+
CZK: 25,
|
|
55
|
+
HUF: 400,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function demoCurrencyFactor(currency: string): number {
|
|
59
|
+
return demoCurrencyFactors[currency] ?? 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Demo copy exists in Slovak and English; other languages reuse English. */
|
|
63
|
+
function demoTranslations<T extends object>(
|
|
64
|
+
languages: readonly string[],
|
|
65
|
+
slovak: T,
|
|
66
|
+
english: T,
|
|
67
|
+
): Array<T & { languageCode: LanguageCode }> {
|
|
68
|
+
return languages.map((languageCode) => ({
|
|
69
|
+
...(languageCode === "sk" ? slovak : english),
|
|
70
|
+
languageCode: languageCode as LanguageCode,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function countryName(countryCode: string, languageCode: string): string {
|
|
75
|
+
return (
|
|
76
|
+
new Intl.DisplayNames([languageCode], { type: "region" }).of(countryCode) ??
|
|
77
|
+
countryCode
|
|
78
|
+
);
|
|
79
|
+
}
|
|
27
80
|
|
|
28
81
|
async function seed(): Promise<void> {
|
|
29
82
|
if (!new Set(["dev", "test"]).has(process.env.APP_ENV ?? "")) {
|
|
@@ -31,6 +84,11 @@ async function seed(): Promise<void> {
|
|
|
31
84
|
"JarShop demo seed is allowed only in APP_ENV=dev or test.",
|
|
32
85
|
);
|
|
33
86
|
}
|
|
87
|
+
const jarShopConfig = loadJarShopConfig();
|
|
88
|
+
const primaryMarket = defaultMarket(jarShopConfig);
|
|
89
|
+
const otherMarkets = jarShopConfig.markets.filter(
|
|
90
|
+
(market) => market !== primaryMarket,
|
|
91
|
+
);
|
|
34
92
|
const app = await bootstrap(config);
|
|
35
93
|
|
|
36
94
|
try {
|
|
@@ -44,6 +102,7 @@ async function seed(): Promise<void> {
|
|
|
44
102
|
const taxCategoryService = app.get(TaxCategoryService);
|
|
45
103
|
const taxRateService = app.get(TaxRateService);
|
|
46
104
|
const channelService = app.get(ChannelService);
|
|
105
|
+
const roleService = app.get(RoleService);
|
|
47
106
|
const globalSettingsService = app.get(GlobalSettingsService);
|
|
48
107
|
const paymentMethodService = app.get(PaymentMethodService);
|
|
49
108
|
const shippingMethodService = app.get(ShippingMethodService);
|
|
@@ -52,32 +111,12 @@ async function seed(): Promise<void> {
|
|
|
52
111
|
|
|
53
112
|
const stockLocation = await stockLocationService.defaultStockLocation(ctx);
|
|
54
113
|
let channel = await channelService.getDefaultChannel(ctx);
|
|
55
|
-
|
|
56
|
-
const taxZone =
|
|
57
|
-
zones.items[0] ??
|
|
58
|
-
(await zoneService.create(ctx, { name: "JarShop default tax zone" }));
|
|
59
|
-
const countries = await countryService.findAll(ctx);
|
|
60
|
-
const slovakia =
|
|
61
|
-
countries.items.find((country) => country.code === "SK") ??
|
|
62
|
-
(await countryService.create(ctx, {
|
|
63
|
-
code: "SK",
|
|
64
|
-
enabled: true,
|
|
65
|
-
translations: [
|
|
66
|
-
{ languageCode: LanguageCode.sk, name: "Slovensko" },
|
|
67
|
-
{ languageCode: LanguageCode.en, name: "Slovakia" },
|
|
68
|
-
],
|
|
69
|
-
}));
|
|
70
|
-
if (!taxZone.members.some((country) => country.id === slovakia.id)) {
|
|
71
|
-
await zoneService.addMembersToZone(ctx, {
|
|
72
|
-
zoneId: taxZone.id,
|
|
73
|
-
memberIds: [slovakia.id],
|
|
74
|
-
});
|
|
75
|
-
}
|
|
114
|
+
|
|
76
115
|
// The Dashboard offers a translation tab per language listed in the global
|
|
77
116
|
// settings, and the Shop API falls back to the channel default language.
|
|
78
|
-
// Both are database state, so an installation created before
|
|
79
|
-
//
|
|
80
|
-
const storeLanguages =
|
|
117
|
+
// Both are database state, so an installation created before the markets
|
|
118
|
+
// were chosen still has to be corrected here rather than in the config.
|
|
119
|
+
const storeLanguages = configuredLanguages(jarShopConfig) as LanguageCode[];
|
|
81
120
|
const globalSettings = await globalSettingsService.getSettings(ctx);
|
|
82
121
|
const missingGlobalLanguages = storeLanguages.filter(
|
|
83
122
|
(languageCode) =>
|
|
@@ -92,24 +131,64 @@ async function seed(): Promise<void> {
|
|
|
92
131
|
});
|
|
93
132
|
}
|
|
94
133
|
|
|
134
|
+
const countries = await countryService.findAll(ctx);
|
|
135
|
+
async function ensureZoneCountries(
|
|
136
|
+
zone: Zone,
|
|
137
|
+
market: JarShopMarket,
|
|
138
|
+
): Promise<void> {
|
|
139
|
+
for (const code of market.countries) {
|
|
140
|
+
let country = countries.items.find((item) => item.code === code);
|
|
141
|
+
if (!country) {
|
|
142
|
+
country = await countryService.create(ctx, {
|
|
143
|
+
code,
|
|
144
|
+
enabled: true,
|
|
145
|
+
translations: storeLanguages.map((languageCode) => ({
|
|
146
|
+
languageCode,
|
|
147
|
+
name: countryName(code, languageCode),
|
|
148
|
+
})),
|
|
149
|
+
});
|
|
150
|
+
countries.items.push(country);
|
|
151
|
+
}
|
|
152
|
+
const countryId = country.id;
|
|
153
|
+
if (!zone.members.some((member) => member.id === countryId)) {
|
|
154
|
+
await zoneService.addMembersToZone(ctx, {
|
|
155
|
+
zoneId: zone.id,
|
|
156
|
+
memberIds: [countryId],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// The default market lives in Vendure's default Channel.
|
|
163
|
+
const zones = await zoneService.findAll(ctx);
|
|
164
|
+
const taxZone =
|
|
165
|
+
zones.items.find((zone) => zone.id === channel.defaultTaxZone?.id) ??
|
|
166
|
+
zones.items[0] ??
|
|
167
|
+
(await zoneService.create(ctx, { name: "JarShop default tax zone" }));
|
|
168
|
+
await ensureZoneCountries(taxZone, primaryMarket);
|
|
169
|
+
|
|
170
|
+
const primaryLanguage = primaryMarket.defaultLanguage as LanguageCode;
|
|
171
|
+
const primaryCurrency = primaryMarket.currency as CurrencyCode;
|
|
95
172
|
const channelLanguagesMissing =
|
|
96
|
-
channel.defaultLanguageCode !==
|
|
97
|
-
|
|
173
|
+
channel.defaultLanguageCode !== primaryLanguage ||
|
|
174
|
+
primaryMarket.languages.some(
|
|
98
175
|
(languageCode) =>
|
|
99
|
-
!(channel.availableLanguageCodes ?? []).includes(
|
|
176
|
+
!(channel.availableLanguageCodes ?? []).includes(
|
|
177
|
+
languageCode as LanguageCode,
|
|
178
|
+
),
|
|
100
179
|
);
|
|
101
180
|
if (
|
|
102
181
|
!channel.defaultTaxZone ||
|
|
103
|
-
channel.defaultCurrencyCode !==
|
|
182
|
+
channel.defaultCurrencyCode !== primaryCurrency ||
|
|
104
183
|
channelLanguagesMissing
|
|
105
184
|
) {
|
|
106
185
|
await channelService.update(ctx, {
|
|
107
186
|
id: channel.id,
|
|
108
187
|
defaultTaxZoneId: taxZone.id,
|
|
109
|
-
defaultCurrencyCode:
|
|
110
|
-
availableCurrencyCodes: [
|
|
111
|
-
defaultLanguageCode:
|
|
112
|
-
availableLanguageCodes:
|
|
188
|
+
defaultCurrencyCode: primaryCurrency,
|
|
189
|
+
availableCurrencyCodes: [primaryCurrency],
|
|
190
|
+
defaultLanguageCode: primaryLanguage,
|
|
191
|
+
availableLanguageCodes: primaryMarket.languages as LanguageCode[],
|
|
113
192
|
});
|
|
114
193
|
channel = await channelService.getDefaultChannel(ctx);
|
|
115
194
|
ctx = await requestContextService.create({
|
|
@@ -118,74 +197,204 @@ async function seed(): Promise<void> {
|
|
|
118
197
|
});
|
|
119
198
|
}
|
|
120
199
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
200
|
+
// Every other market gets its own Channel, tax zone and stock location
|
|
201
|
+
// assignment, with the roles the Admin API grants a Channel it creates.
|
|
202
|
+
const superAdminRole = await roleService.getSuperAdminRole(ctx);
|
|
203
|
+
const customerRole = await roleService.getCustomerRole(ctx);
|
|
204
|
+
const marketChannels: Array<{
|
|
205
|
+
readonly market: JarShopMarket;
|
|
206
|
+
readonly channel: Channel;
|
|
207
|
+
readonly zone: Zone;
|
|
208
|
+
readonly ctx: RequestContext;
|
|
209
|
+
}> = [];
|
|
210
|
+
for (const market of otherMarkets) {
|
|
211
|
+
const zoneName = `JarShop ${market.code.toUpperCase()} market zone`;
|
|
212
|
+
const zone =
|
|
213
|
+
zones.items.find((item) => item.name === zoneName) ??
|
|
214
|
+
(await zoneService.create(ctx, { name: zoneName }));
|
|
215
|
+
await ensureZoneCountries(zone, market);
|
|
216
|
+
const channels = await channelService.findAll(ctx);
|
|
217
|
+
const existingChannel =
|
|
218
|
+
channels.items.find((item) => item.token === market.channelToken) ??
|
|
219
|
+
channels.items.find((item) => item.code === market.code);
|
|
220
|
+
const channelInput = {
|
|
221
|
+
code: market.code,
|
|
222
|
+
token: market.channelToken,
|
|
223
|
+
defaultLanguageCode: market.defaultLanguage as LanguageCode,
|
|
224
|
+
availableLanguageCodes: market.languages as LanguageCode[],
|
|
225
|
+
defaultCurrencyCode: market.currency as CurrencyCode,
|
|
226
|
+
availableCurrencyCodes: [market.currency as CurrencyCode],
|
|
227
|
+
defaultTaxZoneId: zone.id,
|
|
228
|
+
defaultShippingZoneId: zone.id,
|
|
229
|
+
pricesIncludeTax: channel.pricesIncludeTax,
|
|
230
|
+
...(channel.sellerId ? { sellerId: channel.sellerId } : {}),
|
|
231
|
+
};
|
|
232
|
+
const saved = existingChannel
|
|
233
|
+
? await channelService.update(ctx, {
|
|
234
|
+
id: existingChannel.id,
|
|
235
|
+
...channelInput,
|
|
236
|
+
})
|
|
237
|
+
: await channelService.create(ctx, channelInput);
|
|
238
|
+
if (!(saved instanceof Channel)) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Market "${market.code}" Channel could not be saved: ${saved.message}`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
for (const role of [superAdminRole, customerRole]) {
|
|
244
|
+
await roleService.assignRoleToChannel(ctx, role.id, saved.id);
|
|
245
|
+
}
|
|
246
|
+
await channelService.assignToChannels(
|
|
247
|
+
ctx,
|
|
248
|
+
StockLocation,
|
|
249
|
+
stockLocation.id,
|
|
250
|
+
[saved.id],
|
|
251
|
+
);
|
|
252
|
+
marketChannels.push({
|
|
253
|
+
market,
|
|
254
|
+
channel: saved,
|
|
255
|
+
zone,
|
|
256
|
+
ctx: await requestContextService.create({
|
|
257
|
+
apiType: "admin",
|
|
258
|
+
channelOrToken: market.channelToken,
|
|
259
|
+
}),
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// The seed follows the composed configuration, so a Feature switched off
|
|
264
|
+
// in src/client/features.ts gets no demo method or template.
|
|
265
|
+
const registeredOperations = new Set(
|
|
266
|
+
[
|
|
267
|
+
...config.paymentOptions.paymentMethodHandlers,
|
|
268
|
+
...(config.shippingOptions?.shippingEligibilityCheckers ?? []),
|
|
269
|
+
...(config.shippingOptions?.shippingCalculators ?? []),
|
|
270
|
+
].map((operation) => operation.code),
|
|
271
|
+
);
|
|
272
|
+
const isRegistered = (definition: {
|
|
273
|
+
checker: { code: string };
|
|
274
|
+
calculator: { code: string };
|
|
275
|
+
}) =>
|
|
276
|
+
registeredOperations.has(definition.checker.code) &&
|
|
277
|
+
registeredOperations.has(definition.calculator.code);
|
|
278
|
+
|
|
279
|
+
if (config.plugins?.includes(JarShopInvoicingPlugin)) {
|
|
280
|
+
await seedSlovakNonVatInvoiceTemplate(
|
|
281
|
+
ctx,
|
|
282
|
+
new Injector(app.get(ModuleRef)),
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Creates the demo shipping methods for one market. Their rates are in the
|
|
288
|
+
* market currency, so a non-default market owns its own methods with the
|
|
289
|
+
* same codes rather than sharing the default Channel's.
|
|
290
|
+
*/
|
|
291
|
+
async function seedShippingMethods(
|
|
292
|
+
market: JarShopMarket,
|
|
293
|
+
marketCtx: RequestContext,
|
|
294
|
+
marketChannel: Channel,
|
|
295
|
+
): Promise<void> {
|
|
296
|
+
const factor = demoCurrencyFactor(market.currency);
|
|
297
|
+
const shippingMethods =
|
|
298
|
+
await shippingMethodService.getActiveShippingMethods(marketCtx);
|
|
299
|
+
const definitions = [
|
|
300
|
+
{
|
|
301
|
+
code: "pickup",
|
|
302
|
+
checker: {
|
|
303
|
+
code: "default-shipping-eligibility-checker",
|
|
304
|
+
arguments: [{ name: "orderMinimum", value: "0" }],
|
|
145
305
|
},
|
|
146
|
-
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
306
|
+
calculator: {
|
|
307
|
+
code: "jarshop-tariff-shipping-calculator",
|
|
308
|
+
arguments: [
|
|
309
|
+
{
|
|
310
|
+
name: "rate",
|
|
311
|
+
value: String(seededShippingRates.pickup * factor),
|
|
312
|
+
},
|
|
313
|
+
{ name: "includesTax", value: "auto" },
|
|
314
|
+
],
|
|
150
315
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const courier =
|
|
157
|
-
shippingMethods.find((method) => method.code === "courier") ??
|
|
158
|
-
(await shippingMethodService.create(ctx, {
|
|
159
|
-
code: "courier",
|
|
160
|
-
fulfillmentHandler: "manual-fulfillment",
|
|
161
|
-
checker: {
|
|
162
|
-
code: "default-shipping-eligibility-checker",
|
|
163
|
-
arguments: [{ name: "orderMinimum", value: "0" }],
|
|
164
|
-
},
|
|
165
|
-
calculator: {
|
|
166
|
-
code: "default-shipping-calculator",
|
|
167
|
-
arguments: [
|
|
168
|
-
{ name: "rate", value: String(seededShippingRates.courier) },
|
|
169
|
-
{ name: "taxRate", value: "0" },
|
|
170
|
-
{ name: "includesTax", value: "auto" },
|
|
171
|
-
],
|
|
316
|
+
translations: demoTranslations(
|
|
317
|
+
storeLanguages,
|
|
318
|
+
{ name: "Osobný odber", description: "" },
|
|
319
|
+
{ name: "Personal pickup", description: "" },
|
|
320
|
+
),
|
|
172
321
|
},
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
322
|
+
// Only a market that ships to a Packeta country gets the method; its
|
|
323
|
+
// tariff is authored in that market's currency like the other rates.
|
|
324
|
+
...(packetaCountriesForMarket(market).length > 0
|
|
325
|
+
? [
|
|
326
|
+
{
|
|
327
|
+
code: "packeta-pickup",
|
|
328
|
+
checker: { code: "packeta-eligibility", arguments: [] },
|
|
329
|
+
calculator: {
|
|
330
|
+
code: "packeta-calculator",
|
|
331
|
+
arguments: [
|
|
332
|
+
{ name: "priceWithTax", value: String(350 * factor) },
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
translations: demoTranslations(
|
|
336
|
+
storeLanguages,
|
|
337
|
+
{
|
|
338
|
+
name: "Packeta výdajné miesto alebo Z-BOX",
|
|
339
|
+
description: "Doručenie na vybrané výdajné miesto Packeta",
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
name: "Packeta pickup point or Z-BOX",
|
|
343
|
+
description: "Delivery to a selected Packeta pickup point",
|
|
344
|
+
},
|
|
345
|
+
),
|
|
346
|
+
},
|
|
347
|
+
]
|
|
348
|
+
: []),
|
|
349
|
+
{
|
|
350
|
+
code: "courier",
|
|
351
|
+
checker: {
|
|
352
|
+
code: "default-shipping-eligibility-checker",
|
|
353
|
+
arguments: [{ name: "orderMinimum", value: "0" }],
|
|
178
354
|
},
|
|
179
|
-
{
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
355
|
+
calculator: {
|
|
356
|
+
code: "jarshop-tariff-shipping-calculator",
|
|
357
|
+
arguments: [
|
|
358
|
+
{
|
|
359
|
+
name: "rate",
|
|
360
|
+
value: String(seededShippingRates.courier * factor),
|
|
361
|
+
},
|
|
362
|
+
{ name: "includesTax", value: "auto" },
|
|
363
|
+
],
|
|
183
364
|
},
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
365
|
+
translations: demoTranslations(
|
|
366
|
+
storeLanguages,
|
|
367
|
+
{ name: "Kuriér", description: "Doručenie kuriérom" },
|
|
368
|
+
{ name: "Courier", description: "Courier delivery" },
|
|
369
|
+
),
|
|
370
|
+
},
|
|
371
|
+
].filter(isRegistered);
|
|
372
|
+
for (const definition of definitions) {
|
|
373
|
+
const method =
|
|
374
|
+
shippingMethods.find((item) => item.code === definition.code) ??
|
|
375
|
+
(await shippingMethodService.create(marketCtx, {
|
|
376
|
+
...definition,
|
|
377
|
+
fulfillmentHandler: "manual-fulfillment",
|
|
378
|
+
}));
|
|
379
|
+
await channelService.assignToChannels(ctx, ShippingMethod, method.id, [
|
|
380
|
+
marketChannel.id,
|
|
381
|
+
]);
|
|
382
|
+
if (marketChannel.id !== channel.id) {
|
|
383
|
+
// Vendure also assigns a new method to the default Channel, which
|
|
384
|
+
// would then quote this market's currency amounts.
|
|
385
|
+
await channelService.removeFromChannels(
|
|
386
|
+
ctx,
|
|
387
|
+
ShippingMethod,
|
|
388
|
+
method.id,
|
|
389
|
+
[channel.id],
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
await seedShippingMethods(primaryMarket, ctx, channel);
|
|
395
|
+
for (const item of marketChannels) {
|
|
396
|
+
await seedShippingMethods(item.market, item.ctx, item.channel);
|
|
397
|
+
}
|
|
189
398
|
|
|
190
399
|
const paymentMethods = await paymentMethodService.findAll(ctx);
|
|
191
400
|
const legacyDummy = paymentMethods.items.find(
|
|
@@ -197,67 +406,68 @@ async function seed(): Promise<void> {
|
|
|
197
406
|
enabled: false,
|
|
198
407
|
});
|
|
199
408
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
})
|
|
212
|
-
: await paymentMethodService.create(ctx, {
|
|
213
|
-
code: "cod",
|
|
214
|
-
enabled: true,
|
|
215
|
-
handler: {
|
|
216
|
-
code: "jarshop-cod-handler",
|
|
217
|
-
arguments: [],
|
|
218
|
-
},
|
|
219
|
-
translations: [
|
|
220
|
-
{
|
|
221
|
-
languageCode: LanguageCode.sk,
|
|
222
|
-
name: "Dobierka",
|
|
223
|
-
description: "",
|
|
409
|
+
if (registeredOperations.has("jarshop-cod-handler")) {
|
|
410
|
+
const existingCod = paymentMethods.items.find(
|
|
411
|
+
(method) => method.code === "cod",
|
|
412
|
+
);
|
|
413
|
+
const cod = existingCod
|
|
414
|
+
? await paymentMethodService.update(ctx, {
|
|
415
|
+
id: existingCod.id,
|
|
416
|
+
enabled: true,
|
|
417
|
+
handler: {
|
|
418
|
+
code: "jarshop-cod-handler",
|
|
419
|
+
arguments: [],
|
|
224
420
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
421
|
+
})
|
|
422
|
+
: await paymentMethodService.create(ctx, {
|
|
423
|
+
code: "cod",
|
|
424
|
+
enabled: true,
|
|
425
|
+
handler: {
|
|
426
|
+
code: "jarshop-cod-handler",
|
|
427
|
+
arguments: [],
|
|
229
428
|
},
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
429
|
+
translations: demoTranslations(
|
|
430
|
+
storeLanguages,
|
|
431
|
+
{ name: "Dobierka", description: "" },
|
|
432
|
+
{ name: "Cash on delivery", description: "" },
|
|
433
|
+
),
|
|
434
|
+
});
|
|
435
|
+
await channelService.assignToChannels(ctx, PaymentMethod, cod.id, [
|
|
436
|
+
channel.id,
|
|
437
|
+
...marketChannels.map((item) => item.channel.id),
|
|
438
|
+
]);
|
|
439
|
+
}
|
|
235
440
|
|
|
236
441
|
const legalRepository = connection.getRepository(
|
|
237
442
|
ctx,
|
|
238
443
|
JarShopLegalConfiguration,
|
|
239
444
|
);
|
|
240
|
-
for (const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
await legalRepository.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
445
|
+
for (const { market, channel: legalChannel } of [
|
|
446
|
+
{ market: primaryMarket, channel },
|
|
447
|
+
...marketChannels,
|
|
448
|
+
]) {
|
|
449
|
+
for (const languageCode of market.languages) {
|
|
450
|
+
const existingLegal = await legalRepository.findOne({
|
|
451
|
+
where: { channelId: Number(legalChannel.id), languageCode },
|
|
452
|
+
});
|
|
453
|
+
if (!existingLegal) {
|
|
454
|
+
await legalRepository.save(
|
|
455
|
+
legalRepository.create({
|
|
456
|
+
channelId: Number(legalChannel.id),
|
|
457
|
+
languageCode,
|
|
458
|
+
termsVersion: "2026-08-01",
|
|
459
|
+
termsUrl:
|
|
460
|
+
languageCode === LanguageCode.sk
|
|
461
|
+
? "https://example.com/sk/obchodne-podmienky"
|
|
462
|
+
: `https://example.com/${languageCode}/terms`,
|
|
463
|
+
privacyVersion: "2026-08-01",
|
|
464
|
+
privacyUrl:
|
|
465
|
+
languageCode === LanguageCode.sk
|
|
466
|
+
? "https://example.com/sk/ochrana-sukromia"
|
|
467
|
+
: `https://example.com/${languageCode}/privacy`,
|
|
468
|
+
}),
|
|
469
|
+
);
|
|
470
|
+
}
|
|
261
471
|
}
|
|
262
472
|
}
|
|
263
473
|
const taxCategories = await taxCategoryService.findAll(ctx);
|
|
@@ -266,39 +476,40 @@ async function seed(): Promise<void> {
|
|
|
266
476
|
taxCategories.items[0] ??
|
|
267
477
|
(await taxCategoryService.create(ctx, { name: "JarShop demo tax" }));
|
|
268
478
|
const taxRates = await taxRateService.findAll(ctx);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
(
|
|
272
|
-
rate
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
479
|
+
for (const zone of [taxZone, ...marketChannels.map((item) => item.zone)]) {
|
|
480
|
+
if (
|
|
481
|
+
!taxRates.items.some(
|
|
482
|
+
(rate) =>
|
|
483
|
+
rate.zoneId === zone.id && rate.categoryId === taxCategory.id,
|
|
484
|
+
)
|
|
485
|
+
) {
|
|
486
|
+
await taxRateService.create(ctx, {
|
|
487
|
+
zoneId: zone.id,
|
|
488
|
+
categoryId: taxCategory.id,
|
|
489
|
+
name: "JarShop demo zero tax",
|
|
490
|
+
value: 0,
|
|
491
|
+
enabled: true,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
282
494
|
}
|
|
283
495
|
const product =
|
|
284
496
|
existing ??
|
|
285
497
|
(await productService.create(ctx, {
|
|
286
498
|
enabled: true,
|
|
287
|
-
translations:
|
|
499
|
+
translations: demoTranslations(
|
|
500
|
+
storeLanguages,
|
|
288
501
|
{
|
|
289
|
-
languageCode: LanguageCode.sk,
|
|
290
502
|
name: "JarShop ukážkový produkt",
|
|
291
503
|
slug: productSlug,
|
|
292
504
|
description: "Generický produkt pre overenie JarShop startera.",
|
|
293
505
|
},
|
|
294
506
|
{
|
|
295
|
-
languageCode: LanguageCode.en,
|
|
296
507
|
name: "JarShop demo product",
|
|
297
508
|
slug: productSlug,
|
|
298
509
|
description:
|
|
299
510
|
"A generic product used to verify the JarShop starter.",
|
|
300
511
|
},
|
|
301
|
-
|
|
512
|
+
),
|
|
302
513
|
}));
|
|
303
514
|
|
|
304
515
|
const existingVariants = existing
|
|
@@ -308,26 +519,58 @@ async function seed(): Promise<void> {
|
|
|
308
519
|
: undefined;
|
|
309
520
|
if (existingVariants?.totalItems) {
|
|
310
521
|
console.log(`Seed skipped: ${productSlug} already exists`);
|
|
311
|
-
|
|
522
|
+
} else {
|
|
523
|
+
await variantService.create(ctx, [
|
|
524
|
+
{
|
|
525
|
+
productId: product.id,
|
|
526
|
+
sku: "JARSHOP-DEMO-001",
|
|
527
|
+
enabled: true,
|
|
528
|
+
trackInventory: GlobalFlag.TRUE,
|
|
529
|
+
taxCategoryId: taxCategory.id,
|
|
530
|
+
stockLevels: [{ stockLocationId: stockLocation.id, stockOnHand: 10 }],
|
|
531
|
+
price: demoVariantPrice * demoCurrencyFactor(primaryMarket.currency),
|
|
532
|
+
translations: demoTranslations(
|
|
533
|
+
storeLanguages,
|
|
534
|
+
{ name: "JarShop ukážkový variant" },
|
|
535
|
+
{ name: "JarShop demo variant" },
|
|
536
|
+
),
|
|
537
|
+
},
|
|
538
|
+
]);
|
|
539
|
+
console.log(`Seeded ${productSlug}`);
|
|
312
540
|
}
|
|
313
541
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
{
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
542
|
+
// Assigning a catalog checks the active user's permission on the target
|
|
543
|
+
// Channel, which the superadmin role was granted above.
|
|
544
|
+
if (marketChannels.length > 0) {
|
|
545
|
+
const superadminIdentifier =
|
|
546
|
+
config.authOptions?.superadminCredentials?.identifier ?? "";
|
|
547
|
+
const superadmin = await app
|
|
548
|
+
.get(UserService)
|
|
549
|
+
.getUserByEmailAddress(ctx, superadminIdentifier, "administrator");
|
|
550
|
+
if (!superadmin) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
`Superadmin "${superadminIdentifier}" is required to seed market catalogs`,
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
const catalogCtx = await requestContextService.create({
|
|
556
|
+
apiType: "admin",
|
|
557
|
+
channelOrToken: channel.token,
|
|
558
|
+
user: superadmin,
|
|
559
|
+
});
|
|
560
|
+
for (const item of marketChannels) {
|
|
561
|
+
if (await productService.findOne(item.ctx, product.id)) continue;
|
|
562
|
+
await productService.assignProductsToChannel(catalogCtx, {
|
|
563
|
+
productIds: [product.id],
|
|
564
|
+
channelId: item.channel.id,
|
|
565
|
+
priceFactor:
|
|
566
|
+
demoCurrencyFactor(item.market.currency) /
|
|
567
|
+
demoCurrencyFactor(primaryMarket.currency),
|
|
568
|
+
});
|
|
569
|
+
console.log(
|
|
570
|
+
`Assigned ${productSlug} to market ${item.market.code} (${item.market.currency})`,
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
331
574
|
} finally {
|
|
332
575
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
333
576
|
await app.close();
|