@fluid-app/portal-sdk 0.1.1253 → 0.1.1255

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.
@@ -35,7 +35,7 @@ import "./BulletListWidget-Bbn6AV3M.mjs";
35
35
  import "./preview-context-D8_bpnt8.mjs";
36
36
  import "./CalendarWidget-DOBLqQFM.mjs";
37
37
  import "./error-state-D1lbEcUB.mjs";
38
- import { n as subscriptionsScreenPropertySchema, t as SubscriptionsScreen } from "./SubscriptionsScreen-DdVt_D0C.mjs";
38
+ import { n as subscriptionsScreenPropertySchema, t as SubscriptionsScreen } from "./SubscriptionsScreen-yah2TAvw.mjs";
39
39
  import "./WidgetLoadingSkeleton-CH2gVgkd.mjs";
40
40
  import "./CardWidget-CEwOwcPG.mjs";
41
41
  import "./purify.es-Ckb34wqr.mjs";
@@ -70,6 +70,6 @@ require("./translation-adapter-B2E8epKq.cjs");
70
70
  require("./sidebar-BTwncyT-.cjs");
71
71
  require("./ScreenHeaderContext-fJKG4BUl.cjs");
72
72
  require("./use-portal-card-add-3ds-flow-CqDD5rFg.cjs");
73
- const require_SubscriptionsScreen = require("./SubscriptionsScreen-0zJvMW3L.cjs");
73
+ const require_SubscriptionsScreen = require("./SubscriptionsScreen-Cl4wCwAq.cjs");
74
74
  exports.SubscriptionsScreen = require_SubscriptionsScreen.SubscriptionsScreen;
75
75
  exports.subscriptionsScreenPropertySchema = require_SubscriptionsScreen.subscriptionsScreenPropertySchema;
@@ -3615,6 +3615,7 @@ function createPortalBundlesAdapter(client) {
3615
3615
  };
3616
3616
  if (params.address_id !== void 0) bundle.address_id = params.address_id;
3617
3617
  if (params.volume_rep_id !== void 0) bundle.volume_rep_id = params.volume_rep_id;
3618
+ if (params.confirm_early_order !== void 0) bundle.confirm_early_order = params.confirm_early_order;
3618
3619
  if (params.timezone !== void 0) bundle.timezone = params.timezone;
