UNPKG

@adyen/kyc-components

Version:

This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.

208 lines (207 loc) 5.79 kB
try { let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack; n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "f489d985-188f-49c4-b084-68bdfc424c11", e._sentryDebugIdIdentifier = "sentry-dbid-f489d985-188f-49c4-b084-68bdfc424c11"); } catch (e) {} import { t as CountryCodes } from "./country-code-CX5KqMBr.js"; import { r as summaryItem } from "./summaryItem-Dehjwp8D.js"; //#region src/components/Shared/forms/Address/constants.ts var addressFields = [ "address", "otherAddressInformation", "postalCode", "city", "stateOrProvince", "country" ]; var [ADDRESS, OTHER_ADDRESS_INFORMATION, POSTAL_CODE, CITY, STATE, COUNTRY] = addressFields; var COUNTRIES_WITH_STATES_DATASET = [ CountryCodes.Australia, CountryCodes.Brazil, CountryCodes.Canada, CountryCodes.NewZealand, CountryCodes.UnitedStates, CountryCodes.Japan ]; var COUNTRIES_WITH_HOUSE_NUMBER_FIRST = [ CountryCodes.Australia, CountryCodes.Canada, CountryCodes.NewZealand, CountryCodes.PuertoRico, CountryCodes.UnitedStates, CountryCodes.UnitedKingdom, CountryCodes.France ]; var ADDRESS_SCHEMAS = { [CountryCodes.Australia]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, CITY, STATE, POSTAL_CODE ], [CountryCodes.Canada]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, CITY, POSTAL_CODE, STATE ], [CountryCodes.UnitedKingdom]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, CITY, POSTAL_CODE ], [CountryCodes.UnitedStates]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, CITY, STATE, POSTAL_CODE ], [CountryCodes.PuertoRico]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, CITY, POSTAL_CODE ], [CountryCodes.HongKong]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, CITY, STATE ], [CountryCodes.NewZealand]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, POSTAL_CODE, CITY, STATE ], [CountryCodes.UnitedArabEmirates]: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, CITY ], [CountryCodes.Japan]: [ COUNTRY, OTHER_ADDRESS_INFORMATION, POSTAL_CODE, CITY, STATE ], default: [ COUNTRY, ADDRESS, OTHER_ADDRESS_INFORMATION, POSTAL_CODE, CITY, STATE ] }; var CONDENSED_ADDRESS_FIELDS = { [CountryCodes.UnitedStates]: [ CITY, STATE, POSTAL_CODE ] }; var LABELS = { city: { default: CITY, [CountryCodes.UnitedKingdom]: "cityTown" }, country: { default: COUNTRY }, otherAddressInformation: { default: OTHER_ADDRESS_INFORMATION, [CountryCodes.Canada]: "apartmentSuiteOther", [CountryCodes.PuertoRico]: "apartmentSuiteOther", [CountryCodes.UnitedStates]: "apartmentSuiteOther" }, postalCode: { default: POSTAL_CODE, [CountryCodes.PuertoRico]: "zipCode", [CountryCodes.UnitedStates]: "zipCode" }, stateOrProvince: { default: STATE, [CountryCodes.Australia]: "state", [CountryCodes.Brazil]: "state", [CountryCodes.Canada]: "provinceOrTerritory", [CountryCodes.NewZealand]: "region", [CountryCodes.UnitedStates]: "state" }, address: { default: ADDRESS } }; //#endregion //#region src/components/Shared/forms/Address/utils.ts /** * Returns the key for a field of the passed country or the default key for that field. * @param fieldName - The data to pre-fill the address fields * @param country - The selected country */ var getKeyForField = (fieldName, country) => country ? LABELS[fieldName][country] || LABELS[fieldName].default : LABELS[fieldName].default; /** * Returns the address schema of the selected country or the default address schema. * @param country - The selected country */ var getAddressSchemaForCountry = (country) => country && ADDRESS_SCHEMAS[country] ? ADDRESS_SCHEMAS[country] : ADDRESS_SCHEMAS.default; /** * Returns the field labels for each field in the selected countries address schema. * @param country - The selected country */ var getAddressSchemaLabelsByCountry = (country) => { return getAddressSchemaForCountry(country).reduce((labels, field) => ({ ...labels, [field]: getKeyForField(field, country) }), {}); }; var mapAddressLabels = (data, datasetUtils) => { if (data?.country) return getAddressSchemaForCountry(data.country).reduce((mappedAddress, field) => { const labelKey = getKeyForField(field, data.country); const value = data?.[field]; if (!value) return mappedAddress; switch (field) { case "country": return { ...mappedAddress, [field]: summaryItem(labelKey, datasetUtils.getCountryName(value) ?? value) }; case "stateOrProvince": return { ...mappedAddress, [field]: summaryItem(labelKey, datasetUtils.getStateName(value, data.country) ?? value) }; default: return { ...mappedAddress, [field]: summaryItem(labelKey, value) }; } }, {}); return data; }; var mapAddressLabelsNewSummary = (data, datasetUtils) => { if (!data?.country) return {}; const addressSchema = getAddressSchemaForCountry(data.country); const mappedSummary = {}; for (const field of addressSchema) { const labelKey = getKeyForField(field, data.country); const value = data?.[field]; if (field === "country") { mappedSummary[labelKey] = datasetUtils.getCountryName(value) ?? value; continue; } if (field === "stateOrProvince") { mappedSummary[labelKey] = datasetUtils.getStateName(value, data.country) ?? value; continue; } mappedSummary[labelKey] = value; } return mappedSummary; }; //#endregion export { mapAddressLabelsNewSummary as a, COUNTRIES_WITH_STATES_DATASET as c, mapAddressLabels as i, addressFields as l, getAddressSchemaLabelsByCountry as n, CONDENSED_ADDRESS_FIELDS as o, getKeyForField as r, COUNTRIES_WITH_HOUSE_NUMBER_FIRST as s, getAddressSchemaForCountry as t };