@jarwizz/create-jarshop 0.1.3 → 0.1.4

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.
@@ -16,6 +16,19 @@ export function createConfirmationToken(now = Date.now()) {
16
16
  };
17
17
  }
18
18
 
19
+ /**
20
+ * Independent one-time credentials for the browser hand-off and e-mail link.
21
+ *
22
+ * Checkout exchanges the browser token immediately. Reusing it in the outbox
23
+ * would make the e-mail link a replay before the customer receives it.
24
+ */
25
+ export function createConfirmationTokenPair(now = Date.now()) {
26
+ return {
27
+ browser: createConfirmationToken(now),
28
+ email: createConfirmationToken(now),
29
+ };
30
+ }
31
+
19
32
  export function canExchangeConfirmationToken(input: {
20
33
  expiresAt: Date;
21
34
  consumedAt: Date | null;
@@ -27,6 +27,7 @@ import {
27
27
  canExchangeConfirmationToken,
28
28
  canReadConfirmationCredential,
29
29
  createConfirmationToken,
30
+ createConfirmationTokenPair,
30
31
  hashConfirmationToken,
31
32
  readCookieValue,
32
33
  } from "./confirmation.js";
@@ -613,19 +614,25 @@ class JarShopCheckoutResolver {
613
614
  acceptedAt: new Date(),
614
615
  }),
615
616
  );
616
- const confirmation = createConfirmationToken();
617
+ const confirmations = createConfirmationTokenPair();
617
618
  const tokenRepository = this.connection.getRepository(
618
619
  ctx,
619
620
  JarShopConfirmationToken,
620
621
  );
621
- await tokenRepository.save(
622
+ await tokenRepository.save([
622
623
  tokenRepository.create({
623
- tokenHash: confirmation.tokenHash,
624
+ tokenHash: confirmations.browser.tokenHash,
624
625
  orderId: Number(paymentResult.id),
625
- expiresAt: confirmation.expiresAt,
626
+ expiresAt: confirmations.browser.expiresAt,
626
627
  consumedAt: null,
627
628
  }),
628
- );
629
+ tokenRepository.create({
630
+ tokenHash: confirmations.email.tokenHash,
631
+ orderId: Number(paymentResult.id),
632
+ expiresAt: confirmations.email.expiresAt,
633
+ consumedAt: null,
634
+ }),
635
+ ]);
629
636
  const emailDeliveryRepository = this.connection.getRepository(
630
637
  ctx,
631
638
  JarShopOrderEmailDelivery,
@@ -636,7 +643,7 @@ class JarShopCheckoutResolver {
636
643
  orderId: Number(paymentResult.id),
637
644
  checkoutAttemptId: attempt.attemptId,
638
645
  languageCode: input.languageCode,
639
- confirmationToken: confirmation.token,
646
+ confirmationToken: confirmations.email.token,
640
647
  }),
641
648
  ),
642
649
  );
@@ -650,13 +657,13 @@ class JarShopCheckoutResolver {
650
657
  placedOrder,
651
658
  activeOrder.totalWithTax,
652
659
  activeOrder.currencyCode,
653
- confirmation.token,
660
+ confirmations.browser.token,
654
661
  )
655
662
  : success(
656
663
  paymentResult,
657
664
  activeOrder.totalWithTax,
658
665
  activeOrder.currencyCode,
659
- confirmation.token,
666
+ confirmations.browser.token,
660
667
  );
661
668
  }
662
669
 
@@ -1,3 +1,3 @@
1
1
  {
2
- "digest": "sha256:16e696efe1452c2aeac287d87541d38e5254828686eae16084e1562c0e5a6bd1"
2
+ "digest": "sha256:b48464cda2b930fe6992452e539c4f5296ae82c2c8e673591766f263f264b129"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jarwizz/create-jarshop",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "Generate an independent JarShop Client Project.",
6
6
  "license": "MIT",