@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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
2
2
  import { useTranslation, Trans } from 'react-i18next';
3
3
  import { InlineNotification, NotificationType, Typography, Link, ButtonSize, Spinner, Icon, IconSize, Divider, Skeleton, SkeletonAnimation, SkeletonVariant, Grid, GridChild, Pagination, SkeletonBackgroundColor, RadioGroup, Radio, SpinnerSize, FormField, FieldMessageType, Checkbox, Input, SelectAutocomplete, Select as Select$1, OptionGroup, Option, Button, Switch as Switch$1, Textarea, ChipList, Chip, ButtonVariant, ButtonColor, Tag, TagColor, Stepper, Step, IconTooltip, Table, TableBody, TableBaseRow, TableBodyCell, TableHeader, TableHeaderCell, Popover, DropdownOptionList, DatePicker as DatePicker$1, BottomSheet } from '@packlink/giger';
4
- import alchemy, { SE, logger, useValidateAddresses, useListCarriers, useConnectCarrier, useListWarehouses, useUpdateWarehouse, useCreateWarehouse, useDeleteWarehouse, useGetWalletHistory, useGetAccountSettings, useUpdateAccountSettings, AlchemyContext, useAddFunds, useGetCarrierById, useUpdateAutoFunding, useGetAutoFundingConfiguration, Currency, useUpdateFundingSource, useListFundingSources, useCreateFundingSource, useRegisterCarrier, useUpdateSalesOrderShipment, useParseAddress, useListCustomPackageTypes, useCalculateRates, useGetShipmentRates, useListLabels, useCreateLabel, useListSalesOrderShipments, useCreateSalesOrderShipment, useListSalesOrders, useGetSalesOrder, useListOrderSources, useRefreshOrderSource, useCreateShipment, useGetShipment, useGetSalesOrderShipment, useGetLabel, useVoidLabel } from '@shipengine/alchemy';
4
+ import alchemy, { SE, logger, useValidateAddresses, useListCarriers, useConnectCarrier, useListWarehouses, useUpdateWarehouse, useCreateWarehouse, useDeleteWarehouse, useGetWalletHistory, useGetAccountSettings, useUpdateAccountSettings, AlchemyContext, useAddFunds, useGetCarrierById, useUpdateAutoFunding, useGetAutoFundingConfiguration, Currency, useUpdateFundingSource, useListFundingSources, useCreateFundingSource, useRegisterCarrier, useUpdateSalesOrderShipment, useParseAddress, useListCustomPackageTypes, useCalculateRates, useGetShipmentRates, useListLabels, useCreateLabel, useListSalesOrderShipments, useCreateSalesOrderShipment, CodedError, useListSalesOrders, useGetSalesOrder, useListOrderSources, useRefreshOrderSource, useCreateShipment, useGetShipment, useGetSalesOrderShipment, useGetLabel, useVoidLabel } from '@shipengine/alchemy';
5
5
  import axios from 'axios';
6
6
  import _$3, { get as get$1, isEqual } from 'lodash';
7
7
  import { zodResolver } from '@hookform/resolvers/zod';
@@ -2616,6 +2616,15 @@ const featureFlags = {
2616
2616
  * Elements.
2617
2617
  */
2618
2618
  compatibleCountryCodes: ["AU", "CA", "FR", "DE", "GB", "IL", "IT", "NO", "ES", "SE", "US"],
2619
+ /**
2620
+ * `configureShipment` is a group of flags related to the useConfigureShipment functionality
2621
+ */
2622
+ configureShipment: {
2623
+ /**
2624
+ * `enableErrorWhenShipmentCancelled` when enabled will modify the default behavior of creating a new shipment for a salesorder to throwing an error
2625
+ */
2626
+ enableErrorWhenShipmentCancelled: false
2627
+ },
2619
2628
  /**
2620
2629
  * @internal
2621
2630
  *
@@ -3928,11 +3937,29 @@ const getIsCustomsRequiredForShipment = ({
3928
3937
  /**
3929
3938
  * @internal
3930
3939
  *
3940
+ * @deprecated please use getShipmentByStatus instead
3931
3941
  * # Shipment Utilities - getPendingShipment
3932
3942
  *
3933
3943
  * @category Utilities
3934
3944
  */
3935
3945
  const getPendingShipment = shipments => shipments === null || shipments === void 0 ? void 0 : shipments.filter(s => s.shipmentStatus === "pending").sort(sortByCreationDate)[0];
3946
+ /**
3947
+ *
3948
+ * @deprecated please use getShipmentByStatus instead
3949
+ * @internal
3950
+ * @param shipments
3951
+ * @returns the latest created shipment whose status is `cancelled`
3952
+ */
3953
+ const getCancelledShipment = shipments => shipments === null || shipments === void 0 ? void 0 : shipments.filter(shipment => shipment.shipmentStatus === "cancelled").sort(sortByCreationDate)[0];
3954
+ /**
3955
+ *
3956
+ * @param status string containing one of the following values - "pending", "processing", "label_purchased", "cancelled"
3957
+ * @param shipments optional list of shipments to filter from
3958
+ * @returns latest created shipment whose shipmentStatus matches the param status
3959
+ */
3960
+ const getShipmentByStatus = (status, shipments) => shipments === null || shipments === void 0 ? void 0 : shipments.filter(({
3961
+ shipmentStatus
3962
+ }) => shipmentStatus === status).sort(sortByCreationDate)[0];
3936
3963
 
3937
3964
  var uncurryThis$6 = functionUncurryThis;
3938
3965
 
@@ -12800,7 +12827,7 @@ const CustomsItemForm = ({
12800
12827
  }));
