@coras-io/embed 0.12.0 → 0.13.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +18 -8
  3. package/dist/components/attraction-card/base/attraction-card.mixin.js +3 -3
  4. package/dist/components/attraction-card/base/attraction-card.styles.js +8 -0
  5. package/dist/components/button/button.component.d.ts +6 -0
  6. package/dist/components/button/button.component.js +31 -8
  7. package/dist/components/button/button.styles.js +8 -1
  8. package/dist/contexts/basket/basket.provider.js +1 -17
  9. package/dist/core/color-scheme.d.ts +0 -1
  10. package/dist/core/color-scheme.js +4 -6
  11. package/dist/core/utils/mount-root.d.ts +1 -0
  12. package/dist/core/utils/mount-root.js +15 -0
  13. package/dist/core/utils/redaction.js +5 -0
  14. package/dist/errors.js +2 -2
  15. package/dist/mixins/coinbase.mixin.d.ts +12 -2
  16. package/dist/mixins/coinbase.mixin.js +23 -20
  17. package/dist/sdk/mount.js +15 -13
  18. package/dist/sdk/redaction.d.ts +7 -1
  19. package/dist/sdk/redaction.js +32 -1
  20. package/dist/sdk/url.d.ts +44 -2
  21. package/dist/sdk/url.js +54 -6
  22. package/dist/sdk/validation.d.ts +1 -6
  23. package/dist/sdk/validation.js +7 -7
  24. package/dist/views/details-page/partials/location-categories/location-categories.component.d.ts +2 -1
  25. package/dist/views/details-page/partials/location-categories/location-categories.component.js +18 -5
  26. package/dist/views/payment-page/controllers/crypto-auth.controller.js +4 -4
  27. package/dist/views/payment-page/controllers/crypto-transfer.controller.d.ts +4 -4
  28. package/dist/views/payment-page/controllers/crypto-transfer.controller.js +9 -6
  29. package/dist/views/payment-page/controllers/stripe-payment.controller.d.ts +4 -1
  30. package/dist/views/payment-page/controllers/stripe-payment.controller.js +38 -10
  31. package/dist/views/payment-page/partials/activity-details/activity-details.component.js +1 -1
  32. package/dist/views/payment-page/partials/confirmation/confirmation.component.d.ts +2 -0
  33. package/dist/views/payment-page/partials/confirmation/confirmation.component.js +26 -6
  34. package/dist/views/payment-page/partials/confirmation/confirmation.styles.js +4 -0
  35. package/dist/views/payment-page/partials/hotel-pickup-field/hotel-pickup-field.component.js +3 -1
  36. package/dist/views/payment-page/partials/hotel-pickup-list/hotel-pickup-list.component.js +1 -1
  37. package/dist/views/payment-page/payment-page.component.d.ts +2 -1
  38. package/dist/views/payment-page/payment-page.component.js +45 -25
  39. package/dist/views/payment-page/payment-page.utils.d.ts +2 -0
  40. package/dist/views/payment-page/payment-page.utils.js +5 -0
  41. package/dist/views/suggestion-widget/suggestion-widget.component.d.ts +1 -1
  42. package/dist/views/suggestion-widget/suggestion-widget.component.js +11 -4
  43. package/package.json +1 -1
@@ -27,7 +27,8 @@ import "../../components/transfer-modal/transfer-modal.js";
27
27
  import "../../components/crypto-auth-modal/crypto-auth-modal.js";
28
28
  import { BaseMixin } from "../../mixins/base.mixin.js";
29
29
  import { ErrorModalMixin } from "../../mixins/error-modal.mixin.js";
30
- import { CoinbaseMixin } from "../../mixins/coinbase.mixin.js";
30
+ import { formatUnits } from "viem/utils";
31
+ import { CoinbaseMixin, hasSufficientBalance, sumTokenAmountsInBaseUnits, TOKEN_DECIMALS, } from "../../mixins/coinbase.mixin.js";
31
32
  import styles from "./payment-page.styles.js";
32
33
  import "../../components/bottom-drawer/bottom-drawer.js";
33
34
  import "../../components/expiration-timer/expiration-timer.js";