3619
3620
  const bff = (await subscriptionBundlesCreate({
3620
3621
  client,
@@ -3968,6 +3969,24 @@ function billDateMovedNotice(pickedDate, savedDate, t, locale, timeZone) {
3968
3969
  return day ? t("bill_date_moved_notice", { date: formatLongDate$1(parseIsoDate(day), locale) }) : null;
3969
3970
  }
3970
3971
  //#endregion
3972
+ //#region ../../subscriptions/core/src/utils/early-order-refusal.ts
3973
+ /**
3974
+ * Reads an `early_order_confirmation_required` refusal from a thrown API
3975
+ * error, or null for any other error. The client asks the shopper, then
3976
+ * repeats the write with `confirm_early_order`. Structural, so packages that
3977
+ * cannot import an API client can read it.
3978
+ */
3979
+ function readEarlyOrderRefusal(error) {
3980
+ if (typeof error !== "object" || error === null) return null;
3981
+ const { body } = error;
3982
+ const meta = body?.meta;
3983
+ if (meta?.code !== "early_order_confirmation_required" || typeof meta.scheduled_date !== "string") return null;
3984
+ return {
3985
+ scheduledDate: meta.scheduled_date,
3986
+ lastBillDate: typeof meta.last_bill_date === "string" ? meta.last_bill_date : null
3987
+ };
3988
+ }
3989
+ //#endregion
3971
3990
  //#region src/subscriptions/subscription-card-add-success.ts
3972
3991
  /**
3973
3992
  * Build the subscription create-payment-method onSuccess handler. On
@@ -5556,6 +5575,7 @@ function BundleSubscriptionsDrawer({ open, onOpenChange, subscriptions: subscrip
5556
5575
  const { t, locale } = useSubscriptionsTranslation();
5557
5576
  const { isMobile } = useSidebar();
5558
5577
  const [confirmingEarlyOrder, setConfirmingEarlyOrder] = useState(false);
5578
+ const [earlyOrderRefusal, setEarlyOrderRefusal] = useState(null);
5559
5579
  const form = useBundleForm({
5560
5580
  subscriptions: subscriptionList,
5561
5581
  addresses,
@@ -5565,6 +5585,7 @@ function BundleSubscriptionsDrawer({ open, onOpenChange, subscriptions: subscrip
5565
5585
  });
5566
5586
  const handleClose = () => {
5567
5587
  setConfirmingEarlyOrder(false);
5588
+ setEarlyOrderRefusal(null);
5568
5589
  onOpenChange(false);
5569
5590
  };
5570
5591
  const handleNext = () => {
@@ -5580,7 +5601,7 @@ function BundleSubscriptionsDrawer({ open, onOpenChange, subscriptions: subscrip
5580
5601
  const scheduledDay = member.next_bill_date ? calendarDayIso(member.next_bill_date) : "";
5581
5602
  return selectedDayIso !== "" && scheduledDay !== "" && scheduledDay > selectedDayIso;
5582
5603
  });
5583
- const earliestAffectedDay = affectedMembers.map((member) => calendarDayIso(member.next_bill_date)).sort()[0] ?? "";
5604
+ const earliestAffectedDay = earlyOrderRefusal?.scheduledDate ?? affectedMembers.map((member) => calendarDayIso(member.next_bill_date)).sort()[0] ?? "";
5584
5605
  const formatConfirmDay = (iso, style) => {
5585
5606
  const [year, month, day] = iso.slice(0, 10).split("-").map(Number);
5586
5607
  return new Intl.DateTimeFormat(locale, { dateStyle: style }).format(new Date(year ?? 1970, (month ?? 1) - 1, day ?? 1));
@@ -5591,12 +5612,20 @@ function BundleSubscriptionsDrawer({ open, onOpenChange, subscriptions: subscrip
5591
5612
  setConfirmingEarlyOrder(true);
5592
5613
  return;
5593
5614
  }
5594
- await onSubmit({
5595
- subscription_tokens: Array.from(form.selectedTokens),
5596
- next_bill_date: form.formattedDate,
5597
- address_id: form.selectedAddressId,
5598
- payment_method_id: form.selectedPaymentMethodId
5599
- });
5615
+ try {
5616
+ await onSubmit({
5617
+ subscription_tokens: Array.from(form.selectedTokens),
5618
+ next_bill_date: form.formattedDate,
5619
+ address_id: form.selectedAddressId,
5620
+ payment_method_id: form.selectedPaymentMethodId,
5621
+ confirm_early_order: confirmingEarlyOrder
5622
+ });
5623
+ } catch (error) {
5624
+ const refusal = readEarlyOrderRefusal(error);
5625
+ if (!refusal) throw error;
5626
+ setEarlyOrderRefusal(refusal);
5627
+ setConfirmingEarlyOrder(true);
5628
+ }
5600
5629
  };
5601
5630
  const canLeaveStep1 = form.canProceedFromStep1 && !isLoadingSubscriptions;
5602
5631
  const nextDisabled = form.step === 1 && !canLeaveStep1 || form.step === 2 && !form.canProceedFromStep2 || form.step === 3 && !form.canProceedFromStep3;
@@ -5939,10 +5968,15 @@ function SubscriptionsListScreenInner({ customerId, isLoadingCustomer, onToast }
5939
5968
  subscription_tokens: params.subscription_tokens,
5940
5969
  next_bill_date: params.next_bill_date,
5941
5970
  address_id: params.address_id,
5971
+ confirm_early_order: params.confirm_early_order,
5942
5972
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
5943
5973
  });
5944
5974
  movedNotice = billDateMovedNotice(params.next_bill_date, bundle.next_bill_date, t, locale);
5945
5975
  } catch (err) {
5976
+ if (readEarlyOrderRefusal(err)) {
5977
+ setIsBundling(false);
5978
+ throw err;
5979
+ }
5946
5980
  const message = (isApiError(err) && err.status >= 400 && err.status < 500 ? err.message : void 0) ?? t("bundle_failed");
5947
5981
  onToast?.(message, "error");
5948
5982
  setIsBundling(false);
@@ -6925,6 +6959,7 @@ function EditBillDateDialog({ open, onOpenChange, onConfirm, isLoading, errorMes
6925
6959
  const [selectedDate, setSelectedDate] = useState(void 0);
6926
6960
  const [calendarOpen, setCalendarOpen] = useState(false);
6927
6961
  const [confirmingEarlyOrder, setConfirmingEarlyOrder] = useState(false);
6962
+ const [earlyOrderRefusal, setEarlyOrderRefusal] = useState(null);
6928
6963
  const [popoverContainer, setPopoverContainer] = useState(null);
6929
6964
  const today = /* @__PURE__ */ new Date();
6930
6965
  today.setHours(0, 0, 0, 0);
@@ -6987,13 +7022,23 @@ function EditBillDateDialog({ open, onOpenChange, onConfirm, isLoading, errorMes
6987
7022
  setSelectedDate(isBlackoutDay(seeded, blackoutDays) ? void 0 : seeded);
6988
7023
  } else setSelectedDate(void 0);
6989
7024
  }, [open, currentNextBillDate]);
6990
- const scheduledDayIso = currentNextBillDate ? calendarDayIso(currentNextBillDate, timezone) : "";
6991
- const lastOrderDayIso = currentLastBillDate ? calendarDayIso(currentLastBillDate, timezone) : "";
7025
+ const scheduledDate = earlyOrderRefusal?.scheduledDate ?? currentNextBillDate;
7026
+ const lastBillDate = earlyOrderRefusal ? earlyOrderRefusal.lastBillDate : currentLastBillDate;
7027
+ const scheduledDayIso = scheduledDate ? calendarDayIso(scheduledDate, timezone) : "";
7028
+ const lastOrderDayIso = lastBillDate ? calendarDayIso(lastBillDate, timezone) : "";
6992
7029
  const selectedDayIso = selectedDate ? format(selectedDate, "yyyy-MM-dd") : "";
6993
7030
  const placesEarlyOrder = confirmEarlyOrder && selectedDayIso !== "" && scheduledDayIso !== "" && selectedDayIso < scheduledDayIso;
6994
- const submitDate = () => {
7031
+ const submitDate = async () => {
6995
7032
  if (!selectedDayIso) return;
6996
- onConfirm(selectedDayIso, placesEarlyOrder);
7033
+ try {
7034
+ await onConfirm(selectedDayIso, placesEarlyOrder);
7035
+ } catch (error) {
7036
+ const refusal = readEarlyOrderRefusal(error);
7037
+ if (refusal) {
7038
+ setEarlyOrderRefusal(refusal);
7039
+ setConfirmingEarlyOrder(true);
7040
+ }
7041
+ }
6997
7042
  };
6998
7043
  const handleConfirm = () => {
6999
7044
  if (!selectedDayIso) return;
@@ -7007,6 +7052,7 @@ function EditBillDateDialog({ open, onOpenChange, onConfirm, isLoading, errorMes
7007
7052
  if (!next) {
7008
7053
  setSelectedDate(void 0);
7009
7054
  setConfirmingEarlyOrder(false);
7055
+ setEarlyOrderRefusal(null);
7010
7056
  setCalendarOpen(false);
7011
7057
  }
7012
7058
  onOpenChange(next);
@@ -8384,6 +8430,7 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8384
8430
  onError: (err, { subscriptionToken }) => {
8385
8431
  if (latestSubscriptionTokenRef.current !== subscriptionToken) return;
8386
8432
  setPendingNextBillDate(null);
8433
+ if (readEarlyOrderRefusal(err)) return;
8387
8434
  onMutationError?.(t("failed_to_update_bill_date"), err);
8388
8435
  }
8389
8436
  });
@@ -8595,7 +8642,7 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8595
8642
  },
8596
8643
  onConfirm: (nextBillDate, placesEarlyOrder) => {
8597
8644
  setPendingNextBillDate(nextBillDate);
8598
- editBillDateMutation.mutate({
8645
+ return editBillDateMutation.mutateAsync({
8599
8646
  subscriptionToken: token,
8600
8647
  body: {
8601
8648
  next_bill_date: nextBillDate,
@@ -8604,7 +8651,7 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8604
8651
  });
8605
8652
  },
8606
8653
  isLoading: editBillDateMutation.isPending,
8607
- errorMessage: editBillDateMutation.isError ? t("bill_date_error") : void 0,
8654
+ errorMessage: editBillDateMutation.isError && !readEarlyOrderRefusal(editBillDateMutation.error) ? t("bill_date_error") : void 0,
8608
8655
  blackoutDays: subscription.blackout_days,
8609
8656
  currentNextBillDate: subscription.next_bill_date,
8610
8657
  currentLastBillDate: subscription.last_bill_date,
@@ -10628,4 +10675,4 @@ const subscriptionsScreenPropertySchema = {
10628
10675
  //#endregion
10629
10676
  export { subscriptionsScreenPropertySchema as n, SubscriptionsScreen as t };
10630
10677
 
10631
- //# sourceMappingURL=SubscriptionsScreen-DdVt_D0C.mjs.map
10678
+ //# sourceMappingURL=SubscriptionsScreen-yah2TAvw.mjs.map