@shipengine/elements 0.37.1 → 0.37.3

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,15 @@ const featureFlags = {
2648
2648
  * Elements.
2649
2649
  */
2650
2650
  compatibleCountryCodes: ["AU", "CA", "FR", "DE", "GB", "IL", "IT", "NO", "ES", "SE", "US"],
2651
+ /**
2652
+ * `configureShipment` is a group of flags related to the useConfigureShipment functionality
2653
+ */
2654
+ configureShipment: {
2655
+ /**
2656
+ * `enableErrorWhenShipmentCancelled` when enabled will modify the default behavior of creating a new shipment for a salesorder to throwing an error
2657
+ */
2658
+ enableErrorWhenShipmentCancelled: false
2659
+ },
2651
2660
  /**
2652
2661
  * @internal
2653
2662
  *
@@ -3960,11 +3969,29 @@ const getIsCustomsRequiredForShipment = ({
3960
3969
  /**
3961
3970
  * @internal
3962
3971
  *
3972
+ * @deprecated please use getShipmentByStatus instead
3963
3973
  * # Shipment Utilities - getPendingShipment
3964
3974
  *
3965
3975
  * @category Utilities
3966
3976
  */
3967
3977
  const getPendingShipment = shipments => shipments === null || shipments === void 0 ? void 0 : shipments.filter(s => s.shipmentStatus === "pending").sort(sortByCreationDate)[0];
3978
+ /**
3979
+ *
3980
+ * @deprecated please use getShipmentByStatus instead
3981
+ * @internal
3982
+ * @param shipments
3983
+ * @returns the latest created shipment whose status is `cancelled`
3984
+ */
3985
+ const getCancelledShipment = shipments => shipments === null || shipments === void 0 ? void 0 : shipments.filter(shipment => shipment.shipmentStatus === "cancelled").sort(sortByCreationDate)[0];
3986
+ /**
3987
+ *
3988
+ * @param status string containing one of the following values - "pending", "processing", "label_purchased", "cancelled"
3989
+ * @param shipments optional list of shipments to filter from
3990
+ * @returns latest created shipment whose shipmentStatus matches the param status
3991
+ */
3992
+ const getShipmentByStatus = (status, shipments) => shipments === null || shipments === void 0 ? void 0 : shipments.filter(({
3993
+ shipmentStatus
3994
+ }) => shipmentStatus === status).sort(sortByCreationDate)[0];
3968
3995
 
3969
3996
  var uncurryThis$6 = functionUncurryThis;
3970
3997
 
@@ -12832,7 +12859,7 @@ const CustomsItemForm = ({
12832
12859
  }));