@@ -105,7 +106,7 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
105
106
  });
106
107
  this.cryptoTransferController = new CryptoTransferController(this, {
107
108
  logger: this.controllerLogger,
108
- transferTokens: (amount) => this.transferTokens(amount),
109
+ transferTokens: (amountWei) => this.transferTokens(amountWei),
109
110
  confirmReservation: async () => {
110
111
  // Every controller-driven confirmation follows an on-chain transfer,
111
112
  // including recovery on page load where the selector still says card.
@@ -128,8 +129,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
128
129
  submitMfaVerification: (code) => this.submitMfaVerification(code),
129
130
  initiateMfaVerification: () => this.initiateMfaVerification(),
130
131
  resetMfaVerificationState: () => this.resetMfaVerificationState(),
131
- getPendingTransferAmount: () => this.pendingTransferAmount,
132
- getCurrentCartTotal: () => String(this.getReservationsLoyaltyTotal("pay")),
132
+ getPendingTransferAmountWei: () => this.pendingTransferAmountWei,
133
+ getCurrentCartTotal: () => formatUnits(this.getReservationsPayAmountWei() ?? 0n, TOKEN_DECIMALS),
133
134
  setTransactionId: (id) => {
134
135
  this.transactionId = id;
135
136
  },
@@ -311,8 +312,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
311
312
  const { data } = await this.getApiService().fetchReservations(bookingSession);
312
313
  return data || { reservations: [] };
313
314
  }
314
- catch {
315
- this.logger.error("Failed to fetch reservations");
315
+ catch (error) {
316
+ this.logger.error("Failed to fetch reservations", error);
316
317
  return { reservations: [] };
317
318
  }
318
319
  },
@@ -406,8 +407,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
406
407
  return;
407
408
  }
408
409
  await this.syncEmailFromCoinbase();
409
- const tokensAmount = String(this.getReservationsLoyaltyTotal("pay"));
410
- this.pendingTransferAmount = tokensAmount;
410
+ this.pendingTransferAmountWei =
411
+ this.getReservationsPayAmountWei() ?? 0n;
411
412
  // Check for a valid pending transfer from a previous attempt.
412
413
  // If found (same amount, not stale, checksum OK), retry the API
413
414
  // confirmation instead of initiating a new on-chain transfer.
@@ -440,8 +441,17 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
440
441
  this.dispatchPaymentFailure();
441
442
  return;
442
443
  }
443
- clientSecret = confirmationResult
444
- .client_secret;
444
+ if (confirmationResult.client_secret === null) {
445
+ this.logger.error("Stripe reservation returned no client secret", {
446
+ transactionId: confirmationResult.transaction_id,
447
+ });
448
+ this.stripeController.abortAuthorizedPayment();
449
+ this.stripeController.cardError = msg("An unexpected error occurred. Please try again.");
450
+ this.flowController.transition("failed");
451
+ this.dispatchPaymentFailure();
452
+ return;
453
+ }
454
+ clientSecret = confirmationResult.client_secret;
445
455
  }
446
456
  this.flowController.transition("processing_payment");
