Newer
Older
228001
228002
228003
228004
228005
228006
228007
228008
228009
228010
228011
228012
228013
228014
228015
228016
228017
228018
228019
228020
228021
228022
228023
228024
228025
228026
228027
228028
228029
228030
228031
228032
228033
228034
228035
228036
228037
228038
228039
228040
228041
228042
228043
228044
228045
228046
228047
228048
228049
228050
228051
228052
228053
228054
228055
228056
228057
228058
228059
228060
228061
228062
228063
228064
228065
228066
228067
228068
228069
228070
228071
228072
228073
228074
228075
228076
228077
228078
228079
228080
228081
228082
228083
228084
228085
228086
228087
228088
228089
228090
228091
228092
228093
228094
228095
228096
228097
228098
228099
228100
228101
228102
228103
228104
228105
228106
228107
const { log, errors } = __webpack_require__(1)
const soapRequest = __webpack_require__(1331)
const { parseUserPdl, parseTags, parseValue } = __webpack_require__(1555)
const { rechercherPoint } = __webpack_require__(1556)
const xml2js = __webpack_require__(1513)
/**
* @param {string} url
* @param {string} apiAuthKey
* @param {string} appLogin
* @param {string} name
* @param {string} address
* @param {string} postalCode
* @param {string} inseeCode
* @return {Promise<string | null>} User Pdl
*/
async function findUserPdl(
url,
apiAuthKey,
appLogin,
name,
address,
postalCode,
inseeCode
) {
log('info', 'Fetching user data')
const sgeHeaders = {
'Content-Type': 'text/xml;charset=UTF-8',
apikey: apiAuthKey,
}
const { response } = await soapRequest({
url: url,
headers: sgeHeaders,
xml: rechercherPoint(appLogin, name, postalCode, inseeCode, address),
}).catch(err => {
log('error', 'rechercherPointResponse')
log('error', err)
throw errors.LOGIN_FAILED
})
const parsedReply = await xml2js.parseStringPromise(response.body, {
tagNameProcessors: [parseTags],
valueProcessors: [parseValue],
explicitArray: false,
})
try {
return parseUserPdl(parsedReply)
} catch (error) {
log('error', 'Error while parsing user PDL: ' + error)
log(
'error',
`Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}`
)
throw errors.LOGIN_FAILED
}
}
module.exports = { findUserPdl }
/***/ }),
/* 1597 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const { default: axios } = __webpack_require__(1558)
const { log, errors } = __webpack_require__(1)
const API_URL = 'https://apicarto.ign.fr/api/codes-postaux/communes'
/**
* Return inseeCode given a postalCode
* @param {string} postalCode
* @param {string} [city]
* @return {Promise<string>} inseeCode
*/
async function getInseeCode(postalCode, city) {
try {
log('info', `Query getInseeCode for postalCode ${postalCode} / ${city}`)
const response = await axios.get(`${API_URL}/${postalCode}`)
if (response.data.length === 1) {
return response.data[0].codeCommune
} else {
if (!city) throw errors.USER_ACTION_NEEDED
const filteredResponse = response.data.filter(
town => town.nomCommune.toLowerCase() === city.toLowerCase()
)
return filteredResponse[0].codeCommune
}
} catch (error) {
log(
'error',
`Query getInseeCode failed for postalCode ${postalCode} / ${city}`
)
throw errors.USER_ACTION_NEEDED
}
}
module.exports = {
getInseeCode,
}
228108
228109
228110
228111
228112
228113
228114
228115
228116
228117
228118
228119
228120
228121
228122
228123
/***/ }),
/* 1598 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const { log, errors } = __webpack_require__(1)
const soapRequest = __webpack_require__(1331)
const { parseTags, parseValue, parseServiceId } = __webpack_require__(1555)
const { commanderCollectePublicationMesures } = __webpack_require__(1556)
const xml2js = __webpack_require__(1513)
/**
* @param {string} url
* @param {string} apiAuthKey
* @param {string} appLogin
* @param {string} name
228125
228126
228127
228128
228129
228130
228131
228132
228133
228134
228135
228136
228137
228138
228139
228140
228141
228142
228143
228144
228145
* @param {string} startDate
* @param {string} endDate
* @return {Promise<number>} User contractId
*/
async function activateContract(
url,
apiAuthKey,
appLogin,
contractId,
name,
pointId,
startDate,
endDate
) {
log('info', 'activateContract')
const sgeHeaders = {
'Content-Type': 'text/xml;charset=UTF-8',
apikey: apiAuthKey,
}
const { response } = await soapRequest({
url: `${url}/enedis_SGE_CommandeCollectePublicationMesures/1.0`,
228147
228148
228149
228150
228151
228152
228153
228154
228155
228156
228157
228158
228159
228160
228161
228162
228163
228164
228165
228166
228167
228168
228169
228170
headers: sgeHeaders,
xml: commanderCollectePublicationMesures(
appLogin,
contractId,
pointId,
name,
startDate,
endDate
),
}).catch(err => {
log('error', 'commanderCollectePublicationMesures')
log('error', err)
throw errors.LOGIN_FAILED
})
const parsedReply = await xml2js.parseStringPromise(response.body, {
tagNameProcessors: [parseTags],
valueProcessors: [parseValue],
explicitArray: false,
})
try {
return parseServiceId(parsedReply)
} catch (error) {
log('error', 'Error while activating contract: ' + error)
log(
'error',
`Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}`
)
//TODO: handle SGT4B8: Il existe déjà plusieurs demandes en cours sur le point ?
228177
228178
228179
228180
228181
228182
228183
228184
228185
228186
228187
228188
228189
228190
228191
228192
228193
throw errors.LOGIN_FAILED
}
}
module.exports = { activateContract }
/***/ }),
/* 1599 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const { log, errors } = __webpack_require__(1)
const soapRequest = __webpack_require__(1331)
const { parseTags, parseValue, parseContracts } = __webpack_require__(1555)
const { rechercherServicesSouscritsMesures } = __webpack_require__(1556)
const xml2js = __webpack_require__(1513)
const { contractState, contractLibelle } = __webpack_require__(1600)
/**
* @param {string} url
* @param {string} apiAuthKey
* @param {string} appLogin
228201
228202
228203
228204
228205
228206
228207
228208
228209
228210
228211
228212
228213
228214
228215
228216
228217
228218
228219
228220
228221
228222
228223
228224
228225
228226
* @return {Promise<number | null>} User contractId
*/
async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) {
log('info', 'verifyContract')
const sgeHeaders = {
'Content-Type': 'text/xml;charset=UTF-8',
apikey: apiAuthKey,
}
const { response } = await soapRequest({
url: `${url}/enedis_SGE_RechercheServicesMesures/1.0`,
headers: sgeHeaders,
xml: rechercherServicesSouscritsMesures(appLogin, contractId, pointId),
}).catch(err => {
log('error', 'rechercherServicesSouscritsMesures')
log('error', err)
throw errors.LOGIN_FAILED
})
const parsedReply = await xml2js.parseStringPromise(response.body, {
tagNameProcessors: [parseTags],
valueProcessors: [parseValue],
explicitArray: false,
})
try {
const currentContracts = parseContracts(parsedReply)
let currentContract = null
if (Array.isArray(currentContracts)) {
currentContract = parseContracts(parsedReply)[0]
} else {
currentContract = parseContracts(parsedReply)
}
if (
(currentContract.etatCode === contractState.ACTIF ||
currentContract.etatCode === contractState.DEMANDE) &&
currentContract.serviceSouscritLibelle === contractLibelle.ACTIF
)
return currentContract.serviceSouscritId
return null
} catch (error) {
log('error', 'Error while parsing user contract: ' + error)
log(
'error',
`Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}`
)
228247
228248
228249
228250
228251
228252
228253
228254
228255
228256
228257
228258
228259
228260
228261
228262
228263
228264
228265
throw errors.LOGIN_FAILED
}
}
module.exports = { verifyContract }
/***/ }),
/* 1600 */
/***/ ((module) => {
/**
* Enum for contract-state values.
* @readonly
* @enum {number}
*/
const contractState = {
TERMINE: 'TERMINE',
ACTIF: 'ACTIF',
/**
* Enum for contractLibelle values.
* @readonly
* @enum {number}
*/
const contractLibelle = {
ACTIF:
'Collecte de la courbe de charge au pas 30 min avec transmission quotidienne des données brutes en soutirage',
}
module.exports = { contractState, contractLibelle }
228280
228281
228282
228283
228284
228285
228286
228287
228288
228289
228290
228291
228292
228293
228294
228295
228296
/***/ }),
/* 1601 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const { log, errors } = __webpack_require__(1)
const soapRequest = __webpack_require__(1331)
const { parseTags, parseValue } = __webpack_require__(1555)
const { commanderArretServiceSouscritMesures } = __webpack_require__(1556)
const xml2js = __webpack_require__(1513)
/**
* @param {string} url
* @param {string} apiAuthKey
* @param {string} appLogin
* @param {number} serviceId
* @return {Promise<string>} User contractId
*/
async function terminateContract(
url,
apiAuthKey,
appLogin,
contractId,
pointId,
serviceId
) {
log('info', 'terminateContract')
const sgeHeaders = {
'Content-Type': 'text/xml;charset=UTF-8',
apikey: apiAuthKey,
}
const { response } = await soapRequest({
url: `${url}/enedis_SGE_CommandeArretServiceSouscritMesures/1.0`,
228317
228318
228319
228320
228321
228322
228323
228324
228325
228326
228327
228328
228329
228330
228331
228332
228333
228334
228335
228336
228337
headers: sgeHeaders,
xml: commanderArretServiceSouscritMesures(
appLogin,
contractId,
pointId,
serviceId
),
}).catch(err => {
log('error', 'commanderArretServiceSouscritMesures')
log('error', err)
throw errors.VENDOR_DOWN
})
const parsedReply = await xml2js.parseStringPromise(response.body, {
tagNameProcessors: [parseTags],
valueProcessors: [parseValue],
explicitArray: false,
})
try {
// We don't need any action on reply for now
if (parsedReply.Envelope.Body.Fault) {
log(
'error',
`Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}`
)
}
return parsedReply
} catch (error) {
log('error', 'Error while parsing user contract termination: ' + error)
log(
'error',
`Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}`
)
throw errors.VENDOR_DOWN
}
}
module.exports = { terminateContract }
/***/ }),
/* 1602 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
228362
228363
228364
228365
228366
228367
228368
228369
228370
228371
228372
228373
228374
228375
228376
228377
228378
228379
228380
228381
228382
228383
228384
228385
228386
228387
228388
228389
228390
228391
228392
228393
228394
228395
228396
228397
228398
228399
228400
228401
228402
228403
228404
228405
// @ts-check
const { log, errors } = __webpack_require__(1)
const soapRequest = __webpack_require__(1331)
const {
parseTags,
parseValue,
parseContractStartDate,
} = __webpack_require__(1555)
const xml2js = __webpack_require__(1513)
const { consulterDonneesTechniquesContractuelles } = __webpack_require__(1556)
/**
* Get user contract start date
* @param {string} url
* @param {string} apiAuthKey
* @param {string} userLogin
* @param {number} pointId
* @returns {Promise<string>}
*/
async function getContractStartDate(url, apiAuthKey, userLogin, pointId) {
log('info', 'Fetching data start date')
const sgeHeaders = {
'Content-Type': 'text/xml;charset=UTF-8',
apikey: apiAuthKey,
}
const { response } = await soapRequest({
url: `${url}/enedis_SGE_ConsultationDonneesTechniquesContractuelles/1.0`,
headers: sgeHeaders,
xml: consulterDonneesTechniquesContractuelles(pointId, userLogin),
}).catch(err => {
log('error', 'Error while fetching contract start date : ' + err)
throw errors.VENDOR_DOWN
})
const result = await xml2js.parseStringPromise(response.body, {
tagNameProcessors: [parseTags],
valueProcessors: [parseValue],
explicitArray: false,
})
try {
return parseContractStartDate(result)
} catch (error) {
log('error', 'Error while processing contract start date: ' + error)
log(
'error',
`Enedis issue ${result.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${result.Envelope.Body.Fault.faultstring}`
)
throw errors.NOT_EXISTING_DIRECTORY
}
}
module.exports = { getContractStartDate }
/***/ }),
/* 1603 */
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
const { log, updateOrCreate } = __webpack_require__(1)
228423
228424
228425
228426
228427
228428
228429
228430
228431
228432
228433
228434
228435
228436
228437
228438
228439
228440
228441
228442
228443
228444
228445
228446
228447
228448
228449
const cozyClient = __webpack_require__(485)
async function saveAccountData(accountId, accountData) {
log('info', `saveAccountData: ${accountId}`)
let account = await getAccount(accountId)
account = await updateOrCreate(
[{ ...account, data: accountData }],
'io.cozy.accounts'
)
return account
}
async function getAccount(accountId) {
log('info', `getAccount: ${accountId}`)
//TODO: refactor with usageof cozy-libs. Not working during implementation
const accounts = await cozyClient.data.findAll('io.cozy.accounts')
return accounts.filter(account =>
iSLocal() ? account._id === accountId : account.account_type === accountId
)[0]
}
module.exports = { getAccount, saveAccountData }
/***/ }),
/***/ ((module) => {
function iSLocal() {
process.env.NODE_ENV === 'development' ||
process.env.NODE_ENV === 'local' ||
process.env.NODE_ENV === 'standalone'
}
module.exports = { iSLocal }
228464
228465
228466
228467
228468
228469
228470
228471
228472
228473
228474
228475
228476
228477
228478
228479
228480
228481
228482
228483
228484
228485
228486
228487
228488
228489
228490
228491
228492
228493
228494
228495
228496
228497
228498
228499
228500
228501
228502
228503
228504
228505
228506
228507
228508
228509
228510
228511
228512
228513
228514
228515
228516
228517
228518
228519
228520
228521
228522
228523
228524
228525
228526
228527
228528
228529
228530
228531
228532
228533
228534
228535
228536
228537
228538
228539
228540
228541
228542
228543
228544
228545
228546
228547
228548
228549
228550
228551
228552
228553
228554
228555
/***/ })
/******/ ]);
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ id: moduleId,
/******/ loaded: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = __webpack_module_cache__;
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/node module decorator */
/******/ (() => {
/******/ __webpack_require__.nmd = (module) => {
/******/ module.paths = [];
/******/ if (!module.children) module.children = [];
/******/ return module;
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // module cache are used so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ var __webpack_exports__ = __webpack_require__(__webpack_require__.s = 0);
/******/
/******/ })()
;