Newer
Older
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ([
/* 0 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const {
BaseKonnector,
log,
hydrateAndFilter,
addData,
const soapRequest = __webpack_require__(1331)
const moment = __webpack_require__(1373)
__webpack_require__(1510)
const xml2js = __webpack_require__(1513)
const { buildAgregatedData } = __webpack_require__(1554)
const {
parseSgeXmlData,
formateDataForDoctype,
parseTags,
parseValue,
consultationMesuresDetailleesMaxPower,
consultationMesuresDetaillees,
} = __webpack_require__(1556)
const {
updateBoConsent,
createBoConsent,
getBoConsent,
deleteBoConsent,
} = __webpack_require__(1557)
const { verifyUserIdentity } = __webpack_require__(1558)
const { activateContract } = __webpack_require__(1598)
const { verifyContract } = __webpack_require__(1599)
const { terminateContract } = __webpack_require__(1601)
const { getContractStartDate } = __webpack_require__(1602)
const { getAccount, saveAccountData } = __webpack_require__(1603)
const { iSLocal } = __webpack_require__(1604)
moment.locale('fr') // set the language
moment.tz.setDefault('Europe/Paris') // set the timezone
/*** Connector Constants ***/
const manualExecution =
process.env.COZY_JOB_MANUAL_EXECUTION === 'true' ? true : false
let startDailyDate = manualExecution
? moment().subtract(12, 'month')
: moment().subtract(6, 'month')
let startDailyDateString = startDailyDate.format('YYYY-MM-DD')
const startLoadDate = moment().subtract(7, 'day')
const endDate = moment()
const endDateString = endDate.format('YYYY-MM-DD')
const ACCOUNT_ID = iSLocal() ? 'default_account_id' : 'enedis-sge-grandlyon'
/**
* The start function is run by the BaseKonnector instance only when it got all the account
* information (fields). When you run this connector yourself in "standalone" mode or "dev" mode,
* the account information come from ./konnector-dev-config.json file
* cozyParameters are static parameters, independents from the account. Most often, it can be a
* secret api key.
* @param {fields} fields
* @param {{secret: fields}} cozyParameters
*/
async function start(fields, cozyParameters) {
log('info', 'Gathering data ...')
let baseUrl = fields.wso2BaseUrl
let apiAuthKey = fields.apiToken
let contractId = fields.contractId
//TODO switch variable to english
let sgeLogin = fields.sgeLogin
//TODO: Verify if condition is working in local and on build version
if (cozyParameters && Object.keys(cozyParameters).length !== 0) {
log('debug', 'Found COZY_PARAMETERS')
baseUrl = cozyParameters.secret.wso2BaseUrl
apiAuthKey = cozyParameters.secret.apiToken
contractId = cozyParameters.secret.contractId
sgeLogin = cozyParameters.secret.sgeLogin
}
/**
* If it's first start we have to do the following operations:
* - verify pdl are matching
* - BO: create backoffice consent
* - get contract start date and store it
* - activate half-hour
* - BO: update consent with service ID
*/
log('info', 'User Logging...')
if (await isFirstStart(await getAccount('default_account_id'))) {
const user = await verifyUserIdentity(fields, baseUrl, apiAuthKey, sgeLogin)
let consent = await createBoConsent(
pointId,
user.lastname,
user.firstname,
user.address,
user.postalCode,
user.inseeCode
)
// handle user contract start date in order to preperly request data
const userContractstartDate = await getContractStartDate(
baseUrl,
apiAuthKey,
sgeLogin,
pointId
)
startDailyDate = moment(userContractstartDate, 'YYYY-MM-DD')
startDailyDateString = startDailyDate.format('YYYY-MM-DD')
const contractStartDate = moment().format('YYYY-MM-DD')
const contractEndDate = moment()
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.format('YYYY-MM-DD')
let serviceId = await verifyContract(
baseUrl,
apiAuthKey,
sgeLogin,
contractId,
user.pointId
)
if (!serviceId) {
serviceId = await activateContract(
baseUrl,
apiAuthKey,
sgeLogin,
contractId,
user.lastname,
user.pointId,
contractStartDate,
contractEndDate
)
}
consent = await updateBoConsent(consent, serviceId)
// Save bo id into account
const accountData = await getAccount(ACCOUNT_ID)
await saveAccountData(this.accountId, {
...accountData.data,
consentId: consent.id,
})
} else {
// AlternateStart
const accountData = await getAccount(ACCOUNT_ID)
const userConsent = await getBoConsent(accountData.data.consentId)
const user = await verifyUserIdentity(fields, baseUrl, apiAuthKey, sgeLogin)
if (user.lastname !== userConsent.lastname || !user) {
log('error', `Invalid or not found consent for user`)
await deleteBoConsent()
if (userConsent.serviceId) {
await terminateContract(
baseUrl,
apiAuthKey,
sgeLogin,
contractId,
fields.pointId,
userConsent.serviceId
)
} else {
log('error', `No service id retrieved from BO`)
throw errors.VENDOR_DOWN
}
throw errors.TERMS_VERSION_MISMATCH
}
await gatherData(baseUrl, apiAuthKey, sgeLogin, fields.pointId)
}
/**
* Main method for gathering data
* @param {string} baseUrl
* @param {string} apiAuthKey
* @param {string} sgeLogin
* @param {number} pointId
*/
async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) {
await getContractStartDate(baseUrl, apiAuthKey, sgeLogin, pointId)
await getData(
`${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees/1.0`,
apiAuthKey,
)
await getMaxPowerData(
`${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees/1.0`,
apiAuthKey,
Loading
Loading full blame...