447
457
  {
@@ -634,11 +644,20 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
634
644
  hasReservations() {
635
645
  return (this.reservationsTask.value?.reservations?.length ?? 0) > 0;
636
646
  }
637
- getReservationsLoyaltyTotal(field) {
647
+ getReservationsEarnTotal() {
638
648
  const reservations = this.reservationsTask?.value?.reservations;
639
649
  if (!reservations?.length)
640
650
  return 0;
641
- return reservations.reduce((sum, reservation) => sum + getLoyaltyAmount(reservation.loyalty, field), 0);
651
+ return reservations.reduce((sum, reservation) => sum + getLoyaltyAmount(reservation.loyalty, "earn"), 0);
652
+ }
653
+ getReservationsPayAmountWei() {
654
+ const reservations = this.reservationsTask?.value?.reservations ?? [];
655
+ try {
656
+ return sumTokenAmountsInBaseUnits(reservations.map((reservation) => reservation.loyalty?.pay?.FIDA ?? 0));
657
+ }
658
+ catch {
659
+ return null;
660
+ }
642
661
  }
643
662
  formatEarnedTokens() {
644
663
  if (!this.earnedTokensToIssue)
@@ -826,8 +845,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
826
845
  return !!(this.formController.formValues.email || this.coinbaseSession?.email);
827
846
  }
828
847
  renderPaymentDetailsStep() {
829
- const fidaAmount = this.getReservationsLoyaltyTotal("pay");
830
- const formattedFidaAmount = new Intl.NumberFormat(this.locale).format(isNaN(fidaAmount) ? 0 : fidaAmount);
848
+ const fidaAmountWei = this.getReservationsPayAmountWei() ?? 0n;
849
+ const formattedFidaAmount = new Intl.NumberFormat(this.locale).format(Number(formatUnits(fidaAmountWei, TOKEN_DECIMALS)));
831
850
  const termsLabel = this.paymentType === "crypto"
832
851
  ? msg("I confirm I have read and accept FIDA's Terms & Conditions")
833
852
  : msg("I confirm I have read and accept Coras's Terms & Conditions");
@@ -835,9 +854,9 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
835
854
  const isLoggedIn = !!this.coinbaseSession;
836
855
  const isFullyAuthenticated = isLoggedIn && this.isMfaEnrolled;
837
856
  const balance = this.balanceTask.value;
838
- const formattedBalance = balance != null ? this.formatTokenBalance(balance) : "0";
839
- const currentBalance = Number(formattedBalance);
840
- const insufficientBalance = balance === null || balance === 0n || currentBalance < fidaAmount;
857
+ const insufficientBalance = balance === null ||
858
+ balance === 0n ||
859
+ !hasSufficientBalance(balance ?? 0n, fidaAmountWei);
841
860
  return html `
842
861
  ${this.renderBillingAddress()}
843
862
  <div class="footer">
@@ -1182,8 +1201,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1182
1201
  });
1183
1202
  return null;
1184
1203
  }
1185
- catch {
1186
- this.logger.error("Failed to update pickup_id for reservation");
1204
+ catch (error) {
1205
+ this.logger.error("Failed to update pickup_id for reservation", error);
1187
1206
  return fieldName;
1188
1207
  }
1189
1208
  }));
@@ -1479,8 +1498,9 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1479
1498
  }
1480
1499
  renderPaymentTypeSelector() {
1481
1500
  const data = this.reservationsTask.value;
1482
- const payWithTokens = String(this.getReservationsLoyaltyTotal("pay"));
1483
- const earnWithTokens = String(this.getReservationsLoyaltyTotal("earn"));
1501
+ const payAmountWei = this.getReservationsPayAmountWei() ?? 0n;
1502
+ const payWithTokens = formatUnits(payAmountWei, TOKEN_DECIMALS);
1503
+ const earnWithTokens = String(this.getReservationsEarnTotal());
1484
1504
  const price = convertToLocaleCurrency({
1485
1505
  value: data?.total_price || 0,
1486
1506
  locale: this.locale,
@@ -1493,9 +1513,9 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1493
1513
  const balance = this.balanceTask.value;
1494
1514
  const hasBalance = balance != null;
1495
1515
  const formattedBalance = hasBalance ? this.formatTokenBalance(balance) : "";
1496
- const currentBalance = Number(formattedBalance || 0);
1497
- const fidaAmount = Number(payWithTokens || 0);
1498
- const insufficientBalance = !hasBalance || balance === 0n || currentBalance < fidaAmount;
1516
+ const insufficientBalance = !hasBalance ||
1517
+ balance === 0n ||
1518
+ !hasSufficientBalance(balance, payAmountWei);
1499
1519
  return html `
1500
1520
  <coras-payment-type-selector
1501
1521
  .currency=${this.currency}
@@ -1841,7 +1861,7 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1841
1861
  return html `
1842
1862
  <coras-transfer-modal
1843
1863
  ?open=${this.cryptoTransferController.showTransferModal}
1844
- amount=${this.pendingTransferAmount}
1864
+ amount=${formatUnits(this.pendingTransferAmountWei, TOKEN_DECIMALS)}
1845
1865
  masked-phone=${maskedPhone}
1846
1866
  modal-state=${this.cryptoTransferController.transferModalState}
1847
1867
  mfa-error=${this.cryptoTransferController.mfaVerificationError}
@@ -157,6 +157,8 @@ export declare const isApiError: (err: unknown) => err is ApiError;
157
157
  * Callers should provide a domain-specific fallback.
158
158
  */
159
159
  export declare function sanitizeErrorMessage(error: unknown, fallback: string): string;
160
+ /** A redacted message for logging an unknown error without the error object. */
161
+ export declare function redactedErrorMessage(error: unknown): string;
160
162
  /**
161
163
  * Handles API errors by mapping them to form fields
162
164
  */
@@ -1,6 +1,7 @@
1
1
  import { msg } from "@lit/localize";
2
2
  import { apiGet } from "../../core/api/queries.js";
3
3
  import { getLoyaltyAmount } from "../../core/utils/loyalty.js";
4
+ import { redactString } from "../../core/utils/redaction.js";
4
5
  import { getLoyaltyFieldName } from "./payment-page.loyalty.js";
5
6
  import { APIError } from "../../core/api/api-error.js";
6
7
  import { parsePhoneNumberFromString, } from "libphonenumber-js/min";
@@ -550,6 +551,10 @@ export function sanitizeErrorMessage(error, fallback) {
550
551
  }
551
552
  return message;
552
553
  }
554
+ /** A redacted message for logging an unknown error without the error object. */
555
+ export function redactedErrorMessage(error) {
556
+ return redactString(error instanceof Error ? error.message : String(error));
557
+ }
553
558
  /**
554
559
  * Handles API errors by mapping them to form fields
555
560
  */
@@ -33,7 +33,7 @@ export declare class CorasSuggestionWidget extends CorasSuggestionWidget_base {
33
33
  private humanize;
34
34
  private suggestionsTask;
35
35
  private cardTarget;
36
- private handleExploreCardClick;
36
+ private exploreTarget;
37
37
  private renderCard;
38
38
  private renderExploreCard;
39
39
  private renderContent;
@@ -22,6 +22,7 @@ import { BaseMixin } from "../../mixins/base.mixin.js";
22
22
  import { apiGet } from "../../core/api/queries.js";
23
23
  import { convertToLocaleCurrency } from "../../core/currency/index.js";
24
24
  import { renderLoyaltyBadge } from "../../components/loyalty-badge/loyalty-badge.utils.js";
25
+ import { claimLinkClick } from "../../core/utils/link-click.js";
25
26
  let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitElement) {
26
27
  constructor() {
27
28
  super(...arguments);
@@ -70,14 +71,14 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
70
71
  currency: this.currency,
71
72
  };
72
73
  }
73
- handleExploreCardClick(country, city) {
74
- this.dispatchPageUpdate({
74
+ exploreTarget(country, city) {
75
+ return {
75
76
  page: "landing",
76
77
  country,
77
78
  city,
78
79
  locale: this.locale,
79
80
  currency: this.currency,
80
- });
81
+ };
81
82
  }
82
83
  renderCard(card) {
83
84
  const price = card.price[this.currency];
@@ -125,6 +126,8 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
125
126
  imageExtension: "png",
126
127
  params: { auto: "compress,format", ar: "2:3", fit: "crop" },
127
128
  });
129
+ const target = this.exploreTarget(country, city);
130
+ const href = this.pageUpdateHref(target);
128
131
  return html `
129
132
  <coras-explore-card
130
133
  image=${imageUrl}
@@ -134,7 +137,11 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
134
137
  <coras-button
135
138
  slot="button"
136
139
  variant="outlined"
137
- @click=${() => this.handleExploreCardClick(country, city)}
140
+ href=${ifDefined(href)}
141
+ @click=${(event) => {
142
+ if (!href || claimLinkClick(event))
143
+ this.dispatchPageUpdate(target);
144
+ }}
138
145
  >
139
146
  ${msg("See all activities")}
140
147
  </coras-button>
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
23
- "version": "0.12.0",
23
+ "version": "0.13.1",
24
24
  "private": false,
25
25
  "homepage": "https://docs.coras.io",
26
26
  "bugs": {