@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.js CHANGED
@@ -1991,7 +1991,7 @@ const useConfirmationOptions = () => {
1991
1991
  } = useTranslation("common");
1992
1992
  return useMemo(() => Object.values(SE.ConfirmationType)
1993
1993
  // TODO: Remove this filter once these options are better supported by UpdateShipment
1994
- .filter(v => v !== SE.ConfirmationType.VERBAL_CONFIRMATION && v !== SE.ConfirmationType.DELIVERY_MAILED).flatMap(v => v === "none" ? [] : {
1994
+ .filter(v => v !== SE.ConfirmationType.DELIVERY_MAILED && v !== SE.ConfirmationType.DIRECT_SIGNATURE && v !== SE.ConfirmationType.VERBAL_CONFIRMATION).flatMap(v => v === "none" ? [] : {
1995
1995
  label: t(`confirmationTypes.${camelize(v)}`),
1996
1996
  value: v
1997
1997
  }), [t]);
@@ -20702,24 +20702,23 @@ const ElementsContext = /*#__PURE__*/createContext(undefined);
20702
20702
  */
20703
20703
  const ElementsProvider = ({
20704
20704
  baseURL,
20705
+ brandName,
20705
20706
  children,
20706
20707
  environment: _environment = "production",
20707
- onError,
20708
- brandName,
20709
- token
20708
+ getToken,
20709
+ onError
20710
20710
  }) => {
20711
20711
  const value = useMemo(() => ({
20712
20712
  brandName,
20713
20713
  environment: _environment,
20714
- onError,
20715
- token
20716
- }), [_environment, token, onError, brandName]);
20714
+ onError
20715
+ }), [_environment, onError, brandName]);
20717
20716
  return jsx(ShipEngineProvider, Object.assign({
20718
20717
  baseURL: baseURL ? `${baseURL}/api` : "/api",
20718
+ getToken: getToken,
20719
20719
  headers: {
20720
20720
  "X-Environment": `${_environment}`
20721
- },
20722
- token: token
20721
+ }
20723
20722
  }, {
20724
20723
  children: jsx(ElementsContext.Provider, Object.assign({
20725
20724
  value: value
@@ -22413,40 +22412,127 @@ const AddressParser = ({
22413
22412
  }));
22414
22413
  };
22415
22414
 
22416
- var PROPER_FUNCTION_NAME = functionName.PROPER;
22417
- var fails$4 = fails$r;
22418
- var whitespaces = whitespaces$4;
22419
-
22420
- var non = '\u200B\u0085\u180E';
22421
-
22422
- // check that a method works with the correct list
22423
- // of whitespaces and has a correct name
22424
- var stringTrimForced = function (METHOD_NAME) {
22425
- return fails$4(function () {
22426
- return !!whitespaces[METHOD_NAME]()
22427
- || non[METHOD_NAME]() !== non
22428
- || (PROPER_FUNCTION_NAME && whitespaces[METHOD_NAME].name !== METHOD_NAME);
22415
+ const AddressFields = ({
22416
+ domestic,
22417
+ form,
22418
+ formatFieldName: _formatFieldName = fieldName => fieldName,
22419
+ formId
22420
+ }) => {
22421
+ const {
22422
+ t
22423
+ } = useTranslation();
22424
+ const countryCodeOptions = useCountryCodeOptions(domestic);
22425
+ const stateCodeOptions = useStateCodeOptions(domestic);
22426
+ const {
22427
+ isSubmitted
22428
+ } = form.formState;
22429
+ const watchCountryCode = form.watch(_formatFieldName("countryCode"));
22430
+ return jsxs(Fragment, {
22431
+ children: [jsx(TextInput, {
22432
+ control: form.control,
22433
+ form: formId,
22434
+ label: t("address.fields.name"),
22435
+ labelWeight: "normal",
22436
+ name: _formatFieldName("name")
22437
+ }), jsx(TextInput, {
22438
+ control: form.control,
22439
+ form: formId,
22440
+ label: t("address.fields.company"),
22441
+ labelWeight: "normal",
22442
+ name: _formatFieldName("companyName"),
22443
+ subLabel: t("address.subFields.optional")
22444
+ }), jsx(Select, {
22445
+ control: form.control,
22446
+ form: formId,
22447
+ label: t("address.fields.countryCode"),
22448
+ labelWeight: "normal",
22449
+ name: _formatFieldName("countryCode"),
22450
+ onChange: e => {
22451
+ if (typeof e === "string") {
22452
+ form.setValue(_formatFieldName("stateProvince"), null, {
22453
+ shouldValidate: isSubmitted
22454
+ });
22455
+ }
22456
+ },
22457
+ options: countryCodeOptions
22458
+ }), jsx(TextInput, {
22459
+ control: form.control,
22460
+ form: formId,
22461
+ label: t("address.fields.addressLine1"),
22462
+ labelWeight: "normal",
22463
+ name: _formatFieldName("addressLine1")
22464
+ }), jsx(TextInput, {
22465
+ control: form.control,
22466
+ form: formId,
22467
+ label: t("address.fields.addressLine2"),
22468
+ labelWeight: "normal",
22469
+ name: _formatFieldName("addressLine2")
22470
+ }), jsx(TextInput, {
22471
+ control: form.control,
22472
+ form: formId,
22473
+ label: t("address.fields.cityLocality"),
22474
+ labelWeight: "normal",
22475
+ name: _formatFieldName("cityLocality")
22476
+ }), watchCountryCode === "US" ?
22477
+ // Domestic States
22478
+ jsx(Select, {
22479
+ control: form.control,
22480
+ form: formId,
22481
+ label: t("address.fields.stateProvince"),
22482
+ labelWeight: "normal",
22483
+ name: _formatFieldName("stateProvince"),
22484
+ options: stateCodeOptions
22485
+ }) :
22486
+ // International Provinces
22487
+ jsx(TextInput, {
22488
+ control: form.control,
22489
+ form: formId,
22490
+ label: t("address.fields.stateProvince"),
22491
+ labelWeight: "normal",
22492
+ name: _formatFieldName("stateProvince")
22493
+ }), jsx(TextInput, {
22494
+ control: form.control,
22495
+ form: formId,
22496
+ label: t("address.fields.postalCode"),
22497
+ labelWeight: "normal",
22498
+ name: _formatFieldName("postalCode")
22499
+ }), jsx(TextInput, {
22500
+ control: form.control,
22501
+ form: formId,
22502
+ label: t("address.fields.phone"),
22503
+ labelWeight: "normal",
22504
+ name: _formatFieldName("phone"),
22505
+ subLabel: t("address.subFields.optional")
22506
+ }), jsx(TextInput, {
22507
+ control: form.control,
22508
+ form: formId,
22509
+ label: t("address.fields.email"),
22510
+ labelWeight: "normal",
22511
+ name: _formatFieldName("email"),
22512
+ subLabel: t("address.subFields.optional")
22513
+ })]
22429
22514
  });
22430
22515
  };
22431
22516
 
22432
- var $$a = _export;
22433
- var $trim = stringTrim.trim;
22434
- var forcedStringTrimMethod = stringTrimForced;
22435
-
22436
- // `String.prototype.trim` method
22437
- // https://tc39.es/ecma262/#sec-string.prototype.trim
22438
- $$a({ target: 'String', proto: true, forced: forcedStringTrimMethod('trim') }, {
22439
- trim: function trim() {
22440
- return $trim(this);
22441
- }
22442
- });
22517
+ /* eslint-disable @typescript-eslint/no-unused-vars -- Allow unused generics in ZodObject interface overload */
22518
+ function nullishDefault(defaultValue) {
22519
+ return this.nullish().transform(v => v !== null && v !== void 0 ? v : defaultValue);
22520
+ }
22521
+ /**
22522
+ * @category Form Validation
22523
+ */
22524
+ const extendZod = () => {
22525
+ z.ZodString.prototype.nullishDefault = nullishDefault;
22526
+ z.ZodNumber.prototype.nullishDefault = nullishDefault;
22527
+ z.ZodObject.prototype.nullishDefault = nullishDefault;
22528
+ };
22443
22529
 
22444
22530
  // TODO: Remove from `core-js@4` since it's moved to entry points
22445
22531
 
22446
22532
  var uncurryThis$6 = functionUncurryThisClause;
22447
22533
  var defineBuiltIn$3 = defineBuiltIn$8;
22448
22534
  var regexpExec$1 = regexpExec$2;
22449
- var fails$3 = fails$r;
22535
+ var fails$4 = fails$r;
22450
22536
  var wellKnownSymbol$7 = wellKnownSymbol$j;
22451
22537
  var createNonEnumerableProperty = createNonEnumerableProperty$5;
22452
22538
 
@@ -22456,14 +22542,14 @@ var RegExpPrototype = RegExp.prototype;
22456
22542
  var fixRegexpWellKnownSymbolLogic = function (KEY, exec, FORCED, SHAM) {
22457
22543
  var SYMBOL = wellKnownSymbol$7(KEY);
22458
22544
 
22459
- var DELEGATES_TO_SYMBOL = !fails$3(function () {
22545
+ var DELEGATES_TO_SYMBOL = !fails$4(function () {
22460
22546
  // String methods call symbol-named RegEp methods
22461
22547
  var O = {};
22462
22548
  O[SYMBOL] = function () { return 7; };
22463
22549
  return ''[KEY](O) != 7;
22464
22550
  });
22465
22551
 
22466
- var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails$3(function () {
22552
+ var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails$4(function () {
22467
22553
  // Symbol-named RegExp methods call .exec
22468
22554
  var execCalled = false;
22469
22555
  var re = /a/;
@@ -22629,104 +22715,72 @@ fixRegExpWellKnownSymbolLogic$1('match', function (MATCH, nativeMatch, maybeCall
22629
22715
  ];
22630
22716
  });
22631
22717
 
22632
- /* eslint-disable @typescript-eslint/no-unused-vars -- Allow unused generics in ZodObject interface overload */
22633
- function nullishDefault(defaultValue) {
22634
- return this.nullish().transform(v => v !== null && v !== void 0 ? v : defaultValue);
22635
- }
22636
- /**
22637
- * @category Form Validation
22638
- */
22639
- const extendZod = () => {
22640
- z.ZodString.prototype.nullishDefault = nullishDefault;
22641
- z.ZodNumber.prototype.nullishDefault = nullishDefault;
22642
- z.ZodObject.prototype.nullishDefault = nullishDefault;
22718
+ var PROPER_FUNCTION_NAME = functionName.PROPER;
22719
+ var fails$3 = fails$r;
22720
+ var whitespaces = whitespaces$4;
22721
+
22722
+ var non = '\u200B\u0085\u180E';
22723
+
22724
+ // check that a method works with the correct list
22725
+ // of whitespaces and has a correct name
22726
+ var stringTrimForced = function (METHOD_NAME) {
22727
+ return fails$3(function () {
22728
+ return !!whitespaces[METHOD_NAME]()
22729
+ || non[METHOD_NAME]() !== non
22730
+ || (PROPER_FUNCTION_NAME && whitespaces[METHOD_NAME].name !== METHOD_NAME);
22731
+ });
22643
22732
  };
22644
22733
 
22645
- extendZod();
22646
- /**
22647
- * @category Form Validation
22648
- */
22649
- const addressLine1Schema = z.string().trim().min(1);
22650
- /**
22651
- * @category Form Validation
22652
- */
22653
- const addressLine1SchemaNoPoBox = addressLine1Schema.refine(val => !isPoBox(val), {
22654
- message: "schemaErrors.invalidAddressPoBox"
22655
- });
22656
- /**
22657
- * @category Form Validation
22658
- */
22659
- const addressLine2Schema = z.string().trim().nullishDefault(undefined);
22660
- /**
22661
- * @category Form Validation
22662
- */
22663
- const addressLine2SchemaNoPoBox = addressLine2Schema.refine(val => !val || !isPoBox(val), {
22664
- message: "schemaErrors.invalidAddressPoBox"
22665
- });
22734
+ var $$a = _export;
22735
+ var $trim = stringTrim.trim;
22736
+ var forcedStringTrimMethod = stringTrimForced;
22666
22737
 
22667
- /**
22668
- * @category Form Validation
22669
- */
22670
- const moneySchema = z.object({
22671
- amount: z.number().nonnegative(),
22672
- currency: z.nativeEnum(SE.Currency)
22738
+ // `String.prototype.trim` method
22739
+ // https://tc39.es/ecma262/#sec-string.prototype.trim
22740
+ $$a({ target: 'String', proto: true, forced: forcedStringTrimMethod('trim') }, {
22741
+ trim: function trim() {
22742
+ return $trim(this);
22743
+ }
22673
22744
  });
22674
22745
 
22675
- /**
22676
- * @category Form Validation
22677
- */
22678
- const phoneSchema = (defaultCountryCode = "US") => z.string().trim().refine(val => isValidPhoneNumber(val, defaultCountryCode), "schemaErrors.notAValidPhoneNumber");
22679
- /**
22680
- * @category Form Validation
22681
- */
22682
- const phoneSchemaUnvalidated = z.string().trim();
22683
-
22684
22746
  extendZod();
22685
- const postalCodeRegex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
22686
- const baseSchema = z.object({
22687
- addressLine1: addressLine1Schema,
22688
- addressLine2: addressLine2Schema,
22747
+ const refineName = n => n.match(/^[a-zA-Z]{2,} [a-zA-Z]{2,}/);
22748
+ const addressSchema = z.object({
22749
+ addressLine1: z.string().trim().min(1),
22750
+ addressLine2: z.string().trim().nullishDefault(undefined),
22689
22751
  cityLocality: z.string().trim().min(1),
22690
22752
  companyName: z.string().trim().min(2).max(40).nullishDefault(undefined),
22691
22753
  countryCode: z.enum(countryCodes),
22692
22754
  email: z.string().trim().email().nullishDefault(""),
22693
- name: z.string().trim().min(1),
22694
- phone: phoneSchemaUnvalidated.nullishDefault("")
22695
- });
22696
- const domesticSchema = baseSchema.extend({
22697
- __mode: z.literal("domestic"),
22698
- postalCode: z.string().trim().regex(postalCodeRegex),
22699
- stateProvince: z.enum(usStateCodes)
22700
- });
22701
- const foreignSchema = baseSchema.extend({
22702
- __mode: z.literal("foreign"),
22755
+ name: z.string().trim().min(1).refine(refineName, "schemaErrors.invalidAddressName"),
22756
+ phone: z.string().trim().nullishDefault(""),
22703
22757
  postalCode: z.string().trim(),
22704
22758
  stateProvince: z.string().trim().nullishDefault("")
22705
22759
  });
22706
- const addressSchema = z.discriminatedUnion("__mode", [domesticSchema, foreignSchema]).refine(schema => {
22707
- var _a;
22708
- return (_a = schema.name) === null || _a === void 0 ? void 0 : _a.match(/^[a-zA-Z]{2,} [a-zA-Z]{2,}/);
22760
+
22761
+ extendZod();
22762
+ const postalCodeRegex$1 = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
22763
+ const addressFormSchema = addressSchema.refine(schema => !schema.phone || isValidPhoneNumber(schema.phone, schema.countryCode), {
22764
+ message: "schemaErrors.notAValidPhoneNumber",
22765
+ path: ["phone"]
22766
+ }).refine(schema => {
22767
+ if (schema.countryCode === "US") {
22768
+ return schema.stateProvince && usStateCodes.includes(schema.stateProvince);
22769
+ }
22770
+ return true;
22709
22771
  }, {
22710
- message: "schemaErrors.invalidAddressName",
22711
- path: ["name"]
22772
+ message: "schemaErrors.invalidStateProvince",
22773
+ path: ["stateProvince"]
22712
22774
  }).refine(schema => {
22713
- var _a, _b, _c;
22714
- return ((_b = (_a = schema.companyName) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) < 2 ?
22715
- // If companyName is less than 2 characters, name must be 2 words of 2 characters each
22716
- (_c = schema.name) === null || _c === void 0 ? void 0 : _c.match(/^[a-zA-Z]{2,} [a-zA-Z]{2,}/) : true;
22775
+ if (schema.countryCode === "US") {
22776
+ return postalCodeRegex$1.test(schema.postalCode);
22777
+ }
22778
+ return true;
22717
22779
  }, {
22718
- message: "schemaErrors.invalidAddressName",
22719
- path: ["name"]
22720
- }).refine(schema => !schema.phone || isValidPhoneNumber(schema.phone,
22721
- //TODO: Some of our countries appear to be unsupported by libphonenumber. What should we do here?
22722
- schema.countryCode), {
22723
- message: "schemaErrors.notAValidPhoneNumber",
22724
- path: ["phone"]
22780
+ message: "schemaErrors.invalidPostalCode",
22781
+ path: ["postalCode"]
22725
22782
  });
22726
22783
 
22727
- const selectMode = ({
22728
- countryCode
22729
- } = {}) => countryCode === "US" ? "domestic" : "foreign";
22730
22784
  const AddressForm = ({
22731
22785
  address,
22732
22786
  domestic,
@@ -22740,29 +22794,19 @@ const AddressForm = ({
22740
22794
  const {
22741
22795
  t
22742
22796
  } = useTranslation();
22743
- const countryCodeOptions = useCountryCodeOptions(domestic);
22744
- const stateCodeOptions = useStateCodeOptions(domestic);
22745
22797
  const form = useForm({
22746
- defaultValues: Object.assign({
22747
- __mode: selectMode(address)
22748
- }, address && address),
22749
- resolver: validationResolver(addressSchema)
22798
+ defaultValues: Object.assign({}, address && address),
22799
+ resolver: validationResolver(addressFormSchema)
22750
22800
  });
22751
- form.register("__mode");
22752
- const {
22753
- isSubmitted
22754
- } = form.formState;
22755
- const watchCountryCode = form.watch("countryCode");
22756
22801
  const handleSubmit = form.handleSubmit(values => __awaiter(void 0, void 0, void 0, function* () {
22757
- const _a = values,
22758
- payload = __rest(_a, ["__mode"]);
22802
+ const payload = __rest(values, []);
22759
22803
  onSubmit(payload);
22760
22804
  }));
22761
22805
  const handleSubmitParse = useCallback(payload => __awaiter(void 0, void 0, void 0, function* () {
22762
- var _b;
22806
+ var _a;
22763
22807
  const parseResult = yield onSubmitParse === null || onSubmitParse === void 0 ? void 0 : onSubmitParse(payload);
22764
- const _c = (_b = parseResult === null || parseResult === void 0 ? void 0 : parseResult.address) !== null && _b !== void 0 ? _b : {},
22765
- updatedFields = __rest(_c, ["addressResidentialIndicator"]);
22808
+ const _b = (_a = parseResult === null || parseResult === void 0 ? void 0 : parseResult.address) !== null && _a !== void 0 ? _a : {},
22809
+ updatedFields = __rest(_b, ["addressResidentialIndicator"]);
22766
22810
  form.reset(Object.assign(Object.assign({}, form.getValues()), updatedFields), {
22767
22811
  keepDefaultValues: true
22768
22812
  });
@@ -22805,91 +22849,10 @@ const AddressForm = ({
22805
22849
  children: t("address.paste")
22806
22850
  }))
22807
22851
  }))]
22808
- })), jsx(TextInput, {
22809
- control: form.control,
22810
- form: formId,
22811
- label: t("address.fields.name"),
22812
- labelWeight: "normal",
22813
- name: "name"
22814
- }), jsx(TextInput, {
22815
- control: form.control,
22816
- form: formId,
22817
- label: t("address.fields.company"),
22818
- labelWeight: "normal",
22819
- name: "companyName",
22820
- subLabel: t("address.subFields.optional")
22821
- }), jsx(Select, {
22822
- control: form.control,
22823
- form: formId,
22824
- label: t("address.fields.countryCode"),
22825
- labelWeight: "normal",
22826
- name: "countryCode",
22827
- onChange: e => {
22828
- if (typeof e === "string") {
22829
- form.setValue("__mode", selectMode({
22830
- countryCode: e
22831
- }));
22832
- form.setValue("stateProvince", null, {
22833
- shouldValidate: isSubmitted
22834
- });
22835
- }
22836
- },
22837
- options: countryCodeOptions
22838
- }), jsx(TextInput, {
22839
- control: form.control,
22840
- form: formId,
22841
- label: t("address.fields.addressLine1"),
22842
- labelWeight: "normal",
22843
- name: "addressLine1"
22844
- }), jsx(TextInput, {
22845
- control: form.control,
22846
- form: formId,
22847
- label: t("address.fields.addressLine2"),
22848
- labelWeight: "normal",
22849
- name: "addressLine2"
22850
- }), jsx(TextInput, {
22851
- control: form.control,
22852
- form: formId,
22853
- label: t("address.fields.cityLocality"),
22854
- labelWeight: "normal",
22855
- name: "cityLocality"
22856
- }), watchCountryCode === "US" ?
22857
- // Domestic States
22858
- jsx(Select, {
22859
- control: form.control,
22860
- form: formId,
22861
- label: t("address.fields.stateProvince"),
22862
- labelWeight: "normal",
22863
- name: "stateProvince",
22864
- options: stateCodeOptions
22865
- }) :
22866
- // International Provinces
22867
- jsx(TextInput, {
22868
- control: form.control,
22869
- form: formId,
22870
- label: t("address.fields.stateProvince"),
22871
- labelWeight: "normal",
22872
- name: "stateProvince"
22873
- }), jsx(TextInput, {
22874
- control: form.control,
22875
- form: formId,
22876
- label: t("address.fields.postalCode"),
22877
- labelWeight: "normal",
22878
- name: "postalCode"
22879
- }), jsx(TextInput, {
22880
- control: form.control,
22881
- form: formId,
22882
- label: t("address.fields.phone"),
22883
- labelWeight: "normal",
22884
- name: "phone",
22885
- subLabel: t("address.subFields.optional")
22886
- }), jsx(TextInput, {
22887
- control: form.control,
22888
- form: formId,
22889
- label: t("address.fields.email"),
22890
- labelWeight: "normal",
22891
- name: "email",
22892
- subLabel: t("address.subFields.optional")
22852
+ })), jsx(AddressFields, {
22853
+ domestic: domestic,
22854
+ form: form,
22855
+ formId: formId
22893
22856
  }), jsxs(ButtonGroup, Object.assign({
22894
22857
  justify: "end"
22895
22858
  }, {
@@ -23218,6 +23181,45 @@ if (DESCRIPTORS$1 && isCallable$6(NativeSymbol) && (!('description' in SymbolPro
23218
23181
  });
23219
23182
  }
23220
23183
 
23184
+ extendZod();
23185
+ /**
23186
+ * @category Form Validation
23187
+ */
23188
+ const addressLine1Schema = z.string().trim().min(1);
23189
+ /**
23190
+ * @category Form Validation
23191
+ */
23192
+ const addressLine1SchemaNoPoBox = addressLine1Schema.refine(val => !isPoBox(val), {
23193
+ message: "schemaErrors.invalidAddressPoBox"
23194
+ });
23195
+ /**
23196
+ * @category Form Validation
23197
+ */
23198
+ const addressLine2Schema = z.string().trim().nullishDefault(undefined);
23199
+ /**
23200
+ * @category Form Validation
23201
+ */
23202
+ const addressLine2SchemaNoPoBox = addressLine2Schema.refine(val => !val || !isPoBox(val), {
23203
+ message: "schemaErrors.invalidAddressPoBox"
23204
+ });
23205
+
23206
+ /**
23207
+ * @category Form Validation
23208
+ */
23209
+ const moneySchema = z.object({
23210
+ amount: z.number().nonnegative(),
23211
+ currency: z.nativeEnum(SE.Currency)
23212
+ });
23213
+
23214
+ /**
23215
+ * @category Form Validation
23216
+ */
23217
+ const phoneSchema = (defaultCountryCode = "US") => z.string().trim().refine(val => isValidPhoneNumber(val, defaultCountryCode), "schemaErrors.notAValidPhoneNumber");
23218
+ /**
23219
+ * @category Form Validation
23220
+ */
23221
+ const phoneSchemaUnvalidated = z.string().trim();
23222
+
23221
23223
  extendZod();
23222
23224
  const customsItemFormSchema = z.object({
23223
23225
  countryOfOrigin: z.enum(countryCodes),
@@ -25430,23 +25432,52 @@ $$3({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, {
25430
25432
  });
25431
25433
 
25432
25434
  const expirationYears = getExpirationYears(10);
25433
- //TODO: LMNT-781 Integrate reusable address schema
25434
- const billingSchema = baseSchema.extend({
25435
- cvv: z.string().trim().refine(cvv => cardValidator.cvv(cvv).isValid, "Invalid CVV"),
25436
- expirationMonth: z.enum(["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]),
25437
- expirationYear: z.string().trim().length(4).refine(year => expirationYears.includes(year), "Invalid year"),
25438
- number: z.string().trim().refine(number => cardValidator.number(number).isValid, "Invalid card number").refine(number => {
25439
- var _a, _b;
25440
- return !((_a = cardValidator.number(number).card) === null || _a === void 0 ? void 0 : _a.type) || ["visa", "mastercard", "american-express", "discover"].includes((_b = cardValidator.number(number).card) === null || _b === void 0 ? void 0 : _b.type);
25441
- }, "Card type must be Visa, Mastercard, American Express, or Discover"),
25435
+ const postalCodeRegex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
25436
+ const creditCardTypes = ["visa", "mastercard", "american-express", "discover"];
25437
+ const expirationMonths = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
25438
+ const billingSchema = z.object({
25439
+ address: addressSchema.refine(schema => !schema.phone || isValidPhoneNumber(schema.phone, schema.countryCode), {
25440
+ message: "schemaErrors.notAValidPhoneNumber",
25441
+ path: ["phone"]
25442
+ }).refine(schema => {
25443
+ if (schema.countryCode === "US") {
25444
+ return schema.stateProvince && usStateCodes.includes(schema.stateProvince);
25445
+ }
25446
+ return true;
25447
+ }, {
25448
+ message: "schemaErrors.invalidStateProvince",
25449
+ path: ["stateProvince"]
25450
+ }).refine(schema => {
25451
+ if (schema.countryCode === "US") {
25452
+ return postalCodeRegex.test(schema.postalCode);
25453
+ }
25454
+ return true;
25455
+ }, {
25456
+ message: "schemaErrors.invalidPostalCode",
25457
+ path: ["postalCode"]
25458
+ }),
25459
+ creditCard: z.object({
25460
+ cvv: z.string().trim().refine(cvv => cardValidator.cvv(cvv).isValid, "Invalid CVV"),
25461
+ expirationMonth: z.enum(expirationMonths),
25462
+ expirationYear: z.string().trim().length(4).refine(year => expirationYears.includes(year), "Invalid year"),
25463
+ number: z.string().trim().refine(number => cardValidator.number(number).isValid, "Invalid card number").refine(number => {
25464
+ var _a, _b;
25465
+ return !((_a = cardValidator.number(number).card) === null || _a === void 0 ? void 0 : _a.type) || creditCardTypes.includes((_b = cardValidator.number(number).card) === null || _b === void 0 ? void 0 : _b.type);
25466
+ }, "Card type must be Visa, Mastercard, American Express, or Discover"),
25467
+ type: z.string().optional()
25468
+ }),
25442
25469
  setAsDefaultAddress: z.boolean().optional()
25443
25470
  }).transform(schema => {
25444
25471
  var _a;
25445
- const {
25446
- number
25447
- } = schema;
25472
+ const _b = schema.creditCard,
25473
+ creditCard = __rest(_b, ["cvv"]);
25448
25474
  return Object.assign(Object.assign({}, schema), {
25449
- type: (_a = cardValidator.number(number).card) === null || _a === void 0 ? void 0 : _a.type
25475
+ agreeToCarrierTerms: true,
25476
+ creditCard: Object.assign(Object.assign({}, creditCard), {
25477
+ name: schema.address.name,
25478
+ type: (_a = cardValidator.number(creditCard.number).card) === null || _a === void 0 ? void 0 : _a.type
25479
+ }),
25480
+ email: schema.address.email
25450
25481
  });
25451
25482
  });
25452
25483
 
@@ -25464,8 +25495,8 @@ const BillingForm = ({
25464
25495
  resolver: validationResolver(billingSchema)
25465
25496
  });
25466
25497
  const handleSubmit = form.handleSubmit(values => __awaiter(void 0, void 0, void 0, function* () {
25467
- const billingPayload = __rest(values, []);
25468
- onSubmit(billingPayload);
25498
+ const payload = __rest(values, []);
25499
+ onSubmit(payload);
25469
25500
  }));
25470
25501
  const expirationMonthOptions = useExpirationMonthOptions();
25471
25502
  return jsxs("form", Object.assign({
@@ -25475,23 +25506,26 @@ const BillingForm = ({
25475
25506
  control: form.control,
25476
25507
  label: t("billing.fields.cardNumber"),
25477
25508
  labelWeight: "normal",
25478
- name: "number"
25509
+ name: "creditCard.number"
25479
25510
  }), jsx(Select, {
25480
25511
  control: form.control,
25481
25512
  label: t("billing.fields.expirationMonth"),
25482
25513
  labelWeight: "normal",
25483
- name: "expirationMonth",
25514
+ name: "creditCard.expirationMonth",
25484
25515
  options: expirationMonthOptions
25485
25516
  }), jsx(TextInput, {
25486
25517
  control: form.control,
25487
25518
  label: t("billing.fields.expirationYear"),
25488
25519
  labelWeight: "normal",
25489
- name: "expirationYear"
25520
+ name: "creditCard.expirationYear"
25490
25521
  }), jsx(TextInput, {
25491
25522
  control: form.control,
25492
25523
  label: t("billing.fields.cvv"),
25493
25524
  labelWeight: "normal",
25494
- name: "cvv"
25525
+ name: "creditCard.cvv"
25526
+ }), jsx(AddressFields, {
25527
+ form: form,
25528
+ formatFieldName: fieldName => `address.${fieldName}`
25495
25529
  }), jsx(CheckboxInput, {
25496
25530
  checkboxLabel: "Set as my default Ship From address",
25497
25531
  control: form.control,
@@ -27146,7 +27180,8 @@ var index$1 = /*#__PURE__*/Object.freeze({
27146
27180
  AddCarriers: AddCarriers$1,
27147
27181
  AddressDisplay: AddressDisplay,
27148
27182
  AddressForm: AddressForm,
27149
- baseSchema: baseSchema,
27183
+ addressFormSchema: addressFormSchema,
27184
+ AddressFields: AddressFields,
27150
27185
  addressSchema: addressSchema,
27151
27186
  AddressParser: AddressParser,
27152
27187
  addressParserSchema: addressParserSchema,
@@ -28285,6 +28320,8 @@ var common = {
28285
28320
  },
28286
28321
  invalidAddressName: "Recipient Name must have two characters in First and Last Name.",
28287
28322
  invalidAddressPoBox: "A physical address is required for wallet registration. You can add a PO Box as a Ship From address.",
28323
+ invalidPostalCode: "Invalid Postal Code",
28324
+ invalidStateProvince: "Invalid State",
28288
28325
  invalidString: "{{fieldLabel}} is invalid",
28289
28326
  nonnegative: "{{fieldLabel}} must be 0 or more",
28290
28327
  nonnegativeList: "{{ fieldLabels, list }} must each be 0 or more",
@@ -29111,7 +29148,7 @@ const useRatesForm = ({
29111
29148
  errors: labelErrors,
29112
29149
  reset: resetLabel,
29113
29150
  trigger: createLabel
29114
- } = useCreateLabel(printLabelLayout);
29151
+ } = useCreateLabel();
29115
29152
  const {
29116
29153
  ratesCalculating,
29117
29154
  ratesErrors,
@@ -29139,6 +29176,7 @@ const useRatesForm = ({
29139
29176
  }
29140
29177
  try {
29141
29178
  const label = yield createLabel({
29179
+ labelLayout: printLabelLayout,
29142
29180
  rateId
29143
29181
  });
29144
29182
  if (label) {
@@ -29150,7 +29188,7 @@ const useRatesForm = ({
29150
29188
  yield onLabelCreateFailure === null || onLabelCreateFailure === void 0 ? void 0 : onLabelCreateFailure(rate, shipment);
29151
29189
  }
29152
29190
  }
29153
- }), [createLabel, onBeforeLabelCreate, onLabelCreateFailure, onLabelCreateSuccess, ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.rates, shipment]);
29191
+ }), [createLabel, onBeforeLabelCreate, onLabelCreateFailure, onLabelCreateSuccess, printLabelLayout, ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.rates, shipment]);
29154
29192
  const handleSave = useCallback(({
29155
29193
  carrierId,
29156
29194
  serviceCode