@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
|
@@ -5,6 +5,12 @@ import { Allow, Permission } from "@vendure/core";
|
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { parse } from "graphql";
|
|
7
7
|
import { IsNull, MoreThan, type Repository } from "typeorm";
|
|
8
|
+
import {
|
|
9
|
+
JarShopShippingSelection,
|
|
10
|
+
JarShopPaymentReconciliationService,
|
|
11
|
+
JarShopRedirectPaymentPlugin,
|
|
12
|
+
paymentFlowOf,
|
|
13
|
+
} from "@jarwizz/feature-adapter-kit/server";
|
|
8
14
|
import {
|
|
9
15
|
ActiveOrderService,
|
|
10
16
|
Ctx,
|
|
@@ -12,6 +18,7 @@ import {
|
|
|
12
18
|
isGraphQlErrorResult,
|
|
13
19
|
Order,
|
|
14
20
|
OrderService,
|
|
21
|
+
PaymentMethodService,
|
|
15
22
|
PluginCommonModule,
|
|
16
23
|
ProductVariantService,
|
|
17
24
|
RequestContext,
|
|
@@ -20,16 +27,19 @@ import {
|
|
|
20
27
|
TransactionalConnection,
|
|
21
28
|
VendurePlugin,
|
|
22
29
|
} from "@vendure/core";
|
|
30
|
+
import { marketForChannel } from "../../jarshop-config-loader.js";
|
|
23
31
|
import { CheckoutAttempt } from "./checkout-attempt.entity.js";
|
|
24
32
|
import { JarShopConfirmationToken } from "./confirmation-token.entity.js";
|
|
25
33
|
import {
|
|
26
34
|
CONFIRMATION_COOKIE_NAME,
|
|
27
35
|
canExchangeConfirmationToken,
|
|
36
|
+
canReconcilePaymentWithConfirmationCredential,
|
|
28
37
|
canReadConfirmationCredential,
|
|
29
38
|
createConfirmationToken,
|
|
30
39
|
createConfirmationTokenPair,
|
|
31
40
|
hashConfirmationToken,
|
|
32
41
|
readCookieValue,
|
|
42
|
+
toOrderConfirmation,
|
|
33
43
|
} from "./confirmation.js";
|
|
34
44
|
import { JarShopLegalConfiguration } from "./legal.entity.js";
|
|
35
45
|
import { JarShopOrderEmailDelivery } from "./order-email-delivery.entity.js";
|
|
@@ -44,6 +54,8 @@ import {
|
|
|
44
54
|
isOrderAvailableInChannel,
|
|
45
55
|
toOrderEmailDeliveryStatus,
|
|
46
56
|
} from "./order-email-delivery-status.js";
|
|
57
|
+
import { JarShopMarketChannelCheck } from "./market-channels.js";
|
|
58
|
+
import { JarShopOperationCodeCheck } from "./operation-code-check.js";
|
|
47
59
|
import { createPendingOrderEmailDelivery } from "./order-email-outbox.js";
|
|
48
60
|
import { toOrderEmailLanguageCode } from "./order-email-delivery-core.js";
|
|
49
61
|
import {
|
|
@@ -54,7 +66,10 @@ import { JarShopOrderConsent } from "./order-consent.entity.js";
|
|
|
54
66
|
import { registerJarShopOrderLifecycle } from "./order-lifecycle-process.js";
|
|
55
67
|
import {
|
|
56
68
|
compareCheckoutSnapshot,
|
|
69
|
+
mapPaymentTransitionFailure,
|
|
57
70
|
resolveLocalizedShippingMethodName,
|
|
71
|
+
shouldUnsetShippingAddress,
|
|
72
|
+
validateCheckoutMarket,
|
|
58
73
|
validateShippingSelection,
|
|
59
74
|
type CheckoutCartSnapshot,
|
|
60
75
|
type ShippingAddressInput,
|
|
@@ -124,11 +139,23 @@ const schema = parse(`
|
|
|
124
139
|
state: String!
|
|
125
140
|
totalWithTax: Int!
|
|
126
141
|
currencyCode: String!
|
|
142
|
+
shippingAddress: JarShopOrderConfirmationAddress
|
|
143
|
+
}
|
|
144
|
+
type JarShopOrderConfirmationAddress {
|
|
145
|
+
fullName: String!
|
|
146
|
+
streetLine1: String!
|
|
147
|
+
streetLine2: String!
|
|
148
|
+
postalCode: String!
|
|
149
|
+
city: String!
|
|
150
|
+
countryCode: String!
|
|
127
151
|
}
|
|
128
152
|
type JarShopOrderConfirmationExchange {
|
|
129
153
|
credential: String!
|
|
130
154
|
confirmation: JarShopOrderConfirmation!
|
|
131
155
|
}
|
|
156
|
+
type JarShopGuestPaymentReconciliation {
|
|
157
|
+
status: String!
|
|
158
|
+
}
|
|
132
159
|
input JarShopLegalConfigurationInput {
|
|
133
160
|
languageCode: String!
|
|
134
161
|
termsVersion: String!
|
|
@@ -143,6 +170,7 @@ const schema = parse(`
|
|
|
143
170
|
extend type Mutation {
|
|
144
171
|
placeJarShopOrder(input: JarShopPlaceOrderInput!): JarShopPlaceOrderResult!
|
|
145
172
|
exchangeJarShopOrderConfirmation(token: String!): JarShopOrderConfirmationExchange
|
|
173
|
+
reconcileJarShopPayment(orderCode: String!): JarShopGuestPaymentReconciliation
|
|
146
174
|
updateJarShopLegalConfiguration(input: JarShopLegalConfigurationInput!): JarShopLegalConfiguration!
|
|
147
175
|
}
|
|
148
176
|
`);
|
|
@@ -255,10 +283,14 @@ class JarShopCheckoutResolver {
|
|
|
255
283
|
private readonly customerService: CustomerService,
|
|
256
284
|
@Inject(ShippingMethodService)
|
|
257
285
|
private readonly shippingMethodService: ShippingMethodService,
|
|
286
|
+
@Inject(PaymentMethodService)
|
|
287
|
+
private readonly paymentMethodService: PaymentMethodService,
|
|
258
288
|
@Inject(ProductVariantService)
|
|
259
289
|
private readonly productVariantService: ProductVariantService,
|
|
260
290
|
@Inject(TransactionalConnection)
|
|
261
291
|
private readonly connection: TransactionalConnection,
|
|
292
|
+
@Inject(JarShopPaymentReconciliationService)
|
|
293
|
+
private readonly paymentReconciliation: JarShopPaymentReconciliationService,
|
|
262
294
|
) {}
|
|
263
295
|
|
|
264
296
|
@Query()
|
|
@@ -328,6 +360,27 @@ class JarShopCheckoutResolver {
|
|
|
328
360
|
@Ctx() ctx: RequestContext,
|
|
329
361
|
@Args("orderCode") orderCode: string,
|
|
330
362
|
) {
|
|
363
|
+
const order = await this.orderForConfirmationCredential(ctx, orderCode);
|
|
364
|
+
return order ? toOrderConfirmation(order) : null;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Reconciliation is an explicit mutation: a protected confirmation query is
|
|
369
|
+
* cacheable and must never quietly grow a provider-side effect.
|
|
370
|
+
*/
|
|
371
|
+
@Mutation()
|
|
372
|
+
async reconcileJarShopPayment(
|
|
373
|
+
@Ctx() ctx: RequestContext,
|
|
374
|
+
@Args("orderCode") orderCode: string,
|
|
375
|
+
) {
|
|
376
|
+
const order = await this.orderForConfirmationCredential(ctx, orderCode);
|
|
377
|
+
return order ? this.paymentReconciliation.reconcileOrder(order.code) : null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
private async orderForConfirmationCredential(
|
|
381
|
+
ctx: RequestContext,
|
|
382
|
+
orderCode: string,
|
|
383
|
+
): Promise<Order | null> {
|
|
331
384
|
const credential = readCookieValue(
|
|
332
385
|
ctx.req?.headers.cookie ?? "",
|
|
333
386
|
CONFIRMATION_COOKIE_NAME,
|
|
@@ -340,18 +393,22 @@ class JarShopCheckoutResolver {
|
|
|
340
393
|
const record = await repository.findOne({
|
|
341
394
|
where: { tokenHash: hashConfirmationToken(credential) },
|
|
342
395
|
});
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
396
|
+
const credentialPresent = Boolean(
|
|
397
|
+
record &&
|
|
398
|
+
canReadConfirmationCredential({
|
|
346
399
|
expiresAt: record.expiresAt,
|
|
347
400
|
consumedAt: record.consumedAt,
|
|
348
|
-
})
|
|
349
|
-
)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return
|
|
354
|
-
|
|
401
|
+
}),
|
|
402
|
+
);
|
|
403
|
+
const order = credentialPresent
|
|
404
|
+
? await this.orderService.findOne(ctx, record!.orderId)
|
|
405
|
+
: null;
|
|
406
|
+
return canReconcilePaymentWithConfirmationCredential({
|
|
407
|
+
credentialPresent,
|
|
408
|
+
credentialOrderCode: order?.code,
|
|
409
|
+
requestedOrderCode: orderCode,
|
|
410
|
+
})
|
|
411
|
+
? (order ?? null)
|
|
355
412
|
: null;
|
|
356
413
|
}
|
|
357
414
|
|
|
@@ -455,6 +512,17 @@ class JarShopCheckoutResolver {
|
|
|
455
512
|
return failure("TEMPORARY_FAILURE", "Checkout attempt is not available");
|
|
456
513
|
}
|
|
457
514
|
|
|
515
|
+
const market = marketForChannel(ctx.channel.token);
|
|
516
|
+
const marketValidation = validateCheckoutMarket(input, market);
|
|
517
|
+
if (!marketValidation.ok) {
|
|
518
|
+
return await this.failAttempt(
|
|
519
|
+
repository,
|
|
520
|
+
attempt,
|
|
521
|
+
marketValidation.errorCode,
|
|
522
|
+
marketValidation.message,
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
458
526
|
const activeOrderReference = await this.activeOrderService.getActiveOrder(
|
|
459
527
|
ctx,
|
|
460
528
|
undefined,
|
|
@@ -496,7 +564,10 @@ class JarShopCheckoutResolver {
|
|
|
496
564
|
"Legal configuration is not available for this locale",
|
|
497
565
|
);
|
|
498
566
|
}
|
|
499
|
-
const shippingValidation = validateShippingSelection(
|
|
567
|
+
const shippingValidation = validateShippingSelection(
|
|
568
|
+
input,
|
|
569
|
+
market.countries,
|
|
570
|
+
);
|
|
500
571
|
if (!shippingValidation.ok) {
|
|
501
572
|
return await this.failAttempt(
|
|
502
573
|
repository,
|
|
@@ -564,12 +635,15 @@ class JarShopCheckoutResolver {
|
|
|
564
635
|
);
|
|
565
636
|
}
|
|
566
637
|
await this.orderService.addCustomerToOrder(ctx, activeOrder.id, customer);
|
|
638
|
+
const unsetShippingAddress = shouldUnsetShippingAddress(input);
|
|
567
639
|
if (input.shippingAddress) {
|
|
568
640
|
await this.orderService.setShippingAddress(
|
|
569
641
|
ctx,
|
|
570
642
|
activeOrder.id,
|
|
571
643
|
input.shippingAddress,
|
|
572
644
|
);
|
|
645
|
+
} else if (unsetShippingAddress) {
|
|
646
|
+
await this.orderService.unsetShippingAddress(ctx, activeOrder.id);
|
|
573
647
|
}
|
|
574
648
|
if (input.billingAddress) {
|
|
575
649
|
await this.orderService.setBillingAddress(
|
|
@@ -604,55 +678,77 @@ class JarShopCheckoutResolver {
|
|
|
604
678
|
"Selected shipping method is not eligible",
|
|
605
679
|
);
|
|
606
680
|
}
|
|
681
|
+
if (unsetShippingAddress) {
|
|
682
|
+
await this.connection.getRepository(ctx, JarShopShippingSelection).update(
|
|
683
|
+
{
|
|
684
|
+
channelId: Number(ctx.channelId),
|
|
685
|
+
orderCode: activeOrder.code,
|
|
686
|
+
status: "current",
|
|
687
|
+
},
|
|
688
|
+
{ status: "superseded" },
|
|
689
|
+
);
|
|
690
|
+
}
|
|
607
691
|
const paymentState = await this.orderService.transitionToState(
|
|
608
692
|
ctx,
|
|
609
693
|
activeOrder.id,
|
|
610
694
|
"ArrangingPayment",
|
|
611
695
|
);
|
|
612
696
|
if (isGraphQlErrorResult(paymentState)) {
|
|
697
|
+
const failure = mapPaymentTransitionFailure(paymentState.transitionError);
|
|
613
698
|
return await this.failAttempt(
|
|
614
699
|
repository,
|
|
615
700
|
attempt,
|
|
616
|
-
|
|
617
|
-
|
|
701
|
+
failure.errorCode,
|
|
702
|
+
failure.message,
|
|
618
703
|
);
|
|
619
704
|
}
|
|
620
|
-
|
|
705
|
+
let paymentFlow: "synchronous" | "redirect";
|
|
706
|
+
try {
|
|
707
|
+
const { handler } =
|
|
708
|
+
await this.paymentMethodService.getMethodAndOperations(
|
|
709
|
+
ctx,
|
|
710
|
+
input.paymentMethodCode,
|
|
711
|
+
);
|
|
712
|
+
paymentFlow = paymentFlowOf(handler);
|
|
713
|
+
} catch {
|
|
621
714
|
return await this.failAttempt(
|
|
622
715
|
repository,
|
|
623
716
|
attempt,
|
|
624
717
|
"PAYMENT_METHOD_INELIGIBLE",
|
|
625
|
-
"
|
|
718
|
+
"Selected payment method is not available",
|
|
626
719
|
);
|
|
627
720
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (isGraphQlErrorResult(paymentResult)) {
|
|
637
|
-
const paymentErrorCode = paymentResult.errorCode;
|
|
638
|
-
return await this.failAttempt(
|
|
639
|
-
repository,
|
|
640
|
-
attempt,
|
|
641
|
-
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
642
|
-
? "INSUFFICIENT_STOCK"
|
|
643
|
-
: "TEMPORARY_FAILURE",
|
|
644
|
-
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
645
|
-
? "Some cart items are no longer available in the requested quantity"
|
|
646
|
-
: "Payment could not be authorized",
|
|
721
|
+
if (paymentFlow === "synchronous") {
|
|
722
|
+
const added = await this.orderService.addPaymentToOrder(
|
|
723
|
+
ctx,
|
|
724
|
+
activeOrder.id,
|
|
725
|
+
{
|
|
726
|
+
method: input.paymentMethodCode,
|
|
727
|
+
metadata: { attemptId: input.attemptId },
|
|
728
|
+
},
|
|
647
729
|
);
|
|
730
|
+
if (isGraphQlErrorResult(added)) {
|
|
731
|
+
const paymentErrorCode = added.errorCode;
|
|
732
|
+
return await this.failAttempt(
|
|
733
|
+
repository,
|
|
734
|
+
attempt,
|
|
735
|
+
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
736
|
+
? "INSUFFICIENT_STOCK"
|
|
737
|
+
: "TEMPORARY_FAILURE",
|
|
738
|
+
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
739
|
+
? "Some cart items are no longer available in the requested quantity"
|
|
740
|
+
: "Payment could not be authorized",
|
|
741
|
+
);
|
|
742
|
+
}
|
|
648
743
|
}
|
|
649
744
|
const consentRepository = this.connection.getRepository(
|
|
650
745
|
ctx,
|
|
651
746
|
JarShopOrderConsent,
|
|
652
747
|
);
|
|
748
|
+
const orderId = Number(activeOrder.id);
|
|
653
749
|
await consentRepository.save(
|
|
654
750
|
consentRepository.create({
|
|
655
|
-
orderId
|
|
751
|
+
orderId,
|
|
656
752
|
termsVersion: legalConfiguration.termsVersion,
|
|
657
753
|
termsUrl: legalConfiguration.termsUrl,
|
|
658
754
|
privacyUrl: legalConfiguration.privacyUrl,
|
|
@@ -667,13 +763,13 @@ class JarShopCheckoutResolver {
|
|
|
667
763
|
await tokenRepository.save([
|
|
668
764
|
tokenRepository.create({
|
|
669
765
|
tokenHash: confirmations.browser.tokenHash,
|
|
670
|
-
orderId
|
|
766
|
+
orderId,
|
|
671
767
|
expiresAt: confirmations.browser.expiresAt,
|
|
672
768
|
consumedAt: null,
|
|
673
769
|
}),
|
|
674
770
|
tokenRepository.create({
|
|
675
771
|
tokenHash: confirmations.email.tokenHash,
|
|
676
|
-
orderId
|
|
772
|
+
orderId,
|
|
677
773
|
expiresAt: confirmations.email.expiresAt,
|
|
678
774
|
consumedAt: null,
|
|
679
775
|
}),
|
|
@@ -684,7 +780,7 @@ class JarShopCheckoutResolver {
|
|
|
684
780
|
);
|
|
685
781
|
const orderEmailSnapshotSource = await this.orderService.findOne(
|
|
686
782
|
ctx,
|
|
687
|
-
|
|
783
|
+
orderId,
|
|
688
784
|
[
|
|
689
785
|
"customer",
|
|
690
786
|
"lines.productVariant",
|
|
@@ -699,7 +795,7 @@ class JarShopCheckoutResolver {
|
|
|
699
795
|
await emailDeliveryRepository.save(
|
|
700
796
|
emailDeliveryRepository.create(
|
|
701
797
|
createPendingOrderEmailDelivery({
|
|
702
|
-
orderId
|
|
798
|
+
orderId,
|
|
703
799
|
checkoutAttemptId: attempt.attemptId,
|
|
704
800
|
snapshot: {
|
|
705
801
|
recipient: orderEmailSnapshotSource.customer.emailAddress,
|
|
@@ -708,9 +804,10 @@ class JarShopCheckoutResolver {
|
|
|
708
804
|
currencyCode: orderEmailSnapshotSource.currencyCode,
|
|
709
805
|
totalWithTax: orderEmailSnapshotSource.totalWithTax,
|
|
710
806
|
shippingWithTax: orderEmailSnapshotSource.shippingWithTax,
|
|
711
|
-
paymentMethod:
|
|
712
|
-
.
|
|
713
|
-
|
|
807
|
+
paymentMethod:
|
|
808
|
+
orderEmailSnapshotSource.payments
|
|
809
|
+
.map((payment) => payment.method)
|
|
810
|
+
.join(", ") || input.paymentMethodCode,
|
|
714
811
|
shippingMethod: orderEmailSnapshotSource.shippingLines
|
|
715
812
|
.map((line) =>
|
|
716
813
|
resolveLocalizedShippingMethodName(
|
|
@@ -720,6 +817,18 @@ class JarShopCheckoutResolver {
|
|
|
720
817
|
)
|
|
721
818
|
.filter(Boolean)
|
|
722
819
|
.join(", "),
|
|
820
|
+
shippingAddress: {
|
|
821
|
+
fullName: orderEmailSnapshotSource.shippingAddress.fullName ?? "",
|
|
822
|
+
streetLine1:
|
|
823
|
+
orderEmailSnapshotSource.shippingAddress.streetLine1 ?? "",
|
|
824
|
+
streetLine2:
|
|
825
|
+
orderEmailSnapshotSource.shippingAddress.streetLine2 ?? "",
|
|
826
|
+
postalCode:
|
|
827
|
+
orderEmailSnapshotSource.shippingAddress.postalCode ?? "",
|
|
828
|
+
city: orderEmailSnapshotSource.shippingAddress.city ?? "",
|
|
829
|
+
countryCode:
|
|
830
|
+
orderEmailSnapshotSource.shippingAddress.countryCode ?? "",
|
|
831
|
+
},
|
|
723
832
|
confirmationToken: confirmations.email.token,
|
|
724
833
|
lines: orderEmailSnapshotSource.lines.map((line) => ({
|
|
725
834
|
name: line.productVariant.name,
|
|
@@ -731,10 +840,10 @@ class JarShopCheckoutResolver {
|
|
|
731
840
|
),
|
|
732
841
|
);
|
|
733
842
|
attempt.status = "completed";
|
|
734
|
-
attempt.orderId =
|
|
843
|
+
attempt.orderId = orderId;
|
|
735
844
|
attempt.errorCode = null;
|
|
736
845
|
await repository.save(attempt);
|
|
737
|
-
const placedOrder = await this.orderService.findOne(ctx,
|
|
846
|
+
const placedOrder = await this.orderService.findOne(ctx, orderId);
|
|
738
847
|
return placedOrder
|
|
739
848
|
? success(
|
|
740
849
|
placedOrder,
|
|
@@ -743,7 +852,7 @@ class JarShopCheckoutResolver {
|
|
|
743
852
|
confirmations.browser.token,
|
|
744
853
|
)
|
|
745
854
|
: success(
|
|
746
|
-
|
|
855
|
+
activeOrder,
|
|
747
856
|
activeOrder.totalWithTax,
|
|
748
857
|
activeOrder.currencyCode,
|
|
749
858
|
confirmations.browser.token,
|
|
@@ -976,16 +1085,6 @@ function toLegalConfiguration(configuration: JarShopLegalConfiguration) {
|
|
|
976
1085
|
};
|
|
977
1086
|
}
|
|
978
1087
|
|
|
979
|
-
function toOrderConfirmation(order: Order) {
|
|
980
|
-
return {
|
|
981
|
-
orderId: order.id,
|
|
982
|
-
orderCode: order.code,
|
|
983
|
-
state: order.state,
|
|
984
|
-
totalWithTax: order.totalWithTax,
|
|
985
|
-
currencyCode: order.currencyCode,
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
|
|
989
1088
|
/**
|
|
990
1089
|
* JarShop's server-owned checkout seam.
|
|
991
1090
|
*
|
|
@@ -994,8 +1093,13 @@ function toOrderConfirmation(order: Order) {
|
|
|
994
1093
|
*/
|
|
995
1094
|
@VendurePlugin({
|
|
996
1095
|
dashboard: "./dashboard/index.tsx",
|
|
997
|
-
imports: [PluginCommonModule],
|
|
998
|
-
providers: [
|
|
1096
|
+
imports: [PluginCommonModule, JarShopRedirectPaymentPlugin],
|
|
1097
|
+
providers: [
|
|
1098
|
+
JarShopMarketChannelCheck,
|
|
1099
|
+
JarShopOperationCodeCheck,
|
|
1100
|
+
JarShopOrderEmailLifecycleOutbox,
|
|
1101
|
+
JarShopOrderEmailWorker,
|
|
1102
|
+
],
|
|
999
1103
|
configuration: (config) =>
|
|
1000
1104
|
registerJarShopOrderEmailWorkerTask(registerJarShopOrderLifecycle(config)),
|
|
1001
1105
|
entities: [
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { parseJarShopConfig } from "../../jarshop-config.js";
|
|
4
|
+
import {
|
|
5
|
+
marketsWithoutChannel,
|
|
6
|
+
reportMarketChannels,
|
|
7
|
+
} from "./market-channels.js";
|
|
8
|
+
|
|
9
|
+
const market = (code: string, currency: string, country: string) => ({
|
|
10
|
+
code,
|
|
11
|
+
channelToken: `${code}-token`,
|
|
12
|
+
defaultLanguage: "en",
|
|
13
|
+
languages: ["en"],
|
|
14
|
+
currency,
|
|
15
|
+
countries: [country],
|
|
16
|
+
domains: [`shop.example.${code}`],
|
|
17
|
+
});
|
|
18
|
+
const config = parseJarShopConfig({
|
|
19
|
+
defaultMarket: "sk",
|
|
20
|
+
markets: [market("sk", "EUR", "SK"), market("cz", "CZK", "CZ")],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("market Channel check", () => {
|
|
24
|
+
it("passes when every market token names a Channel", () => {
|
|
25
|
+
expect(
|
|
26
|
+
reportMarketChannels(config, ["sk-token", "cz-token", "other"], {
|
|
27
|
+
APP_ENV: "production",
|
|
28
|
+
}),
|
|
29
|
+
).toEqual({ level: "ok" });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("stops a production server that lacks a market Channel", () => {
|
|
33
|
+
expect(marketsWithoutChannel(config, ["sk-token"])).toHaveLength(1);
|
|
34
|
+
const report = reportMarketChannels(config, ["sk-token"], {
|
|
35
|
+
APP_ENV: "production",
|
|
36
|
+
});
|
|
37
|
+
expect(report).toMatchObject({ level: "error" });
|
|
38
|
+
expect(report).toHaveProperty(
|
|
39
|
+
"message",
|
|
40
|
+
expect.stringContaining('"cz" (channelToken "cz-token")'),
|
|
41
|
+
);
|
|
42
|
+
expect(
|
|
43
|
+
reportMarketChannels(config, ["sk-token"], {
|
|
44
|
+
APP_ENV: "production",
|
|
45
|
+
JARSHOP_MARKET_CHANNEL_CHECK: "warn",
|
|
46
|
+
}),
|
|
47
|
+
).toMatchObject({ level: "warn" });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("only warns in development, before the seed creates the Channels", () => {
|
|
51
|
+
expect(
|
|
52
|
+
reportMarketChannels(config, ["sk-token"], { APP_ENV: "dev" }),
|
|
53
|
+
).toMatchObject({
|
|
54
|
+
level: "warn",
|
|
55
|
+
message: expect.stringContaining("pnpm db:seed"),
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Inject,
|
|
3
|
+
Injectable,
|
|
4
|
+
type OnApplicationBootstrap,
|
|
5
|
+
} from "@nestjs/common";
|
|
6
|
+
import {
|
|
7
|
+
Channel,
|
|
8
|
+
Logger,
|
|
9
|
+
ProcessContext,
|
|
10
|
+
TransactionalConnection,
|
|
11
|
+
} from "@vendure/core";
|
|
12
|
+
|
|
13
|
+
import type { JarShopConfig, JarShopMarket } from "../../jarshop-config.js";
|
|
14
|
+
import { loadJarShopConfig } from "../../jarshop-config-loader.js";
|
|
15
|
+
|
|
16
|
+
const loggerContext = "JarShopMarkets";
|
|
17
|
+
|
|
18
|
+
export type MarketChannelReport =
|
|
19
|
+
| { readonly level: "ok" }
|
|
20
|
+
| { readonly level: "warn" | "error"; readonly message: string };
|
|
21
|
+
|
|
22
|
+
/** Markets whose `channelToken` names no existing Vendure Channel. */
|
|
23
|
+
export function marketsWithoutChannel(
|
|
24
|
+
config: JarShopConfig,
|
|
25
|
+
channelTokens: readonly string[],
|
|
26
|
+
): JarShopMarket[] {
|
|
27
|
+
const existing = new Set(channelTokens);
|
|
28
|
+
return config.markets.filter((market) => !existing.has(market.channelToken));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A market without its Channel would silently serve the default Channel's
|
|
33
|
+
* prices and carts. Outside development and test that stops the server;
|
|
34
|
+
* `JARSHOP_MARKET_CHANNEL_CHECK=warn` lets an operator start it once to create
|
|
35
|
+
* the Channels in the Dashboard.
|
|
36
|
+
*/
|
|
37
|
+
export function reportMarketChannels(
|
|
38
|
+
config: JarShopConfig,
|
|
39
|
+
channelTokens: readonly string[],
|
|
40
|
+
environment: NodeJS.ProcessEnv = process.env,
|
|
41
|
+
): MarketChannelReport {
|
|
42
|
+
const missing = marketsWithoutChannel(config, channelTokens);
|
|
43
|
+
if (missing.length === 0) return { level: "ok" };
|
|
44
|
+
const development =
|
|
45
|
+
environment.APP_ENV === "dev" || environment.APP_ENV === "test";
|
|
46
|
+
const lenient = environment.JARSHOP_MARKET_CHANNEL_CHECK === "warn";
|
|
47
|
+
const list = missing
|
|
48
|
+
.map((market) => `"${market.code}" (channelToken "${market.channelToken}")`)
|
|
49
|
+
.join(", ");
|
|
50
|
+
const remedy = development
|
|
51
|
+
? "Run `pnpm db:seed` to create them."
|
|
52
|
+
: "Create a Channel with exactly that token for each market in the Dashboard (Settings > Channels). " +
|
|
53
|
+
"To start the server once for that, set JARSHOP_MARKET_CHANNEL_CHECK=warn.";
|
|
54
|
+
return {
|
|
55
|
+
level: development || lenient ? "warn" : "error",
|
|
56
|
+
message: `jarshop.config.ts declares markets without a Vendure Channel: ${list}. ${remedy}`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Checks on server start that every configured market has its Channel. */
|
|
61
|
+
@Injectable()
|
|
62
|
+
export class JarShopMarketChannelCheck implements OnApplicationBootstrap {
|
|
63
|
+
constructor(
|
|
64
|
+
@Inject(TransactionalConnection)
|
|
65
|
+
private readonly connection: TransactionalConnection,
|
|
66
|
+
@Inject(ProcessContext)
|
|
67
|
+
private readonly processContext: ProcessContext,
|
|
68
|
+
) {}
|
|
69
|
+
|
|
70
|
+
async onApplicationBootstrap(): Promise<void> {
|
|
71
|
+
if (!this.processContext.isServer) return;
|
|
72
|
+
const channels = await this.connection.rawConnection
|
|
73
|
+
.getRepository(Channel)
|
|
74
|
+
.find({ select: { token: true } });
|
|
75
|
+
const report = reportMarketChannels(
|
|
76
|
+
loadJarShopConfig(),
|
|
77
|
+
channels.map((channel) => channel.token),
|
|
78
|
+
);
|
|
79
|
+
if (report.level === "ok") return;
|
|
80
|
+
if (report.level === "warn") {
|
|
81
|
+
Logger.warn(report.message, loggerContext);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
Logger.error(report.message, loggerContext);
|
|
85
|
+
throw new Error(report.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Inject,
|
|
3
|
+
Injectable,
|
|
4
|
+
type OnApplicationBootstrap,
|
|
5
|
+
} from "@nestjs/common";
|
|
6
|
+
import { ConfigService } from "@vendure/core";
|
|
7
|
+
|
|
8
|
+
import { assertUniqueOperationCodes } from "../../operation-codes.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Plugins in `features.plugins`, and Feature plugins such as the redirect
|
|
12
|
+
* payment plugin, may add payment handlers or shipping operations in their own
|
|
13
|
+
* `configuration` hook, after `createVendureConfig` has checked the client's
|
|
14
|
+
* lists. This check reads Vendure's final configuration on startup, so a code
|
|
15
|
+
* that a plugin registers twice, or that clashes with a client operation,
|
|
16
|
+
* stops the server instead of silently shadowing the other one.
|
|
17
|
+
*/
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class JarShopOperationCodeCheck implements OnApplicationBootstrap {
|
|
20
|
+
constructor(
|
|
21
|
+
@Inject(ConfigService) private readonly configService: ConfigService,
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
onApplicationBootstrap(): void {
|
|
25
|
+
const { paymentOptions, shippingOptions } = this.configService;
|
|
26
|
+
assertUniqueOperationCodes(
|
|
27
|
+
{
|
|
28
|
+
"Payment method handler": paymentOptions.paymentMethodHandlers,
|
|
29
|
+
"Shipping eligibility checker":
|
|
30
|
+
shippingOptions.shippingEligibilityCheckers ?? [],
|
|
31
|
+
"Shipping calculator": shippingOptions.shippingCalculators ?? [],
|
|
32
|
+
},
|
|
33
|
+
"Duplicate operation codes in the Vendure configuration, including operations added by plugins",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import type { FulfillmentLifecycleEmailKind } from "./order-email-outbox.js";
|
|
10
10
|
|
|
11
11
|
export type ConfigurableOrderEmailKind =
|
|
12
|
-
FulfillmentLifecycleEmailKind | "order-cancelled";
|
|
12
|
+
FulfillmentLifecycleEmailKind | "order-cancelled" | "invoice-issued";
|
|
13
13
|
|
|
14
14
|
export type OrderEmailShippingMethodConfiguration = {
|
|
15
15
|
code: string;
|