@jarwizz/create-jarshop 0.1.9 → 0.4.0

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