@shipengine/elements 0.14.0 → 0.15.0

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
@@ -2022,7 +2022,7 @@ const useConfirmationOptions = () => {
2022
2022
  } = reactI18next.useTranslation("common");
2023
2023
  return React.useMemo(() => Object.values(SE__namespace.ConfirmationType)
2024
2024
  // TODO: Remove this filter once these options are better supported by UpdateShipment
2025
- .filter(v => v !== SE__namespace.ConfirmationType.VERBAL_CONFIRMATION && v !== SE__namespace.ConfirmationType.DELIVERY_MAILED).flatMap(v => v === "none" ? [] : {
2025
+ .filter(v => v !== SE__namespace.ConfirmationType.DELIVERY_MAILED && v !== SE__namespace.ConfirmationType.DIRECT_SIGNATURE && v !== SE__namespace.ConfirmationType.VERBAL_CONFIRMATION).flatMap(v => v === "none" ? [] : {
2026
2026
  label: t(`confirmationTypes.${humps.camelize(v)}`),
2027
2027
  value: v
2028
2028
  }), [t]);
@@ -20733,24 +20733,23 @@ const ElementsContext = /*#__PURE__*/React.createContext(undefined);
20733
20733
  */
20734
20734
  const ElementsProvider = ({
20735
20735
  baseURL,
20736
+ brandName,
20736
20737
  children,
20737
20738
  environment: _environment = "production",
20738
- onError,
20739
- brandName,
20740
- token
20739
+ getToken,
20740
+ onError
20741
20741
  }) => {
20742
20742
  const value = React.useMemo(() => ({
20743
20743
  brandName,
20744
20744
  environment: _environment,
20745
- onError,
20746
- token
20747
- }), [_environment, token, onError, brandName]);
20745
+ onError
20746
+ }), [_environment, onError, brandName]);
20748
20747
  return jsxRuntime.jsx(react.ShipEngineProvider, Object.assign({
20749
20748
  baseURL: baseURL ? `${baseURL}/api` : "/api",
20749
+ getToken: getToken,
20750
20750
  headers: {
20751
20751
  "X-Environment": `${_environment}`
20752
- },
20753
- token: token
20752
+ }
20754
20753
  }, {
20755
20754
  children: jsxRuntime.jsx(ElementsContext.Provider, Object.assign({
20756
20755
  value: value
@@ -22444,40 +22443,127 @@ const AddressParser = ({
22444
22443
  }));
22445
22444
  };
22446
22445
 
22447
- var PROPER_FUNCTION_NAME = functionName.PROPER;
22448
- var fails$4 = fails$r;
22449
- var whitespaces = whitespaces$4;
22450
-
22451
- var non = '\u200B\u0085\u180E';
22452
-
22453
- // check that a method works with the correct list
22454
- // of whitespaces and has a correct name
22455
- var stringTrimForced = function (METHOD_NAME) {
22456
- return fails$4(function () {
22457
- return !!whitespaces[METHOD_NAME]()
22458
- || non[METHOD_NAME]() !== non
22459
- || (PROPER_FUNCTION_NAME && whitespaces[METHOD_NAME].name !== METHOD_NAME);
22446
+ const AddressFields = ({
22447
+ domestic,
22448
+ form,
22449
+ formatFieldName: _formatFieldName = fieldName => fieldName,
22450
+ formId
22451
+ }) => {
22452
+ const {
22453
+ t
22454
+ } = reactI18next.useTranslation();
22455
+ const countryCodeOptions = useCountryCodeOptions(domestic);
22456
+ const stateCodeOptions = useStateCodeOptions(domestic);
22457
+ const {
22458
+ isSubmitted
22459
+ } = form.formState;
22460
+ const watchCountryCode = form.watch(_formatFieldName("countryCode"));
22461
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
22462
+ children: [jsxRuntime.jsx(TextInput, {
22463
+ control: form.control,
22464
+ form: formId,
22465
+ label: t("address.fields.name"),
22466
+ labelWeight: "normal",
22467
+ name: _formatFieldName("name")
22468
+ }), jsxRuntime.jsx(TextInput, {
22469
+ control: form.control,
22470
+ form: formId,
22471
+ label: t("address.fields.company"),
22472
+ labelWeight: "normal",
22473
+ name: _formatFieldName("companyName"),
22474
+ subLabel: t("address.subFields.optional")
22475
+ }), jsxRuntime.jsx(Select, {
22476
+ control: form.control,
22477
+ form: formId,
22478
+ label: t("address.fields.countryCode"),
22479
+ labelWeight: "normal",
22480
+ name: _formatFieldName("countryCode"),
22481
+ onChange: e => {
22482
+ if (typeof e === "string") {
22483
+ form.setValue(_formatFieldName("stateProvince"), null, {
22484
+ shouldValidate: isSubmitted
22485
+ });
22486
+ }
22487
+ },
22488
+ options: countryCodeOptions
22489
+ }), jsxRuntime.jsx(TextInput, {
22490
+ control: form.control,
22491
+ form: formId,
22492
+ label: t("address.fields.addressLine1"),
22493
+ labelWeight: "normal",
22494
+ name: _formatFieldName("addressLine1")
22495
+ }), jsxRuntime.jsx(TextInput, {
22496
+ control: form.control,
22497
+ form: formId,
22498
+ label: t("address.fields.addressLine2"),
22499
+ labelWeight: "normal",
22500
+ name: _formatFieldName("addressLine2")
22501
+ }), jsxRuntime.jsx(TextInput, {
22502
+ control: form.control,
22503
+ form: formId,
22504
+ label: t("address.fields.cityLocality"),
22505
+ labelWeight: "normal",
22506
+ name: _formatFieldName("cityLocality")
22507
+ }), watchCountryCode === "US" ?
22508
+ // Domestic States
22509
+ jsxRuntime.jsx(Select, {
22510
+ control: form.control,
22511
+ form: formId,
22512
+ label: t("address.fields.stateProvince"),
22513
+ labelWeight: "normal",
22514
+ name: _formatFieldName("stateProvince"),
22515
+ options: stateCodeOptions
22516
+ }) :
22517
+ // International Provinces
22518
+ jsxRuntime.jsx(TextInput, {
22519
+ control: form.control,
22520
+ form: formId,
22521
+ label: t("address.fields.stateProvince"),
22522
+ labelWeight: "normal",
22523
+ name: _formatFieldName("stateProvince")
22524
+ }), jsxRuntime.jsx(TextInput, {
22525
+ control: form.control,
22526
+ form: formId,
22527
+ label: t("address.fields.postalCode"),
22528
+ labelWeight: "normal",
22529
+ name: _formatFieldName("postalCode")
22530
+ }), jsxRuntime.jsx(TextInput, {
22531
+ control: form.control,
22532
+ form: formId,
22533
+ label: t("address.fields.phone"),
22534
+ labelWeight: "normal",
22535
+ name: _formatFieldName("phone"),
22536
+ subLabel: t("address.subFields.optional")
22537
+ }), jsxRuntime.jsx(TextInput, {
22538
+ control: form.control,
22539
+ form: formId,
22540
+ label: t("address.fields.email"),
22541
+ labelWeight: "normal",
22542
+ name: _formatFieldName("email"),
22543
+ subLabel: t("address.subFields.optional")
22544
+ })]
22460
22545
  });
22461
22546
  };
22462
22547
 
22463
- var $$a = _export;
22464
- var $trim = stringTrim.trim;
22465
- var forcedStringTrimMethod = stringTrimForced;
22466
-
22467
- // `String.prototype.trim` method
22468
- // https://tc39.es/ecma262/#sec-string.prototype.trim
22469
- $$a({ target: 'String', proto: true, forced: forcedStringTrimMethod('trim') }, {
22470
- trim: function trim() {
22471
- return $trim(this);
22472
- }
22473
- });
22548
+ /* eslint-disable @typescript-eslint/no-unused-vars -- Allow unused generics in ZodObject interface overload */
22549
+ function nullishDefault(defaultValue) {
22550
+ return this.nullish().transform(v => v !== null && v !== void 0 ? v : defaultValue);
22551
+ }
22552
+ /**
22553
+ * @category Form Validation
22554
+ */
22555
+ const extendZod = () => {
22556
+ zod.z.ZodString.prototype.nullishDefault = nullishDefault;
22557
+ zod.z.ZodNumber.prototype.nullishDefault = nullishDefault;
22558
+ zod.z.ZodObject.prototype.nullishDefault = nullishDefault;
22559
+ };
22474
22560
 
22475
22561
  // TODO: Remove from `core-js@4` since it's moved to entry points
22476
22562
 
22477
22563
  var uncurryThis$6 = functionUncurryThisClause;
22478
22564
  var defineBuiltIn$3 = defineBuiltIn$8;
22479
22565
  var regexpExec$1 = regexpExec$2;
22480
- var fails$3 = fails$r;
22566
+ var fails$4 = fails$r;
22481
22567
  var wellKnownSymbol$7 = wellKnownSymbol$j;
22482
22568
  var createNonEnumerableProperty = createNonEnumerableProperty$5;
22483
22569
 
@@ -22487,14 +22573,14 @@ var RegExpPrototype = RegExp.prototype;
22487
22573
  var fixRegexpWellKnownSymbolLogic = function (KEY, exec, FORCED, SHAM) {
22488
22574
  var SYMBOL = wellKnownSymbol$7(KEY);
22489
22575
 
22490
- var DELEGATES_TO_SYMBOL = !fails$3(function () {
22576
+ var DELEGATES_TO_SYMBOL = !fails$4(function () {
22491
22577
  // String methods call symbol-named RegEp methods
22492
22578
  var O = {};
22493
22579
  O[SYMBOL] = function () { return 7; };
22494
22580
  return ''[KEY](O) != 7;
22495
22581
  });
22496
22582
 
22497
- var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails$3(function () {
22583
+ var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails$4(function () {
22498
22584
  // Symbol-named RegExp methods call .exec
22499
22585
  var execCalled = false;
22500
22586
  var re = /a/;
@@ -22660,104 +22746,72 @@ fixRegExpWellKnownSymbolLogic$1('match', function (MATCH, nativeMatch, maybeCall
22660
22746
  ];
22661
22747
  });
22662
22748
 
22663
- /* eslint-disable @typescript-eslint/no-unused-vars -- Allow unused generics in ZodObject interface overload */
22664
- function nullishDefault(defaultValue) {
22665
- return this.nullish().transform(v => v !== null && v !== void 0 ? v : defaultValue);
22666
- }
22667
- /**
22668
- * @category Form Validation
22669
- */
22670
- const extendZod = () => {
22671
- zod.z.ZodString.prototype.nullishDefault = nullishDefault;
22672
- zod.z.ZodNumber.prototype.nullishDefault = nullishDefault;
22673
- zod.z.ZodObject.prototype.nullishDefault = nullishDefault;
22749
+ var PROPER_FUNCTION_NAME = functionName.PROPER;
22750
+ var fails$3 = fails$r;
22751
+ var whitespaces = whitespaces$4;
22752
+
22753
+ var non = '\u200B\u0085\u180E';
22754
+
22755
+ // check that a method works with the correct list
22756
+ // of whitespaces and has a correct name
22757
+ var stringTrimForced = function (METHOD_NAME) {
22758
+ return fails$3(function () {
22759
+ return !!whitespaces[METHOD_NAME]()
22760
+ || non[METHOD_NAME]() !== non
22761
+ || (PROPER_FUNCTION_NAME && whitespaces[METHOD_NAME].name !== METHOD_NAME);
22762
+ });
22674
22763
  };
22675
22764
 
22676
- extendZod();
22677
- /**
22678
- * @category Form Validation
22679
- */
22680
- const addressLine1Schema = zod.z.string().trim().min(1);
22681
- /**
22682
- * @category Form Validation
22683
- */
22684
- const addressLine1SchemaNoPoBox = addressLine1Schema.refine(val => !isPoBox(val), {
22685
- message: "schemaErrors.invalidAddressPoBox"
22686
- });
22687
- /**
22688
- * @category Form Validation
22689
- */
22690
- const addressLine2Schema = zod.z.string().trim().nullishDefault(undefined);
22691
- /**
22692
- * @category Form Validation
22693
- */
22694
- const addressLine2SchemaNoPoBox = addressLine2Schema.refine(val => !val || !isPoBox(val), {
22695
- message: "schemaErrors.invalidAddressPoBox"
22696
- });
22765
+ var $$a = _export;
22766
+ var $trim = stringTrim.trim;
22767
+ var forcedStringTrimMethod = stringTrimForced;
22697
22768
 
22698
- /**
22699
- * @category Form Validation
22700
- */
22701
- const moneySchema = zod.z.object({
22702
- amount: zod.z.number().nonnegative(),
22703
- currency: zod.z.nativeEnum(SE__namespace.Currency)
22769
+ // `String.prototype.trim` method
22770
+ // https://tc39.es/ecma262/#sec-string.prototype.trim
22771
+ $$a({ target: 'String', proto: true, forced: forcedStringTrimMethod('trim') }, {
22772
+ trim: function trim() {
22773
+ return $trim(this);
22774
+ }
22704
22775
  });
22705
22776
 
22706
- /**
22707
- * @category Form Validation
22708
- */
22709
- const phoneSchema = (defaultCountryCode = "US") => zod.z.string().trim().refine(val => min$4.isValidPhoneNumber(val, defaultCountryCode), "schemaErrors.notAValidPhoneNumber");
22710
- /**
22711
- * @category Form Validation
22712
- */
22713
- const phoneSchemaUnvalidated = zod.z.string().trim();
22714
-
22715
22777
  extendZod();
22716
- const postalCodeRegex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
22717
- const baseSchema = zod.z.object({
22718
- addressLine1: addressLine1Schema,
22719
- addressLine2: addressLine2Schema,
22778
+ const refineName = n => n.match(/^[a-zA-Z]{2,} [a-zA-Z]{2,}/);
22779
+ const addressSchema = zod.z.object({
22780
+ addressLine1: zod.z.string().trim().min(1),
22781
+ addressLine2: zod.z.string().trim().nullishDefault(undefined),
22720
22782
  cityLocality: zod.z.string().trim().min(1),
22721
22783
  companyName: zod.z.string().trim().min(2).max(40).nullishDefault(undefined),
22722
22784
  countryCode: zod.z.enum(countryCodes),
22723
22785
  email: zod.z.string().trim().email().nullishDefault(""),
22724
- name: zod.z.string().trim().min(1),
22725
- phone: phoneSchemaUnvalidated.nullishDefault("")
22726
- });
22727
- const domesticSchema = baseSchema.extend({
22728
- __mode: zod.z.literal("domestic"),
22729
- postalCode: zod.z.string().trim().regex(postalCodeRegex),
22730
- stateProvince: zod.z.enum(usStateCodes)
22731
- });
22732
- const foreignSchema = baseSchema.extend({
22733
- __mode: zod.z.literal("foreign"),
22786
+ name: zod.z.string().trim().min(1).refine(refineName, "schemaErrors.invalidAddressName"),
22787
+ phone: zod.z.string().trim().nullishDefault(""),
22734
22788
  postalCode: zod.z.string().trim(),
22735
22789
  stateProvince: zod.z.string().trim().nullishDefault("")
22736
22790
  });
22737
- const addressSchema = zod.z.discriminatedUnion("__mode", [domesticSchema, foreignSchema]).refine(schema => {
22738
- var _a;
22739
- return (_a = schema.name) === null || _a === void 0 ? void 0 : _a.match(/^[a-zA-Z]{2,} [a-zA-Z]{2,}/);
22791
+
22792
+ extendZod();
22793
+ const postalCodeRegex$1 = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
22794
+ const addressFormSchema = addressSchema.refine(schema => !schema.phone || min$4.isValidPhoneNumber(schema.phone, schema.countryCode), {
22795
+ message: "schemaErrors.notAValidPhoneNumber",
22796
+ path: ["phone"]
22797
+ }).refine(schema => {
22798
+ if (schema.countryCode === "US") {
22799
+ return schema.stateProvince && usStateCodes.includes(schema.stateProvince);
22800
+ }
22801
+ return true;
22740
22802
  }, {
22741
- message: "schemaErrors.invalidAddressName",
22742
- path: ["name"]
22803
+ message: "schemaErrors.invalidStateProvince",
22804
+ path: ["stateProvince"]
22743
22805
  }).refine(schema => {
22744
- var _a, _b, _c;
22745
- return ((_b = (_a = schema.companyName) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) < 2 ?
22746
- // If companyName is less than 2 characters, name must be 2 words of 2 characters each
22747
- (_c = schema.name) === null || _c === void 0 ? void 0 : _c.match(/^[a-zA-Z]{2,} [a-zA-Z]{2,}/) : true;
22806
+ if (schema.countryCode === "US") {
22807
+ return postalCodeRegex$1.test(schema.postalCode);
22808
+ }
22809
+ return true;
22748
22810
  }, {
22749
- message: "schemaErrors.invalidAddressName",
22750
- path: ["name"]
22751
- }).refine(schema => !schema.phone || min$4.isValidPhoneNumber(schema.phone,
22752
- //TODO: Some of our countries appear to be unsupported by libphonenumber. What should we do here?
22753
- schema.countryCode), {
22754
- message: "schemaErrors.notAValidPhoneNumber",
22755
- path: ["phone"]
22811
+ message: "schemaErrors.invalidPostalCode",
22812
+ path: ["postalCode"]
22756
22813
  });
22757
22814
 
22758
- const selectMode = ({
22759
- countryCode
22760
- } = {}) => countryCode === "US" ? "domestic" : "foreign";
22761
22815
  const AddressForm = ({
22762
22816
  address,
22763
22817
  domestic,
@@ -22771,29 +22825,19 @@ const AddressForm = ({
22771
22825
  const {
22772
22826
  t
22773
22827
  } = reactI18next.useTranslation();
22774
- const countryCodeOptions = useCountryCodeOptions(domestic);
22775
- const stateCodeOptions = useStateCodeOptions(domestic);
22776
22828
  const form = reactHookForm.useForm({
22777
- defaultValues: Object.assign({
22778
- __mode: selectMode(address)
22779
- }, address && address),
22780
- resolver: validationResolver(addressSchema)
22829
+ defaultValues: Object.assign({}, address && address),
22830
+ resolver: validationResolver(addressFormSchema)
22781
22831
  });
22782
- form.register("__mode");
22783
- const {
22784
- isSubmitted
22785
- } = form.formState;
22786
- const watchCountryCode = form.watch("countryCode");
22787
22832
  const handleSubmit = form.handleSubmit(values => __awaiter(void 0, void 0, void 0, function* () {
22788
- const _a = values,
22789
- payload = __rest(_a, ["__mode"]);
22833
+ const payload = __rest(values, []);
22790
22834
  onSubmit(payload);
22791
22835
  }));
22792
22836
  const handleSubmitParse = React.useCallback(payload => __awaiter(void 0, void 0, void 0, function* () {
22793
- var _b;
22837
+ var _a;
22794
22838
  const parseResult = yield onSubmitParse === null || onSubmitParse === void 0 ? void 0 : onSubmitParse(payload);
22795
- const _c = (_b = parseResult === null || parseResult === void 0 ? void 0 : parseResult.address) !== null && _b !== void 0 ? _b : {},
22796
- updatedFields = __rest(_c, ["addressResidentialIndicator"]);
22839
+ const _b = (_a = parseResult === null || parseResult === void 0 ? void 0 : parseResult.address) !== null && _a !== void 0 ? _a : {},
22840
+ updatedFields = __rest(_b, ["addressResidentialIndicator"]);
22797
22841
  form.reset(Object.assign(Object.assign({}, form.getValues()), updatedFields), {
22798
22842
  keepDefaultValues: true
22799
22843
  });
@@ -22836,91 +22880,10 @@ const AddressForm = ({
22836
22880
  children: t("address.paste")
22837
22881
  }))
22838
22882
  }))]
22839
- })), jsxRuntime.jsx(TextInput, {
22840
- control: form.control,
22841
- form: formId,
22842
- label: t("address.fields.name"),
22843
- labelWeight: "normal",
22844
- name: "name"
22845
- }), jsxRuntime.jsx(TextInput, {
22846
- control: form.control,
22847
- form: formId,
22848
- label: t("address.fields.company"),
22849
- labelWeight: "normal",
22850
- name: "companyName",
22851
- subLabel: t("address.subFields.optional")
22852
- }), jsxRuntime.jsx(Select, {
22853
- control: form.control,
22854
- form: formId,
22855
- label: t("address.fields.countryCode"),
22856
- labelWeight: "normal",
22857
- name: "countryCode",
22858
- onChange: e => {
22859
- if (typeof e === "string") {
22860
- form.setValue("__mode", selectMode({
22861
- countryCode: e
22862
- }));
22863
- form.setValue("stateProvince", null, {
22864
- shouldValidate: isSubmitted
22865
- });
22866
- }
22867
- },
22868
- options: countryCodeOptions
22869
- }), jsxRuntime.jsx(TextInput, {
22870
- control: form.control,
22871
- form: formId,
22872
- label: t("address.fields.addressLine1"),
22873
- labelWeight: "normal",
22874
- name: "addressLine1"
22875
- }), jsxRuntime.jsx(TextInput, {
22876
- control: form.control,
22877
- form: formId,
22878
- label: t("address.fields.addressLine2"),
22879
- labelWeight: "normal",
22880
- name: "addressLine2"
22881
- }), jsxRuntime.jsx(TextInput, {
22882
- control: form.control,
22883
- form: formId,
22884
- label: t("address.fields.cityLocality"),
22885
- labelWeight: "normal",
22886
- name: "cityLocality"
22887
- }), watchCountryCode === "US" ?
22888
- // Domestic States
22889
- jsxRuntime.jsx(Select, {
22890
- control: form.control,
22891
- form: formId,
22892
- label: t("address.fields.stateProvince"),
22893
- labelWeight: "normal",
22894
- name: "stateProvince",
22895
- options: stateCodeOptions
22896
- }) :
22897
- // International Provinces
22898
- jsxRuntime.jsx(TextInput, {
22899
- control: form.control,
22900
- form: formId,
22901
- label: t("address.fields.stateProvince"),
22902
- labelWeight: "normal",
22903
- name: "stateProvince"
22904
- }), jsxRuntime.jsx(TextInput, {
22905
- control: form.control,
22906
- form: formId,
22907
- label: t("address.fields.postalCode"),
22908
- labelWeight: "normal",
22909
- name: "postalCode"
22910
- }), jsxRuntime.jsx(TextInput, {
22911
- control: form.control,
22912
- form: formId,
22913
- label: t("address.fields.phone"),
22914
- labelWeight: "normal",
22915
- name: "phone",
22916
- subLabel: t("address.subFields.optional")
22917
- }), jsxRuntime.jsx(TextInput, {
22918
- control: form.control,
22919
- form: formId,
22920
- label: t("address.fields.email"),
22921
- labelWeight: "normal",
22922
- name: "email",
22923
- subLabel: t("address.subFields.optional")
22883
+ })), jsxRuntime.jsx(AddressFields, {
22884
+ domestic: domestic,
22885
+ form: form,
22886
+ formId: formId
22924
22887
  }), jsxRuntime.jsxs(ButtonGroup, Object.assign({
22925
22888
  justify: "end"
22926
22889
  }, {
@@ -23249,6 +23212,45 @@ if (DESCRIPTORS$1 && isCallable$6(NativeSymbol) && (!('description' in SymbolPro
23249
23212
  });
23250
23213
  }
23251
23214
 
23215
+ extendZod();
23216
+ /**
23217
+ * @category Form Validation
23218
+ */
23219
+ const addressLine1Schema = zod.z.string().trim().min(1);
23220
+ /**
23221
+ * @category Form Validation
23222
+ */
23223
+ const addressLine1SchemaNoPoBox = addressLine1Schema.refine(val => !isPoBox(val), {
23224
+ message: "schemaErrors.invalidAddressPoBox"
23225
+ });
23226
+ /**
23227
+ * @category Form Validation
23228
+ */
23229
+ const addressLine2Schema = zod.z.string().trim().nullishDefault(undefined);
23230
+ /**
23231
+ * @category Form Validation
23232
+ */
23233
+ const addressLine2SchemaNoPoBox = addressLine2Schema.refine(val => !val || !isPoBox(val), {
23234
+ message: "schemaErrors.invalidAddressPoBox"
23235
+ });
23236
+
23237
+ /**
23238
+ * @category Form Validation
23239
+ */
23240
+ const moneySchema = zod.z.object({
23241
+ amount: zod.z.number().nonnegative(),
23242
+ currency: zod.z.nativeEnum(SE__namespace.Currency)
23243
+ });
23244
+
23245
+ /**
23246
+ * @category Form Validation
23247
+ */
23248
+ const phoneSchema = (defaultCountryCode = "US") => zod.z.string().trim().refine(val => min$4.isValidPhoneNumber(val, defaultCountryCode), "schemaErrors.notAValidPhoneNumber");
23249
+ /**
23250
+ * @category Form Validation
23251
+ */
23252
+ const phoneSchemaUnvalidated = zod.z.string().trim();
23253
+
23252
23254
  extendZod();
23253
23255
  const customsItemFormSchema = zod.z.object({
23254
23256
  countryOfOrigin: zod.z.enum(countryCodes),
@@ -25461,23 +25463,52 @@ $$3({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, {
25461
25463
  });
25462
25464
 
25463
25465
  const expirationYears = getExpirationYears(10);
25464
- //TODO: LMNT-781 Integrate reusable address schema
25465
- const billingSchema = baseSchema.extend({
25466
- cvv: zod.z.string().trim().refine(cvv => cardValidator__default["default"].cvv(cvv).isValid, "Invalid CVV"),
25467
- expirationMonth: zod.z.enum(["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]),
25468
- expirationYear: zod.z.string().trim().length(4).refine(year => expirationYears.includes(year), "Invalid year"),
25469
- number: zod.z.string().trim().refine(number => cardValidator__default["default"].number(number).isValid, "Invalid card number").refine(number => {
25470
- var _a, _b;
25471
- return !((_a = cardValidator__default["default"].number(number).card) === null || _a === void 0 ? void 0 : _a.type) || ["visa", "mastercard", "american-express", "discover"].includes((_b = cardValidator__default["default"].number(number).card) === null || _b === void 0 ? void 0 : _b.type);
25472
- }, "Card type must be Visa, Mastercard, American Express, or Discover"),
25466
+ const postalCodeRegex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
25467
+ const creditCardTypes = ["visa", "mastercard", "american-express", "discover"];
25468
+ const expirationMonths = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
25469
+ const billingSchema = zod.z.object({
25470
+ address: addressSchema.refine(schema => !schema.phone || min$4.isValidPhoneNumber(schema.phone, schema.countryCode), {
25471
+ message: "schemaErrors.notAValidPhoneNumber",
25472
+ path: ["phone"]
25473
+ }).refine(schema => {
25474
+ if (schema.countryCode === "US") {
25475
+ return schema.stateProvince && usStateCodes.includes(schema.stateProvince);
25476
+ }
25477
+ return true;
25478
+ }, {
25479
+ message: "schemaErrors.invalidStateProvince",
25480
+ path: ["stateProvince"]
25481
+ }).refine(schema => {
25482
+ if (schema.countryCode === "US") {
25483
+ return postalCodeRegex.test(schema.postalCode);
25484
+ }
25485
+ return true;
25486
+ }, {
25487
+ message: "schemaErrors.invalidPostalCode",
25488
+ path: ["postalCode"]
25489
+ }),
25490
+ creditCard: zod.z.object({
25491
+ cvv: zod.z.string().trim().refine(cvv => cardValidator__default["default"].cvv(cvv).isValid, "Invalid CVV"),
25492
+ expirationMonth: zod.z.enum(expirationMonths),
25493
+ expirationYear: zod.z.string().trim().length(4).refine(year => expirationYears.includes(year), "Invalid year"),
25494
+ number: zod.z.string().trim().refine(number => cardValidator__default["default"].number(number).isValid, "Invalid card number").refine(number => {
25495
+ var _a, _b;
25496
+ return !((_a = cardValidator__default["default"].number(number).card) === null || _a === void 0 ? void 0 : _a.type) || creditCardTypes.includes((_b = cardValidator__default["default"].number(number).card) === null || _b === void 0 ? void 0 : _b.type);
25497
+ }, "Card type must be Visa, Mastercard, American Express, or Discover"),
25498
+ type: zod.z.string().optional()
25499
+ }),
25473
25500
  setAsDefaultAddress: zod.z.boolean().optional()
25474
25501
  }).transform(schema => {
25475
25502
  var _a;
25476
- const {
25477
- number
25478
- } = schema;
25503
+ const _b = schema.creditCard,
25504
+ creditCard = __rest(_b, ["cvv"]);
25479
25505
  return Object.assign(Object.assign({}, schema), {
25480
- type: (_a = cardValidator__default["default"].number(number).card) === null || _a === void 0 ? void 0 : _a.type
25506
+ agreeToCarrierTerms: true,
25507
+ creditCard: Object.assign(Object.assign({}, creditCard), {
25508
+ name: schema.address.name,
25509
+ type: (_a = cardValidator__default["default"].number(creditCard.number).card) === null || _a === void 0 ? void 0 : _a.type
25510
+ }),
25511
+ email: schema.address.email
25481
25512
  });
25482
25513
  });
25483
25514
 
@@ -25495,8 +25526,8 @@ const BillingForm = ({
25495
25526
  resolver: validationResolver(billingSchema)
25496
25527
  });
25497
25528
  const handleSubmit = form.handleSubmit(values => __awaiter(void 0, void 0, void 0, function* () {
25498
- const billingPayload = __rest(values, []);
25499
- onSubmit(billingPayload);
25529
+ const payload = __rest(values, []);
25530
+ onSubmit(payload);
25500
25531
  }));
25501
25532
  const expirationMonthOptions = useExpirationMonthOptions();
25502
25533
  return jsxRuntime.jsxs("form", Object.assign({
@@ -25506,23 +25537,26 @@ const BillingForm = ({
25506
25537
  control: form.control,
25507
25538
  label: t("billing.fields.cardNumber"),
25508
25539
  labelWeight: "normal",
25509
- name: "number"
25540
+ name: "creditCard.number"
25510
25541
  }), jsxRuntime.jsx(Select, {
25511
25542
  control: form.control,
25512
25543
  label: t("billing.fields.expirationMonth"),
25513
25544
  labelWeight: "normal",
25514
- name: "expirationMonth",
25545
+ name: "creditCard.expirationMonth",
25515
25546
  options: expirationMonthOptions
25516
25547
  }), jsxRuntime.jsx(TextInput, {
25517
25548
  control: form.control,
25518
25549
  label: t("billing.fields.expirationYear"),
25519
25550
  labelWeight: "normal",
25520
- name: "expirationYear"
25551
+ name: "creditCard.expirationYear"
25521
25552
  }), jsxRuntime.jsx(TextInput, {
25522
25553
  control: form.control,
25523
25554
  label: t("billing.fields.cvv"),
25524
25555
  labelWeight: "normal",
25525
- name: "cvv"
25556
+ name: "creditCard.cvv"
25557
+ }), jsxRuntime.jsx(AddressFields, {
25558
+ form: form,
25559
+ formatFieldName: fieldName => `address.${fieldName}`
25526
25560
  }), jsxRuntime.jsx(CheckboxInput, {
25527
25561
  checkboxLabel: "Set as my default Ship From address",
25528
25562
  control: form.control,
@@ -27177,7 +27211,8 @@ var index$1 = /*#__PURE__*/Object.freeze({
27177
27211
  AddCarriers: AddCarriers$1,
27178
27212
  AddressDisplay: AddressDisplay,
27179
27213
  AddressForm: AddressForm,
27180
- baseSchema: baseSchema,
27214
+ addressFormSchema: addressFormSchema,
27215
+ AddressFields: AddressFields,
27181
27216
  addressSchema: addressSchema,
27182
27217
  AddressParser: AddressParser,
27183
27218
  addressParserSchema: addressParserSchema,
@@ -28316,6 +28351,8 @@ var common = {
28316
28351
  },
28317
28352
  invalidAddressName: "Recipient Name must have two characters in First and Last Name.",
28318
28353
  invalidAddressPoBox: "A physical address is required for wallet registration. You can add a PO Box as a Ship From address.",
28354
+ invalidPostalCode: "Invalid Postal Code",
28355
+ invalidStateProvince: "Invalid State",
28319
28356
  invalidString: "{{fieldLabel}} is invalid",
28320
28357
  nonnegative: "{{fieldLabel}} must be 0 or more",
28321
28358
  nonnegativeList: "{{ fieldLabels, list }} must each be 0 or more",
@@ -29142,7 +29179,7 @@ const useRatesForm = ({
29142
29179
  errors: labelErrors,
29143
29180
  reset: resetLabel,
29144
29181
  trigger: createLabel
29145
- } = react.useCreateLabel(printLabelLayout);
29182
+ } = react.useCreateLabel();
29146
29183
  const {
29147
29184
  ratesCalculating,
29148
29185
  ratesErrors,
@@ -29170,6 +29207,7 @@ const useRatesForm = ({
29170
29207
  }
29171
29208
  try {
29172
29209
  const label = yield createLabel({
29210
+ labelLayout: printLabelLayout,
29173
29211
  rateId
29174
29212
  });
29175
29213
  if (label) {
@@ -29181,7 +29219,7 @@ const useRatesForm = ({
29181
29219
  yield onLabelCreateFailure === null || onLabelCreateFailure === void 0 ? void 0 : onLabelCreateFailure(rate, shipment);
29182
29220
  }
29183
29221
  }
29184
- }), [createLabel, onBeforeLabelCreate, onLabelCreateFailure, onLabelCreateSuccess, ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.rates, shipment]);
29222
+ }), [createLabel, onBeforeLabelCreate, onLabelCreateFailure, onLabelCreateSuccess, printLabelLayout, ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.rates, shipment]);
29185
29223
  const handleSave = React.useCallback(({
29186
29224
  carrierId,
29187
29225
  serviceCode