12833
12860
  const formInterface = jsxRuntime.jsxs("section", Object.assign({
12834
12861
  css: theme => ({
12835
- backgroundColor: theme.palette.gray.megaLight,
12862
+ backgroundColor: theme.palette.gray.ultraLight,
12836
12863
  padding: theme.spacing(2)
12837
12864
  })
12838
12865
  }, {
@@ -14635,22 +14662,21 @@ const rateSchema = zod.z.object({
14635
14662
  const RateForm = ({
14636
14663
  carriers,
14637
14664
  disabled,
14638
- errors,
14639
14665
  displayableRateErrors,
14640
- displayableLabelErrors,
14666
+ errors,
14641
14667
  features,
14668
+ isLoading,
14642
14669
  labelErrors,
14643
14670
  labels,
14644
14671
  labelsLoading,
14645
- isLoading,
14646
14672
  onSave,
14647
14673
  onSelectRate,
14648
14674
  onSubmit,
14649
- rates,
14650
- preferredRates,
14651
- shipment,
14652
14675
  outOfBandDisplayableErrors,
14653
- preferredServiceCodes
14676
+ preferredRates,
14677
+ preferredServiceCodes,
14678
+ rates,
14679
+ shipment
14654
14680
  }) => {
14655
14681
  var _a, _b, _c, _d, _e, _f;
14656
14682
  features = Object.assign({
@@ -14664,7 +14690,6 @@ const RateForm = ({
14664
14690
  saveRate: true
14665
14691
  }
14666
14692
  }, features !== null && features !== void 0 ? features : {});
14667
- const allDisplayableErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14668
14693
  const {
14669
14694
  t
14670
14695
  } = reactI18next.useTranslation();
@@ -14762,6 +14787,22 @@ const RateForm = ({
14762
14787
  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
14788
  return !!preferredRate;
14764
14789
  }, [preferredRates, selectedRate]);
14790
+ const displayableErrors = React.useMemo(() => {
14791
+ const rateAndShipmentErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14792
+ if (rateAndShipmentErrors.length && rateOptions.length === 0) {
14793
+ return {
14794
+ messages: rateAndShipmentErrors,
14795
+ title: "errorTypes.rateInvalid"
14796
+ };
14797
+ }
14798
+ if (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) {
14799
+ return {
14800
+ messages: labelErrors,
14801
+ title: "errorTypes.purchase"
14802
+ };
14803
+ }
14804
+ return undefined;
14805
+ }, [rateOptions, labelErrors, displayableRateErrors, outOfBandDisplayableErrors]);
14765
14806
  return jsxRuntime.jsxs("form", Object.assign({
14766
14807
  id: "rate-form",
14767
14808
  onSubmit: handleSubmit,
@@ -14806,7 +14847,7 @@ const RateForm = ({
14806
14847
  children: showHiddenRates ? t("purchase-label:actions.showFewerRates") : t("purchase-label:actions.showMoreRates")
14807
14848
  }))
14808
14849
  }))]
14809
- }) : !isLoading && !!allDisplayableErrors.length ? null : jsxRuntime.jsxs("article", Object.assign({
14850
+ }) : !isLoading && !!displayableErrors ? null : jsxRuntime.jsxs("article", Object.assign({
14810
14851
  css: styles$3.ratesInterstitial,
14811
14852
  role: "presentation"
14812
14853
  }, {
@@ -14815,13 +14856,11 @@ const RateForm = ({
14815
14856
  }), jsxRuntime.jsx(Spacer, {}), isLoading ? t("purchase-label:loading.calculatingRates") : t("purchase-label:cta.addPackageDetails")]
14816
14857
  })), jsxRuntime.jsx(Spacer, {
14817
14858
  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"),
14859
+ }), !isLoading && !!displayableErrors && jsxRuntime.jsx(giger.InlineNotification, Object.assign({
14860
+ title: t(displayableErrors.title),
14820
14861
  type: giger.NotificationType.ERROR
14821
14862
  }, {
14822
- children: jsxRuntime.jsxs(jsxRuntime.Fragment, {
14823
- children: [displayableRateErrors, outOfBandDisplayableErrors, displayableLabelErrors]
14824
- })
14863
+ children: displayableErrors.messages
14825
14864
  }))]
14826
14865
  })), ((_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
14866
  title: t("manage-defaults:label.title")
@@ -14990,21 +15029,37 @@ const styles$1 = createStyles({
14990
15029
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
14991
15030
  width: theme.spacing(5)
14992
15031
  }),
15032
+ header: theme => ({
15033
+ "& > tr > th": {
15034
+ "&:after": {
15035
+ borderBottom: "none"
15036
+ }
15037
+ }
15038
+ }),
15039
+ headerActions: theme => ({
15040
+ backgroundColor: theme.palette.gray.ultraLight,
15041
+ padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
15042
+ width: theme.spacing(5)
15043
+ }),
14993
15044
  headerDescription: theme => ({
15045
+ backgroundColor: theme.palette.gray.ultraLight,
14994
15046
  overflow: "visible",
14995
15047
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`
14996
15048
  }),
14997
15049
  headerEach: theme => ({
15050
+ backgroundColor: theme.palette.gray.ultraLight,
14998
15051
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
14999
15052
  textAlign: "right",
15000
15053
  width: theme.spacing(10)
15001
15054
  }),
15002
15055
  headerQty: theme => ({
15056
+ backgroundColor: theme.palette.gray.ultraLight,
15003
15057
  padding: theme.spacing(1),
15004
15058
  textAlign: "right",
15005
15059
  width: theme.spacing(5)
15006
15060
  }),
15007
15061
  headerTotal: theme => ({
15062
+ backgroundColor: theme.palette.gray.ultraLight,
15008
15063
  padding: `${theme.spacing(1)}px 0 ${theme.spacing(1)}px ${theme.spacing(1)}px`,
15009
15064
  textAlign: "right",
15010
15065
  width: theme.spacing(10)
@@ -15026,7 +15081,7 @@ const styles$1 = createStyles({
15026
15081
  itemQty: theme => ({
15027
15082
  overflow: "visible",
15028
15083
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
15029
- textAlign: "center",
15084
+ textAlign: "right",
15030
15085
  width: theme.spacing(5)
15031
15086
  }),
15032
15087
  itemTotal: theme => ({
@@ -15034,6 +15089,14 @@ const styles$1 = createStyles({
15034
15089
  padding: `${theme.spacing(1)}px 0 0 ${theme.spacing(1)}px`,
15035
15090
  textAlign: "right",
15036
15091
  width: theme.spacing(10)
15092
+ }),
15093
+ subtitle: () => ({
15094
+ letterSpacing: "0.01em"
15095
+ }),
15096
+ table: () => ({
15097
+ border: "1px solid #d4e4e8",
15098
+ borderRadius: "0",
15099
+ boxShadow: "none"
15037
15100
  })
15038
15101
  });
15039
15102
 
@@ -15144,12 +15207,15 @@ const CustomsItemsDisplay = ({
15144
15207
  }))]
15145
15208
  })), customsItems.length > 0 && jsxRuntime.jsxs(jsxRuntime.Fragment, {
15146
15209
  children: [jsxRuntime.jsx(Spacer, {}), jsxRuntime.jsx(giger.Table, Object.assign({
15147
- header: jsxRuntime.jsx(giger.TableHeader, {
15210
+ header: jsxRuntime.jsx(giger.TableHeader, Object.assign({
15211
+ css: styles$1.header
15212
+ }, {
15148
15213
  children: jsxRuntime.jsxs(giger.TableBaseRow, {
15149
15214
  children: [jsxRuntime.jsx(giger.TableHeaderCell, Object.assign({
15150
15215
  css: styles$1.headerDescription
15151
15216
  }, {
15152
15217
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15218
+ css: styles$1.subtitle,
15153
15219
  variant: "subtitle2"
15154
15220
  }, {
15155
15221
  children: t("customs.fields.description")
@@ -15158,6 +15224,7 @@ const CustomsItemsDisplay = ({
15158
15224
  css: styles$1.headerEach
15159
15225
  }, {
15160
15226
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15227
+ css: styles$1.subtitle,
15161
15228
  variant: "subtitle2"
15162
15229
  }, {
15163
15230
  children: t("customs.each", {
@@ -15168,6 +15235,7 @@ const CustomsItemsDisplay = ({
15168
15235
  css: styles$1.headerQty
15169
15236
  }, {
15170
15237
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15238
+ css: styles$1.subtitle,
15171
15239
  variant: "subtitle2"
15172
15240
  }, {
15173
15241
  children: t("customs.fields.quantity")
@@ -15176,6 +15244,7 @@ const CustomsItemsDisplay = ({
15176
15244
  css: styles$1.headerTotal
15177
15245
  }, {
15178
15246
  children: jsxRuntime.jsx(giger.Typography, Object.assign({
15247
+ css: styles$1.subtitle,
15179
15248
  variant: "subtitle2"
15180
15249
  }, {
15181
15250
  children: t("customs.total", {
@@ -15183,10 +15252,11 @@ const CustomsItemsDisplay = ({
15183
15252
  })
15184
15253
  }))
15185
15254
  })), jsxRuntime.jsx(giger.TableHeaderCell, {
15186
- css: styles$1.actionsColumn
15255
+ css: styles$1.headerActions
15187
15256
  })]
15188
15257
  })
15189
- })
15258
+ })),
15259
+ outerWrapperStyles: styles$1.table
15190
15260
  }, {
15191
15261
  children: jsxRuntime.jsx(giger.TableBody, {
15192
15262
  children: customsItems.map(item => jsxRuntime.jsxs(React.Fragment, {
@@ -16819,6 +16889,7 @@ var common = {
16819
16889
  invalidNameOrCompany: "Recipient name and company name (if provided) must have two characters in first and last name.",
16820
16890
  parsingFailure: "Parsing failed. Please check address and try again.",
16821
16891
  incompleteLabelPurchaseRequirements: "Please add your {{requirements}} to continue purchasing a label.",
16892
+ shipmentCancelled: "This shipment is Cancelled in ShipStation. Log into ShipStation to restore the order to Awaiting Shipment status.",
16822
16893
  unableToLoad: {
16823
16894
  accountSettings: "Unable to load account settings",
16824
16895
  autoFundingSettings: "Unable to load auto funding settings",
@@ -16839,6 +16910,7 @@ var common = {
16839
16910
  purchase: "Purchase error",
16840
16911
  rateInvalid: "Invalid rate configuration",
16841
16912
  security: "Security error",
16913
+ shipmentStatus: "Shipment status error",
16842
16914
  system: "System error",
16843
16915
  unknown: "Unknown error",
16844
16916
  validation: "Unable to validate address"
@@ -16897,7 +16969,7 @@ var common = {
16897
16969
  invalidAddressNameStrict: "Recipient Name must have two characters in First and Last Name.",
16898
16970
  invalidAddressPoBox: "A physical address is required for wallet registration. You can add a PO Box as a Ship From address.",
16899
16971
  invalidCreditCardType: "Card type must be Visa, Mastercard, American Express, or Discover",
16900
- invalidExpiration: "Invalid Expiration Date",
16972
+ invalidExpirationDate: "Invalid Expiration Date",
16901
16973
  invalidPostalCode: "Invalid Postal Code",
16902
16974
  invalidStateProvince: "Invalid State",
16903
16975
  invalidString: "{{fieldLabel}} is invalid",
@@ -17933,12 +18005,12 @@ const useRequestRates = ({
17933
18005
  getPreferredRates
17934
18006
  });
17935
18007
  const requestRates = React.useCallback((shipment, isInternational) => __awaiter(void 0, void 0, void 0, function* () {
17936
- var _a, _b;
17937
- const internationalCarrierIds = (_a = carriers === null || carriers === void 0 ? void 0 : carriers.map(c => c.carrierId)) !== null && _a !== void 0 ? _a : [];
17938
- 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 : [];
18008
+ var _a;
18009
+ // filter out DHL for domestic shipments
18010
+ 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 : [];
17939
18011
  const standardRatesResponse = yield calculateRates({
17940
18012
  rateOptions: {
17941
- carrierIds: shipment.carrierId ? [shipment.carrierId] : isInternational ? internationalCarrierIds : domesticCarrierIds,
18013
+ carrierIds: shipment.carrierId ? [shipment.carrierId] : carrierIds,
17942
18014
  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
17943
18015
  : shipment.packages.map(pkg => pkg.packageCode),
17944
18016
  serviceCodes: shipment.serviceCode ? [shipment.serviceCode] : undefined
@@ -18236,11 +18308,10 @@ const useRatesForm = ({
18236
18308
  });
18237
18309
  return {
18238
18310
  carriers,
18239
- displayableLabelErrors,
18240
18311
  displayableRateErrors,
18241
18312
  errors: errors.length > 0 ? errors : undefined,
18242
18313
  isLoading: ratesCalculating,
18243
- labelErrors: (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) ? labelErrors : undefined,
18314
+ labelErrors: displayableLabelErrors,
18244
18315
  labels,
18245
18316
  labelsLoading,
18246
18317
  onSave: handleSave,
@@ -18358,7 +18429,9 @@ const useShipmentForm = ({
18358
18429
  };
18359
18430
 
18360
18431
  const ConfigureShipment = _a => {
18432
+ var _b;
18361
18433
  var {
18434
+ errors,
18362
18435
  features,
18363
18436
  getPreferredRates,
18364
18437
  onAddressValidation,
@@ -18376,12 +18449,13 @@ const ConfigureShipment = _a => {
18376
18449
  shipment,
18377
18450
  onBeforeRateSaved
18378
18451
  } = _a,
18379
- props = __rest(_a, ["features", "getPreferredRates", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "preferredServiceCodes", "salesOrder", "shipment", "onBeforeRateSaved"]);
18452
+ props = __rest(_a, ["errors", "features", "getPreferredRates", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "preferredServiceCodes", "salesOrder", "shipment", "onBeforeRateSaved"]);
18380
18453
  const hydrateRef = React.useRef();
18454
+ reactI18next.useTranslation();
18381
18455
  const {
18382
18456
  isInternational
18383
18457
  } = useShipmentMetadata(shipment);
18384
- const _b = useRatesForm({
18458
+ const _c = useRatesForm({
18385
18459
  getPreferredRates,
18386
18460
  onBeforeLabelCreate,
18387
18461
  onBeforeRateSaved,
@@ -18402,17 +18476,17 @@ const ConfigureShipment = _a => {
18402
18476
  resetRates,
18403
18477
  resetLabel,
18404
18478
  preferredRates
18405
- } = _b,
18406
- rateFormProps = __rest(_b, ["requestRates", "resetRates", "resetLabel", "preferredRates"]);
18407
- const _c = useShipmentForm({
18479
+ } = _c,
18480
+ rateFormProps = __rest(_c, ["requestRates", "resetRates", "resetLabel", "preferredRates"]);
18481
+ const _d = useShipmentForm({
18408
18482
  compatibleCountryCodes: features === null || features === void 0 ? void 0 : features.compatibleCountryCodes,
18409
18483
  onAddressValidation,
18410
18484
  onApplyPreset: React.useCallback((_preset, shipment) => __awaiter(void 0, void 0, void 0, function* () {
18411
- var _d;
18485
+ var _e;
18412
18486
  if (shipment.packages[0].weight.value) {
18413
18487
  yield requestRates(shipment, isInternational);
18414
18488
  }
18415
- (_d = hydrateRef.current) === null || _d === void 0 ? void 0 : _d.call(hydrateRef, shipment);
18489
+ (_e = hydrateRef.current) === null || _e === void 0 ? void 0 : _e.call(hydrateRef, shipment);
18416
18490
  }), [requestRates, isInternational]),
18417
18491
  onChangeAddress,
18418
18492
  onShipmentUpdated,
@@ -18425,8 +18499,8 @@ const ConfigureShipment = _a => {
18425
18499
  {
18426
18500
  charsetWarning,
18427
18501
  resetSalesOrderShipment
18428
- } = _c,
18429
- shipmentFormProps = __rest(_c, ["charsetWarning", "resetSalesOrderShipment"]);
18502
+ } = _d,
18503
+ shipmentFormProps = __rest(_d, ["charsetWarning", "resetSalesOrderShipment"]);
18430
18504
  const handleOnDirty = React.useCallback(() => {
18431
18505
  resetRates();
18432
18506
  resetLabel();
@@ -18446,6 +18520,9 @@ const ConfigureShipment = _a => {
18446
18520
  return self.indexOf(item) === pos;
18447
18521
  });
18448
18522
  }, [preferredRates, preferredServiceCodes]);
18523
+ if (((_b = features === null || features === void 0 ? void 0 : features.configureShipment) === null || _b === void 0 ? void 0 : _b.enableErrorWhenShipmentCancelled) && (errors === null || errors === void 0 ? void 0 : errors.filter(e => e.message === "shipment_cancelled"))) {
18524
+ throw new Error("errorMessages.shipmentCancelled");
18525
+ }
18449
18526
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
18450
18527
  children: [jsxRuntime.jsx(ShipmentForm, Object.assign({}, shipmentFormProps, props, {
18451
18528
  charsetWarning: charsetWarning,
@@ -18464,6 +18541,7 @@ const ConfigureShipment = _a => {
18464
18541
  };
18465
18542
 
18466
18543
  const usePendingShipment = ({
18544
+ breakOnCancelledShipment: _breakOnCancelledShipment = false,
18467
18545
  onLoad,
18468
18546
  salesOrder,
18469
18547
  warehouseId
@@ -18487,17 +18565,18 @@ const usePendingShipment = ({
18487
18565
  isLoading: isShipmentCreating,
18488
18566
  mutateAsync: createShipment
18489
18567
  } = alchemy.useCreateSalesOrderShipment();
18490
- const pendingShipment = getPendingShipment(shipments);
18568
+ const pendingShipment = getShipmentByStatus("pending", shipments);
18569
+ const cancelledShipment = getShipmentByStatus("cancelled", shipments);
18491
18570
  const defaultWarehouse = (_a = warehouses === null || warehouses === void 0 ? void 0 : warehouses.find(w => w.warehouseId === warehouseId)) !== null && _a !== void 0 ? _a : warehouses === null || warehouses === void 0 ? void 0 : warehouses[0];
18492
18571
  // On page load, check for a shipment and either call the onLoad callback or create a new shipment
18493
18572
  React.useEffect(() => {
18494
18573
  if (salesOrder && (shipments === null || shipments === void 0 ? void 0 : shipments.length) && shipments.every(s => s.shipmentStatus === "label_purchased")) {
18495
- onLoad === null || onLoad === void 0 ? void 0 : onLoad(salesOrder, shipments, pendingShipment);
18574
+ void (onLoad === null || onLoad === void 0 ? void 0 : onLoad(salesOrder, shipments, pendingShipment));
18496
18575
  return;
18497
18576
  }
18498
- if (!salesOrder || !defaultWarehouse || !shipments || pendingShipment) return;
18577
+ if (!salesOrder || !defaultWarehouse || !shipments || _breakOnCancelledShipment && cancelledShipment || pendingShipment) return;
18499
18578
  if (isListShipmentsLoading || isListShipmentsValidating || isShipmentCreating) return;
18500
- createShipment(Object.assign(Object.assign({
18579
+ void createShipment(Object.assign(Object.assign({
18501
18580
  salesOrderId: salesOrder === null || salesOrder === void 0 ? void 0 : salesOrder.salesOrderId,
18502
18581
  // /v-beta/shipments/sales_order/:salesOrderId requires at minimum
18503
18582
  // a (warehouseId or shipFrom)
@@ -18513,14 +18592,18 @@ const usePendingShipment = ({
18513
18592
  }
18514
18593
  }]
18515
18594
  })).then(shipment => shipment && reloadShipments());
18516
- }, [createShipment, defaultWarehouse, isListShipmentsLoading, isListShipmentsValidating, isShipmentCreating, onLoad, pendingShipment, reloadShipments, salesOrder, shipments, warehouseId]);
18595
+ }, [cancelledShipment, createShipment, defaultWarehouse, isListShipmentsLoading, isListShipmentsValidating, isShipmentCreating, onLoad, pendingShipment, reloadShipments, salesOrder, shipments, warehouseId, _breakOnCancelledShipment]);
18517
18596
  const reloadPendingShipment = React.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
18518
18597
  const {
18519
18598
  data: shipments
18520
18599
  } = yield reloadShipments();
18521
- return getPendingShipment(shipments);
18600
+ return getShipmentByStatus("pending", shipments);
18522
18601
  }), [reloadShipments]);
18523
- const errors = [...(listWarehouseErrors !== null && listWarehouseErrors !== void 0 ? listWarehouseErrors : []), ...(createShipmentErrors !== null && createShipmentErrors !== void 0 ? createShipmentErrors : []), ...(listShipmentsErrors !== null && listShipmentsErrors !== void 0 ? listShipmentsErrors : [])];
18602
+ const errors = [...(listWarehouseErrors !== null && listWarehouseErrors !== void 0 ? listWarehouseErrors : []), ...(createShipmentErrors !== null && createShipmentErrors !== void 0 ? createShipmentErrors : []), ...(listShipmentsErrors !== null && listShipmentsErrors !== void 0 ? listShipmentsErrors : []), ...(_breakOnCancelledShipment && cancelledShipment ? [new alchemy.CodedError("shipment_cancelled", {
18603
+ errorCode: "invalid_status",
18604
+ errorSource: "elements",
18605
+ errorType: "business_rules"
18606
+ })] : [])];
18524
18607
  return {
18525
18608
  isPendingShipmentLoading: !pendingShipment && errors.length === 0,
18526
18609
  pendingShipment,
@@ -18531,6 +18614,7 @@ const usePendingShipment = ({
18531
18614
 
18532
18615
  const useConfigureShipment = ({
18533
18616
  onLoad,
18617
+ errorWhenShipmentCancelled: _errorWhenShipmentCancelled = false,
18534
18618
  onShipmentUpdated,
18535
18619
  salesOrder,
18536
18620
  warehouseId,
@@ -18543,6 +18627,7 @@ const useConfigureShipment = ({
18543
18627
  pendingShipmentErrors,
18544
18628
  reloadPendingShipment
18545
18629
  } = usePendingShipment({
18630
+ breakOnCancelledShipment: _errorWhenShipmentCancelled,
18546
18631
  onLoad,
18547
18632
  salesOrder,
18548
18633
  warehouseId
@@ -18619,6 +18704,7 @@ const useImportSalesOrder = ({
18619
18704
  };
18620
18705
 
18621
18706
  const PurchaseLabelBySalesOrder = _a => {
18707
+ var _b;
18622
18708
  var {
18623
18709
  features,
18624
18710
  externalOrderId,
@@ -18631,7 +18717,7 @@ const PurchaseLabelBySalesOrder = _a => {
18631
18717
  printLabelLayout
18632
18718
  } = _a,
18633
18719
  props = __rest(_a, ["features", "externalOrderId", "externalOrderNumber", "onLoad", "onShipmentUpdated", "orderSourceCode", "salesOrderId", "warehouseId", "printLabelLayout"]);
18634
- const _b = useImportSalesOrder({
18720
+ const _c = useImportSalesOrder({
18635
18721
  externalOrderId,
18636
18722
  externalOrderNumber,
18637
18723
  orderSourceCode,
@@ -18640,9 +18726,10 @@ const PurchaseLabelBySalesOrder = _a => {
18640
18726
  {
18641
18727
  salesOrder,
18642
18728
  isLoading: salesOrderLoading
18643
- } = _b,
18644
- salesOrderProps = __rest(_b, ["salesOrder", "isLoading"]);
18729
+ } = _c,
18730
+ salesOrderProps = __rest(_c, ["salesOrder", "isLoading"]);
18645
18731
  const configureShipmentProps = useConfigureShipment({
18732
+ errorWhenShipmentCancelled: (_b = features === null || features === void 0 ? void 0 : features.configureShipment) === null || _b === void 0 ? void 0 : _b.enableErrorWhenShipmentCancelled,
18646
18733
  onLoad,
18647
18734
  onShipmentUpdated,
18648
18735
  printLabelLayout,
@@ -18783,7 +18870,9 @@ const Component$2 = _a => {
18783
18870
  });
18784
18871
  if (incompleteRequirementsKeys.length > 0) throw new Error(incompleteRequirementsError);
18785
18872
  if ("salesOrderId" in props || "orderSourceCode" in props) {
18786
- return jsxRuntime.jsx(PurchaseLabelBySalesOrder, Object.assign({}, props));
18873
+ return jsxRuntime.jsx(PurchaseLabelBySalesOrder, Object.assign({
18874
+ features: features
18875
+ }, props));
18787
18876
  } else {
18788
18877
  return jsxRuntime.jsx(PurchaseLabelByShipment, Object.assign({}, props));
18789
18878
  }
@@ -19404,6 +19493,7 @@ exports.formatExpiration = formatExpiration;
19404
19493
  exports.formatFractionalWeight = formatFractionalWeight;
19405
19494
  exports.formatMoney = formatMoney;
19406
19495
  exports.getAddFundsSchema = getAddFundsSchema;
19496
+ exports.getCancelledShipment = getCancelledShipment;
19407
19497
  exports.getCarrierIdByCarrierCode = getCarrierIdByCarrierCode;
19408
19498
  exports.getCustomsFromSalesOrder = getCustomsFromSalesOrder;
19409
19499
  exports.getExpirationYears = getExpirationYears;
@@ -19416,6 +19506,7 @@ exports.getRateRequiresAcknowledgement = getRateRequiresAcknowledgement;
19416
19506
  exports.getRelativeDates = getRelativeDates;
19417
19507
  exports.getRequestedServices = getRequestedServices;
19418
19508
  exports.getSalesOrderItemsFromSalesOrderOrShipment = getSalesOrderItemsFromSalesOrderOrShipment;
19509
+ exports.getShipmentByStatus = getShipmentByStatus;
19419
19510
  exports.getTotalRateAmount = getTotalRateAmount;
19420
19511
  exports.isDecimalWeight = isDecimalWeight;
19421
19512
  exports.isDomesticAddress = isDomesticAddress;