@nuskin/shipping-address-form 1.5.1 → 1.7.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.
Files changed (96) hide show
  1. package/README.md +54 -12
  2. package/dist/addressLookup/AddressLookup.js +74 -0
  3. package/dist/addressLookup/AddressLookup.js.map +1 -0
  4. package/dist/addressLookup/components/LocationPinIcon.js +33 -0
  5. package/dist/addressLookup/components/LocationPinIcon.js.map +1 -0
  6. package/dist/addressLookup/components/SmartyIntlResults.js +1020 -0
  7. package/dist/addressLookup/components/SmartyIntlResults.js.map +1 -0
  8. package/dist/addressLookup/components/SmartyUSResults.js +1001 -0
  9. package/dist/addressLookup/components/SmartyUSResults.js.map +1 -0
  10. package/dist/addressLookup/config/address/countries.js +61 -0
  11. package/dist/addressLookup/config/address/countries.js.map +1 -0
  12. package/dist/addressLookup/config/address/index.js +19 -0
  13. package/dist/addressLookup/config/address/index.js.map +1 -0
  14. package/dist/addressLookup/config/googleMaps.js +12 -0
  15. package/dist/addressLookup/config/googleMaps.js.map +1 -0
  16. package/dist/addressLookup/countries.js +19 -0
  17. package/dist/addressLookup/countries.js.map +1 -0
  18. package/dist/addressLookup/hooks/useAddressFieldLabels.js +41 -0
  19. package/dist/addressLookup/hooks/useAddressFieldLabels.js.map +1 -0
  20. package/dist/addressLookup/hooks/useAddressForm.js +36 -0
  21. package/dist/addressLookup/hooks/useAddressForm.js.map +1 -0
  22. package/dist/addressLookup/hooks/useAddressMapModal.js +136 -0
  23. package/dist/addressLookup/hooks/useAddressMapModal.js.map +1 -0
  24. package/dist/addressLookup/hooks/useAddressValidationBase.js +143 -0
  25. package/dist/addressLookup/hooks/useAddressValidationBase.js.map +1 -0
  26. package/dist/addressLookup/hooks/useInitialAddressVerification.js +57 -0
  27. package/dist/addressLookup/hooks/useInitialAddressVerification.js.map +1 -0
  28. package/dist/addressLookup/hooks/useIntlAddressValidation.js +122 -0
  29. package/dist/addressLookup/hooks/useIntlAddressValidation.js.map +1 -0
  30. package/dist/addressLookup/hooks/useSmartyInternationalLookup.js +74 -0
  31. package/dist/addressLookup/hooks/useSmartyInternationalLookup.js.map +1 -0
  32. package/dist/addressLookup/hooks/useSmartyLookupBase.js +152 -0
  33. package/dist/addressLookup/hooks/useSmartyLookupBase.js.map +1 -0
  34. package/dist/addressLookup/hooks/useSmartyUSLookup.js +79 -0
  35. package/dist/addressLookup/hooks/useSmartyUSLookup.js.map +1 -0
  36. package/dist/addressLookup/hooks/useUSAddressValidation.js +166 -0
  37. package/dist/addressLookup/hooks/useUSAddressValidation.js.map +1 -0
  38. package/dist/addressLookup/index.js +41 -0
  39. package/dist/addressLookup/index.js.map +1 -0
  40. package/dist/addressLookup/styles/addressLookup.css +383 -0
  41. package/dist/addressLookup/utils/addressForm.js +150 -0
  42. package/dist/addressLookup/utils/addressForm.js.map +1 -0
  43. package/dist/addressLookup/utils/addressMapping.js +190 -0
  44. package/dist/addressLookup/utils/addressMapping.js.map +1 -0
  45. package/dist/addressLookup/utils/addressStatus.js +173 -0
  46. package/dist/addressLookup/utils/addressStatus.js.map +1 -0
  47. package/dist/addressLookup/utils/addressStrings.js +159 -0
  48. package/dist/addressLookup/utils/addressStrings.js.map +1 -0
  49. package/dist/addressLookup/utils/addressVerification.js +66 -0
  50. package/dist/addressLookup/utils/addressVerification.js.map +1 -0
  51. package/dist/addressLookup/utils/addressWrapper.js +40 -0
  52. package/dist/addressLookup/utils/addressWrapper.js.map +1 -0
  53. package/dist/addressLookup/utils/componentPropTypes.js +118 -0
  54. package/dist/addressLookup/utils/componentPropTypes.js.map +1 -0
  55. package/dist/addressLookup/utils/googleMapsLoader.js +68 -0
  56. package/dist/addressLookup/utils/googleMapsLoader.js.map +1 -0
  57. package/dist/addressLookup/utils/inFlightRequests.js +50 -0
  58. package/dist/addressLookup/utils/inFlightRequests.js.map +1 -0
  59. package/dist/addressLookup/utils/intlAutocompleteBusinessRules.js +62 -0
  60. package/dist/addressLookup/utils/intlAutocompleteBusinessRules.js.map +1 -0
  61. package/dist/addressLookup/utils/requestCache.js +44 -0
  62. package/dist/addressLookup/utils/requestCache.js.map +1 -0
  63. package/dist/addressLookup/utils/requestRateLimiter.js +53 -0
  64. package/dist/addressLookup/utils/requestRateLimiter.js.map +1 -0
  65. package/dist/addressLookup/utils/smartyConfig.js +11 -0
  66. package/dist/addressLookup/utils/smartyConfig.js.map +1 -0
  67. package/dist/addressLookup/utils/validators.js +45 -0
  68. package/dist/addressLookup/utils/validators.js.map +1 -0
  69. package/dist/index.js +28 -1
  70. package/dist/index.js.map +1 -1
  71. package/dist/{ShippingAddressForm.js → shippingAddressForm/ShippingAddressForm.js} +10 -2
  72. package/dist/shippingAddressForm/ShippingAddressForm.js.map +1 -0
  73. package/dist/{components → shippingAddressForm/components}/ShippingField.js +32 -22
  74. package/dist/shippingAddressForm/components/ShippingField.js.map +1 -0
  75. package/dist/shippingAddressForm/hooks/useAddressFieldLabels.js.map +1 -0
  76. package/dist/shippingAddressForm/hooks/useShippingAddressForm.js.map +1 -0
  77. package/dist/shippingAddressForm/hooks/useShippingFormState.js.map +1 -0
  78. package/dist/shippingAddressForm/utils/emailVerify.js.map +1 -0
  79. package/dist/{utils → shippingAddressForm/utils}/shippingAddressForm.js +3 -3
  80. package/dist/shippingAddressForm/utils/shippingAddressForm.js.map +1 -0
  81. package/dist/shippingAddressForm/utils/shippingStrings.js.map +1 -0
  82. package/package.json +2 -3
  83. package/dist/ShippingAddressForm.js.map +0 -1
  84. package/dist/components/ShippingField.js.map +0 -1
  85. package/dist/hooks/useAddressFieldLabels.js.map +0 -1
  86. package/dist/hooks/useShippingAddressForm.js.map +0 -1
  87. package/dist/hooks/useShippingFormState.js.map +0 -1
  88. package/dist/utils/emailVerify.js.map +0 -1
  89. package/dist/utils/shippingAddressForm.js.map +0 -1
  90. package/dist/utils/shippingStrings.js.map +0 -1
  91. /package/dist/{hooks → shippingAddressForm/hooks}/useAddressFieldLabels.js +0 -0
  92. /package/dist/{hooks → shippingAddressForm/hooks}/useShippingAddressForm.js +0 -0
  93. /package/dist/{hooks → shippingAddressForm/hooks}/useShippingFormState.js +0 -0
  94. /package/dist/{styles → shippingAddressForm/styles}/shippingAddressForm.css +0 -0
  95. /package/dist/{utils → shippingAddressForm/utils}/emailVerify.js +0 -0
  96. /package/dist/{utils → shippingAddressForm/utils}/shippingStrings.js +0 -0
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.preserveBlankConfiguredMappings = exports.buildUSVerifiedAddressMapping = exports.buildUSFormattedAddress = exports.buildIntlVerifiedAddressMapping = exports.buildIntlFormattedAddress = exports.buildIntlConfiguredVerificationMapping = exports.buildIntlAutocompleteAddressMapping = void 0;
7
+ var _validators = require("./validators");
8
+ const joinAddressParts = (parts = []) => parts.filter(Boolean).join(' ').replace(/\s+/g, ' ').trim();
9
+ const MANAGED_ADDRESS_FIELDS = new Set(['address1', 'address2', 'city', 'district', 'region', 'postalCode']);
10
+ const getMappedFieldValue = (source, context) => {
11
+ if (!source) {
12
+ return '';
13
+ }
14
+ return String(source.split('.').reduce((value, key) => value && value[key] !== undefined ? value[key] : undefined, context) || '').trim();
15
+ };
16
+ const hasConfiguredMappings = (mappingType, addressElements = []) => addressElements.some(element => {
17
+ var _element$apiMappings;
18
+ return (_element$apiMappings = element.apiMappings) === null || _element$apiMappings === void 0 ? void 0 : _element$apiMappings[mappingType];
19
+ });
20
+ const buildMappedFieldsFromConfig = (mappingType, context, addressElements = []) => {
21
+ const mapped = {};
22
+ addressElements.forEach(element => {
23
+ var _element$apiMappings2;
24
+ if (!(element !== null && element !== void 0 && element.field) || !MANAGED_ADDRESS_FIELDS.has(element.field)) {
25
+ return;
26
+ }
27
+ const value = getMappedFieldValue((_element$apiMappings2 = element.apiMappings) === null || _element$apiMappings2 === void 0 ? void 0 : _element$apiMappings2[mappingType], context);
28
+ mapped[element.field] = element.field === 'postalCode' ? (0, _validators.normalizePostalCodeValue)(value) : value;
29
+ });
30
+ return mapped;
31
+ };
32
+ const STRUCTURED_LOCATION_TOKENS = new Set(['locality', 'dependent_locality', 'double_dependent_locality', 'administrative_area', 'sub_administrative_area', 'postal_code', 'sorting_code', 'country']);
33
+ const stripEdgeCommasAndSpaces = (value = '') => {
34
+ let start = 0;
35
+ let end = value.length;
36
+ while (start < end && [',', ' '].includes(value[start])) {
37
+ start += 1;
38
+ }
39
+ while (end > start && [',', ' '].includes(value[end - 1])) {
40
+ end -= 1;
41
+ }
42
+ return value.slice(start, end);
43
+ };
44
+ const normalizeFormattedLine = (value = '') => stripEdgeCommasAndSpaces(String(value).split(',').map(part => part.trim()).filter(Boolean).join(', ').split(/\s+/).filter(Boolean).join(' '));
45
+ const buildFormattedAddressLines = (addressFormat = '', components = {}) => String(addressFormat).split('|').map(line => normalizeFormattedLine(line.replace(/\b[a-z_]+\b/g, token => components[token] || ''))).filter(Boolean);
46
+ const getAddressFormatTokens = (addressFormatLine = '') => String(addressFormatLine).match(/[a-z_]+/g) || [];
47
+ const isStructuredOnlyAddressFormatLine = (addressFormatLine = '') => {
48
+ const tokens = getAddressFormatTokens(addressFormatLine);
49
+ return tokens.length > 0 && tokens.every(token => STRUCTURED_LOCATION_TOKENS.has(token));
50
+ };
51
+ const buildUSFormattedAddress = (validatedAddress = {}) => {
52
+ const components = validatedAddress.components || {};
53
+ const streetLine = joinAddressParts([components.primary_number, components.street_predirection, components.street_name, components.street_suffix, components.street_postdirection]);
54
+ const secondaryLine = [joinAddressParts([components.secondary_designator, components.secondary_number]), joinAddressParts([components.extra_secondary_designator, components.extra_secondary_number]), joinAddressParts([components.pmb_designator, components.pmb_number])].filter(Boolean).join(', ').trim();
55
+ return {
56
+ formatted: {
57
+ address1: streetLine || validatedAddress.delivery_line_1 || '',
58
+ address2: secondaryLine || validatedAddress.delivery_line_2 || ''
59
+ }
60
+ };
61
+ };
62
+ exports.buildUSFormattedAddress = buildUSFormattedAddress;
63
+ const buildIntlFormattedAddress = (validatedAddress = {}) => {
64
+ var _validatedAddress$met, _validatedAddress$met2;
65
+ const components = validatedAddress.components || {};
66
+ const addressFormat = ((_validatedAddress$met = validatedAddress.metadata) === null || _validatedAddress$met === void 0 ? void 0 : _validatedAddress$met.address_format) || ((_validatedAddress$met2 = validatedAddress.meta) === null || _validatedAddress$met2 === void 0 ? void 0 : _validatedAddress$met2.address_format) || '';
67
+ const addressFormatLines = String(addressFormat).split('|');
68
+ const formattedAddressLines = buildFormattedAddressLines(addressFormat, components);
69
+ const responseAddressLines = [validatedAddress.address1, validatedAddress.address2, validatedAddress.address3].filter(Boolean);
70
+ const fallbackAddress1 = joinAddressParts([components.thoroughfare, components.premise]);
71
+ const leadingStreetLineIndexes = addressFormatLines.reduce((indexes, line, index) => {
72
+ if (indexes.stopped) {
73
+ return indexes;
74
+ }
75
+ if (isStructuredOnlyAddressFormatLine(line)) {
76
+ indexes.stopped = true;
77
+ return indexes;
78
+ }
79
+ if (formattedAddressLines[index]) {
80
+ indexes.values.push(index);
81
+ }
82
+ return indexes;
83
+ }, {
84
+ values: [],
85
+ stopped: false
86
+ }).values;
87
+ const address1 = formattedAddressLines[leadingStreetLineIndexes[0]] || fallbackAddress1 || '';
88
+ const address2 = leadingStreetLineIndexes.length > 1 ? formattedAddressLines[leadingStreetLineIndexes[1]] || '' : '';
89
+ return {
90
+ formatted: {
91
+ address1,
92
+ address2
93
+ },
94
+ responseAddressLines,
95
+ formattedAddressLines
96
+ };
97
+ };
98
+ exports.buildIntlFormattedAddress = buildIntlFormattedAddress;
99
+ const buildIntlVerifiedAddressMapping = (validatedAddress = {}) => {
100
+ const components = validatedAddress.components || {};
101
+ const {
102
+ formatted,
103
+ responseAddressLines,
104
+ formattedAddressLines
105
+ } = buildIntlFormattedAddress(validatedAddress);
106
+ return {
107
+ formatted,
108
+ mapped: {
109
+ address1: formatted.address1,
110
+ address2: formatted.address2,
111
+ city: components.locality || '',
112
+ postalCode: (0, _validators.normalizePostalCodeValue)(components.postal_code || '')
113
+ },
114
+ mapAddressLines: responseAddressLines.length ? responseAddressLines : formattedAddressLines
115
+ };
116
+ };
117
+ exports.buildIntlVerifiedAddressMapping = buildIntlVerifiedAddressMapping;
118
+ const buildIntlAutocompleteAddressMapping = (selectedAddress = {}, addressForm = null) => {
119
+ const addressElements = (addressForm === null || addressForm === void 0 ? void 0 : addressForm.addressElements) || [];
120
+ const fallbackMapped = {
121
+ address1: selectedAddress.street || '',
122
+ address2: '',
123
+ city: selectedAddress.locality || '',
124
+ region: selectedAddress.administrative_area || '',
125
+ postalCode: (0, _validators.normalizePostalCodeValue)(selectedAddress.postal_code || '')
126
+ };
127
+ if (!hasConfiguredMappings('autocomplete', addressElements)) {
128
+ return fallbackMapped;
129
+ }
130
+ return buildMappedFieldsFromConfig('autocomplete', selectedAddress, addressElements);
131
+ };
132
+ exports.buildIntlAutocompleteAddressMapping = buildIntlAutocompleteAddressMapping;
133
+ const buildIntlConfiguredVerificationMapping = (validatedAddress = {}, addressForm = null) => {
134
+ const fallback = buildIntlVerifiedAddressMapping(validatedAddress);
135
+ const addressElements = (addressForm === null || addressForm === void 0 ? void 0 : addressForm.addressElements) || [];
136
+ if (!hasConfiguredMappings('verification', addressElements)) {
137
+ return fallback;
138
+ }
139
+ const mappingContext = {
140
+ ...validatedAddress,
141
+ formatted: fallback.formatted
142
+ };
143
+ return {
144
+ ...fallback,
145
+ mapped: buildMappedFieldsFromConfig('verification', mappingContext, addressElements)
146
+ };
147
+ };
148
+ exports.buildIntlConfiguredVerificationMapping = buildIntlConfiguredVerificationMapping;
149
+ const preserveBlankConfiguredMappings = (mapped = {}, currentValues = {}, addressElements = [], mappingType) => {
150
+ const nextMapped = {
151
+ ...mapped
152
+ };
153
+ addressElements.forEach(element => {
154
+ var _element$apiMappings3;
155
+ if (!(element !== null && element !== void 0 && element.field) || !MANAGED_ADDRESS_FIELDS.has(element.field)) {
156
+ return;
157
+ }
158
+ if (!((_element$apiMappings3 = element.apiMappings) !== null && _element$apiMappings3 !== void 0 && _element$apiMappings3[mappingType])) {
159
+ return;
160
+ }
161
+ if (nextMapped[element.field] !== '') {
162
+ return;
163
+ }
164
+ nextMapped[element.field] = currentValues[element.field] || '';
165
+ });
166
+ return nextMapped;
167
+ };
168
+ exports.preserveBlankConfiguredMappings = preserveBlankConfiguredMappings;
169
+ const buildUSVerifiedAddressMapping = (validatedAddress = {}) => {
170
+ const components = validatedAddress.components || {};
171
+ const {
172
+ formatted
173
+ } = buildUSFormattedAddress(validatedAddress);
174
+ const city = components.city_name || '';
175
+ const region = components.state_abbreviation || '';
176
+ const postalCode = (0, _validators.normalizePostalCodeValue)(components.zipcode || '');
177
+ return {
178
+ formatted,
179
+ mapped: {
180
+ address1: formatted.address1,
181
+ address2: formatted.address2,
182
+ city,
183
+ region,
184
+ postalCode
185
+ },
186
+ mapAddressLines: [formatted.address1, formatted.address2, [city, region, postalCode].filter(Boolean).join(' ')].filter(Boolean)
187
+ };
188
+ };
189
+ exports.buildUSVerifiedAddressMapping = buildUSVerifiedAddressMapping;
190
+ //# sourceMappingURL=addressMapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressMapping.js","names":["_validators","require","joinAddressParts","parts","filter","Boolean","join","replace","trim","MANAGED_ADDRESS_FIELDS","Set","getMappedFieldValue","source","context","String","split","reduce","value","key","undefined","hasConfiguredMappings","mappingType","addressElements","some","element","_element$apiMappings","apiMappings","buildMappedFieldsFromConfig","mapped","forEach","_element$apiMappings2","field","has","normalizePostalCodeValue","STRUCTURED_LOCATION_TOKENS","stripEdgeCommasAndSpaces","start","end","length","includes","slice","normalizeFormattedLine","map","part","buildFormattedAddressLines","addressFormat","components","line","token","getAddressFormatTokens","addressFormatLine","match","isStructuredOnlyAddressFormatLine","tokens","every","buildUSFormattedAddress","validatedAddress","streetLine","primary_number","street_predirection","street_name","street_suffix","street_postdirection","secondaryLine","secondary_designator","secondary_number","extra_secondary_designator","extra_secondary_number","pmb_designator","pmb_number","formatted","address1","delivery_line_1","address2","delivery_line_2","exports","buildIntlFormattedAddress","_validatedAddress$met","_validatedAddress$met2","metadata","address_format","meta","addressFormatLines","formattedAddressLines","responseAddressLines","address3","fallbackAddress1","thoroughfare","premise","leadingStreetLineIndexes","indexes","index","stopped","values","push","buildIntlVerifiedAddressMapping","city","locality","postalCode","postal_code","mapAddressLines","buildIntlAutocompleteAddressMapping","selectedAddress","addressForm","fallbackMapped","street","region","administrative_area","buildIntlConfiguredVerificationMapping","fallback","mappingContext","preserveBlankConfiguredMappings","currentValues","nextMapped","_element$apiMappings3","buildUSVerifiedAddressMapping","city_name","state_abbreviation","zipcode"],"sources":["../../../src/addressLookup/utils/addressMapping.js"],"sourcesContent":["import { normalizePostalCodeValue } from './validators';\n\nconst joinAddressParts = (parts = []) => (\n parts.filter(Boolean).join(' ').replace(/\\s+/g, ' ').trim()\n);\n\nconst MANAGED_ADDRESS_FIELDS = new Set([\n 'address1',\n 'address2',\n 'city',\n 'district',\n 'region',\n 'postalCode'\n]);\n\nconst getMappedFieldValue = (source, context) => {\n if (!source) {\n return '';\n }\n\n return String(\n source.split('.').reduce((value, key) => (\n value && value[key] !== undefined ? value[key] : undefined\n ), context) || ''\n ).trim();\n};\n\nconst hasConfiguredMappings = (mappingType, addressElements = []) => (\n addressElements.some((element) => element.apiMappings?.[mappingType])\n);\n\nconst buildMappedFieldsFromConfig = (mappingType, context, addressElements = []) => {\n const mapped = {};\n\n addressElements.forEach((element) => {\n if (!element?.field || !MANAGED_ADDRESS_FIELDS.has(element.field)) {\n return;\n }\n\n const value = getMappedFieldValue(element.apiMappings?.[mappingType], context);\n mapped[element.field] = element.field === 'postalCode' ? normalizePostalCodeValue(value) : value;\n });\n\n return mapped;\n};\n\nconst STRUCTURED_LOCATION_TOKENS = new Set([\n 'locality',\n 'dependent_locality',\n 'double_dependent_locality',\n 'administrative_area',\n 'sub_administrative_area',\n 'postal_code',\n 'sorting_code',\n 'country'\n]);\n\nconst stripEdgeCommasAndSpaces = (value = '') => {\n let start = 0;\n let end = value.length;\n\n while (start < end && [',', ' '].includes(value[start])) {\n start += 1;\n }\n\n while (end > start && [',', ' '].includes(value[end - 1])) {\n end -= 1;\n }\n\n return value.slice(start, end);\n};\n\nconst normalizeFormattedLine = (value = '') => (\n stripEdgeCommasAndSpaces(\n String(value)\n .split(',')\n .map((part) => part.trim())\n .filter(Boolean)\n .join(', ')\n .split(/\\s+/)\n .filter(Boolean)\n .join(' ')\n )\n);\n\nconst buildFormattedAddressLines = (addressFormat = '', components = {}) => (\n String(addressFormat)\n .split('|')\n .map((line) => normalizeFormattedLine(\n line.replace(/\\b[a-z_]+\\b/g, (token) => components[token] || '')\n ))\n .filter(Boolean)\n);\n\nconst getAddressFormatTokens = (addressFormatLine = '') => (\n String(addressFormatLine).match(/[a-z_]+/g) || []\n);\n\nconst isStructuredOnlyAddressFormatLine = (addressFormatLine = '') => {\n const tokens = getAddressFormatTokens(addressFormatLine);\n return tokens.length > 0 && tokens.every((token) => STRUCTURED_LOCATION_TOKENS.has(token));\n};\n\nexport const buildUSFormattedAddress = (validatedAddress = {}) => {\n const components = validatedAddress.components || {};\n\n const streetLine = joinAddressParts([\n components.primary_number,\n components.street_predirection,\n components.street_name,\n components.street_suffix,\n components.street_postdirection\n ]);\n\n const secondaryLine = [\n joinAddressParts([components.secondary_designator, components.secondary_number]),\n joinAddressParts([components.extra_secondary_designator, components.extra_secondary_number]),\n joinAddressParts([components.pmb_designator, components.pmb_number])\n ].filter(Boolean).join(', ').trim();\n\n return {\n formatted: {\n address1: streetLine || validatedAddress.delivery_line_1 || '',\n address2: secondaryLine || validatedAddress.delivery_line_2 || ''\n }\n };\n};\n\nexport const buildIntlFormattedAddress = (validatedAddress = {}) => {\n const components = validatedAddress.components || {};\n const addressFormat = validatedAddress.metadata?.address_format || validatedAddress.meta?.address_format || '';\n const addressFormatLines = String(addressFormat).split('|');\n const formattedAddressLines = buildFormattedAddressLines(addressFormat, components);\n const responseAddressLines = [\n validatedAddress.address1,\n validatedAddress.address2,\n validatedAddress.address3\n ].filter(Boolean);\n\n const fallbackAddress1 = joinAddressParts([components.thoroughfare, components.premise]);\n const leadingStreetLineIndexes = addressFormatLines.reduce((indexes, line, index) => {\n if (indexes.stopped) {\n return indexes;\n }\n\n if (isStructuredOnlyAddressFormatLine(line)) {\n indexes.stopped = true;\n return indexes;\n }\n\n if (formattedAddressLines[index]) {\n indexes.values.push(index);\n }\n\n return indexes;\n }, { values: [], stopped: false }).values;\n\n const address1 = (\n formattedAddressLines[leadingStreetLineIndexes[0]] ||\n fallbackAddress1 ||\n ''\n );\n const address2 = leadingStreetLineIndexes.length > 1 ?\n (formattedAddressLines[leadingStreetLineIndexes[1]] || '') :\n '';\n\n return {\n formatted: {\n address1,\n address2\n },\n responseAddressLines,\n formattedAddressLines\n };\n};\n\nexport const buildIntlVerifiedAddressMapping = (validatedAddress = {}) => {\n const components = validatedAddress.components || {};\n const {\n formatted,\n responseAddressLines,\n formattedAddressLines\n } = buildIntlFormattedAddress(validatedAddress);\n\n return {\n formatted,\n mapped: {\n address1: formatted.address1,\n address2: formatted.address2,\n city: components.locality || '',\n postalCode: normalizePostalCodeValue(components.postal_code || '')\n },\n mapAddressLines: responseAddressLines.length ? responseAddressLines : formattedAddressLines\n };\n};\n\nexport const buildIntlAutocompleteAddressMapping = (\n selectedAddress = {},\n addressForm = null\n) => {\n const addressElements = addressForm?.addressElements || [];\n const fallbackMapped = {\n address1: selectedAddress.street || '',\n address2: '',\n city: selectedAddress.locality || '',\n region: selectedAddress.administrative_area || '',\n postalCode: normalizePostalCodeValue(selectedAddress.postal_code || '')\n };\n\n if (!hasConfiguredMappings('autocomplete', addressElements)) {\n return fallbackMapped;\n }\n\n return buildMappedFieldsFromConfig('autocomplete', selectedAddress, addressElements);\n};\n\nexport const buildIntlConfiguredVerificationMapping = (\n validatedAddress = {},\n addressForm = null\n) => {\n const fallback = buildIntlVerifiedAddressMapping(validatedAddress);\n const addressElements = addressForm?.addressElements || [];\n\n if (!hasConfiguredMappings('verification', addressElements)) {\n return fallback;\n }\n\n const mappingContext = {\n ...validatedAddress,\n formatted: fallback.formatted\n };\n\n return {\n ...fallback,\n mapped: buildMappedFieldsFromConfig('verification', mappingContext, addressElements)\n };\n};\n\nexport const preserveBlankConfiguredMappings = (mapped = {}, currentValues = {}, addressElements = [], mappingType) => {\n const nextMapped = { ...mapped };\n\n addressElements.forEach((element) => {\n if (!element?.field || !MANAGED_ADDRESS_FIELDS.has(element.field)) {\n return;\n }\n\n if (!element.apiMappings?.[mappingType]) {\n return;\n }\n\n if (nextMapped[element.field] !== '') {\n return;\n }\n\n nextMapped[element.field] = currentValues[element.field] || '';\n });\n\n return nextMapped;\n};\n\nexport const buildUSVerifiedAddressMapping = (validatedAddress = {}) => {\n const components = validatedAddress.components || {};\n const { formatted } = buildUSFormattedAddress(validatedAddress);\n const city = components.city_name || '';\n const region = components.state_abbreviation || '';\n const postalCode = normalizePostalCodeValue(components.zipcode || '');\n\n return {\n formatted,\n mapped: {\n address1: formatted.address1,\n address2: formatted.address2,\n city,\n region,\n postalCode\n },\n mapAddressLines: [\n formatted.address1,\n formatted.address2,\n [city, region, postalCode].filter(Boolean).join(' ')\n ].filter(Boolean)\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,MAAMC,gBAAgB,GAAGA,CAACC,KAAK,GAAG,EAAE,KAClCA,KAAK,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAACC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAACC,IAAI,CAAC,CAC3D;AAED,MAAMC,sBAAsB,GAAG,IAAIC,GAAG,CAAC,CACrC,UAAU,EACV,UAAU,EACV,MAAM,EACN,UAAU,EACV,QAAQ,EACR,YAAY,CACb,CAAC;AAEF,MAAMC,mBAAmB,GAAGA,CAACC,MAAM,EAAEC,OAAO,KAAK;EAC/C,IAAI,CAACD,MAAM,EAAE;IACX,OAAO,EAAE;EACX;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AAU,CAACsE,SAAS,IAAI,EAAE;EACvC,MAAMV,MAAM,GAAG5D,UAAU,CAACuE,kBAAkB,IAAI,EAAE;EAClD,MAAMnB,UAAU,GAAG,IAAAjE,oCAAwB,EAACa,UAAU,CAACwE,OAAO,IAAI,EAAE,CAAC;EAErE,OAAO;IACLhD,SAAS;IACT1C,MAAM,EAAE;MACN2C,QAAQ,EAAED,SAAS,CAACC,QAAQ;MAC5BE,QAAQ,EAAEH,SAAS,CAACG,QAAQ;MAC5BuB,IAAI;MACJU,MAAM;MACNR;IACF,CAAC;IACDE,eAAe,EAAE,CACf9B,SAAS,CAACC,QAAQ,EAClBD,SAAS,CAACG,QAAQ,EAClB,CAACuB,IAAI,EAAEU,MAAM,EAAER,UAAU,CAAC,CAAC9F,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CACrD,CAACF,MAAM,CAACC,OAAO;EAClB,CAAC;AACH,CAAC;AAACsE,OAAA,CAAAwC,6BAAA,GAAAA,6BAAA","ignoreList":[]}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shouldVerifyAutocompleteSelection = exports.getRequiredFieldsFromAddressForm = exports.getMissingRequiredFields = exports.buildAddressStatus = void 0;
7
+ var _validators = require("./validators");
8
+ const DEFAULT_RESOLVED_ADDRESS_FORM = {
9
+ addressElements: [],
10
+ lookupField: 'address1',
11
+ requiredFields: [],
12
+ postalCodeRegex: null,
13
+ verifyAfterAutocomplete: false,
14
+ wrapAddress1ToAddress2: false
15
+ };
16
+ const OPTIONAL_FIELDS = new Set(['address2', 'email']);
17
+ const isBlank = value => {
18
+ if (value === null || value === undefined) {
19
+ return true;
20
+ }
21
+ return String(value).trim() === '';
22
+ };
23
+ const resolveAddressForm = (addressForm = null) => {
24
+ if (addressForm && Array.isArray(addressForm.addressElements)) {
25
+ return {
26
+ ...DEFAULT_RESOLVED_ADDRESS_FORM,
27
+ ...addressForm
28
+ };
29
+ }
30
+ return DEFAULT_RESOLVED_ADDRESS_FORM;
31
+ };
32
+ const getRequiredFieldsFromAddressForm = (addressForm = null) => {
33
+ var _resolvedAddressForm$;
34
+ const resolvedAddressForm = resolveAddressForm(addressForm);
35
+ const configRequired = resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.requiredFields;
36
+ const formFields = (resolvedAddressForm === null || resolvedAddressForm === void 0 || (_resolvedAddressForm$ = resolvedAddressForm.addressElements) === null || _resolvedAddressForm$ === void 0 ? void 0 : _resolvedAddressForm$.map(field => field.field)) || [];
37
+ const formFieldSet = new Set(formFields);
38
+ const normalizeRequired = fields => {
39
+ const seen = new Set();
40
+ return fields.filter(field => {
41
+ if (!formFieldSet.has(field) || seen.has(field)) {
42
+ return false;
43
+ }
44
+ seen.add(field);
45
+ return true;
46
+ });
47
+ };
48
+ if (Array.isArray(configRequired) && configRequired.length > 0) {
49
+ return normalizeRequired(configRequired);
50
+ }
51
+ return normalizeRequired(formFields.filter(field => !OPTIONAL_FIELDS.has(field)));
52
+ };
53
+ exports.getRequiredFieldsFromAddressForm = getRequiredFieldsFromAddressForm;
54
+ const getMissingRequiredFields = (addressForm = null, formData = {}) => {
55
+ const requiredFields = getRequiredFieldsFromAddressForm(addressForm);
56
+ return requiredFields.filter(field => isBlank(formData === null || formData === void 0 ? void 0 : formData[field]));
57
+ };
58
+ exports.getMissingRequiredFields = getMissingRequiredFields;
59
+ const shouldVerifyAutocompleteSelection = ({
60
+ addressForm = null,
61
+ formData = {},
62
+ requireValidation = true
63
+ }) => {
64
+ if (!requireValidation) {
65
+ return false;
66
+ }
67
+ const resolvedAddressForm = resolveAddressForm(addressForm);
68
+ if (resolvedAddressForm.verifyAfterAutocomplete) {
69
+ return true;
70
+ }
71
+ return getMissingRequiredFields(resolvedAddressForm, formData).length > 0;
72
+ };
73
+ exports.shouldVerifyAutocompleteSelection = shouldVerifyAutocompleteSelection;
74
+ const getPostalCodeStatus = (formData, requiredFields, addressForm = null) => {
75
+ const resolvedAddressForm = resolveAddressForm(addressForm);
76
+ const hasPostalField = ((resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements) || []).some(field => field.field === 'postalCode');
77
+ if (!hasPostalField) {
78
+ return {
79
+ applicable: false,
80
+ required: false,
81
+ value: '',
82
+ isValid: null
83
+ };
84
+ }
85
+ const postalCode = (formData === null || formData === void 0 ? void 0 : formData.postalCode) || '';
86
+ const value = (0, _validators.normalizePostalCodeValue)(postalCode);
87
+ const required = requiredFields.includes('postalCode');
88
+ const regex = resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.postalCodeRegex;
89
+ if (value === '') {
90
+ return {
91
+ applicable: true,
92
+ required,
93
+ value,
94
+ isValid: required ? false : null
95
+ };
96
+ }
97
+ if (!regex) {
98
+ return {
99
+ applicable: true,
100
+ required,
101
+ value,
102
+ isValid: null
103
+ };
104
+ }
105
+ return {
106
+ applicable: true,
107
+ required,
108
+ value,
109
+ isValid: regex.test(value)
110
+ };
111
+ };
112
+ const getEmailStatus = (formData, requiredFields, addressForm = null) => {
113
+ const resolvedAddressForm = resolveAddressForm(addressForm);
114
+ const hasEmailField = ((resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements) || []).some(field => field.field === 'email');
115
+ if (!hasEmailField) {
116
+ return null;
117
+ }
118
+ const value = String((formData === null || formData === void 0 ? void 0 : formData.email) || '').trim();
119
+ const required = requiredFields.includes('email');
120
+ if (value === '') {
121
+ return {
122
+ applicable: true,
123
+ required,
124
+ value,
125
+ isValid: required ? false : null
126
+ };
127
+ }
128
+ return {
129
+ applicable: true,
130
+ required,
131
+ value,
132
+ isValid: (0, _validators.isValidEmail)(value)
133
+ };
134
+ };
135
+ const buildAddressStatus = ({
136
+ addressForm = null,
137
+ formData,
138
+ verificationStatus,
139
+ mode,
140
+ requireValidation = true
141
+ }) => {
142
+ var _formData$verificatio;
143
+ const resolvedAddressForm = resolveAddressForm(addressForm);
144
+ const formAvailable = resolvedAddressForm.addressElements.length > 0;
145
+ const requiredFields = getRequiredFieldsFromAddressForm(resolvedAddressForm);
146
+ const missingFields = getMissingRequiredFields(resolvedAddressForm, formData);
147
+ const postalCode = getPostalCodeStatus(formData, requiredFields, resolvedAddressForm);
148
+ const email = getEmailStatus(formData, requiredFields, resolvedAddressForm);
149
+ const hasInvalidPostalCode = postalCode.applicable && postalCode.value !== '' && postalCode.isValid === false;
150
+ const hasInvalidEmail = (email === null || email === void 0 ? void 0 : email.applicable) && email.value !== '' && email.isValid === false;
151
+ const isComplete = formAvailable && missingFields.length === 0 && !hasInvalidPostalCode && !hasInvalidEmail;
152
+ const completeness = isComplete ? 'complete' : 'incomplete';
153
+ return {
154
+ formAvailable,
155
+ verification: verificationStatus,
156
+ ...(formData !== null && formData !== void 0 && (_formData$verificatio = formData.verification) !== null && _formData$verificatio !== void 0 && _formData$verificatio.manuallyEdited ? {
157
+ manualChanges: {
158
+ manuallyEdited: true,
159
+ editedFields: formData.verification.editedFields || []
160
+ }
161
+ } : {}),
162
+ needsValidation: Boolean(requireValidation && mode === 'manual' && verificationStatus !== 'verified'),
163
+ completeness,
164
+ missingFields,
165
+ mode,
166
+ postalCode,
167
+ ...(email ? {
168
+ email
169
+ } : {})
170
+ };
171
+ };
172
+ exports.buildAddressStatus = buildAddressStatus;
173
+ //# sourceMappingURL=addressStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressStatus.js","names":["_validators","require","DEFAULT_RESOLVED_ADDRESS_FORM","addressElements","lookupField","requiredFields","postalCodeRegex","verifyAfterAutocomplete","wrapAddress1ToAddress2","OPTIONAL_FIELDS","Set","isBlank","value","undefined","String","trim","resolveAddressForm","addressForm","Array","isArray","getRequiredFieldsFromAddressForm","_resolvedAddressForm$","resolvedAddressForm","configRequired","formFields","map","field","formFieldSet","normalizeRequired","fields","seen","filter","has","add","length","exports","getMissingRequiredFields","formData","shouldVerifyAutocompleteSelection","requireValidation","getPostalCodeStatus","hasPostalField","some","applicable","required","isValid","postalCode","normalizePostalCodeValue","includes","regex","test","getEmailStatus","hasEmailField","email","isValidEmail","buildAddressStatus","verificationStatus","mode","_formData$verificatio","formAvailable","missingFields","hasInvalidPostalCode","hasInvalidEmail","isComplete","completeness","verification","manuallyEdited","manualChanges","editedFields","needsValidation","Boolean"],"sources":["../../../src/addressLookup/utils/addressStatus.js"],"sourcesContent":["import { isValidEmail, normalizePostalCodeValue } from './validators';\n\nconst DEFAULT_RESOLVED_ADDRESS_FORM = {\n addressElements: [],\n lookupField: 'address1',\n requiredFields: [],\n postalCodeRegex: null,\n verifyAfterAutocomplete: false,\n wrapAddress1ToAddress2: false\n};\n\nconst OPTIONAL_FIELDS = new Set(['address2', 'email']);\n\nconst isBlank = (value) => {\n if (value === null || value === undefined) {\n return true;\n }\n\n return String(value).trim() === '';\n};\n\nconst resolveAddressForm = (addressForm = null) => {\n if (addressForm && Array.isArray(addressForm.addressElements)) {\n return {\n ...DEFAULT_RESOLVED_ADDRESS_FORM,\n ...addressForm\n };\n }\n\n return DEFAULT_RESOLVED_ADDRESS_FORM;\n};\n\nexport const getRequiredFieldsFromAddressForm = (addressForm = null) => {\n const resolvedAddressForm = resolveAddressForm(addressForm);\n const configRequired = resolvedAddressForm?.requiredFields;\n const formFields = resolvedAddressForm?.addressElements?.map((field) => field.field) || [];\n const formFieldSet = new Set(formFields);\n const normalizeRequired = (fields) => {\n const seen = new Set();\n return fields.filter((field) => {\n if (!formFieldSet.has(field) || seen.has(field)) {\n return false;\n }\n seen.add(field);\n return true;\n });\n };\n\n if (Array.isArray(configRequired) && configRequired.length > 0) {\n return normalizeRequired(configRequired);\n }\n\n return normalizeRequired(formFields.filter((field) => !OPTIONAL_FIELDS.has(field)));\n};\n\nexport const getMissingRequiredFields = (addressForm = null, formData = {}) => {\n const requiredFields = getRequiredFieldsFromAddressForm(addressForm);\n return requiredFields.filter((field) => isBlank(formData?.[field]));\n};\n\nexport const shouldVerifyAutocompleteSelection = ({\n addressForm = null,\n formData = {},\n requireValidation = true\n}) => {\n if (!requireValidation) {\n return false;\n }\n\n const resolvedAddressForm = resolveAddressForm(addressForm);\n\n if (resolvedAddressForm.verifyAfterAutocomplete) {\n return true;\n }\n\n return getMissingRequiredFields(resolvedAddressForm, formData).length > 0;\n};\n\nconst getPostalCodeStatus = (formData, requiredFields, addressForm = null) => {\n const resolvedAddressForm = resolveAddressForm(addressForm);\n const hasPostalField = (resolvedAddressForm?.addressElements || []).some((field) => field.field === 'postalCode');\n\n if (!hasPostalField) {\n return {\n applicable: false,\n required: false,\n value: '',\n isValid: null\n };\n }\n\n const postalCode = formData?.postalCode || '';\n const value = normalizePostalCodeValue(postalCode);\n const required = requiredFields.includes('postalCode');\n const regex = resolvedAddressForm?.postalCodeRegex;\n\n if (value === '') {\n return {\n applicable: true,\n required,\n value,\n isValid: required ? false : null\n };\n }\n\n if (!regex) {\n return {\n applicable: true,\n required,\n value,\n isValid: null\n };\n }\n\n return {\n applicable: true,\n required,\n value,\n isValid: regex.test(value)\n };\n};\n\nconst getEmailStatus = (formData, requiredFields, addressForm = null) => {\n const resolvedAddressForm = resolveAddressForm(addressForm);\n const hasEmailField = (resolvedAddressForm?.addressElements || []).some((field) => field.field === 'email');\n\n if (!hasEmailField) {\n return null;\n }\n\n const value = String(formData?.email || '').trim();\n const required = requiredFields.includes('email');\n\n if (value === '') {\n return {\n applicable: true,\n required,\n value,\n isValid: required ? false : null\n };\n }\n\n return {\n applicable: true,\n required,\n value,\n isValid: isValidEmail(value)\n };\n};\n\nexport const buildAddressStatus = ({\n addressForm = null,\n formData,\n verificationStatus,\n mode,\n requireValidation = true\n}) => {\n const resolvedAddressForm = resolveAddressForm(addressForm);\n const formAvailable = resolvedAddressForm.addressElements.length > 0;\n const requiredFields = getRequiredFieldsFromAddressForm(resolvedAddressForm);\n const missingFields = getMissingRequiredFields(resolvedAddressForm, formData);\n const postalCode = getPostalCodeStatus(formData, requiredFields, resolvedAddressForm);\n const email = getEmailStatus(formData, requiredFields, resolvedAddressForm);\n\n const hasInvalidPostalCode = postalCode.applicable && postalCode.value !== '' && postalCode.isValid === false;\n const hasInvalidEmail = email?.applicable && email.value !== '' && email.isValid === false;\n const isComplete = formAvailable &&\n missingFields.length === 0 &&\n !hasInvalidPostalCode &&\n !hasInvalidEmail;\n const completeness = isComplete ? 'complete' : 'incomplete';\n\n return {\n formAvailable,\n verification: verificationStatus,\n ...(formData?.verification?.manuallyEdited ? {\n manualChanges: {\n manuallyEdited: true,\n editedFields: formData.verification.editedFields || []\n }\n } : {}),\n needsValidation: Boolean(requireValidation && mode === 'manual' && verificationStatus !== 'verified'),\n completeness,\n missingFields,\n mode,\n postalCode,\n ...(email ? { email } : {})\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,MAAMC,6BAA6B,GAAG;EACpCC,eAAe,EAAE,EAAE;EACnBC,WAAW,EAAE,UAAU;EACvBC,cAAc,EAAE,EAAE;EAClBC,eAAe,EAAE,IAAI;EACrBC,uBAAuB,EAAE,KAAK;EAC9BC,sBAAsB,EAAE;AAC1B,CAAC;AAED,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAEtD,MAAMC,OAAO,GAAIC,KAAK,IAAK;EACzB,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKC,SAAS,EAAE;IACzC,OAAO,IAAI;EACb;EAEA,OAAOC,MAAM,CAACF,KAAK,CAAC,CAACG,IAAI,CAAC,CAAC,KAAK,EAAE;AACpC,CAAC;AAED,MAAMC,kBAAkB,GAAGA,CAACC,WAAW,GAAG,IAAI,KAAK;EACjD,IAAIA,WAAW,IAAIC,KAAK,CAACC,OAAO,CAACF,WAAW,CAACd,eAAe,CAAC,EAAE;IAC7D,OAAO;MACL,GAAGD,6BAA6B;MAChC,GAAGe;IACL,CAAC;EACH;EAEA,O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,KAAK,EAAE,IAAIyC,KAAK,CAACR,OAAO,KAAK,KAAK;EAC1F,MAAMkB,UAAU,GAAGJ,aAAa,IAC9BC,aAAa,CAAC1B,MAAM,KAAK,CAAC,IAC1B,CAAC2B,oBAAoB,IACrB,CAACC,eAAe;EAClB,MAAME,YAAY,GAAGD,UAAU,GAAG,UAAU,GAAG,YAAY;EAE3D,OAAO;IACLJ,aAAa;IACbM,YAAY,EAAET,kBAAkB;IAChC,IAAInB,QAAQ,aAARA,QAAQ,gBAAAqB,qBAAA,GAARrB,QAAQ,CAAE4B,YAAY,cAAAP,qBAAA,eAAtBA,qBAAA,CAAwBQ,cAAc,GAAG;MAC3CC,aAAa,EAAE;QACbD,cAAc,EAAE,IAAI;QACpBE,YAAY,EAAE/B,QAAQ,CAAC4B,YAAY,CAACG,YAAY,IAAI;MACtD;IACF,CAAC,GAAG,CAAC,CAAC,CAAC;IACPC,eAAe,EAAEC,OAAO,CAAC/B,iBAAiB,IAAIkB,IAAI,KAAK,QAAQ,IAAID,kBAAkB,KAAK,UAAU,CAAC;IACrGQ,YAAY;IACZJ,aAAa;IACbH,IAAI;IACJX,UAAU;IACV,IAAIO,KAAK,GAAG;MAAEA;IAAM,CAAC,GAAG,CAAC,CAAC;EAC5B,CAAC;AACH,CAAC;AAAClB,OAAA,CAAAoB,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeAddressFieldLabels = exports.getAddressFieldLabels = exports.clearAddressFieldLabelCache = exports.DEFAULT_LABELS = void 0;
7
+ var _contentstackLib = require("@nuskin/contentstack-lib");
8
+ /* eslint-disable max-len */
9
+
10
+ const CONTENT_TYPE_UIDS = ['shipping_component'];
11
+ const DEFAULT_LABELS = exports.DEFAULT_LABELS = {
12
+ address1: 'Street Address',
13
+ address2: 'Apartment, suite, etc.',
14
+ city: 'City',
15
+ district: 'District',
16
+ region: 'Region',
17
+ postalCode: 'Postal Code',
18
+ invalidEmail: 'Invalid email address.',
19
+ fieldRequired: 'This field is required.',
20
+ illegalCharacters: 'Contains invalid characters.',
21
+ invalidPostalCode: 'Invalid postal code.',
22
+ rateLimited: 'Too many requests. Please wait a moment and try again.',
23
+ lookupError: 'We could not look up that address right now.',
24
+ validationError: 'We could not validate that address right now.',
25
+ loadingAddressForm: 'Loading address form...',
26
+ switchToAutocomplete: 'Switch to Autocomplete',
27
+ switchToManualEntry: 'Switch to Manual Entry',
28
+ addressLocation: 'Address location',
29
+ openInMaps: 'Open in Google Maps',
30
+ usVerified: 'Verified',
31
+ usVerifiedMessage: 'This address is fully verified.',
32
+ usMissingSecondaryTitle: 'Apartment or suite needed',
33
+ usMissingSecondaryMessage: 'The main address is valid, but a unit number is required.',
34
+ usInvalidSecondaryRequiredTitle: 'Apartment or suite not recognized',
35
+ usInvalidSecondaryRequiredMessage: 'The street address is valid, but the unit number was not recognized and is required.',
36
+ usInvalidSecondaryOptionalTitle: 'Unit not recognized',
37
+ usInvalidSecondaryOptionalMessage: 'The main address is valid, but the unit number was not recognized.',
38
+ usVacantTitle: 'Verified, but marked vacant',
39
+ usVacantMessage: 'This address is valid but marked as vacant.',
40
+ usNoStatTitle: 'Verified with caution',
41
+ usNoStatMessage: 'This address is valid, but USPS indicates limited delivery status.',
42
+ usNotConfirmedTitle: 'Not verified',
43
+ usNotConfirmedMessage: 'This address could not be confirmed.',
44
+ usNoResults: 'We couldn’t verify this address. Check the address and try again.',
45
+ intlVerifiedTitle: 'Verified',
46
+ intlVerifiedMessage: 'This address is verified.',
47
+ intlVerifiedSubBuildingChangedTitle: 'Verified with unit changes',
48
+ intlVerifiedSubBuildingChangedMessage: 'This address is verified, but the apartment or suite information was changed.',
49
+ intlPartialTitle: 'Partially verified',
50
+ intlPartialMessage: 'This address could only be partially verified.',
51
+ intlAmbiguousTitle: 'Multiple matches found',
52
+ intlAmbiguousMessage: 'Multiple possible matches were found for this address.',
53
+ intlNotVerifiedTitle: 'Not verified',
54
+ intlNotVerifiedMessage: 'This address could not be verified.',
55
+ intlNoResults: 'We couldn’t verify this address. Check the address and try again.'
56
+ };
57
+ const cache = {};
58
+ const mergeResultEntries = (results = []) => {
59
+ const entries = Array.isArray(results) ? results : [results];
60
+ return entries.reduce((acc, entry) => ({
61
+ ...acc,
62
+ ...(entry || {})
63
+ }), {});
64
+ };
65
+ const getUsValidationStrings = (source = {}) => source.smartyUsValidationStrings || {};
66
+ const getIntlValidationStrings = (source = {}) => source.smartyIntlValidationStrings || {};
67
+ const mapFieldLabels = (source = {}) => {
68
+ const usValidationStrings = getUsValidationStrings(source);
69
+ const intlValidationStrings = getIntlValidationStrings(source);
70
+ return {
71
+ address1: source.address1Label || DEFAULT_LABELS.address1,
72
+ address2: source.address2Label || DEFAULT_LABELS.address2,
73
+ city: source.cityLabel || DEFAULT_LABELS.city,
74
+ district: source.districtLabel || DEFAULT_LABELS.district,
75
+ region: source.regionLabel || DEFAULT_LABELS.region,
76
+ postalCode: source.postalCodeLabel || DEFAULT_LABELS.postalCode,
77
+ invalidEmail: source.invalidEmail || DEFAULT_LABELS.invalidEmail,
78
+ fieldRequired: source.fieldRequired || DEFAULT_LABELS.fieldRequired,
79
+ illegalCharacters: source.illegalCharacters || DEFAULT_LABELS.illegalCharacters,
80
+ invalidPostalCode: source.invalidPostalCode || DEFAULT_LABELS.invalidPostalCode,
81
+ rateLimited: source.rateLimited || DEFAULT_LABELS.rateLimited,
82
+ lookupError: source.lookupError || DEFAULT_LABELS.lookupError,
83
+ validationError: source.validationError || DEFAULT_LABELS.validationError,
84
+ loadingAddressForm: source.loadingAddressForm || DEFAULT_LABELS.loadingAddressForm,
85
+ switchToAutocomplete: source.switchToAutocomplete || DEFAULT_LABELS.switchToAutocomplete,
86
+ switchToManualEntry: source.switchToManuelEntry || DEFAULT_LABELS.switchToManualEntry,
87
+ addressLocation: source.addressLocation || DEFAULT_LABELS.addressLocation,
88
+ openInMaps: source.openInMaps || DEFAULT_LABELS.openInMaps,
89
+ usVerified: usValidationStrings.usVerified || source.usVerified || DEFAULT_LABELS.usVerified,
90
+ usVerifiedMessage: usValidationStrings.usVerifiedMessage || source.usVerifiedMessage || DEFAULT_LABELS.usVerifiedMessage,
91
+ usMissingSecondaryTitle: usValidationStrings.usMissingSecondaryTitle || source.usMissingSecondaryTitle || DEFAULT_LABELS.usMissingSecondaryTitle,
92
+ usMissingSecondaryMessage: usValidationStrings.usMissingSecondaryMessage || source.usMissingSecondaryMessage || DEFAULT_LABELS.usMissingSecondaryMessage,
93
+ usInvalidSecondaryRequiredTitle: usValidationStrings.usInvalidSecondaryRequiredTitle || source.usInvalidSecondaryRequiredTitle || DEFAULT_LABELS.usInvalidSecondaryRequiredTitle,
94
+ usInvalidSecondaryRequiredMessage: usValidationStrings.usInvalidSecondaryRequiredMessage || source.usInvalidSecondaryRequiredMessage || DEFAULT_LABELS.usInvalidSecondaryRequiredMessage,
95
+ usInvalidSecondaryOptionalTitle: usValidationStrings.usInvalidSecondaryOptionalTitle || source.usInvalidSecondaryOptionalTitle || DEFAULT_LABELS.usInvalidSecondaryOptionalTitle,
96
+ usInvalidSecondaryOptionalMessage: usValidationStrings.usInvalidSecondaryOptionalMessage || source.usInvalidSecondaryOptionalMessage || DEFAULT_LABELS.usInvalidSecondaryOptionalMessage,
97
+ usVacantTitle: usValidationStrings.usVacantTitle || source.usVacantTitle || DEFAULT_LABELS.usVacantTitle,
98
+ usVacantMessage: usValidationStrings.usVacantMessage || source.usVacantMessage || DEFAULT_LABELS.usVacantMessage,
99
+ usNoStatTitle: usValidationStrings.usNoStatTitle || source.usNoStatTitle || DEFAULT_LABELS.usNoStatTitle,
100
+ usNoStatMessage: usValidationStrings.usNoStatMessage || source.usNoStatMessage || DEFAULT_LABELS.usNoStatMessage,
101
+ usNotConfirmedTitle: usValidationStrings.usNotConfirmedTitle || source.usNotConfirmedTitle || DEFAULT_LABELS.usNotConfirmedTitle,
102
+ usNotConfirmedMessage: usValidationStrings.usNotConfirmedMessage || source.usNotConfirmedMessage || DEFAULT_LABELS.usNotConfirmedMessage,
103
+ usNoResults: usValidationStrings.usNoResults || source.usNoResults || DEFAULT_LABELS.usNoResults,
104
+ intlVerifiedTitle: intlValidationStrings.intlVerifiedTitle || source.intlVerifiedTitle || DEFAULT_LABELS.intlVerifiedTitle,
105
+ intlVerifiedMessage: intlValidationStrings.intlVerifiedMessage || source.intlVerifiedMessage || DEFAULT_LABELS.intlVerifiedMessage,
106
+ intlVerifiedSubBuildingChangedTitle: intlValidationStrings.intlVerifiedSubBuildingChangedTitle || source.intlVerifiedSubBuildingChangedTitle || DEFAULT_LABELS.intlVerifiedSubBuildingChangedTitle,
107
+ intlVerifiedSubBuildingChangedMessage: intlValidationStrings.intlVerifiedSubBuildingChangedMessage || source.intlVerifiedSubBuildingChangedMessage || DEFAULT_LABELS.intlVerifiedSubBuildingChangedMessage,
108
+ intlPartialTitle: intlValidationStrings.intlPartialTitle || source.intlPartialTitle || DEFAULT_LABELS.intlPartialTitle,
109
+ intlPartialMessage: intlValidationStrings.intlPartialMessage || source.intlPartialMessage || DEFAULT_LABELS.intlPartialMessage,
110
+ intlAmbiguousTitle: intlValidationStrings.intlAmbiguousTitle || source.intlAmbiguousTitle || DEFAULT_LABELS.intlAmbiguousTitle,
111
+ intlAmbiguousMessage: intlValidationStrings.intlAmbiguousMessage || source.intlAmbiguousMessage || DEFAULT_LABELS.intlAmbiguousMessage,
112
+ intlNotVerifiedTitle: intlValidationStrings.intlNotVerifiedTitle || source.intlNotVerifiedTitle || DEFAULT_LABELS.intlNotVerifiedTitle,
113
+ intlNotVerifiedMessage: intlValidationStrings.intlNotVerifiedMessage || source.intlNotVerifiedMessage || DEFAULT_LABELS.intlNotVerifiedMessage,
114
+ intlNoResults: intlValidationStrings.intlNoResults || source.intlNoResults || DEFAULT_LABELS.intlNoResults
115
+ };
116
+ };
117
+ const normalizeAddressFieldLabels = (source = {}) => {
118
+ return {
119
+ ...DEFAULT_LABELS,
120
+ ...mapFieldLabels(source || {})
121
+ };
122
+ };
123
+ exports.normalizeAddressFieldLabels = normalizeAddressFieldLabels;
124
+ const getAddressFieldLabels = async ({
125
+ country,
126
+ language
127
+ }) => {
128
+ const countryCode = country || 'US';
129
+ const locale = language || 'en';
130
+ const cacheKey = `${locale}_${countryCode}`;
131
+ if (cache[cacheKey]) {
132
+ return cache[cacheKey];
133
+ }
134
+ try {
135
+ const stack = (0, _contentstackLib.getStack)();
136
+ const results = await stack.getSingletonEntries({
137
+ contentTypeUIDs: CONTENT_TYPE_UIDS,
138
+ country: countryCode,
139
+ language: locale,
140
+ camelcase: true,
141
+ mergeWithFallback: true
142
+ });
143
+ const merged = mergeResultEntries(results);
144
+ const labels = normalizeAddressFieldLabels(merged);
145
+ cache[cacheKey] = labels;
146
+ return labels;
147
+ } catch (err) {
148
+ cache[cacheKey] = DEFAULT_LABELS;
149
+ return DEFAULT_LABELS;
150
+ }
151
+ };
152
+ exports.getAddressFieldLabels = getAddressFieldLabels;
153
+ const clearAddressFieldLabelCache = () => {
154
+ Object.keys(cache).forEach(cacheKey => {
155
+ delete cache[cacheKey];
156
+ });
157
+ };
158
+ exports.clearAddressFieldLabelCache = clearAddressFieldLabelCache;
159
+ //# sourceMappingURL=addressStrings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressStrings.js","names":["_contentstackLib","require","CONTENT_TYPE_UIDS","DEFAULT_LABELS","exports","address1","address2","city","district","region","postalCode","invalidEmail","fieldRequired","illegalCharacters","invalidPostalCode","rateLimited","lookupError","validationError","loadingAddressForm","switchToAutocomplete","switchToManualEntry","addressLocation","openInMaps","usVerified","usVerifiedMessage","usMissingSecondaryTitle","usMissingSecondaryMessage","usInvalidSecondaryRequiredTitle","usInvalidSecondaryRequiredMessage","usInvalidSecondaryOptionalTitle","usInvalidSecondaryOptionalMessage","usVacantTitle","usVacantMessage","usNoStatTitle","usNoStatMessage","usNotConfirmedTitle","usNotConfirmedMessage","usNoResults","intlVerifiedTitle","intlVerifiedMessage","intlVerifiedSubBuildingChangedTitle","intlVerifiedSubBuildingChangedMessage","intlPartialTitle","intlPartialMessage","intlAmbiguousTitle","intlAmbiguousMessage","intlNotVerifiedTitle","intlNotVerifiedMessage","intlNoResults","cache","mergeResultEntries","results","entries","Array","isArray","reduce","acc","entry","getUsValidationStrings","source","smartyUsValidationStrings","getIntlValidationStrings","smartyIntlValidationStrings","mapFieldLabels","usValidationStrings","intlValidationStrings","address1Label","address2Label","cityLabel","districtLabel","regionLabel","postalCodeLabel","switchToManuelEntry","normalizeAddressFieldLabels","getAddressFieldLabels","country","language","countryCode","locale","cacheKey","stack","getStack","getSingletonEntries","contentTypeUIDs","camelcase","mergeWithFallback","merged","labels","err","clearAddressFieldLabelCache","Object","keys","forEach"],"sources":["../../../src/addressLookup/utils/addressStrings.js"],"sourcesContent":["/* eslint-disable max-len */\nimport { getStack } from '@nuskin/contentstack-lib';\n\nconst CONTENT_TYPE_UIDS = ['shipping_component']\n\nconst DEFAULT_LABELS = {\n address1: 'Street Address',\n address2: 'Apartment, suite, etc.',\n city: 'City',\n district: 'District',\n region: 'Region',\n postalCode: 'Postal Code',\n invalidEmail: 'Invalid email address.',\n fieldRequired: 'This field is required.',\n illegalCharacters: 'Contains invalid characters.',\n invalidPostalCode: 'Invalid postal code.',\n rateLimited: 'Too many requests. Please wait a moment and try again.',\n lookupError: 'We could not look up that address right now.',\n validationError: 'We could not validate that address right now.',\n loadingAddressForm: 'Loading address form...',\n switchToAutocomplete: 'Switch to Autocomplete',\n switchToManualEntry: 'Switch to Manual Entry',\n addressLocation: 'Address location',\n openInMaps: 'Open in Google Maps',\n usVerified: 'Verified',\n usVerifiedMessage: 'This address is fully verified.',\n usMissingSecondaryTitle: 'Apartment or suite needed',\n usMissingSecondaryMessage: 'The main address is valid, but a unit number is required.',\n usInvalidSecondaryRequiredTitle: 'Apartment or suite not recognized',\n usInvalidSecondaryRequiredMessage: 'The street address is valid, but the unit number was not recognized and is required.',\n usInvalidSecondaryOptionalTitle: 'Unit not recognized',\n usInvalidSecondaryOptionalMessage: 'The main address is valid, but the unit number was not recognized.',\n usVacantTitle: 'Verified, but marked vacant',\n usVacantMessage: 'This address is valid but marked as vacant.',\n usNoStatTitle: 'Verified with caution',\n usNoStatMessage: 'This address is valid, but USPS indicates limited delivery status.',\n usNotConfirmedTitle: 'Not verified',\n usNotConfirmedMessage: 'This address could not be confirmed.',\n usNoResults: 'We couldn’t verify this address. Check the address and try again.',\n intlVerifiedTitle: 'Verified',\n intlVerifiedMessage: 'This address is verified.',\n intlVerifiedSubBuildingChangedTitle: 'Verified with unit changes',\n intlVerifiedSubBuildingChangedMessage: 'This address is verified, but the apartment or suite information was changed.',\n intlPartialTitle: 'Partially verified',\n intlPartialMessage: 'This address could only be partially verified.',\n intlAmbiguousTitle: 'Multiple matches found',\n intlAmbiguousMessage: 'Multiple possible matches were found for this address.',\n intlNotVerifiedTitle: 'Not verified',\n intlNotVerifiedMessage: 'This address could not be verified.',\n intlNoResults: 'We couldn’t verify this address. Check the address and try again.'\n};\n\nconst cache = {};\n\nconst mergeResultEntries = (results = []) => {\n const entries = Array.isArray(results) ? results : [results];\n return entries.reduce((acc, entry) => ({ ...acc, ...(entry || {}) }), {});\n};\n\nconst getUsValidationStrings = (source = {}) => source.smartyUsValidationStrings || {};\n\nconst getIntlValidationStrings = (source = {}) => source.smartyIntlValidationStrings || {};\n\nconst mapFieldLabels = (source = {}) => {\n const usValidationStrings = getUsValidationStrings(source);\n const intlValidationStrings = getIntlValidationStrings(source);\n\n return {\n address1: source.address1Label || DEFAULT_LABELS.address1,\n address2: source.address2Label || DEFAULT_LABELS.address2,\n city: source.cityLabel || DEFAULT_LABELS.city,\n district: source.districtLabel || DEFAULT_LABELS.district,\n region: source.regionLabel || DEFAULT_LABELS.region,\n postalCode: source.postalCodeLabel || DEFAULT_LABELS.postalCode,\n invalidEmail: source.invalidEmail || DEFAULT_LABELS.invalidEmail,\n fieldRequired: source.fieldRequired || DEFAULT_LABELS.fieldRequired,\n illegalCharacters: source.illegalCharacters || DEFAULT_LABELS.illegalCharacters,\n invalidPostalCode: source.invalidPostalCode || DEFAULT_LABELS.invalidPostalCode,\n rateLimited: source.rateLimited || DEFAULT_LABELS.rateLimited,\n lookupError: source.lookupError || DEFAULT_LABELS.lookupError,\n validationError: source.validationError || DEFAULT_LABELS.validationError,\n loadingAddressForm: source.loadingAddressForm || DEFAULT_LABELS.loadingAddressForm,\n switchToAutocomplete: source.switchToAutocomplete || DEFAULT_LABELS.switchToAutocomplete,\n switchToManualEntry: source.switchToManuelEntry || DEFAULT_LABELS.switchToManualEntry,\n addressLocation: source.addressLocation || DEFAULT_LABELS.addressLocation,\n openInMaps: source.openInMaps || DEFAULT_LABELS.openInMaps,\n usVerified: usValidationStrings.usVerified || source.usVerified || DEFAULT_LABELS.usVerified,\n usVerifiedMessage: usValidationStrings.usVerifiedMessage || source.usVerifiedMessage || DEFAULT_LABELS.usVerifiedMessage,\n usMissingSecondaryTitle: usValidationStrings.usMissingSecondaryTitle || source.usMissingSecondaryTitle || DEFAULT_LABELS.usMissingSecondaryTitle,\n usMissingSecondaryMessage: usValidationStrings.usMissingSecondaryMessage || source.usMissingSecondaryMessage || DEFAULT_LABELS.usMissingSecondaryMessage,\n usInvalidSecondaryRequiredTitle: usValidationStrings.usInvalidSecondaryRequiredTitle || source.usInvalidSecondaryRequiredTitle || DEFAULT_LABELS.usInvalidSecondaryRequiredTitle,\n usInvalidSecondaryRequiredMessage: usValidationStrings.usInvalidSecondaryRequiredMessage || source.usInvalidSecondaryRequiredMessage || DEFAULT_LABELS.usInvalidSecondaryRequiredMessage,\n usInvalidSecondaryOptionalTitle: usValidationStrings.usInvalidSecondaryOptionalTitle || source.usInvalidSecondaryOptionalTitle || DEFAULT_LABELS.usInvalidSecondaryOptionalTitle,\n usInvalidSecondaryOptionalMessage: usValidationStrings.usInvalidSecondaryOptionalMessage || source.usInvalidSecondaryOptionalMessage || DEFAULT_LABELS.usInvalidSecondaryOptionalMessage,\n usVacantTitle: usValidationStrings.usVacantTitle || source.usVacantTitle || DEFAULT_LABELS.usVacantTitle,\n usVacantMessage: usValidationStrings.usVacantMessage || source.usVacantMessage || DEFAULT_LABELS.usVacantMessage,\n usNoStatTitle: usValidationStrings.usNoStatTitle || source.usNoStatTitle || DEFAULT_LABELS.usNoStatTitle,\n usNoStatMessage: usValidationStrings.usNoStatMessage || source.usNoStatMessage || DEFAULT_LABELS.usNoStatMessage,\n usNotConfirmedTitle: usValidationStrings.usNotConfirmedTitle || source.usNotConfirmedTitle || DEFAULT_LABELS.usNotConfirmedTitle,\n usNotConfirmedMessage: usValidationStrings.usNotConfirmedMessage || source.usNotConfirmedMessage || DEFAULT_LABELS.usNotConfirmedMessage,\n usNoResults: usValidationStrings.usNoResults || source.usNoResults || DEFAULT_LABELS.usNoResults,\n intlVerifiedTitle: intlValidationStrings.intlVerifiedTitle || source.intlVerifiedTitle || DEFAULT_LABELS.intlVerifiedTitle,\n intlVerifiedMessage: intlValidationStrings.intlVerifiedMessage || source.intlVerifiedMessage || DEFAULT_LABELS.intlVerifiedMessage,\n intlVerifiedSubBuildingChangedTitle: intlValidationStrings.intlVerifiedSubBuildingChangedTitle || source.intlVerifiedSubBuildingChangedTitle || DEFAULT_LABELS.intlVerifiedSubBuildingChangedTitle,\n intlVerifiedSubBuildingChangedMessage: intlValidationStrings.intlVerifiedSubBuildingChangedMessage || source.intlVerifiedSubBuildingChangedMessage || DEFAULT_LABELS.intlVerifiedSubBuildingChangedMessage,\n intlPartialTitle: intlValidationStrings.intlPartialTitle || source.intlPartialTitle || DEFAULT_LABELS.intlPartialTitle,\n intlPartialMessage: intlValidationStrings.intlPartialMessage || source.intlPartialMessage || DEFAULT_LABELS.intlPartialMessage,\n intlAmbiguousTitle: intlValidationStrings.intlAmbiguousTitle || source.intlAmbiguousTitle || DEFAULT_LABELS.intlAmbiguousTitle,\n intlAmbiguousMessage: intlValidationStrings.intlAmbiguousMessage || source.intlAmbiguousMessage || DEFAULT_LABELS.intlAmbiguousMessage,\n intlNotVerifiedTitle: intlValidationStrings.intlNotVerifiedTitle || source.intlNotVerifiedTitle || DEFAULT_LABELS.intlNotVerifiedTitle,\n intlNotVerifiedMessage: intlValidationStrings.intlNotVerifiedMessage || source.intlNotVerifiedMessage || DEFAULT_LABELS.intlNotVerifiedMessage,\n intlNoResults: intlValidationStrings.intlNoResults || source.intlNoResults || DEFAULT_LABELS.intlNoResults\n };\n};\n\nexport const normalizeAddressFieldLabels = (source = {}) => {\n return {\n ...DEFAULT_LABELS,\n ...mapFieldLabels(source || {})\n };\n};\n\nexport const getAddressFieldLabels = async ({ country, language }) => {\n const countryCode = country || 'US';\n const locale = language || 'en';\n const cacheKey = `${locale}_${countryCode}`;\n\n if (cache[cacheKey]) {\n return cache[cacheKey];\n }\n\n try {\n const stack = getStack();\n const results = await stack.getSingletonEntries({\n contentTypeUIDs: CONTENT_TYPE_UIDS,\n country: countryCode,\n language: locale,\n camelcase: true,\n mergeWithFallback: true\n });\n\n const merged = mergeResultEntries(results);\n const labels = normalizeAddressFieldLabels(merged);\n cache[cacheKey] = labels;\n return labels;\n } catch (err) {\n cache[cacheKey] = DEFAULT_LABELS;\n return DEFAULT_LABELS;\n }\n};\n\nexport const clearAddressFieldLabelCache = () => {\n Object.keys(cache).forEach((cacheKey) => {\n delete cache[cacheKey];\n });\n};\n\nexport { DEFAULT_LABELS };\n"],"mappings":";;;;;;AACA,IAAAA,gBAAA,GAAAC,OAAA;AADA;;AAGA,MAAMC,iBAAiB,GAAG,CAAC,oBAAoB,CAAC;AAEhD,MAAMC,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG;EACrBE,QAAQ,EAAE,gBAAgB;EAC1BC,QAAQ,EAAE,wBAAwB;EAClCC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,MAAM,EAAE,QAAQ;EAChBC,UAAU,EAAE,aAAa;EACzBC,YAAY,EAAE,wBAAwB;EAC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