12801
12828
  const formInterface = jsxs("section", Object.assign({
12802
12829
  css: theme => ({
12803
- backgroundColor: theme.palette.gray.megaLight,
12830
+ backgroundColor: theme.palette.gray.ultraLight,
12804
12831
  padding: theme.spacing(2)
12805
12832
  })
12806
12833
  }, {
@@ -14603,22 +14630,21 @@ const rateSchema = z.object({
14603
14630
  const RateForm = ({
14604
14631
  carriers,
14605
14632
  disabled,
14606
- errors,
14607
14633
  displayableRateErrors,
14608
- displayableLabelErrors,
14634
+ errors,
14609
14635
  features,
14636
+ isLoading,
14610
14637
  labelErrors,
14611
14638
  labels,
14612
14639
  labelsLoading,
14613
- isLoading,
14614
14640
  onSave,
14615
14641
  onSelectRate,
14616
14642
  onSubmit,
14617
- rates,
14618
- preferredRates,
14619
- shipment,
14620
14643
  outOfBandDisplayableErrors,
14621
- preferredServiceCodes
14644
+ preferredRates,
14645
+ preferredServiceCodes,
14646
+ rates,
14647
+ shipment
14622
14648
  }) => {
14623
14649
  var _a, _b, _c, _d, _e, _f;
14624
14650
  features = Object.assign({
@@ -14632,7 +14658,6 @@ const RateForm = ({
14632
14658
  saveRate: true
14633
14659
  }
14634
14660
  }, features !== null && features !== void 0 ? features : {});
14635
- const allDisplayableErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14636
14661
  const {
14637
14662
  t
14638
14663
  } = useTranslation();
@@ -14730,6 +14755,22 @@ const RateForm = ({
14730
14755
  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
14756
  return !!preferredRate;
14732
14757
  }, [preferredRates, selectedRate]);
14758
+ const displayableErrors = useMemo(() => {
14759
+ const rateAndShipmentErrors = [...(displayableRateErrors !== null && displayableRateErrors !== void 0 ? displayableRateErrors : []), ...(outOfBandDisplayableErrors !== null && outOfBandDisplayableErrors !== void 0 ? outOfBandDisplayableErrors : [])];
14760
+ if (rateAndShipmentErrors.length && rateOptions.length === 0) {
14761
+ return {
14762
+ messages: rateAndShipmentErrors,
14763
+ title: "errorTypes.rateInvalid"
14764
+ };
14765
+ }
14766
+ if (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) {
14767
+ return {
14768
+ messages: labelErrors,
14769
+ title: "errorTypes.purchase"
14770
+ };
14771
+ }
14772
+ return undefined;
14773
+ }, [rateOptions, labelErrors, displayableRateErrors, outOfBandDisplayableErrors]);
14733
14774
  return jsxs("form", Object.assign({
14734
14775
  id: "rate-form",
14735
14776
  onSubmit: handleSubmit,
@@ -14774,7 +14815,7 @@ const RateForm = ({
14774
14815
  children: showHiddenRates ? t("purchase-label:actions.showFewerRates") : t("purchase-label:actions.showMoreRates")
14775
14816
  }))
14776
14817
  }))]
14777
- }) : !isLoading && !!allDisplayableErrors.length ? null : jsxs("article", Object.assign({
14818
+ }) : !isLoading && !!displayableErrors ? null : jsxs("article", Object.assign({
14778
14819
  css: styles$3.ratesInterstitial,
14779
14820
  role: "presentation"
14780
14821
  }, {
@@ -14783,13 +14824,11 @@ const RateForm = ({
14783
14824
  }), jsx(Spacer, {}), isLoading ? t("purchase-label:loading.calculatingRates") : t("purchase-label:cta.addPackageDetails")]
14784
14825
  })), jsx(Spacer, {
14785
14826
  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"),
14827
+ }), !isLoading && !!displayableErrors && jsx(InlineNotification, Object.assign({
14828
+ title: t(displayableErrors.title),
14788
14829
  type: NotificationType.ERROR
14789
14830
  }, {
14790
- children: jsxs(Fragment, {
14791
- children: [displayableRateErrors, outOfBandDisplayableErrors, displayableLabelErrors]
14792
- })
14831
+ children: displayableErrors.messages
14793
14832
  }))]
14794
14833
  })), ((_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
14834
  title: t("manage-defaults:label.title")
@@ -14958,21 +14997,37 @@ const styles$1 = createStyles({
14958
14997
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
14959
14998
  width: theme.spacing(5)
14960
14999
  }),
15000
+ header: theme => ({
15001
+ "& > tr > th": {
15002
+ "&:after": {
15003
+ borderBottom: "none"
15004
+ }
15005
+ }
15006
+ }),
15007
+ headerActions: theme => ({
15008
+ backgroundColor: theme.palette.gray.ultraLight,
15009
+ padding: `${theme.spacing(1)}px ${theme.spacing(2)}px 0 ${theme.spacing(1)}px`,
15010
+ width: theme.spacing(5)
15011
+ }),
14961
15012
  headerDescription: theme => ({
15013
+ backgroundColor: theme.palette.gray.ultraLight,
14962
15014
  overflow: "visible",
14963
15015
  padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`
14964
15016
  }),
14965
15017
  headerEach: theme => ({
15018
+ backgroundColor: theme.palette.gray.ultraLight,
14966
15019
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
14967
15020
  textAlign: "right",
14968
15021
  width: theme.spacing(10)
14969
15022
  }),
14970
15023
  headerQty: theme => ({
15024
+ backgroundColor: theme.palette.gray.ultraLight,
14971
15025
  padding: theme.spacing(1),
14972
15026
  textAlign: "right",
14973
15027
  width: theme.spacing(5)
14974
15028
  }),
14975
15029
  headerTotal: theme => ({
15030
+ backgroundColor: theme.palette.gray.ultraLight,
14976
15031
  padding: `${theme.spacing(1)}px 0 ${theme.spacing(1)}px ${theme.spacing(1)}px`,
14977
15032
  textAlign: "right",
14978
15033
  width: theme.spacing(10)
@@ -14994,7 +15049,7 @@ const styles$1 = createStyles({
14994
15049
  itemQty: theme => ({
14995
15050
  overflow: "visible",
14996
15051
  padding: `${theme.spacing(1)}px ${theme.spacing(1)}px 0`,
14997
- textAlign: "center",
15052
+ textAlign: "right",
14998
15053
  width: theme.spacing(5)
14999
15054
  }),
15000
15055
  itemTotal: theme => ({
@@ -15002,6 +15057,14 @@ const styles$1 = createStyles({
15002
15057
  padding: `${theme.spacing(1)}px 0 0 ${theme.spacing(1)}px`,
15003
15058
  textAlign: "right",
15004
15059
  width: theme.spacing(10)
15060
+ }),
15061
+ subtitle: () => ({
15062
+ letterSpacing: "0.01em"
15063
+ }),
15064
+ table: () => ({
15065
+ border: "1px solid #d4e4e8",
15066
+ borderRadius: "0",
15067
+ boxShadow: "none"
15005
15068
  })
15006
15069
  });
15007
15070
 
@@ -15112,12 +15175,15 @@ const CustomsItemsDisplay = ({
15112
15175
  }))]
15113
15176
  })), customsItems.length > 0 && jsxs(Fragment, {
15114
15177
  children: [jsx(Spacer, {}), jsx(Table, Object.assign({
15115
- header: jsx(TableHeader, {
15178
+ header: jsx(TableHeader, Object.assign({
15179
+ css: styles$1.header
15180
+ }, {
15116
15181
  children: jsxs(TableBaseRow, {
15117
15182
  children: [jsx(TableHeaderCell, Object.assign({
15118
15183
  css: styles$1.headerDescription
15119
15184
  }, {
15120
15185
  children: jsx(Typography, Object.assign({
15186
+ css: styles$1.subtitle,
15121
15187
  variant: "subtitle2"
15122
15188
  }, {
15123
15189
  children: t("customs.fields.description")
@@ -15126,6 +15192,7 @@ const CustomsItemsDisplay = ({
15126
15192
  css: styles$1.headerEach
15127
15193
  }, {
15128
15194
  children: jsx(Typography, Object.assign({
15195
+ css: styles$1.subtitle,
15129
15196
  variant: "subtitle2"
15130
15197
  }, {
15131
15198
  children: t("customs.each", {
@@ -15136,6 +15203,7 @@ const CustomsItemsDisplay = ({
15136
15203
  css: styles$1.headerQty
15137
15204
  }, {
15138
15205
  children: jsx(Typography, Object.assign({
15206
+ css: styles$1.subtitle,
15139
15207
  variant: "subtitle2"
15140
15208
  }, {
15141
15209
  children: t("customs.fields.quantity")
@@ -15144,6 +15212,7 @@ const CustomsItemsDisplay = ({
15144
15212
  css: styles$1.headerTotal
15145
15213
  }, {
15146
15214
  children: jsx(Typography, Object.assign({
15215
+ css: styles$1.subtitle,
15147
15216
  variant: "subtitle2"
15148
15217
  }, {
15149
15218
  children: t("customs.total", {
@@ -15151,10 +15220,11 @@ const CustomsItemsDisplay = ({
15151
15220
  })
15152
15221
  }))
15153
15222
  })), jsx(TableHeaderCell, {
15154
- css: styles$1.actionsColumn
15223
+ css: styles$1.headerActions
15155
15224
  })]
15156
15225
  })
15157
- })
15226
+ })),
15227
+ outerWrapperStyles: styles$1.table
15158
15228
  }, {
15159
15229
  children: jsx(TableBody, {
15160
15230
  children: customsItems.map(item => jsxs(Fragment$1, {
@@ -16787,6 +16857,7 @@ var common = {
16787
16857
  invalidNameOrCompany: "Recipient name and company name (if provided) must have two characters in first and last name.",
16788
16858
  parsingFailure: "Parsing failed. Please check address and try again.",
16789
16859
  incompleteLabelPurchaseRequirements: "Please add your {{requirements}} to continue purchasing a label.",
16860
+ shipmentCancelled: "This shipment is Cancelled in ShipStation. Log into ShipStation to restore the order to Awaiting Shipment status.",
16790
16861
  unableToLoad: {
16791
16862
  accountSettings: "Unable to load account settings",
16792
16863
  autoFundingSettings: "Unable to load auto funding settings",
@@ -16807,6 +16878,7 @@ var common = {
16807
16878
  purchase: "Purchase error",
16808
16879
  rateInvalid: "Invalid rate configuration",
16809
16880
  security: "Security error",
16881
+ shipmentStatus: "Shipment status error",
16810
16882
  system: "System error",
16811
16883
  unknown: "Unknown error",
16812
16884
  validation: "Unable to validate address"
@@ -16865,7 +16937,7 @@ var common = {
16865
16937
  invalidAddressNameStrict: "Recipient Name must have two characters in First and Last Name.",
16866
16938
  invalidAddressPoBox: "A physical address is required for wallet registration. You can add a PO Box as a Ship From address.",
16867
16939
  invalidCreditCardType: "Card type must be Visa, Mastercard, American Express, or Discover",
16868
- invalidExpiration: "Invalid Expiration Date",
16940
+ invalidExpirationDate: "Invalid Expiration Date",
16869
16941
  invalidPostalCode: "Invalid Postal Code",
16870
16942
  invalidStateProvince: "Invalid State",
16871
16943
  invalidString: "{{fieldLabel}} is invalid",
@@ -17901,12 +17973,12 @@ const useRequestRates = ({
17901
17973
  getPreferredRates
17902
17974
  });
17903
17975
  const requestRates = useCallback((shipment, isInternational) => __awaiter(void 0, void 0, void 0, function* () {
17904
- var _a, _b;
17905
- const internationalCarrierIds = (_a = carriers === null || carriers === void 0 ? void 0 : carriers.map(c => c.carrierId)) !== null && _a !== void 0 ? _a : [];
17906
- 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 : [];
17976
+ var _a;
17977
+ // filter out DHL for domestic shipments
17978
+ 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 : [];
17907
17979
  const standardRatesResponse = yield calculateRates({
17908
17980
  rateOptions: {
17909
- carrierIds: shipment.carrierId ? [shipment.carrierId] : isInternational ? internationalCarrierIds : domesticCarrierIds,
17981
+ carrierIds: shipment.carrierId ? [shipment.carrierId] : carrierIds,
17910
17982
  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
17911
17983
  : shipment.packages.map(pkg => pkg.packageCode),
17912
17984
  serviceCodes: shipment.serviceCode ? [shipment.serviceCode] : undefined
@@ -18204,11 +18276,10 @@ const useRatesForm = ({
18204
18276
  });
18205
18277
  return {
18206
18278
  carriers,
18207
- displayableLabelErrors,
18208
18279
  displayableRateErrors,
18209
18280
  errors: errors.length > 0 ? errors : undefined,
18210
18281
  isLoading: ratesCalculating,
18211
- labelErrors: (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) ? labelErrors : undefined,
18282
+ labelErrors: displayableLabelErrors,
18212
18283
  labels,
18213
18284
  labelsLoading,
18214
18285
  onSave: handleSave,
@@ -18326,7 +18397,9 @@ const useShipmentForm = ({
18326
18397
  };
18327
18398
 
18328
18399
  const ConfigureShipment = _a => {
18400
+ var _b;
18329
18401
  var {
18402
+ errors,
18330
18403
  features,
18331
18404
  getPreferredRates,
18332
18405
  onAddressValidation,
@@ -18344,12 +18417,13 @@ const ConfigureShipment = _a => {
18344
18417
  shipment,
18345
18418
  onBeforeRateSaved
18346
18419
  } = _a,
18347
- props = __rest(_a, ["features", "getPreferredRates", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "preferredServiceCodes", "salesOrder", "shipment", "onBeforeRateSaved"]);
18420
+ props = __rest(_a, ["errors", "features", "getPreferredRates", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "preferredServiceCodes", "salesOrder", "shipment", "onBeforeRateSaved"]);
18348
18421
  const hydrateRef = useRef();
18422
+ useTranslation();
18349
18423
  const {
18350
18424
  isInternational
18351
18425
  } = useShipmentMetadata(shipment);
18352
- const _b = useRatesForm({
18426
+ const _c = useRatesForm({
18353
18427
  getPreferredRates,
18354
18428
  onBeforeLabelCreate,
18355
18429
  onBeforeRateSaved,
@@ -18370,17 +18444,17 @@ const ConfigureShipment = _a => {
18370
18444
  resetRates,
18371
18445
  resetLabel,
18372
18446
  preferredRates
18373
- } = _b,
18374
- rateFormProps = __rest(_b, ["requestRates", "resetRates", "resetLabel", "preferredRates"]);
18375
- const _c = useShipmentForm({
18447
+ } = _c,
18448
+ rateFormProps = __rest(_c, ["requestRates", "resetRates", "resetLabel", "preferredRates"]);
18449
+ const _d = useShipmentForm({
18376
18450
  compatibleCountryCodes: features === null || features === void 0 ? void 0 : features.compatibleCountryCodes,
18377
18451
  onAddressValidation,
18378
18452
  onApplyPreset: useCallback((_preset, shipment) => __awaiter(void 0, void 0, void 0, function* () {
18379
- var _d;
18453
+ var _e;
18380
18454
  if (shipment.packages[0].weight.value) {
18381
18455
  yield requestRates(shipment, isInternational);
18382
18456
  }
18383
- (_d = hydrateRef.current) === null || _d === void 0 ? void 0 : _d.call(hydrateRef, shipment);
18457
+ (_e = hydrateRef.current) === null || _e === void 0 ? void 0 : _e.call(hydrateRef, shipment);
18384
18458
  }), [requestRates, isInternational]),
18385
18459
  onChangeAddress,
18386
18460
  onShipmentUpdated,
@@ -18393,8 +18467,8 @@ const ConfigureShipment = _a => {
18393
18467
  {
18394
18468
  charsetWarning,
18395
18469
  resetSalesOrderShipment
18396
- } = _c,
18397
- shipmentFormProps = __rest(_c, ["charsetWarning", "resetSalesOrderShipment"]);
18470
+ } = _d,
18471
+ shipmentFormProps = __rest(_d, ["charsetWarning", "resetSalesOrderShipment"]);
18398
18472
  const handleOnDirty = useCallback(() => {
18399
18473
  resetRates();
18400
18474
  resetLabel();
@@ -18414,6 +18488,9 @@ const ConfigureShipment = _a => {
18414
18488
  return self.indexOf(item) === pos;
18415
18489
  });
18416
18490
  }, [preferredRates, preferredServiceCodes]);
18491
+ 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"))) {
18492
+ throw new Error("errorMessages.shipmentCancelled");
18493
+ }
18417
18494
  return jsxs(Fragment, {
18418
18495
  children: [jsx(ShipmentForm, Object.assign({}, shipmentFormProps, props, {
18419
18496
  charsetWarning: charsetWarning,
@@ -18432,6 +18509,7 @@ const ConfigureShipment = _a => {
18432
18509
  };
18433
18510
 
18434
18511
  const usePendingShipment = ({
18512
+ breakOnCancelledShipment: _breakOnCancelledShipment = false,
18435
18513
  onLoad,
18436
18514
  salesOrder,
18437
18515
  warehouseId
@@ -18455,17 +18533,18 @@ const usePendingShipment = ({
18455
18533
  isLoading: isShipmentCreating,
18456
18534
  mutateAsync: createShipment
18457
18535
  } = useCreateSalesOrderShipment();
18458
- const pendingShipment = getPendingShipment(shipments);
18536
+ const pendingShipment = getShipmentByStatus("pending", shipments);
18537
+ const cancelledShipment = getShipmentByStatus("cancelled", shipments);
18459
18538
  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];
18460
18539
  // On page load, check for a shipment and either call the onLoad callback or create a new shipment
18461
18540
  useEffect(() => {
18462
18541
  if (salesOrder && (shipments === null || shipments === void 0 ? void 0 : shipments.length) && shipments.every(s => s.shipmentStatus === "label_purchased")) {
18463
- onLoad === null || onLoad === void 0 ? void 0 : onLoad(salesOrder, shipments, pendingShipment);
18542
+ void (onLoad === null || onLoad === void 0 ? void 0 : onLoad(salesOrder, shipments, pendingShipment));
18464
18543
  return;
18465
18544
  }
18466
- if (!salesOrder || !defaultWarehouse || !shipments || pendingShipment) return;
18545
+ if (!salesOrder || !defaultWarehouse || !shipments || _breakOnCancelledShipment && cancelledShipment || pendingShipment) return;
18467
18546
  if (isListShipmentsLoading || isListShipmentsValidating || isShipmentCreating) return;
18468
- createShipment(Object.assign(Object.assign({
18547
+ void createShipment(Object.assign(Object.assign({
18469
18548
  salesOrderId: salesOrder === null || salesOrder === void 0 ? void 0 : salesOrder.salesOrderId,
18470
18549
  // /v-beta/shipments/sales_order/:salesOrderId requires at minimum
18471
18550
  // a (warehouseId or shipFrom)
@@ -18481,14 +18560,18 @@ const usePendingShipment = ({
18481
18560
  }
18482
18561
  }]
18483
18562
  })).then(shipment => shipment && reloadShipments());
18484
- }, [createShipment, defaultWarehouse, isListShipmentsLoading, isListShipmentsValidating, isShipmentCreating, onLoad, pendingShipment, reloadShipments, salesOrder, shipments, warehouseId]);
18563
+ }, [cancelledShipment, createShipment, defaultWarehouse, isListShipmentsLoading, isListShipmentsValidating, isShipmentCreating, onLoad, pendingShipment, reloadShipments, salesOrder, shipments, warehouseId, _breakOnCancelledShipment]);
18485
18564
  const reloadPendingShipment = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
18486
18565
  const {
18487
18566
  data: shipments
18488
18567
  } = yield reloadShipments();
18489
- return getPendingShipment(shipments);
18568
+ return getShipmentByStatus("pending", shipments);
18490
18569
  }), [reloadShipments]);
18491
- const errors = [...(listWarehouseErrors !== null && listWarehouseErrors !== void 0 ? listWarehouseErrors : []), ...(createShipmentErrors !== null && createShipmentErrors !== void 0 ? createShipmentErrors : []), ...(listShipmentsErrors !== null && listShipmentsErrors !== void 0 ? listShipmentsErrors : [])];
18570
+ const errors = [...(listWarehouseErrors !== null && listWarehouseErrors !== void 0 ? listWarehouseErrors : []), ...(createShipmentErrors !== null && createShipmentErrors !== void 0 ? createShipmentErrors : []), ...(listShipmentsErrors !== null && listShipmentsErrors !== void 0 ? listShipmentsErrors : []), ...(_breakOnCancelledShipment && cancelledShipment ? [new CodedError("shipment_cancelled", {
18571
+ errorCode: "invalid_status",
18572
+ errorSource: "elements",
18573
+ errorType: "business_rules"
18574
+ })] : [])];
18492
18575
  return {
18493
18576
  isPendingShipmentLoading: !pendingShipment && errors.length === 0,
18494
18577
  pendingShipment,
@@ -18499,6 +18582,7 @@ const usePendingShipment = ({
18499
18582
 
18500
18583
  const useConfigureShipment = ({
18501
18584
  onLoad,
18585
+ errorWhenShipmentCancelled: _errorWhenShipmentCancelled = false,
18502
18586
  onShipmentUpdated,
18503
18587
  salesOrder,
18504
18588
  warehouseId,
@@ -18511,6 +18595,7 @@ const useConfigureShipment = ({
18511
18595
  pendingShipmentErrors,
18512
18596
  reloadPendingShipment
18513
18597
  } = usePendingShipment({
18598
+ breakOnCancelledShipment: _errorWhenShipmentCancelled,
18514
18599
  onLoad,
18515
18600
  salesOrder,
18516
18601
  warehouseId
@@ -18587,6 +18672,7 @@ const useImportSalesOrder = ({
18587
18672
  };
18588
18673
 
18589
18674
  const PurchaseLabelBySalesOrder = _a => {
18675
+ var _b;
18590
18676
  var {
18591
18677
  features,
18592
18678
  externalOrderId,
@@ -18599,7 +18685,7 @@ const PurchaseLabelBySalesOrder = _a => {
18599
18685
  printLabelLayout
18600
18686
  } = _a,
18601
18687
  props = __rest(_a, ["features", "externalOrderId", "externalOrderNumber", "onLoad", "onShipmentUpdated", "orderSourceCode", "salesOrderId", "warehouseId", "printLabelLayout"]);
18602
- const _b = useImportSalesOrder({
18688
+ const _c = useImportSalesOrder({
18603
18689
  externalOrderId,
18604
18690
  externalOrderNumber,
18605
18691
  orderSourceCode,
@@ -18608,9 +18694,10 @@ const PurchaseLabelBySalesOrder = _a => {
18608
18694
  {
18609
18695
  salesOrder,
18610
18696
  isLoading: salesOrderLoading
18611
- } = _b,
18612
- salesOrderProps = __rest(_b, ["salesOrder", "isLoading"]);
18697
+ } = _c,
18698
+ salesOrderProps = __rest(_c, ["salesOrder", "isLoading"]);
18613
18699
  const configureShipmentProps = useConfigureShipment({
18700
+ errorWhenShipmentCancelled: (_b = features === null || features === void 0 ? void 0 : features.configureShipment) === null || _b === void 0 ? void 0 : _b.enableErrorWhenShipmentCancelled,
18614
18701
  onLoad,
18615
18702
  onShipmentUpdated,
18616
18703
  printLabelLayout,
@@ -18751,7 +18838,9 @@ const Component$2 = _a => {
18751
18838
  });
18752
18839
  if (incompleteRequirementsKeys.length > 0) throw new Error(incompleteRequirementsError);
18753
18840
  if ("salesOrderId" in props || "orderSourceCode" in props) {
18754
- return jsx(PurchaseLabelBySalesOrder, Object.assign({}, props));
18841
+ return jsx(PurchaseLabelBySalesOrder, Object.assign({
18842
+ features: features
18843
+ }, props));
18755
18844
  } else {
18756
18845
  return jsx(PurchaseLabelByShipment, Object.assign({}, props));
18757
18846
  }
@@ -19303,4 +19392,4 @@ var labelWorkflow = /*#__PURE__*/Object.freeze({
19303
19392
  Element: Element
19304
19393
  });
19305
19394
 
19306
- export { accountSettings as AccountSettings, AddFundsForm, AutoFundingForm, ButtonGroup, CarrierBalance, CollapsiblePanel, CopyButton, Country, Cube, DateRangeCombo, DateRangeSelect, ErrorFallback, fields as Field, FieldLabel, FormPortal, FundAndPurchase, InlineLabel, ItemsBreakdown, labelWorkflow as LabelWorkflow, LinkAction, listCarriers$1 as ListCarriers, Loader, ManageFunding, manageWarehouses$1 as ManageWarehouses, onboarding as Onboarding, PageLayoutProvider, PaymentMethodSettings, Portal, PoweredByShipEngine, purchaseLabel as PurchaseLabel, RootPortalProvider, Section, Spacer, Spread, StoryNotes, index as Templates, UsState, UsaCity, viewShipment as ViewShipment, voidLabel as VoidLabel, autoFundingSchema, calculateTotal, capitalizeFirstLetter, convertDecimalWeightToFractionalWeight, convertDimensions, convertFractionalWeightToDecimalWeight, convertPoundsAndOuncesToOunces, convertWeight, countries, countryCodes, createCodedErrors, createDictionary, createStyles, currencySymbol, daysAfter, errorMap, euCountryCodes, extendZod, featureFlagComponentNameLookup, featureFlags, formLogger, formatCreditCardNumber, formatDate, formatDateDDMMYY, formatDimensions, formatExpiration, formatFractionalWeight, formatMoney, getAddFundsSchema, getCarrierIdByCarrierCode, getCustomsFromSalesOrder, getExpirationYears, getFeatures, getIsCustomsRequiredForSalesOrder, getIsCustomsRequiredForShipment, getIsInternationalShipment, getPendingShipment, getRateRequiresAcknowledgement, getRelativeDates, getRequestedServices, getSalesOrderItemsFromSalesOrderOrShipment, getTotalRateAmount, isDecimalWeight, isDomesticAddress, isEmptyAddress, isFlatRatePackageCode, isMetricWeightUnit, isMilitaryAddress, isNowOrInTheFuture, isPoBox, isPoBoxAddress, isString, isUnitedStatesTerritory, isUnsupportedByUps, isUpsCarrier, isUspsCarrier, moneySchema, mostRecent, nextDayCutoff, omitTime, overrideCarrierCodes$1 as overrideCarrierCodes, phoneSchema, phoneSchemaUnvalidated, postalCodeRegex$3 as postalCodeRegex, sortByCreationDate, throwAny, throwJoinedMessages, usCities, usStateCodes, usStates, useAddressValidation, useBlackboxDetection, useCarrierMetadata, useConfirmationOptions, useCountryCodeOptions, useCustomsContentsOptions, useCustomsNonDeliveryOptions, useDateRangeOptions, useExpirationMonthOptions, useFeatures, useInsuranceProviderOptions, useNestedForm, usePackageOptions, usePageLayout, useRateOptions, useRootPortal, useRunOnceOnTrue, useScrubErrors, useServiceCodeOptions, useShipmentMetadata, useShippingPresetsOptions, useStateCodeOptions, useToggle, useWarehouseOptions, validationResolver };
19395
+ export { accountSettings as AccountSettings, AddFundsForm, AutoFundingForm, ButtonGroup, CarrierBalance, CollapsiblePanel, CopyButton, Country, Cube, DateRangeCombo, DateRangeSelect, ErrorFallback, fields as Field, FieldLabel, FormPortal, FundAndPurchase, InlineLabel, ItemsBreakdown, labelWorkflow as LabelWorkflow, LinkAction, listCarriers$1 as ListCarriers, Loader, ManageFunding, manageWarehouses$1 as ManageWarehouses, onboarding as Onboarding, PageLayoutProvider, PaymentMethodSettings, Portal, PoweredByShipEngine, purchaseLabel as PurchaseLabel, RootPortalProvider, Section, Spacer, Spread, StoryNotes, index as Templates, UsState, UsaCity, viewShipment as ViewShipment, voidLabel as VoidLabel, autoFundingSchema, calculateTotal, capitalizeFirstLetter, convertDecimalWeightToFractionalWeight, convertDimensions, convertFractionalWeightToDecimalWeight, convertPoundsAndOuncesToOunces, convertWeight, countries, countryCodes, createCodedErrors, createDictionary, createStyles, currencySymbol, daysAfter, errorMap, euCountryCodes, extendZod, featureFlagComponentNameLookup, featureFlags, formLogger, formatCreditCardNumber, formatDate, formatDateDDMMYY, formatDimensions, formatExpiration, formatFractionalWeight, formatMoney, getAddFundsSchema, getCancelledShipment, getCarrierIdByCarrierCode, getCustomsFromSalesOrder, getExpirationYears, getFeatures, getIsCustomsRequiredForSalesOrder, getIsCustomsRequiredForShipment, getIsInternationalShipment, getPendingShipment, getRateRequiresAcknowledgement, getRelativeDates, getRequestedServices, getSalesOrderItemsFromSalesOrderOrShipment, getShipmentByStatus, getTotalRateAmount, isDecimalWeight, isDomesticAddress, isEmptyAddress, isFlatRatePackageCode, isMetricWeightUnit, isMilitaryAddress, isNowOrInTheFuture, isPoBox, isPoBoxAddress, isString, isUnitedStatesTerritory, isUnsupportedByUps, isUpsCarrier, isUspsCarrier, moneySchema, mostRecent, nextDayCutoff, omitTime, overrideCarrierCodes$1 as overrideCarrierCodes, phoneSchema, phoneSchemaUnvalidated, postalCodeRegex$3 as postalCodeRegex, sortByCreationDate, throwAny, throwJoinedMessages, usCities, usStateCodes, usStates, useAddressValidation, useBlackboxDetection, useCarrierMetadata, useConfirmationOptions, useCountryCodeOptions, useCustomsContentsOptions, useCustomsNonDeliveryOptions, useDateRangeOptions, useExpirationMonthOptions, useFeatures, useInsuranceProviderOptions, useNestedForm, usePackageOptions, usePageLayout, useRateOptions, useRootPortal, useRunOnceOnTrue, useScrubErrors, useServiceCodeOptions, useShipmentMetadata, useShippingPresetsOptions, useStateCodeOptions, useToggle, useWarehouseOptions, validationResolver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipengine/elements",
3
- "version": "0.37.1",
3
+ "version": "0.37.3",
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;
@@ -624,6 +624,7 @@ export declare const Element: ({ resources, ...props }: ComponentProps & {
624
624
  invalidNameOrCompany: string;
625
625
  parsingFailure: string;
626
626
  incompleteLabelPurchaseRequirements: string;
627
+ shipmentCancelled: string;
627
628
  unableToLoad: {
628
629
  accountSettings: string;
629
630
  autoFundingSettings: string;
@@ -644,6 +645,7 @@ export declare const Element: ({ resources, ...props }: ComponentProps & {
644
645
  purchase: string;
645
646
  rateInvalid: string;
646
647
  security: string;
648
+ shipmentStatus: string;
647
649
  system: string;
648
650
  unknown: string;
649
651
  validation: string;
@@ -702,7 +704,7 @@ export declare const Element: ({ resources, ...props }: ComponentProps & {
702
704
  invalidAddressNameStrict: string;
703
705
  invalidAddressPoBox: string;
704
706
  invalidCreditCardType: string;
705
- invalidExpiration: string;
707
+ invalidExpirationDate: string;
706
708
  invalidPostalCode: string;
707
709
  invalidStateProvince: string;
708
710
  invalidString: string;
@@ -25,6 +25,9 @@ export type RateFormFeatures = {
25
25
  };
26
26
  export type ConfigureShipmentFeatures = {
27
27
  compatibleCountryCodes?: UseShipmentFormProps["compatibleCountryCodes"];
28
+ configureShipment?: {
29
+ enableErrorWhenShipmentCancelled: boolean;
30
+ };
28
31
  partnerMessages?: {
29
32
  incompleteLabelPurchaseRequirements?: string;
30
33
  };
@@ -58,4 +61,4 @@ export type ConfigureShipmentProps = {
58
61
  shippingPresets?: UseShippingPresetsOptionsProps;
59
62
  warehouseId?: string;
60
63
  };
61
- export declare const ConfigureShipment: ({ features, getPreferredRates, onAddressValidation, onApplyPreset, onBeforeLabelCreate, onChangeAddress, onLabelCreateFailure, onLabelCreateSuccess, onRateSaved, onRatesCalculated, onShipmentUpdated, printLabelLayout, preferredServiceCodes, salesOrder, shipment, onBeforeRateSaved, ...props }: ConfigureShipmentProps) => import("@emotion/react/jsx-runtime").JSX.Element;
64
+ export declare const ConfigureShipment: ({ errors, features, getPreferredRates, onAddressValidation, onApplyPreset, onBeforeLabelCreate, onChangeAddress, onLabelCreateFailure, onLabelCreateSuccess, onRateSaved, onRatesCalculated, onShipmentUpdated, printLabelLayout, preferredServiceCodes, salesOrder, shipment, onBeforeRateSaved, ...props }: ConfigureShipmentProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -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>;