@shipengine/elements 0.37.0 → 0.37.2

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/index.cjs CHANGED
@@ -2648,6 +2648,14 @@ const featureFlags = {
2648
2648
  * Elements.
2649
2649
  */
2650
2650
  compatibleCountryCodes: ["AU", "CA", "FR", "DE", "GB", "IL", "IT", "NO", "ES", "SE", "US"],
2651
+ /**
2652
+ * @internal
2653
+ *
2654
+ * `partnerMessages` enables the partner consuming elements to specify override messages in specific cases.
2655
+ */
2656
+ partnerMessages: {
2657
+ incompleteLabelPurchaseRequirements: undefined
2658
+ },
2651
2659
  /**
2652
2660
  * `rateForm` all scoped feature flags for the `rate form` section of the `<PurchaseLabel />`
2653
2661
  * element.
@@ -2701,14 +2709,6 @@ const featureFlags = {
2701
2709
  * to opt for third party insurance when insuring their shipment.
2702
2710
  */
2703
2711
  includeThirdPartyInsurance: true,
2704
- /**
2705
- * @internal
2706
- *
2707
- * `partnerMessages` enables the partner consuming elements to specify override messages in specific cases.
2708
- */
2709
- partnerMessages: {
2710
- incompleteLabelPurchaseRequirements: undefined
2711
- },
2712
2712
  /**
2713
2713
  * `selectService` enables the `select service` feature, allowing users to select a service
2714
2714
  * when rate shopping across multiple carrier providers.
@@ -12832,7 +12832,7 @@ const CustomsItemForm = ({
12832
12832
  }));
12833
12833
  const formInterface = jsxRuntime.jsxs("section", Object.assign({
12834
12834
  css: theme => ({
12835
- backgroundColor: theme.palette.gray.megaLight,
12835
+ backgroundColor: theme.palette.gray.ultraLight,
12836
12836
  padding: theme.spacing(2)
12837
12837
  })
12838
12838
  }, {
@@ -14635,22 +14635,21 @@ const rateSchema = zod.z.object({
14635
14635
  const RateForm = ({
14636
14636
  carriers,
14637
14637
  disabled,
14638
- errors,
14639
14638
  displayableRateErrors,
14640
- displayableLabelErrors,
14639
+ errors,
14641
14640
  features,
14641
+ isLoading,
14642
14642
  labelErrors,
14643
14643
  labels,
14644
14644
  labelsLoading,
14645
- isLoading,
14646
14645
  onSave,
14647
14646
  onSelectRate,
14648
14647
  onSubmit,
14649
- rates,
14650
- preferredRates,
14651
- shipment,
14652
14648
  outOfBandDisplayableErrors,
14653
- preferredServiceCodes
14649
+ preferredRates,
14650
+ preferredServiceCodes,
14651
+ rates,
14652
+ shipment
14654
14653
  }) => {
14655
14654
  var _a, _b, _c, _d, _e, _f;
14656
14655
  features = Object.assign({
@@ -14664,7 +14663,6 @@ const RateForm = ({
14664
14663
  saveRate: true
14665
14664
  }
14666
14665
  }, features !== null && features !== void 0 ? features : {});
14667
- const allDisplayableErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14668
14666
  const {
14669
14667
  t
14670
14668
  } = reactI18next.useTranslation();
@@ -14762,6 +14760,22 @@ const RateForm = ({
14762
14760
  const preferredRate = preferredRates === null || preferredRates === void 0 ? void 0 : preferredRates.find(r => r.rate.rateId === (selectedRate === null || selectedRate === void 0 ? void 0 : selectedRate.rateId));
14763
14761
  return !!preferredRate;
14764
14762
  }, [preferredRates, selectedRate]);
14763
+ const displayableErrors = React.useMemo(() => {
14764
+ const rateAndShipmentErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14765
+ if (rateAndShipmentErrors.length && rateOptions.length === 0) {
14766
+ return {
14767
+ messages: rateAndShipmentErrors,
14768
+ title: "errorTypes.rateInvalid"
14769
+ };
14770
+ }
14771
+ if (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) {
14772
+ return {
14773
+ messages: labelErrors,
14774
+ title: "errorTypes.purchase"
14775
+ };
14776
+ }
14777
+ return undefined;
14778
+ }, [rateOptions, labelErrors, displayableRateErrors, outOfBandDisplayableErrors]);
14765
14779
  return jsxRuntime.jsxs("form", Object.assign({
14766
14780
  id: "rate-form",
14767
14781
  onSubmit: handleSubmit,
@@ -14806,7 +14820,7 @@ const RateForm = ({
14806
14820
  children: showHiddenRates ? t("purchase-label:actions.showFewerRates") : t("purchase-label:actions.showMoreRates")
14807
14821
  }))
14808
14822
  }))]
14809
- }) : !isLoading && !!allDisplayableErrors.length ? null : jsxRuntime.jsxs("article", Object.assign({
14823
+ }) : !isLoading && !!displayableErrors ? null : jsxRuntime.jsxs("article", Object.assign({
14810
14824
  css: styles$3.ratesInterstitial,
14811
14825
  role: "presentation"
14812
14826
  }, {
@@ -14815,13 +14829,11 @@ const RateForm = ({
14815
14829
  }), jsxRuntime.jsx(Spacer, {}), isLoading ? t("purchase-label:loading.calculatingRates") : t("purchase-label:cta.addPackageDetails")]
14816
14830
  })), jsxRuntime.jsx(Spacer, {
14817
14831
  multiplier: 2
14818
- }), !isLoading && (!!allDisplayableErrors.length && rateOptions.length === 0 || !!(labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length)) && jsxRuntime.jsx(giger.InlineNotification, Object.assign({
14819
- title: t("errorTypes.rateInvalid"),
14832
+ }), !isLoading && !!displayableErrors && jsxRuntime.jsx(giger.InlineNotification, Object.assign({
14833
+ title: t(displayableErrors.title),
14820
14834
  type: giger.NotificationType.ERROR
14821
14835
  }, {
14822
- children: jsxRuntime.jsxs(jsxRuntime.Fragment, {
14823
- children: [displayableRateErrors, outOfBandDisplayableErrors, displayableLabelErrors]
14824
- })
14836
+ children: displayableErrors.messages
14825
14837
  }))]
14826
14838
  })), ((_d = features === null || features === void 0 ? void 0 : features.rateForm) === null || _d === void 0 ? void 0 : _d.labelLayout) && !labelsLoading && !(labels === null || labels === void 0 ? void 0 : labels.length) && jsxRuntime.jsx(Section, Object.assign({
14827
14839
  title: t("manage-defaults:label.title")
@@ -14990,21 +15002,37 @@ const styles$1 = createStyles({
14990
15002
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
14991
15003
  width: theme.spacing(5)
14992
15004
  }),
15005
+ header: theme => ({
15006
+ "& > tr > th": {
15007
+ "&:after": {
15008
+ borderBottom: "none"
15009
+ }
15010
+ }
15011
+ }),
15012
+ headerActions: theme => ({
15013
+ backgroundColor: theme.palette.gray.ultraLight,
15014
+ padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
15015
+ width: theme.spacing(5)
15016
+ }),
14993
15017
  headerDescription: theme => ({
15018
+ backgroundColor: theme.palette.gray.ultraLight,
14994
15019
  overflow: "visible",
14995
15020
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`
14996
15021
  }),
14997
15022
  headerEach: theme => ({
15023
+ backgroundColor: theme.palette.gray.ultraLight,
14998
15024
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
14999
15025
  textAlign: "right",
15000
15026
  width: theme.spacing(10)
15001
15027
  }),
15002
15028
  headerQty: theme => ({
15029
+ backgroundColor: theme.palette.gray.ultraLight,
15003
15030
  padding: theme.spacing(1),
15004
15031
  textAlign: "right",
15005
15032
  width: theme.spacing(5)
15006
15033
  }),
15007
15034
  headerTotal: theme => ({
15035
+ backgroundColor: theme.palette.gray.ultraLight,
15008
15036
  padding: `${theme.spacing(1)}px 0 ${theme.spacing(1)}px ${theme.spacing(1)}px`,
15009
15037
  textAlign: "right",
15010
15038
  width: theme.spacing(10)
@@ -15026,7 +15054,7 @@ const styles$1 = createStyles({
15026
15054
  itemQty: theme => ({
15027
15055
  overflow: "visible",
15028
15056
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
15029
- textAlign: "center",
15057
+ textAlign: "right",
15030
15058
  width: theme.spacing(5)
15031
15059
  }),
15032
15060
  itemTotal: theme => ({
@@ -15034,6 +15062,14 @@ const styles$1 = createStyles({
15034
15062
  padding: `${theme.spacing(1)}px 0 0 ${theme.spacing(1)}px`,
15035
15063
  textAlign: "right",
15036
15064
  width: theme.spacing(10)
15065
+ }),
15066
+ subtitle: () => ({
15067
+ letterSpacing: "0.01em"
15068
+ }),
15069
+ table: () => ({
15070
+ border: "1px solid #d4e4e8",
15071
+ borderRadius: "0",
15072
+ boxShadow: "none"
15037
15073
  })
15038
15074
  });
15039
15075
 
@@ -15144,12 +15180,15 @@ const CustomsItemsDisplay = ({
15144
15180
  }))]
15145
15181
  })), customsItems.length > 0 && jsxRuntime.jsxs(jsxRuntime.Fragment, {
15146
15182
  children: [jsxRuntime.jsx(Spacer, {}), jsxRuntime.jsx(giger.Table, Object.assign({
15147
- header: jsxRuntime.jsx(giger.TableHeader, {
15183
+ header: jsxRuntime.jsx(giger.TableHeader, Object.assign({
15184
+ css: styles$1.header
15185
+ }, {
15148
15186
  children: jsxRuntime.jsxs(giger.TableBaseRow, {
15149
15187
  children: [jsxRuntime.jsx(giger.TableHeaderCell, Object.assign({
15150
15188
  css: styles$1.headerDescription
15151
15189
  }, {
15152
15190
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15191
+ css: styles$1.subtitle,
15153
15192
  variant: "subtitle2"
15154
15193
  }, {
15155
15194
  children: t("customs.fields.description")
@@ -15158,6 +15197,7 @@ const CustomsItemsDisplay = ({
15158
15197
  css: styles$1.headerEach
15159
15198
  }, {
15160
15199
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15200
+ css: styles$1.subtitle,
15161
15201
  variant: "subtitle2"
15162
15202
  }, {
15163
15203
  children: t("customs.each", {
@@ -15168,6 +15208,7 @@ const CustomsItemsDisplay = ({
15168
15208
  css: styles$1.headerQty
15169
15209
  }, {
15170
15210
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15211
+ css: styles$1.subtitle,
15171
15212
  variant: "subtitle2"
15172
15213
  }, {
15173
15214
  children: t("customs.fields.quantity")
@@ -15176,6 +15217,7 @@ const CustomsItemsDisplay = ({
15176
15217
  css: styles$1.headerTotal
15177
15218
  }, {
15178
15219
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15220
+ css: styles$1.subtitle,
15179
15221
  variant: "subtitle2"
15180
15222
  }, {
15181
15223
  children: t("customs.total", {
@@ -15183,10 +15225,11 @@ const CustomsItemsDisplay = ({
15183
15225
  })
15184
15226
  }))
15185
15227
  })), jsxRuntime.jsx(giger.TableHeaderCell, {
15186
- css: styles$1.actionsColumn
15228
+ css: styles$1.headerActions
15187
15229
  })]
15188
15230
  })
15189
- })
15231
+ })),
15232
+ outerWrapperStyles: styles$1.table
15190
15233
  }, {
15191
15234
  children: jsxRuntime.jsx(giger.TableBody, {
15192
15235
  children: customsItems.map(item => jsxRuntime.jsxs(React.Fragment, {
@@ -15411,7 +15454,7 @@ const ShipmentForm = ({
15411
15454
  warehouseId,
15412
15455
  warehouses
15413
15456
  }) => {
15414
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
15457
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
15415
15458
  features = Object.assign({
15416
15459
  browseRates: true,
15417
15460
  includeShipsuranceInsurance: true,
@@ -15597,16 +15640,16 @@ const ShipmentForm = ({
15597
15640
  }, [form]);
15598
15641
  const handleSubmit = form.handleSubmit(values => __awaiter(void 0, void 0, void 0, function* () {
15599
15642
  try {
15600
- const _o = values,
15643
+ const _l = values,
15601
15644
  {
15602
15645
  __mode: discard
15603
- } = _o,
15604
- payload = __rest(_o, ["__mode"]);
15646
+ } = _l,
15647
+ payload = __rest(_l, ["__mode"]);
15605
15648
  const updatedShipment = yield onSubmit(Object.assign(Object.assign({}, shipment || {}), payload));
15606
15649
  // Defer shipment hydration to the task queue so that the submission promise resolves first, otherwise the
15607
15650
  // submission count will increment after hydration resets the form, keeping it in revalidate mode
15608
15651
  if (updatedShipment) setTimeout(() => hydrateShipment(updatedShipment), 0);
15609
- } catch (_p) {
15652
+ } catch (_m) {
15610
15653
  // Reset the form to its current state, but as a side effect this sets isDirty to false
15611
15654
  // That way, form lifecycle contract is upheld
15612
15655
  form.reset(form.getValues());
@@ -15739,19 +15782,6 @@ const ShipmentForm = ({
15739
15782
  const hasUpsOptions = React.useMemo(() => {
15740
15783
  return (packageOptions === null || packageOptions === void 0 ? void 0 : packageOptions.some(option => option.label === "UPS")) && ((selectedPackage === null || selectedPackage === void 0 ? void 0 : selectedPackage.code) === "package" || selectedCarrierId === upsCarrierId);
15741
15784
  }, [packageOptions, selectedPackage, selectedCarrierId, upsCarrierId]);
15742
- const incompleteRequirementsKeys = React.useMemo(() => {
15743
- if ((warehouses === null || warehouses === void 0 ? void 0 : warehouses.length) === 0 && (carriers === null || carriers === void 0 ? void 0 : carriers.length) === 0) {
15744
- return ["noWarehouseOrCarrier"];
15745
- } else {
15746
- const keys = [(warehouses === null || warehouses === void 0 ? void 0 : warehouses.length) === 0 && "noWarehouse", (carriers === null || carriers === void 0 ? void 0 : carriers.length) === 0 && "noCarrier"].filter(Boolean);
15747
- return keys;
15748
- }
15749
- }, [carriers, warehouses]);
15750
- const isPartnerMessagingEnabled = !!((_d = features.partnerMessages) === null || _d === void 0 ? void 0 : _d.incompleteLabelPurchaseRequirements);
15751
- const incompleteRequirementsError = isPartnerMessagingEnabled ? (_e = features.partnerMessages) === null || _e === void 0 ? void 0 : _e.incompleteLabelPurchaseRequirements : t("errorMessages.incompleteLabelPurchaseRequirements", {
15752
- requirements: incompleteRequirementsKeys.map(key => t(`purchase-label:requirements.${key}`))
15753
- });
15754
- if (incompleteRequirementsKeys.length > 0) throw new Error(incompleteRequirementsError);
15755
15785
  if (isLoading) return jsxRuntime.jsx(Loader, {
15756
15786
  message: t("loading.shipment")
15757
15787
  });
@@ -15825,7 +15855,7 @@ const ShipmentForm = ({
15825
15855
  }, {
15826
15856
  children: formatDate(salesOrder.orderDate)
15827
15857
  })), jsxRuntime.jsx(Spacer, {})]
15828
- })), ((_f = salesOrder === null || salesOrder === void 0 ? void 0 : salesOrder.paymentDetails) === null || _f === void 0 ? void 0 : _f.grandTotal) && jsxRuntime.jsxs(FieldLabel, Object.assign({
15858
+ })), ((_d = salesOrder === null || salesOrder === void 0 ? void 0 : salesOrder.paymentDetails) === null || _d === void 0 ? void 0 : _d.grandTotal) && jsxRuntime.jsxs(FieldLabel, Object.assign({
15829
15859
  label: t("purchase-label:fields.orderValue")
15830
15860
  }, {
15831
15861
  children: [jsxRuntime.jsx(giger.Typography, Object.assign({
@@ -15903,7 +15933,7 @@ const ShipmentForm = ({
15903
15933
  }), jsxRuntime.jsx(CustomsItemsDisplay, {
15904
15934
  onUpdate: handleUpdateCustomsItems,
15905
15935
  shipment: shipment
15906
- }), ((_g = customsErrors === null || customsErrors === void 0 ? void 0 : customsErrors.customsItems) === null || _g === void 0 ? void 0 : _g.type) === "too_small" && jsxRuntime.jsxs(jsxRuntime.Fragment, {
15936
+ }), ((_e = customsErrors === null || customsErrors === void 0 ? void 0 : customsErrors.customsItems) === null || _e === void 0 ? void 0 : _e.type) === "too_small" && jsxRuntime.jsxs(jsxRuntime.Fragment, {
15907
15937
  children: [jsxRuntime.jsx(Spacer, {}), jsxRuntime.jsx(giger.InlineNotification, {
15908
15938
  title: t("purchase-label:errorMessages.customsItemsRequired"),
15909
15939
  type: giger.NotificationType.ERROR
@@ -16094,14 +16124,14 @@ const ShipmentForm = ({
16094
16124
  label: "purchase-label:fields.addOns"
16095
16125
  }, {
16096
16126
  children: [jsxRuntime.jsx(Switch, Object.assign({
16097
- defaultChecked: ((_h = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _h !== void 0 ? _h : "none") !== "none",
16127
+ defaultChecked: ((_f = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _f !== void 0 ? _f : "none") !== "none",
16098
16128
  label: t("purchase-label:fields.confirmation"),
16099
16129
  name: "confirmationEnabled",
16100
16130
  onChange: e => form.setValue("confirmation", e.target.checked ? alchemy.SE.ConfirmationType.DELIVERY : undefined, {
16101
16131
  shouldDirty: true
16102
16132
  }),
16103
16133
  shouldUnmount: true,
16104
- value: ((_j = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _j !== void 0 ? _j : "none") !== "none"
16134
+ value: ((_g = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _g !== void 0 ? _g : "none") !== "none"
16105
16135
  }, {
16106
16136
  children: jsxRuntime.jsx(Select, {
16107
16137
  control: form.control,
@@ -16113,7 +16143,7 @@ const ShipmentForm = ({
16113
16143
  shouldUnregister: true
16114
16144
  })
16115
16145
  })), jsxRuntime.jsxs(Switch, Object.assign({
16116
- defaultChecked: ((_k = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _k !== void 0 ? _k : "none") !== "none",
16146
+ defaultChecked: ((_h = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _h !== void 0 ? _h : "none") !== "none",
16117
16147
  label: t("purchase-label:fields.insurance"),
16118
16148
  name: "insuranceEnabled",
16119
16149
  onChange: e => {
@@ -16123,7 +16153,7 @@ const ShipmentForm = ({
16123
16153
  });
16124
16154
  },
16125
16155
  shouldUnmount: true,
16126
- value: ((_l = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _l !== void 0 ? _l : "none") !== "none"
16156
+ value: ((_j = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _j !== void 0 ? _j : "none") !== "none"
16127
16157
  }, {
16128
16158
  children: [insuranceProviderOptions.length === 1 && insuranceProviderOptions[0].value === "carrier" ? null : jsxRuntime.jsx(Select, {
16129
16159
  control: form.control,
@@ -16147,7 +16177,7 @@ const ShipmentForm = ({
16147
16177
  showCurrencySymbol: true
16148
16178
  })]
16149
16179
  })), hasUpsOptions && jsxRuntime.jsx(Switch, {
16150
- defaultChecked: ((_m = shipment === null || shipment === void 0 ? void 0 : shipment.advancedOptions) === null || _m === void 0 ? void 0 : _m.additionalHandling) || false,
16180
+ defaultChecked: ((_k = shipment === null || shipment === void 0 ? void 0 : shipment.advancedOptions) === null || _k === void 0 ? void 0 : _k.additionalHandling) || false,
16151
16181
  label: jsxRuntime.jsx(reactI18next.Trans, {
16152
16182
  components: {
16153
16183
  Link: jsxRuntime.jsx(giger.Link, {
@@ -16910,7 +16940,7 @@ var common = {
16910
16940
  invalidAddressNameStrict: "Recipient Name must have two characters in First and Last Name.",
16911
16941
  invalidAddressPoBox: "A physical address is required for wallet registration. You can add a PO Box as a Ship From address.",
16912
16942
  invalidCreditCardType: "Card type must be Visa, Mastercard, American Express, or Discover",
16913
- invalidExpiration: "Invalid Expiration Date",
16943
+ invalidExpirationDate: "Invalid Expiration Date",
16914
16944
  invalidPostalCode: "Invalid Postal Code",
16915
16945
  invalidStateProvince: "Invalid State",
16916
16946
  invalidString: "{{fieldLabel}} is invalid",
@@ -17946,12 +17976,12 @@ const useRequestRates = ({
17946
17976
  getPreferredRates
17947
17977
  });
17948
17978
  const requestRates = React.useCallback((shipment, isInternational) => __awaiter(void 0, void 0, void 0, function* () {
17949
- var _a, _b;
17950
- const internationalCarrierIds = (_a = carriers === null || carriers === void 0 ? void 0 : carriers.map(c => c.carrierId)) !== null && _a !== void 0 ? _a : [];
17951
- const domesticCarrierIds = (_b = carriers === null || carriers === void 0 ? void 0 : carriers.filter(c => !["dhl"].includes(c.carrierCode)).map(c => c.carrierId)) !== null && _b !== void 0 ? _b : [];
17979
+ var _a;
17980
+ // filter out DHL for domestic shipments
17981
+ const carrierIds = (_a = carriers === null || carriers === void 0 ? void 0 : carriers.filter(c => isInternational || !c.carrierCode.includes("dhl")).map(c => c.carrierId)) !== null && _a !== void 0 ? _a : [];
17952
17982
  const standardRatesResponse = yield calculateRates({
17953
17983
  rateOptions: {
17954
- carrierIds: shipment.carrierId ? [shipment.carrierId] : isInternational ? internationalCarrierIds : domesticCarrierIds,
17984
+ carrierIds: shipment.carrierId ? [shipment.carrierId] : carrierIds,
17955
17985
  packageTypes: (customPackageTypes === null || customPackageTypes === void 0 ? void 0 : customPackageTypes.find(p => p.packageId === shipment.packages[0].packageId)) ? ["package"] // Only specify package types for non-custom packages
17956
17986
  : shipment.packages.map(pkg => pkg.packageCode),
17957
17987
  serviceCodes: shipment.serviceCode ? [shipment.serviceCode] : undefined
@@ -18249,11 +18279,10 @@ const useRatesForm = ({
18249
18279
  });
18250
18280
  return {
18251
18281
  carriers,
18252
- displayableLabelErrors,
18253
18282
  displayableRateErrors,
18254
18283
  errors: errors.length > 0 ? errors : undefined,
18255
18284
  isLoading: ratesCalculating,
18256
- labelErrors: (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) ? labelErrors : undefined,
18285
+ labelErrors: displayableLabelErrors,
18257
18286
  labels,
18258
18287
  labelsLoading,
18259
18288
  onSave: handleSave,
@@ -18774,7 +18803,27 @@ const PurchaseLabelByShipment = _a => {
18774
18803
  * @see {@link PurchaseLabel.Element | The **Element** created to render `<PurchaseLabel />`}
18775
18804
  */
18776
18805
  const Component$2 = _a => {
18777
- var props = __rest(_a, []);
18806
+ var _b;
18807
+ var {
18808
+ features
18809
+ } = _a,
18810
+ props = __rest(_a, ["features"]);
18811
+ const {
18812
+ t
18813
+ } = reactI18next.useTranslation();
18814
+ const warehouses = alchemy.useListWarehouses();
18815
+ const carriers = alchemy.useListCarriers();
18816
+ const incompleteRequirementsKeys = React.useMemo(() => {
18817
+ var _a, _b;
18818
+ const isMissingWarehouse = ((_a = warehouses.data) === null || _a === void 0 ? void 0 : _a.length) === 0;
18819
+ const isMissingCarrier = ((_b = carriers.data) === null || _b === void 0 ? void 0 : _b.length) === 0;
18820
+ return isMissingWarehouse && isMissingCarrier ? ["noWarehouseOrCarrier"] : [isMissingWarehouse && "noWarehouse", isMissingCarrier && "noCarrier"].filter(Boolean);
18821
+ }, [carriers, warehouses]);
18822
+ const partnerMessages = (_b = features === null || features === void 0 ? void 0 : features.partnerMessages) === null || _b === void 0 ? void 0 : _b.incompleteLabelPurchaseRequirements;
18823
+ const incompleteRequirementsError = partnerMessages ? partnerMessages : t("errorMessages.incompleteLabelPurchaseRequirements", {
18824
+ requirements: incompleteRequirementsKeys.map(key => t(`purchase-label:requirements.${key}`))
18825
+ });
18826
+ if (incompleteRequirementsKeys.length > 0) throw new Error(incompleteRequirementsError);
18778
18827
  if ("salesOrderId" in props || "orderSourceCode" in props) {
18779
18828
  return jsxRuntime.jsx(PurchaseLabelBySalesOrder, Object.assign({}, props));
18780
18829
  } else {
package/index.js CHANGED
@@ -2616,6 +2616,14 @@ const featureFlags = {
2616
2616
  * Elements.
2617
2617
  */
2618
2618
  compatibleCountryCodes: ["AU", "CA", "FR", "DE", "GB", "IL", "IT", "NO", "ES", "SE", "US"],
2619
+ /**
2620
+ * @internal
2621
+ *
2622
+ * `partnerMessages` enables the partner consuming elements to specify override messages in specific cases.
2623
+ */
2624
+ partnerMessages: {
2625
+ incompleteLabelPurchaseRequirements: undefined
2626
+ },
2619
2627
  /**
2620
2628
  * `rateForm` all scoped feature flags for the `rate form` section of the `<PurchaseLabel />`
2621
2629
  * element.
@@ -2669,14 +2677,6 @@ const featureFlags = {
2669
2677
  * to opt for third party insurance when insuring their shipment.
2670
2678
  */
2671
2679
  includeThirdPartyInsurance: true,
2672
- /**
2673
- * @internal
2674
- *
2675
- * `partnerMessages` enables the partner consuming elements to specify override messages in specific cases.
2676
- */
2677
- partnerMessages: {
2678
- incompleteLabelPurchaseRequirements: undefined
2679
- },
2680
2680
  /**
2681
2681
  * `selectService` enables the `select service` feature, allowing users to select a service
2682
2682
  * when rate shopping across multiple carrier providers.
@@ -12800,7 +12800,7 @@ const CustomsItemForm = ({
12800
12800
  }));
12801
12801
  const formInterface = jsxs("section", Object.assign({
12802
12802
  css: theme => ({
12803
- backgroundColor: theme.palette.gray.megaLight,
12803
+ backgroundColor: theme.palette.gray.ultraLight,
12804
12804
  padding: theme.spacing(2)
12805
12805
  })
12806
12806
  }, {
@@ -14603,22 +14603,21 @@ const rateSchema = z.object({
14603
14603
  const RateForm = ({
14604
14604
  carriers,
14605
14605
  disabled,
14606
- errors,
14607
14606
  displayableRateErrors,
14608
- displayableLabelErrors,
14607
+ errors,
14609
14608
  features,
14609
+ isLoading,
14610
14610
  labelErrors,
14611
14611
  labels,
14612
14612
  labelsLoading,
14613
- isLoading,
14614
14613
  onSave,
14615
14614
  onSelectRate,
14616
14615
  onSubmit,
14617
- rates,
14618
- preferredRates,
14619
- shipment,
14620
14616
  outOfBandDisplayableErrors,
14621
- preferredServiceCodes
14617
+ preferredRates,
14618
+ preferredServiceCodes,
14619
+ rates,
14620
+ shipment
14622
14621
  }) => {
14623
14622
  var _a, _b, _c, _d, _e, _f;
14624
14623
  features = Object.assign({
@@ -14632,7 +14631,6 @@ const RateForm = ({
14632
14631
  saveRate: true
14633
14632
  }
14634
14633
  }, features !== null && features !== void 0 ? features : {});
14635
- const allDisplayableErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14636
14634
  const {
14637
14635
  t
14638
14636
  } = useTranslation();
@@ -14730,6 +14728,22 @@ const RateForm = ({
14730
14728
  const preferredRate = preferredRates === null || preferredRates === void 0 ? void 0 : preferredRates.find(r => r.rate.rateId === (selectedRate === null || selectedRate === void 0 ? void 0 : selectedRate.rateId));
14731
14729
  return !!preferredRate;
14732
14730
  }, [preferredRates, selectedRate]);
14731
+ const displayableErrors = useMemo(() => {
14732
+ const rateAndShipmentErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14733
+ if (rateAndShipmentErrors.length && rateOptions.length === 0) {
14734
+ return {
14735
+ messages: rateAndShipmentErrors,
14736
+ title: "errorTypes.rateInvalid"
14737
+ };
14738
+ }
14739
+ if (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) {
14740
+ return {
14741
+ messages: labelErrors,
14742
+ title: "errorTypes.purchase"
14743
+ };
14744
+ }
14745
+ return undefined;
14746
+ }, [rateOptions, labelErrors, displayableRateErrors, outOfBandDisplayableErrors]);
14733
14747
  return jsxs("form", Object.assign({
14734
14748
  id: "rate-form",
14735
14749
  onSubmit: handleSubmit,
@@ -14774,7 +14788,7 @@ const RateForm = ({
14774
14788
  children: showHiddenRates ? t("purchase-label:actions.showFewerRates") : t("purchase-label:actions.showMoreRates")
14775
14789
  }))
14776
14790
  }))]
14777
- }) : !isLoading && !!allDisplayableErrors.length ? null : jsxs("article", Object.assign({
14791
+ }) : !isLoading && !!displayableErrors ? null : jsxs("article", Object.assign({
14778
14792
  css: styles$3.ratesInterstitial,
14779
14793
  role: "presentation"
14780
14794
  }, {
@@ -14783,13 +14797,11 @@ const RateForm = ({
14783
14797
  }), jsx(Spacer, {}), isLoading ? t("purchase-label:loading.calculatingRates") : t("purchase-label:cta.addPackageDetails")]
14784
14798
  })), jsx(Spacer, {
14785
14799
  multiplier: 2
14786
- }), !isLoading && (!!allDisplayableErrors.length && rateOptions.length === 0 || !!(labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length)) && jsx(InlineNotification, Object.assign({
14787
- title: t("errorTypes.rateInvalid"),
14800
+ }), !isLoading && !!displayableErrors && jsx(InlineNotification, Object.assign({
14801
+ title: t(displayableErrors.title),
14788
14802
  type: NotificationType.ERROR
14789
14803
  }, {
14790
- children: jsxs(Fragment, {
14791
- children: [displayableRateErrors, outOfBandDisplayableErrors, displayableLabelErrors]
14792
- })
14804
+ children: displayableErrors.messages
14793
14805
  }))]
14794
14806
  })), ((_d = features === null || features === void 0 ? void 0 : features.rateForm) === null || _d === void 0 ? void 0 : _d.labelLayout) && !labelsLoading && !(labels === null || labels === void 0 ? void 0 : labels.length) && jsx(Section, Object.assign({
14795
14807
  title: t("manage-defaults:label.title")
@@ -14958,21 +14970,37 @@ const styles$1 = createStyles({
14958
14970
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
14959
14971
  width: theme.spacing(5)
14960
14972
  }),
14973
+ header: theme => ({
14974
+ "& > tr > th": {
14975
+ "&:after": {
14976
+ borderBottom: "none"
14977
+ }
14978
+ }
14979
+ }),
14980
+ headerActions: theme => ({
14981
+ backgroundColor: theme.palette.gray.ultraLight,
14982
+ padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
14983
+ width: theme.spacing(5)
14984
+ }),
14961
14985
  headerDescription: theme => ({
14986
+ backgroundColor: theme.palette.gray.ultraLight,
14962
14987
  overflow: "visible",
14963
14988
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`
14964
14989
  }),
14965
14990
  headerEach: theme => ({
14991
+ backgroundColor: theme.palette.gray.ultraLight,
14966
14992
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
14967
14993
  textAlign: "right",
14968
14994
  width: theme.spacing(10)
14969
14995
  }),
14970
14996
  headerQty: theme => ({
14997
+ backgroundColor: theme.palette.gray.ultraLight,
14971
14998
  padding: theme.spacing(1),
14972
14999
  textAlign: "right",
14973
15000
  width: theme.spacing(5)
14974
15001
  }),
14975
15002
  headerTotal: theme => ({
15003
+ backgroundColor: theme.palette.gray.ultraLight,
14976
15004
  padding: `${theme.spacing(1)}px 0 ${theme.spacing(1)}px ${theme.spacing(1)}px`,
14977
15005
  textAlign: "right",
14978
15006
  width: theme.spacing(10)
@@ -14994,7 +15022,7 @@ const styles$1 = createStyles({
14994
15022
  itemQty: theme => ({
14995
15023
  overflow: "visible",
14996
15024
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
14997
- textAlign: "center",
15025
+ textAlign: "right",
14998
15026
  width: theme.spacing(5)
14999
15027
  }),
15000
15028
  itemTotal: theme => ({
@@ -15002,6 +15030,14 @@ const styles$1 = createStyles({
15002
15030
  padding: `${theme.spacing(1)}px 0 0 ${theme.spacing(1)}px`,
15003
15031
  textAlign: "right",
15004
15032
  width: theme.spacing(10)
15033
+ }),
15034
+ subtitle: () => ({
15035
+ letterSpacing: "0.01em"
15036
+ }),
15037
+ table: () => ({
15038
+ border: "1px solid #d4e4e8",
15039
+ borderRadius: "0",
15040
+ boxShadow: "none"
15005
15041
  })
15006
15042
  });
15007
15043
 
@@ -15112,12 +15148,15 @@ const CustomsItemsDisplay = ({
15112
15148
  }))]
15113
15149
  })), customsItems.length > 0 && jsxs(Fragment, {
15114
15150
  children: [jsx(Spacer, {}), jsx(Table, Object.assign({
15115
- header: jsx(TableHeader, {
15151
+ header: jsx(TableHeader, Object.assign({
15152
+ css: styles$1.header
15153
+ }, {
15116
15154
  children: jsxs(TableBaseRow, {
15117
15155
  children: [jsx(TableHeaderCell, Object.assign({
15118
15156
  css: styles$1.headerDescription
15119
15157
  }, {
15120
15158
  children: jsx(Typography, Object.assign({
15159
+ css: styles$1.subtitle,
15121
15160
  variant: "subtitle2"
15122
15161
  }, {
15123
15162
  children: t("customs.fields.description")
@@ -15126,6 +15165,7 @@ const CustomsItemsDisplay = ({
15126
15165
  css: styles$1.headerEach
15127
15166
  }, {
15128
15167
  children: jsx(Typography, Object.assign({
15168
+ css: styles$1.subtitle,
15129
15169
  variant: "subtitle2"
15130
15170
  }, {
15131
15171
  children: t("customs.each", {
@@ -15136,6 +15176,7 @@ const CustomsItemsDisplay = ({
15136
15176
  css: styles$1.headerQty
15137
15177
  }, {
15138
15178
  children: jsx(Typography, Object.assign({
15179
+ css: styles$1.subtitle,
15139
15180
  variant: "subtitle2"
15140
15181
  }, {
15141
15182
  children: t("customs.fields.quantity")
@@ -15144,6 +15185,7 @@ const CustomsItemsDisplay = ({
15144
15185
  css: styles$1.headerTotal
15145
15186
  }, {
15146
15187
  children: jsx(Typography, Object.assign({
15188
+ css: styles$1.subtitle,
15147
15189
  variant: "subtitle2"
15148
15190
  }, {
15149
15191
  children: t("customs.total", {
@@ -15151,10 +15193,11 @@ const CustomsItemsDisplay = ({
15151
15193
  })
15152
15194
  }))
15153
15195
  })), jsx(TableHeaderCell, {
15154
- css: styles$1.actionsColumn
15196
+ css: styles$1.headerActions
15155
15197
  })]
15156
15198
  })
15157
- })
15199
+ })),
15200
+ outerWrapperStyles: styles$1.table
15158
15201
  }, {
15159
15202
  children: jsx(TableBody, {
15160
15203
  children: customsItems.map(item => jsxs(Fragment$1, {
@@ -15379,7 +15422,7 @@ const ShipmentForm = ({
15379
15422
  warehouseId,
15380
15423
  warehouses
15381
15424
  }) => {
15382
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
15425
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
15383
15426
  features = Object.assign({
15384
15427
  browseRates: true,
15385
15428
  includeShipsuranceInsurance: true,
@@ -15565,16 +15608,16 @@ const ShipmentForm = ({
15565
15608
  }, [form]);
15566
15609
  const handleSubmit = form.handleSubmit(values => __awaiter(void 0, void 0, void 0, function* () {
15567
15610
  try {
15568
- const _o = values,
15611
+ const _l = values,
15569
15612
  {
15570
15613
  __mode: discard
15571
- } = _o,
15572
- payload = __rest(_o, ["__mode"]);
15614
+ } = _l,
15615
+ payload = __rest(_l, ["__mode"]);
15573
15616
  const updatedShipment = yield onSubmit(Object.assign(Object.assign({}, shipment || {}), payload));
15574
15617
  // Defer shipment hydration to the task queue so that the submission promise resolves first, otherwise the
15575
15618
  // submission count will increment after hydration resets the form, keeping it in revalidate mode
15576
15619
  if (updatedShipment) setTimeout(() => hydrateShipment(updatedShipment), 0);
15577
- } catch (_p) {
15620
+ } catch (_m) {
15578
15621
  // Reset the form to its current state, but as a side effect this sets isDirty to false
15579
15622
  // That way, form lifecycle contract is upheld
15580
15623
  form.reset(form.getValues());
@@ -15707,19 +15750,6 @@ const ShipmentForm = ({
15707
15750
  const hasUpsOptions = useMemo(() => {
15708
15751
  return (packageOptions === null || packageOptions === void 0 ? void 0 : packageOptions.some(option => option.label === "UPS")) && ((selectedPackage === null || selectedPackage === void 0 ? void 0 : selectedPackage.code) === "package" || selectedCarrierId === upsCarrierId);
15709
15752
  }, [packageOptions, selectedPackage, selectedCarrierId, upsCarrierId]);
15710
- const incompleteRequirementsKeys = useMemo(() => {
15711
- if ((warehouses === null || warehouses === void 0 ? void 0 : warehouses.length) === 0 && (carriers === null || carriers === void 0 ? void 0 : carriers.length) === 0) {
15712
- return ["noWarehouseOrCarrier"];
15713
- } else {
15714
- const keys = [(warehouses === null || warehouses === void 0 ? void 0 : warehouses.length) === 0 && "noWarehouse", (carriers === null || carriers === void 0 ? void 0 : carriers.length) === 0 && "noCarrier"].filter(Boolean);
15715
- return keys;
15716
- }
15717
- }, [carriers, warehouses]);
15718
- const isPartnerMessagingEnabled = !!((_d = features.partnerMessages) === null || _d === void 0 ? void 0 : _d.incompleteLabelPurchaseRequirements);
15719
- const incompleteRequirementsError = isPartnerMessagingEnabled ? (_e = features.partnerMessages) === null || _e === void 0 ? void 0 : _e.incompleteLabelPurchaseRequirements : t("errorMessages.incompleteLabelPurchaseRequirements", {
15720
- requirements: incompleteRequirementsKeys.map(key => t(`purchase-label:requirements.${key}`))
15721
- });
15722
- if (incompleteRequirementsKeys.length > 0) throw new Error(incompleteRequirementsError);
15723
15753
  if (isLoading) return jsx(Loader, {
15724
15754
  message: t("loading.shipment")
15725
15755
  });
@@ -15793,7 +15823,7 @@ const ShipmentForm = ({
15793
15823
  }, {
15794
15824
  children: formatDate(salesOrder.orderDate)
15795
15825
  })), jsx(Spacer, {})]
15796
- })), ((_f = salesOrder === null || salesOrder === void 0 ? void 0 : salesOrder.paymentDetails) === null || _f === void 0 ? void 0 : _f.grandTotal) && jsxs(FieldLabel, Object.assign({
15826
+ })), ((_d = salesOrder === null || salesOrder === void 0 ? void 0 : salesOrder.paymentDetails) === null || _d === void 0 ? void 0 : _d.grandTotal) && jsxs(FieldLabel, Object.assign({
15797
15827
  label: t("purchase-label:fields.orderValue")
15798
15828
  }, {
15799
15829
  children: [jsx(Typography, Object.assign({
@@ -15871,7 +15901,7 @@ const ShipmentForm = ({
15871
15901
  }), jsx(CustomsItemsDisplay, {
15872
15902
  onUpdate: handleUpdateCustomsItems,
15873
15903
  shipment: shipment
15874
- }), ((_g = customsErrors === null || customsErrors === void 0 ? void 0 : customsErrors.customsItems) === null || _g === void 0 ? void 0 : _g.type) === "too_small" && jsxs(Fragment, {
15904
+ }), ((_e = customsErrors === null || customsErrors === void 0 ? void 0 : customsErrors.customsItems) === null || _e === void 0 ? void 0 : _e.type) === "too_small" && jsxs(Fragment, {
15875
15905
  children: [jsx(Spacer, {}), jsx(InlineNotification, {
15876
15906
  title: t("purchase-label:errorMessages.customsItemsRequired"),
15877
15907
  type: NotificationType.ERROR
@@ -16062,14 +16092,14 @@ const ShipmentForm = ({
16062
16092
  label: "purchase-label:fields.addOns"
16063
16093
  }, {
16064
16094
  children: [jsx(Switch, Object.assign({
16065
- defaultChecked: ((_h = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _h !== void 0 ? _h : "none") !== "none",
16095
+ defaultChecked: ((_f = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _f !== void 0 ? _f : "none") !== "none",
16066
16096
  label: t("purchase-label:fields.confirmation"),
16067
16097
  name: "confirmationEnabled",
16068
16098
  onChange: e => form.setValue("confirmation", e.target.checked ? SE.ConfirmationType.DELIVERY : undefined, {
16069
16099
  shouldDirty: true
16070
16100
  }),
16071
16101
  shouldUnmount: true,
16072
- value: ((_j = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _j !== void 0 ? _j : "none") !== "none"
16102
+ value: ((_g = shipment === null || shipment === void 0 ? void 0 : shipment.confirmation) !== null && _g !== void 0 ? _g : "none") !== "none"
16073
16103
  }, {
16074
16104
  children: jsx(Select, {
16075
16105
  control: form.control,
@@ -16081,7 +16111,7 @@ const ShipmentForm = ({
16081
16111
  shouldUnregister: true
16082
16112
  })
16083
16113
  })), jsxs(Switch, Object.assign({
16084
- defaultChecked: ((_k = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _k !== void 0 ? _k : "none") !== "none",
16114
+ defaultChecked: ((_h = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _h !== void 0 ? _h : "none") !== "none",
16085
16115
  label: t("purchase-label:fields.insurance"),
16086
16116
  name: "insuranceEnabled",
16087
16117
  onChange: e => {
@@ -16091,7 +16121,7 @@ const ShipmentForm = ({
16091
16121
  });
16092
16122
  },
16093
16123
  shouldUnmount: true,
16094
- value: ((_l = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _l !== void 0 ? _l : "none") !== "none"
16124
+ value: ((_j = shipment === null || shipment === void 0 ? void 0 : shipment.insuranceProvider) !== null && _j !== void 0 ? _j : "none") !== "none"
16095
16125
  }, {
16096
16126
  children: [insuranceProviderOptions.length === 1 && insuranceProviderOptions[0].value === "carrier" ? null : jsx(Select, {
16097
16127
  control: form.control,
@@ -16115,7 +16145,7 @@ const ShipmentForm = ({
16115
16145
  showCurrencySymbol: true
16116
16146
  })]
16117
16147
  })), hasUpsOptions && jsx(Switch, {
16118
- defaultChecked: ((_m = shipment === null || shipment === void 0 ? void 0 : shipment.advancedOptions) === null || _m === void 0 ? void 0 : _m.additionalHandling) || false,
16148
+ defaultChecked: ((_k = shipment === null || shipment === void 0 ? void 0 : shipment.advancedOptions) === null || _k === void 0 ? void 0 : _k.additionalHandling) || false,
16119
16149
  label: jsx(Trans, {
16120
16150
  components: {
16121
16151
  Link: jsx(Link, {
@@ -16878,7 +16908,7 @@ var common = {
16878
16908
  invalidAddressNameStrict: "Recipient Name must have two characters in First and Last Name.",
16879
16909
  invalidAddressPoBox: "A physical address is required for wallet registration. You can add a PO Box as a Ship From address.",
16880
16910
  invalidCreditCardType: "Card type must be Visa, Mastercard, American Express, or Discover",
16881
- invalidExpiration: "Invalid Expiration Date",
16911
+ invalidExpirationDate: "Invalid Expiration Date",
16882
16912
  invalidPostalCode: "Invalid Postal Code",
16883
16913
  invalidStateProvince: "Invalid State",
16884
16914
  invalidString: "{{fieldLabel}} is invalid",
@@ -17914,12 +17944,12 @@ const useRequestRates = ({
17914
17944
  getPreferredRates
17915
17945
  });
17916
17946
  const requestRates = useCallback((shipment, isInternational) => __awaiter(void 0, void 0, void 0, function* () {
17917
- var _a, _b;
17918
- const internationalCarrierIds = (_a = carriers === null || carriers === void 0 ? void 0 : carriers.map(c => c.carrierId)) !== null && _a !== void 0 ? _a : [];
17919
- const domesticCarrierIds = (_b = carriers === null || carriers === void 0 ? void 0 : carriers.filter(c => !["dhl"].includes(c.carrierCode)).map(c => c.carrierId)) !== null && _b !== void 0 ? _b : [];
17947
+ var _a;
17948
+ // filter out DHL for domestic shipments
17949
+ const carrierIds = (_a = carriers === null || carriers === void 0 ? void 0 : carriers.filter(c => isInternational || !c.carrierCode.includes("dhl")).map(c => c.carrierId)) !== null && _a !== void 0 ? _a : [];
17920
17950
  const standardRatesResponse = yield calculateRates({
17921
17951
  rateOptions: {
17922
- carrierIds: shipment.carrierId ? [shipment.carrierId] : isInternational ? internationalCarrierIds : domesticCarrierIds,
17952
+ carrierIds: shipment.carrierId ? [shipment.carrierId] : carrierIds,
17923
17953
  packageTypes: (customPackageTypes === null || customPackageTypes === void 0 ? void 0 : customPackageTypes.find(p => p.packageId === shipment.packages[0].packageId)) ? ["package"] // Only specify package types for non-custom packages
17924
17954
  : shipment.packages.map(pkg => pkg.packageCode),
17925
17955
  serviceCodes: shipment.serviceCode ? [shipment.serviceCode] : undefined
@@ -18217,11 +18247,10 @@ const useRatesForm = ({
18217
18247
  });
18218
18248
  return {
18219
18249
  carriers,
18220
- displayableLabelErrors,
18221
18250
  displayableRateErrors,
18222
18251
  errors: errors.length > 0 ? errors : undefined,
18223
18252
  isLoading: ratesCalculating,
18224
- labelErrors: (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) ? labelErrors : undefined,
18253
+ labelErrors: displayableLabelErrors,
18225
18254
  labels,
18226
18255
  labelsLoading,
18227
18256
  onSave: handleSave,
@@ -18742,7 +18771,27 @@ const PurchaseLabelByShipment = _a => {
18742
18771
  * @see {@link PurchaseLabel.Element | The **Element** created to render `<PurchaseLabel />`}
18743
18772
  */
18744
18773
  const Component$2 = _a => {
18745
- var props = __rest(_a, []);
18774
+ var _b;
18775
+ var {
18776
+ features
18777
+ } = _a,
18778
+ props = __rest(_a, ["features"]);
18779
+ const {
18780
+ t
18781
+ } = useTranslation();
18782
+ const warehouses = useListWarehouses();
18783
+ const carriers = useListCarriers();
18784
+ const incompleteRequirementsKeys = useMemo(() => {
18785
+ var _a, _b;
18786
+ const isMissingWarehouse = ((_a = warehouses.data) === null || _a === void 0 ? void 0 : _a.length) === 0;
18787
+ const isMissingCarrier = ((_b = carriers.data) === null || _b === void 0 ? void 0 : _b.length) === 0;
18788
+ return isMissingWarehouse && isMissingCarrier ? ["noWarehouseOrCarrier"] : [isMissingWarehouse && "noWarehouse", isMissingCarrier && "noCarrier"].filter(Boolean);
18789
+ }, [carriers, warehouses]);
18790
+ const partnerMessages = (_b = features === null || features === void 0 ? void 0 : features.partnerMessages) === null || _b === void 0 ? void 0 : _b.incompleteLabelPurchaseRequirements;
18791
+ const incompleteRequirementsError = partnerMessages ? partnerMessages : t("errorMessages.incompleteLabelPurchaseRequirements", {
18792
+ requirements: incompleteRequirementsKeys.map(key => t(`purchase-label:requirements.${key}`))
18793
+ });
18794
+ if (incompleteRequirementsKeys.length > 0) throw new Error(incompleteRequirementsError);
18746
18795
  if ("salesOrderId" in props || "orderSourceCode" in props) {
18747
18796
  return jsx(PurchaseLabelBySalesOrder, Object.assign({}, props));
18748
18797
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipengine/elements",
3
- "version": "0.37.0",
3
+ "version": "0.37.2",
4
4
  "peerDependencies": {
5
5
  "@packlink/giger": "*",
6
6
  "react-i18next": "*",
@@ -12,21 +12,37 @@ export declare const styles: {
12
12
  padding: string;
13
13
  width: number;
14
14
  };
15
+ header: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
16
+ "& > tr > th": {
17
+ "&:after": {
18
+ borderBottom: string;
19
+ };
20
+ };
21
+ };
22
+ headerActions: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
23
+ backgroundColor: string;
24
+ padding: string;
25
+ width: number;
26
+ };
15
27
  headerDescription: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
28
+ backgroundColor: string;
16
29
  overflow: "visible";
17
30
  padding: string;
18
31
  };
19
32
  headerEach: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
33
+ backgroundColor: string;
20
34
  padding: string;
21
35
  textAlign: "right";
22
36
  width: number;
23
37
  };
24
38
  headerQty: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
39
+ backgroundColor: string;
25
40
  padding: number;
26
41
  textAlign: "right";
27
42
  width: number;
28
43
  };
29
44
  headerTotal: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
45
+ backgroundColor: string;
30
46
  padding: string;
31
47
  textAlign: "right";
32
48
  width: number;
@@ -48,7 +64,7 @@ export declare const styles: {
48
64
  itemQty: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
49
65
  overflow: "visible";
50
66
  padding: string;
51
- textAlign: "center";
67
+ textAlign: "right";
52
68
  width: number;
53
69
  };
54
70
  itemTotal: (theme: import("@packlink/giger-theme/dist/lib/Theme").Theme) => {
@@ -57,4 +73,12 @@ export declare const styles: {
57
73
  textAlign: "right";
58
74
  width: number;
59
75
  };
76
+ subtitle: () => {
77
+ letterSpacing: string;
78
+ };
79
+ table: () => {
80
+ border: string;
81
+ borderRadius: string;
82
+ boxShadow: "none";
83
+ };
60
84
  };
@@ -3,12 +3,11 @@ import { ConfigureShipmentFeatures, PreferredRatesResponse } from "../../../elem
3
3
  export type RateFormProps = {
4
4
  carriers?: SE.Carrier[];
5
5
  disabled?: boolean;
6
- displayableLabelErrors?: string[];
7
6
  displayableRateErrors?: string[];
8
7
  errors?: SE.CodedError[];
9
8
  features?: ConfigureShipmentFeatures;
10
9
  isLoading?: boolean;
11
- labelErrors?: SE.CodedError[];
10
+ labelErrors?: string[];
12
11
  labels?: SE.Label[];
13
12
  labelsLoading?: boolean;
14
13
  onSave?: (rate: Pick<SE.Rate, "carrierId" | "serviceCode">) => Promise<void> | void;
@@ -20,4 +19,4 @@ export type RateFormProps = {
20
19
  rates?: SE.Rate[];
21
20
  shipment?: SE.SalesOrderShipment;
22
21
  };
23
- export declare const RateForm: ({ carriers, disabled, errors, displayableRateErrors, displayableLabelErrors, features, labelErrors, labels, labelsLoading, isLoading, onSave, onSelectRate, onSubmit, rates, preferredRates, shipment, outOfBandDisplayableErrors, preferredServiceCodes, }: RateFormProps) => import("@emotion/react/jsx-runtime").JSX.Element;
22
+ export declare const RateForm: ({ carriers, disabled, displayableRateErrors, errors, features, isLoading, labelErrors, labels, labelsLoading, onSave, onSelectRate, onSubmit, outOfBandDisplayableErrors, preferredRates, preferredServiceCodes, rates, shipment, }: RateFormProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -12,9 +12,6 @@ export type ShipmentFormFeatures = {
12
12
  browseRates?: boolean;
13
13
  includeShipsuranceInsurance?: boolean;
14
14
  includeThirdPartyInsurance?: boolean;
15
- partnerMessages?: {
16
- incompleteLabelPurchaseRequirements?: string;
17
- };
18
15
  selectService?: boolean;
19
16
  shippingPresets?: boolean;
20
17
  };
@@ -702,7 +702,7 @@ export declare const Element: ({ resources, ...props }: ComponentProps & {
702
702
  invalidAddressNameStrict: string;
703
703
  invalidAddressPoBox: string;
704
704
  invalidCreditCardType: string;
705
- invalidExpiration: string;
705
+ invalidExpirationDate: string;
706
706
  invalidPostalCode: string;
707
707
  invalidStateProvince: string;
708
708
  invalidString: string;
@@ -25,6 +25,9 @@ export type RateFormFeatures = {
25
25
  };
26
26
  export type ConfigureShipmentFeatures = {
27
27
  compatibleCountryCodes?: UseShipmentFormProps["compatibleCountryCodes"];
28
+ partnerMessages?: {
29
+ incompleteLabelPurchaseRequirements?: string;
30
+ };
28
31
  presentation?: {
29
32
  poweredByShipEngine?: boolean;
30
33
  };
@@ -5,7 +5,7 @@ export type UseRatesFormProps = {
5
5
  onBeforeLabelCreate?: (rate: SE.Rate, shipment: SE.SalesOrderShipment) => Promise<void> | Promise<{
6
6
  error?: SE.CodedError;
7
7
  rate?: SE.Rate;
8
- }> | void;
8
+ } | undefined> | void;
9
9
  onBeforeRateSaved?: (carrierId: string, serviceCode: string) => Promise<void> | Promise<{
10
10
  data?: {
11
11
  carrierId: string;
@@ -23,11 +23,10 @@ export type UseRatesFormProps = {
23
23
  };
24
24
  export declare const useRatesForm: ({ getPreferredRates, onBeforeRateSaved, onBeforeLabelCreate, onLabelCreateFailure, onLabelCreateSuccess, onRateSaved, onRatesCalculated, onShipmentUpdated, printLabelLayout, shipment, }: UseRatesFormProps) => {
25
25
  carriers: SE.Carrier[] | undefined;
26
- displayableLabelErrors: string[] | undefined;
27
26
  displayableRateErrors: string[] | undefined;
28
27
  errors: SE.CodedError[] | undefined;
29
28
  isLoading: boolean;
30
- labelErrors: SE.CodedError[] | undefined;
29
+ labelErrors: string[] | undefined;
31
30
  labels: SE.Label[] | undefined;
32
31
  labelsLoading: boolean;
33
32
  onSave: ({ carrierId, serviceCode }: Pick<SE.Rate, "carrierId" | "serviceCode">) => Promise<void>;
@@ -664,7 +664,7 @@ export declare const Element: ({ resources, ...props }: ComponentProps & {
664
664
  invalidAddressNameStrict: string;
665
665
  invalidAddressPoBox: string;
666
666
  invalidCreditCardType: string;
667
- invalidExpiration: string;
667
+ invalidExpirationDate: string;
668
668
  invalidPostalCode: string;
669
669
  invalidStateProvince: string;
670
670
  invalidString: string;
@@ -149,7 +149,7 @@ export type ElementProps = PurchaseLabelByShipmentProps | PurchaseLabelSalesOrde
149
149
  *
150
150
  * @see {@link PurchaseLabel.Element | The **Element** created to render `<PurchaseLabel />`}
151
151
  */
152
- export declare const Component: ({ ...props }: ElementProps) => import("@emotion/react/jsx-runtime").JSX.Element;
152
+ export declare const Component: ({ features, ...props }: ElementProps) => import("@emotion/react/jsx-runtime").JSX.Element;
153
153
  /**
154
154
  * # Registered Purchase Label Element
155
155
  *
@@ -254,7 +254,14 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
254
254
  highVolumeForms: string;
255
255
  multipleShippingServices: string;
256
256
  sections: {
257
- labels: string;
257
+ labels: string; /**
258
+ *`getPreferredRates is an async/sync optional callback function that will be invoked each time rates are caculated.
259
+ * This is an optional callback function that returns an array of ShipEngine rates. The rates from this response will
260
+ * be spliced into the normal get rates response the Elements makes internally. If a service code matches a service
261
+ * code on a rate returned from getPreferredRates, the rate returned from getPreferredRates will not be shown in the
262
+ * rate form. These preferred rates will be displayed with a set of UI enhancements that incude a dynamic cost savings
263
+ * flag and green checkmark when the rate is selected.
264
+ */
258
265
  };
259
266
  noLabels: string;
260
267
  };
@@ -328,22 +335,12 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
328
335
  currentBalance: string;
329
336
  insufficientBalanceCTA: string;
330
337
  };
331
- /**
332
- * # Purchase Label Component Props
333
- *
334
- * These are the shared props that will be passed into the `<PurchaseLabel.Element />`, and work
335
- * for either shipment-based or sales order-based label purchasing.
336
- *
337
- * @see {@link PurchaseLabel.Element | This prop types usage in `<PurchaseLabel.Element />`}
338
- */
339
338
  cta: {
340
339
  addPackageDetails: string;
341
340
  };
342
341
  errorMessages: {
343
342
  customsItemsRequired: string;
344
- invalidAddress: string; /**
345
- * `features` is a set of feature flags you would like to enable or disable in this component.
346
- */
343
+ invalidAddress: string;
347
344
  noRates: string;
348
345
  salesOrderNotLoaded: string;
349
346
  unsupportedAddress: string;
@@ -367,19 +364,13 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
367
364
  estimatedShipping: string;
368
365
  insurance: string;
369
366
  insuranceProvider: string;
370
- insuredValue: string; /**
371
- * `onApplyPreset` is an async/sync callback function that will be invoked each time a `Preset`
372
- * has been applied to a shipment.
373
- */
367
+ insuredValue: string;
374
368
  items: string;
375
369
  orderDate: string;
376
370
  orderValue: string;
377
371
  packageCode: string;
378
372
  requestedShipping: string;
379
- shipDate: string; /**
380
- * `onBeforeLabelCreate` is an async/sync callback function that will be invoked before every
381
- * label purchase.
382
- */
373
+ shipDate: string;
383
374
  service: string;
384
375
  shipTo: string;
385
376
  addShipToAddress: string;
@@ -392,6 +383,10 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
392
383
  today: string;
393
384
  };
394
385
  hints: {
386
+ /**
387
+ * `onBeforeRateSave` is an async/sync callback function that will be invoked before each time a user
388
+ * saves a rate.
389
+ */
395
390
  contentDescription: string;
396
391
  };
397
392
  loading: {
@@ -410,15 +405,15 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
410
405
  rates: {
411
406
  uspsMediaMailAcknowledgement: string;
412
407
  uspsFirstClassMailAcknowledgement_leof: string;
413
- rateSavings: string;
408
+ rateSavings: string; /**
409
+ * `onLabelCreateSuccess` is an async/sync callback provided by the client that is invoked if the
410
+ * label is successfully created/purchased.
411
+ */
414
412
  upsGroundSaverTermsAcknowledgement: string;
415
413
  dhlExpressTermsAcknowledgement: string;
416
414
  };
417
415
  requirements: {
418
- noWarehouse: string; /**
419
- * `onRateSaved` is an async/sync callback function that will be invoked each time a rate is
420
- * saved by the user when rate shopping in the host application.
421
- */
416
+ noWarehouse: string;
422
417
  noCarrier: string;
423
418
  noWarehouseOrCarrier: string;
424
419
  };
@@ -458,6 +453,9 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
458
453
  inlineMessage: string;
459
454
  };
460
455
  success: {
456
+ /**
457
+ * `features` is a set of feature flags you would like to enable or disable in this component.
458
+ */
461
459
  title: string;
462
460
  subtitle: string;
463
461
  action: string;
@@ -482,14 +480,6 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
482
480
  status: {
483
481
  saving: string;
484
482
  saved: string;
485
- /**
486
- * # Purchase Label Component Props
487
- *
488
- * These are the shared props that will be passed into the `<PurchaseLabel.Element />`, and work
489
- * for either shipment-based or sales order-based label purchasing.
490
- *
491
- * @see {@link PurchaseLabel.Element | This prop types usage in `<PurchaseLabel.Element />`}
492
- */
493
483
  savingFailed: string;
494
484
  };
495
485
  units: {
@@ -503,9 +493,7 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
503
493
  title: string;
504
494
  standard: string;
505
495
  g: string;
506
- kg: string; /**
507
- * `features` is a set of feature flags you would like to enable or disable in this component.
508
- */
496
+ kg: string;
509
497
  };
510
498
  };
511
499
  };
@@ -683,10 +671,7 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
683
671
  none: string;
684
672
  signature: string;
685
673
  verbalConfirmation: string;
686
- }; /**
687
- * `onLabelCreateFailure` is an async/sync callback function that will be invoked each time a
688
- * label purchase fails.
689
- */
674
+ };
690
675
  customs: {
691
676
  addDeclaration: string;
692
677
  contents: {
@@ -725,6 +710,12 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
725
710
  autoFundingSettings: string;
726
711
  carrier: string;
727
712
  carriers: string;
713
+ /**
714
+ * `onToggleAddressPreferenceDisclosure` is an async/sync callback function that will be invoked
715
+ * each time the user toggles the `Address Preference` disclosure. This disclosure component
716
+ * allows the user to select whether they would like to use the address they entered, or
717
+ * the formatted address that we return after validation.
718
+ */
728
719
  label: string;
729
720
  salesOrder: string;
730
721
  shipment: string;
@@ -757,7 +748,10 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
757
748
  connectingCarriers: string;
758
749
  data: string;
759
750
  importingSalesOrder: string;
760
- label: string;
751
+ label: string; /**
752
+ * `warehouseId` is a string that represents a previously configured warehouse you would
753
+ * like to use as the `Ship From Address` when purchasing a label.
754
+ */
761
755
  onboarding: string;
762
756
  salesOrder: string;
763
757
  shipment: string;
@@ -798,7 +792,7 @@ export declare const Element: ({ resources, ...props }: ElementProps & {
798
792
  invalidAddressNameStrict: string;
799
793
  invalidAddressPoBox: string;
800
794
  invalidCreditCardType: string;
801
- invalidExpiration: string;
795
+ invalidExpirationDate: string;
802
796
  invalidPostalCode: string;
803
797
  invalidStateProvince: string;
804
798
  invalidString: string;
@@ -699,7 +699,7 @@ export declare const Element: ({ resources, ...props }: ComponentProps & {
699
699
  invalidAddressNameStrict: string;
700
700
  invalidAddressPoBox: string;
701
701
  invalidCreditCardType: string;
702
- invalidExpiration: string;
702
+ invalidExpirationDate: string;
703
703
  invalidPostalCode: string;
704
704
  invalidStateProvince: string;
705
705
  invalidString: string;
@@ -702,7 +702,7 @@ export declare const Element: ({ resources, ...props }: ComponentProps & {
702
702
  invalidAddressNameStrict: string;
703
703
  invalidAddressPoBox: string;
704
704
  invalidCreditCardType: string;
705
- invalidExpiration: string;
705
+ invalidExpirationDate: string;
706
706
  invalidPostalCode: string;
707
707
  invalidStateProvince: string;
708
708
  invalidString: string;
@@ -574,7 +574,7 @@ declare const _default: {
574
574
  invalidAddressNameStrict: string;
575
575
  invalidAddressPoBox: string;
576
576
  invalidCreditCardType: string;
577
- invalidExpiration: string;
577
+ invalidExpirationDate: string;
578
578
  invalidPostalCode: string;
579
579
  invalidStateProvince: string;
580
580
  invalidString: string;
@@ -51,6 +51,14 @@ export declare const featureFlags: {
51
51
  * Elements.
52
52
  */
53
53
  readonly compatibleCountryCodes: readonly ["AU", "CA", "FR", "DE", "GB", "IL", "IT", "NO", "ES", "SE", "US"];
54
+ /**
55
+ * @internal
56
+ *
57
+ * `partnerMessages` enables the partner consuming elements to specify override messages in specific cases.
58
+ */
59
+ readonly partnerMessages: {
60
+ readonly incompleteLabelPurchaseRequirements: undefined;
61
+ };
54
62
  /**
55
63
  * `rateForm` all scoped feature flags for the `rate form` section of the `<PurchaseLabel />`
56
64
  * element.
@@ -104,14 +112,6 @@ export declare const featureFlags: {
104
112
  * to opt for third party insurance when insuring their shipment.
105
113
  */
106
114
  readonly includeThirdPartyInsurance: true;
107
- /**
108
- * @internal
109
- *
110
- * `partnerMessages` enables the partner consuming elements to specify override messages in specific cases.
111
- */
112
- readonly partnerMessages: {
113
- readonly incompleteLabelPurchaseRequirements: undefined;
114
- };
115
115
  /**
116
116
  * `selectService` enables the `select service` feature, allowing users to select a service
117
117
  * when rate shopping across multiple carrier providers.