From 44e78df6bd8ee8a103ac69e641ea2c6d67bb631d Mon Sep 17 00:00:00 2001 From: build-token <build-token> Date: Wed, 7 Feb 2024 10:44:33 +0000 Subject: [PATCH] publish: Typo + README documentation link generated from commit fccfa5bb0a52b4f0c44b1c29ff9d097575fadb5d --- README.md | 2 +- index.js | 132 +++++---------------------------------------- onDeleteAccount.js | 26 --------- 3 files changed, 15 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index f70e988..b01b30f 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ Retrieving consumption data from Enedis SGE SOAP api ## Documentation -[Enedis SGE Konnector - Self-Data](https://doc.self-data.alpha.grandlyon.com/konnectors/enedis-sge/) +[Enedis SGE Konnector - Self-Data](https://doc-self-data.apps.grandlyon.com/konnectors/enedis-sge/) diff --git a/index.js b/index.js index 98e8742..414a368 100644 --- a/index.js +++ b/index.js @@ -23,12 +23,10 @@ const { parseValue, parseValueHalfHour, parsePointId, - parseUserOffPeakHours, } = __webpack_require__(1599) const { consultationMesuresDetailleesMaxPower, consultationMesuresDetaillees, - consulterDonneesTechniquesContractuelles, } = __webpack_require__(1680) const { updateBoConsent, @@ -155,6 +153,7 @@ async function start(fields, cozyParameters) { */ log('info', 'User Logging...') + const boUrlSGE = new URL('/api/sge', boBaseUrl).href if (isFirstStart(await getAccount(ACCOUNT_ID))) { log('info', 'First start...') transaction.startChild({ op: 'First start' }) @@ -168,7 +167,7 @@ async function start(fields, cozyParameters) { exitIfDebug(user) let consent = await createBoConsent( - boBaseUrl, + boUrlSGE, boToken, pointId, user.lastname, @@ -203,12 +202,12 @@ async function start(fields, cozyParameters) { contractStartDate, contractEndDate ).catch(async err => { - await deleteBoConsent(boBaseUrl, boToken, consent.ID) + await deleteBoConsent(boUrlSGE, boToken, consent.ID) throw err }) } consent = await updateBoConsent( - boBaseUrl, + boUrlSGE, boToken, consent, serviceId.toString() @@ -227,7 +226,7 @@ async function start(fields, cozyParameters) { transaction.startChild({ op: 'Alternate start' }) const accountData = await getAccount(ACCOUNT_ID) const userConsent = await getBoConsent( - boBaseUrl, + boUrlSGE, boToken, accountData.data.consentId ) @@ -266,7 +265,7 @@ async function start(fields, cozyParameters) { sgeLogin, contractId, pointId, - boBaseUrl, + boUrlSGE, boToken, consentEndDate < today ) @@ -354,93 +353,16 @@ async function deleteConsent( */ async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) { log('info', 'Querying data...') - await getOffPeakHours( - `${baseUrl}/enedis_SGE_ConsultationDonneesTechniquesContractuelles/1.0`, - apiAuthKey, - sgeLogin, - pointId - ) - await getData( - `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`, - apiAuthKey, - sgeLogin, - pointId - ) - await getMaxPowerData( - `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`, - apiAuthKey, - sgeLogin, - pointId - ) - await getDataHalfHour( - `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`, - apiAuthKey, - sgeLogin, - pointId - ) + const measuresUrl = new URL( + '/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0', + baseUrl + ).href + await getData(measuresUrl, apiAuthKey, sgeLogin, pointId) + await getMaxPowerData(measuresUrl, apiAuthKey, sgeLogin, pointId) + await getDataHalfHour(measuresUrl, apiAuthKey, sgeLogin, pointId) log('info', 'Querying data: done') } -/** - * Get hour data - * @param {string} url - * @param {string} apiAuthKey - * @param {string} userLogin - * @param {string} pointId - */ -async function getOffPeakHours(url, apiAuthKey, userLogin, pointId) { - log('info', 'Fetching off-peak hours') - const sgeHeaders = { - 'Content-Type': 'text/xml;charset=UTF-8', - apikey: apiAuthKey, - } - - const { response } = await soapRequest({ - url: url, - headers: sgeHeaders, - xml: consulterDonneesTechniquesContractuelles(pointId, userLogin, false), - }).catch(err => { - log('error', 'consulterDonneesTechniquesContractuelles') - log('error', err) - Sentry.captureException( - `consulterDonneesTechniquesContractuelles: ${err}`, - { - tags: { section: 'getOffPeakHour' }, - extra: { - pointId: pointId, - }, - } - ) - return err - }) - - const result = await xml2js.parseStringPromise(response.body, { - tagNameProcessors: [parseTags], - valueProcessors: [parseValue], - explicitArray: false, - }) - - try { - const offPeakHours = parseUserOffPeakHours(result) - log( - 'debug', - `Found off-peak hours : ${offPeakHours}, store them in account data` - ) - const accountData = await getAccount(ACCOUNT_ID) - await saveAccountData(ACCOUNT_ID, { - ...accountData.data, - offPeakHours, - }) - } catch (error) { - log('debug', 'Off-peak hours not found, remove them from account data') - let accountData = await getAccount(ACCOUNT_ID) - delete accountData.data.offPeakHours - await saveAccountData(ACCOUNT_ID, { - ...accountData.data, - }) - } -} - /** * Get hour data * @param {string} url @@ -229164,31 +229086,6 @@ function parseUserAddress(result) { ]['point']['donneesGenerales']['adresseInstallation'] } -/** - * Return User off-peak hours - * @param {string} result - * @returns {string} - * @example "3H00-8H00;13H30-16H30" - */ -function parseUserOffPeakHours(result) { - log('info', 'Parsing user off-peak hours') - const json = JSON.stringify(result) - const rawOffPeakHours = - JSON.parse(json)['Envelope']['Body'][ - 'consulterDonneesTechniquesContractuellesResponse' - ]['point']['situationComptage']['dispositifComptage']['relais'][ - 'plageHeuresCreuses' - ] - // extract off-peak hours from parentheses - let match = rawOffPeakHours.match(/\((.*?)\)/) - // Check if there is a match and return the content - if (match) { - return match[1] - } else { - throw new Error('invalid off-peak hours format') - } -} - /** * Return User contract start date * @param {string} result @@ -229379,7 +229276,6 @@ module.exports = { parseSgeXmlData, parseTags, parseUserAddress, - parseUserOffPeakHours, parseUserPdl, parseValue, parseValueHalfHour, @@ -247514,7 +247410,7 @@ async function verifyUserIdentity( // Store if user is going through safety sge onboarding let userSafetyOnBoarding = false - // First try with user adresse + // First try with user address let pdl = await findUserPdl( `${baseUrl}/enedis_SDE_recherche-point/1.0`, apiAuthKey, diff --git a/onDeleteAccount.js b/onDeleteAccount.js index 30be199..db81f44 100644 --- a/onDeleteAccount.js +++ b/onDeleteAccount.js @@ -228345,31 +228345,6 @@ function parseUserAddress(result) { ]['point']['donneesGenerales']['adresseInstallation'] } -/** - * Return User off-peak hours - * @param {string} result - * @returns {string} - * @example "3H00-8H00;13H30-16H30" - */ -function parseUserOffPeakHours(result) { - log('info', 'Parsing user off-peak hours') - const json = JSON.stringify(result) - const rawOffPeakHours = - JSON.parse(json)['Envelope']['Body'][ - 'consulterDonneesTechniquesContractuellesResponse' - ]['point']['situationComptage']['dispositifComptage']['relais'][ - 'plageHeuresCreuses' - ] - // extract off-peak hours from parentheses - let match = rawOffPeakHours.match(/\((.*?)\)/) - // Check if there is a match and return the content - if (match) { - return match[1] - } else { - throw new Error('invalid off-peak hours format') - } -} - /** * Return User contract start date * @param {string} result @@ -228560,7 +228535,6 @@ module.exports = { parseSgeXmlData, parseTags, parseUserAddress, - parseUserOffPeakHours, parseUserPdl, parseValue, parseValueHalfHour, -- GitLab