diff --git a/index.js b/index.js index 6056fa8f7ee552f609ef8b1ef7402866c3ceb9ee..ae4781e42a3b77329665e458ff6e64b04e554c20 100644 --- a/index.js +++ b/index.js @@ -229245,6 +229245,32 @@ function removeMultipleSpaces(str) { return str.replace(/ +/g, ' ') } +/** + * Remove SGE useless dots + * This regular expression matches one or more consecutive dots + * and then in the replacement function, it checks if the dots are surrounded by non-dot characters. + * If so, it replaces them with a space; otherwise, it removes them + * @example + * console.log(removeDots(".....03G2")); // Outputs: "03G2" + * console.log(removeDots("....ETG..4...D")); // Outputs: "ETG 4 D" + * console.log(removeDots("ETG 4 D")); // Outputs: "ETG 4 D" + * @param {string} input - The input string containing dots to be removed. + * @returns {string} The input string without dots. + */ +function removeDots(input) { + return input.replace(/\.+/g, (match, offset, string) => { + if ( + offset > 0 && + offset < string.length - match.length && + string[offset - 1] !== '.' && + string[offset + match.length] !== '.' + ) { + return ' ' + } + return '' + }) +} + /** * Remove SGE address number * @param {string} str @@ -229286,6 +229312,7 @@ module.exports = { parseValueHalfHour, removeAddressNumber, removeMultipleSpaces, + removeDots, } @@ -247365,6 +247392,7 @@ const { getInseeCode } = __webpack_require__(1727) const { findUserAddress } = __webpack_require__(1728) const { removeMultipleSpaces, + removeDots, removeAddressNumber, } = __webpack_require__(1599) const Sentry = __webpack_require__(1639) @@ -247438,7 +247466,7 @@ async function verifyUserIdentity( escalierEtEtageEtAppartement ) - // Third try, remove address number because it's buggy on SGE side + // Third try, remove address number if (!pdl) { log('warn', 'Third try onboarding for sge') pdl = await findUserPdl( @@ -247452,9 +247480,24 @@ async function verifyUserIdentity( ) } - // Fourth try, remove address number and add escalierEtEtageEtAppartement because it's buggy on SGE side + // Fourth try, add escalierEtEtageEtAppartement if (!pdl) { log('warn', 'Fourth try onboarding for sge') + pdl = await findUserPdl( + `${baseUrl}/enedis_SDE_recherche-point/1.0`, + apiAuthKey, + loginUtilisateur, + lastname, + removeMultipleSpaces(userAddress.numeroEtNomVoie), + userAddress.codePostal, + userAddress.commune.$.code, + removeDots(escalierEtEtageEtAppartement) + ) + } + + // Fifth try, remove address number and add escalierEtEtageEtAppartement + if (!pdl) { + log('warn', 'Fifth try onboarding for sge') pdl = await findUserPdl( `${baseUrl}/enedis_SDE_recherche-point/1.0`, apiAuthKey, @@ -247463,7 +247506,7 @@ async function verifyUserIdentity( removeMultipleSpaces(removeAddressNumber(userAddress.numeroEtNomVoie)), userAddress.codePostal, userAddress.commune.$.code, - escalierEtEtageEtAppartement + removeDots(escalierEtEtageEtAppartement) ) } diff --git a/onDeleteAccount.js b/onDeleteAccount.js index 5b776813966f1ed22ffd4823d5e0e6efce510ea6..71e230d9b76bd8628fb8388f913d6762c1fc3cd0 100644 --- a/onDeleteAccount.js +++ b/onDeleteAccount.js @@ -228478,6 +228478,32 @@ function removeMultipleSpaces(str) { return str.replace(/ +/g, ' ') } +/** + * Remove SGE useless dots + * This regular expression matches one or more consecutive dots + * and then in the replacement function, it checks if the dots are surrounded by non-dot characters. + * If so, it replaces them with a space; otherwise, it removes them + * @example + * console.log(removeDots(".....03G2")); // Outputs: "03G2" + * console.log(removeDots("....ETG..4...D")); // Outputs: "ETG 4 D" + * console.log(removeDots("ETG 4 D")); // Outputs: "ETG 4 D" + * @param {string} input - The input string containing dots to be removed. + * @returns {string} The input string without dots. + */ +function removeDots(input) { + return input.replace(/\.+/g, (match, offset, string) => { + if ( + offset > 0 && + offset < string.length - match.length && + string[offset - 1] !== '.' && + string[offset + match.length] !== '.' + ) { + return ' ' + } + return '' + }) +} + /** * Remove SGE address number * @param {string} str @@ -228519,6 +228545,7 @@ module.exports = { parseValueHalfHour, removeAddressNumber, removeMultipleSpaces, + removeDots, }