Skip to content
Snippets Groups Projects
Commit 4f148f02 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

chore: node 20 + refactor dependencies

parent ff644c52
Branches
Tags
2 merge requests!43Merge dev into master,!38chore: node 20 + refactor dependencies
node_modules/
build/
data/
\ No newline at end of file
module.exports = {
extends: ['cozy-app', 'plugin:prettier/recommended'],
plugins: ['prettier'],
rules: {
'prettier/prettier': [
'error',
{ trailingComma: 'es5', arrowParens: 'avoid' },
],
},
}
...@@ -33,7 +33,7 @@ include: ...@@ -33,7 +33,7 @@ include:
- template: Security/SAST.gitlab-ci.yml - template: Security/SAST.gitlab-ci.yml
build: build:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14 image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:20.12.0-alpine3.19
stage: build stage: build
before_script: before_script:
- apk add git - apk add git
...@@ -50,7 +50,7 @@ build: ...@@ -50,7 +50,7 @@ build:
- build/ - build/
br_build_test: br_build_test:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14 image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:20.12.0-alpine3.19
stage: push-build stage: push-build
before_script: before_script:
- apk add git - apk add git
...@@ -71,7 +71,7 @@ br_build_test: ...@@ -71,7 +71,7 @@ br_build_test:
when: manual when: manual
br_build_dev: br_build_dev:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14 image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:20.12.0-alpine3.19
stage: push-build stage: push-build
before_script: before_script:
- apk add git - apk add git
...@@ -91,7 +91,7 @@ br_build_dev: ...@@ -91,7 +91,7 @@ br_build_dev:
- build - build
br_build: br_build:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14 image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:20.12.0-alpine3.19
stage: push-build stage: push-build
before_script: before_script:
- apk add git - apk add git
...@@ -111,7 +111,7 @@ br_build: ...@@ -111,7 +111,7 @@ br_build:
- build - build
unit-test: unit-test:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14 image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:20.12.0-alpine3.19
stage: test stage: test
before_script: before_script:
- apk add git - apk add git
...@@ -182,4 +182,4 @@ publish: ...@@ -182,4 +182,4 @@ publish:
- yarn cozyPublish - yarn cozyPublish
only: only:
- tags - tags
when: manual when: manual
\ No newline at end of file
v20.12.0
\ No newline at end of file
{ {
"endOfLine": "auto",
"semi": false,
"singleQuote": true, "singleQuote": true,
"semi": false "tabWidth": 2,
} "trailingComma": "es5",
"arrowParens": "avoid"
}
\ No newline at end of file
{
"presets": [
[
"cozy-app",
{
"node": true,
"react": false,
"lib": true
}
]
]
}
...@@ -13,24 +13,6 @@ ...@@ -13,24 +13,6 @@
"author": "Grand Lyon", "author": "Grand Lyon",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "./src/index.js", "main": "./src/index.js",
"eslintConfig": {
"extends": [
"cozy-app"
],
"prettier/prettier": [
"error",
{
"semi": true
}
]
},
"eslintIgnore": [
"build",
"data"
],
"husky": {
"hooks": {}
},
"jest": { "jest": {
"setupFiles": [ "setupFiles": [
"./setupTests.js" "./setupTests.js"
...@@ -53,30 +35,23 @@ ...@@ -53,30 +35,23 @@
"deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build}", "deploy": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build}",
"deploy-dev": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-dev}", "deploy-dev": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-dev}",
"deploy-test": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-test}", "deploy-test": "git-directory-deploy --directory build/ --branch ${DEPLOY_BRANCH:-build-test}",
"cozyPublish": "cozy-app-publish --token $REGISTRY_TOKEN --build-commit $(git rev-parse ${DEPLOY_BRANCH:-build})",
"travisDeployKey": "./bin/generate_travis_deploy_key" "travisDeployKey": "./bin/generate_travis_deploy_key"
}, },
"dependencies": { "dependencies": {
"@sentry/node": "^7.113.0", "@sentry/node": "^8.17.0",
"@sentry/tracing": "^7.113.0", "@sentry/tracing": "^7.113.0",
"axios": "^0.20.0", "axios": "^1.7.2",
"cozy-client": "23.22.0", "cozy-client": "48.7.0",
"cozy-konnector-libs": "5.10.1", "cozy-konnector-libs": "5.11.0",
"jest": "^29.7.0",
"moment": "^2.30.1", "moment": "^2.30.1",
"moment-timezone": "^0.5.45", "moment-timezone": "^0.5.45",
"qs": "^6.12.1" "qs": "^6.12.1"
}, },
"devDependencies": { "devDependencies": {
"copy-webpack-plugin": "6.1.1", "cozy-jobs-cli": "2.4.2",
"cozy-app-publish": "0.34.0", "cozy-konnector-build": "1.7.0",
"cozy-jobs-cli": "1.13.6", "jest": "^29.7.0",
"eslint-config-cozy-app": "1.6.0",
"git-directory-deploy": "1.5.1",
"jest-junit": "^16.0.0", "jest-junit": "^16.0.0",
"standard-version": "^9.5.0", "standard-version": "^9.5.0"
"svgo": "1.3.2",
"webpack": "5.91.0",
"webpack-cli": "5.1.4"
} }
} }
const { log } = require('cozy-konnector-libs')
const CozyClient = require('cozy-client').default
const { Q } = require('cozy-client')
const {
APP_NAME,
DOCTYPE_ACCOUNTS,
DOCTYPE_ACCOUNTS_VERSION
} = require('./constants')
function getAccessToken(environment) {
try {
if (environment === 'development') {
const cozyCredentials = JSON.parse(process.env.COZY_CREDENTIALS)
return cozyCredentials.token.accessToken
} else {
return process.env.COZY_CREDENTIALS.trim()
}
} catch (err) {
log(
'error',
`Please provide proper COZY_CREDENTIALS environment variable. ${process.env.COZY_CREDENTIALS} is not OK`
)
throw err
}
}
function getCozyUrl() {
if (process.env.COZY_URL === undefined) {
log('error', 'Please provide COZY_URL environment variable.')
throw new Error('COZY_URL environment variable is absent/not valid')
} else {
return process.env.COZY_URL
}
}
function getSchema() {
return {
accounts: {
doctype: DOCTYPE_ACCOUNTS,
doctypeVersion: DOCTYPE_ACCOUNTS_VERSION
}
}
}
function initCozyClient(accountId) {
const environment =
process.env.NODE_ENV === 'none' ? 'production' : process.env.NODE_ENV
try {
const uri = getCozyUrl(environment)
const token = getAccessToken(environment)
const appMetadata = {
slug: APP_NAME,
sourceAccount: accountId,
version: '1.0.3'
}
const schema = getSchema()
return new CozyClient({ uri, token, appMetadata, schema })
} catch (err) {
log('error', 'Unable to initialize cozy client')
throw err
}
}
class CozyUtils {
constructor(accountId) {
this.client = initCozyClient(accountId)
}
/*
Update io.cozy.accounts auth.accountName field
*/
async getAccountInfos(accountId) {
try {
log('debug', 'SENDING FIND HARVEST ECOLYO REQUEST ACCOUNT : ' + accountId)
const query = Q(DOCTYPE_ACCOUNTS)
// eslint-disable-next-line @typescript-eslint/camelcase
.where({ account_type: 'grdfgrandlyon' })
.limitBy(1)
const { data: accounts } = await this.client.query(query)
return accounts[0] ? accounts[0] : null
} catch (err) {
log(
'warn',
`Error while trying to fetch account info (for ${accountId}): ${err.message}`
)
}
}
save(params) {
return this.client.save(params)
}
}
module.exports = CozyUtils
...@@ -6,21 +6,21 @@ const DOCTYPE_ACCOUNTS_VERSION = 1 ...@@ -6,21 +6,21 @@ const DOCTYPE_ACCOUNTS_VERSION = 1
const rangeDate = { const rangeDate = {
day: { day: {
doctype: 'com.grandlyon.grdf.day', doctype: 'com.grandlyon.grdf.day',
keys: ['year', 'month', 'day'] keys: ['year', 'month', 'day'],
}, },
month: { month: {
doctype: 'com.grandlyon.grdf.month', doctype: 'com.grandlyon.grdf.month',
keys: ['year', 'month'] keys: ['year', 'month'],
}, },
year: { year: {
doctype: 'com.grandlyon.grdf.year', doctype: 'com.grandlyon.grdf.year',
keys: ['year'] keys: ['year'],
} },
} }
module.exports = { module.exports = {
APP_NAME, APP_NAME,
DOCTYPE_ACCOUNTS, DOCTYPE_ACCOUNTS,
DOCTYPE_ACCOUNTS_VERSION, DOCTYPE_ACCOUNTS_VERSION,
rangeDate rangeDate,
} }
...@@ -55,7 +55,7 @@ async function handleConsents(consents, boUrlGRDF, boToken) { ...@@ -55,7 +55,7 @@ async function handleConsents(consents, boUrlGRDF, boToken) {
await deleteBoConsent({ await deleteBoConsent({
boUrlGRDF, boUrlGRDF,
boToken, boToken,
consentId: accountData.data.consentId consentId: accountData.data.consentId,
}) })
delete accountData.data.consentId delete accountData.data.consentId
await saveAccountData(accountData) await saveAccountData(accountData)
...@@ -85,12 +85,12 @@ async function createConsent({ ...@@ -85,12 +85,12 @@ async function createConsent({
startDate, startDate,
endDate, endDate,
boToken, boToken,
boUrlGRDF boUrlGRDF,
}) { }) {
const transaction = Sentry.startTransaction({ const transaction = Sentry.startTransaction({
op: 'konnector', op: 'konnector',
name: 'createConsent', name: 'createConsent',
tags: { pce } tags: { pce },
}) })
const startDateString = moment(startDate).format('YYYY-MM-DD') const startDateString = moment(startDate).format('YYYY-MM-DD')
const endDateString = moment(endDate).format('YYYY-MM-DD') const endDateString = moment(endDate).format('YYYY-MM-DD')
...@@ -108,7 +108,7 @@ async function createConsent({ ...@@ -108,7 +108,7 @@ async function createConsent({
firstname, firstname,
lastname, lastname,
postalCode, postalCode,
endDate endDate,
}).catch(err => { }).catch(err => {
log('error', `Failed to create BO consent, ${err}`) log('error', `Failed to create BO consent, ${err}`)
throw errors.MAINTENANCE throw errors.MAINTENANCE
...@@ -118,7 +118,7 @@ async function createConsent({ ...@@ -118,7 +118,7 @@ async function createConsent({
const accountData = await getAccount(ACCOUNT_ID) const accountData = await getAccount(ACCOUNT_ID)
await saveAccountData(ACCOUNT_ID, { await saveAccountData(ACCOUNT_ID, {
...accountData.data, ...accountData.data,
consentId: consentId consentId: consentId,
}) })
await createGRDFConsent({ await createGRDFConsent({
...@@ -128,12 +128,12 @@ async function createConsent({ ...@@ -128,12 +128,12 @@ async function createConsent({
pce, pce,
postalCode, postalCode,
startDate: startDateString, startDate: startDateString,
endDate: endDateString endDate: endDateString,
}).catch(async err => { }).catch(async err => {
await deleteBoConsent({ await deleteBoConsent({
boUrlGRDF, boUrlGRDF,
boToken, boToken,
consentId: consentId consentId: consentId,
}) })
throw err throw err
}) })
......
...@@ -21,10 +21,10 @@ function formatData(data) { ...@@ -21,10 +21,10 @@ function formatData(data) {
month: parseInt(date.format('M')), month: parseInt(date.format('M')),
day: parseInt(date.format('D')), day: parseInt(date.format('D')),
hour: parseInt(date.format('H')), hour: parseInt(date.format('H')),
minute: parseInt(date.format('m')) minute: parseInt(date.format('m')),
} }
} }
module.exports = { module.exports = {
formatData formatData,
} }
...@@ -22,7 +22,7 @@ function aggregateMonthlyLoad(data) { ...@@ -22,7 +22,7 @@ function aggregateMonthlyLoad(data) {
month: month, month: month,
day: 0, day: 0,
hour: 0, hour: 0,
minute: 0 minute: 0,
} }
} else { } else {
monthlyLoad[monthKey].load += load monthlyLoad[monthKey].load += load
...@@ -52,7 +52,7 @@ function aggregateYearlyLoad(data) { ...@@ -52,7 +52,7 @@ function aggregateYearlyLoad(data) {
month: 0, month: 0,
day: 0, day: 0,
hour: 0, hour: 0,
minute: 0 minute: 0,
} }
} else { } else {
yearlyLoad[year].load += load yearlyLoad[year].load += load
...@@ -79,7 +79,7 @@ async function filterFirstMonthlyLoad(firstMonth, firstYear, monthlyLoads) { ...@@ -79,7 +79,7 @@ async function filterFirstMonthlyLoad(firstMonth, firstYear, monthlyLoads) {
) )
const startDateMonthlyLoad = await cozyClient.data.query(monthlyLoadRef, { const startDateMonthlyLoad = await cozyClient.data.query(monthlyLoadRef, {
selector: { year: firstYear, month: firstMonth }, selector: { year: firstYear, month: firstMonth },
limit: 1 limit: 1,
}) })
if (!startDateMonthlyLoad.length) { if (!startDateMonthlyLoad.length) {
...@@ -108,7 +108,7 @@ async function filterFirstYearlyLoad(firstYear, yearlyLoads) { ...@@ -108,7 +108,7 @@ async function filterFirstYearlyLoad(firstYear, yearlyLoads) {
) )
const startDateYearlyLoad = await cozyClient.data.query(yearlyLoadRef, { const startDateYearlyLoad = await cozyClient.data.query(yearlyLoadRef, {
selector: { year: firstYear }, selector: { year: firstYear },
limit: 1 limit: 1,
}) })
if (!startDateYearlyLoad.length) { if (!startDateYearlyLoad.length) {
return yearlyLoads return yearlyLoads
...@@ -122,5 +122,5 @@ module.exports = { ...@@ -122,5 +122,5 @@ module.exports = {
aggregateMonthlyLoad, aggregateMonthlyLoad,
aggregateYearlyLoad, aggregateYearlyLoad,
filterFirstMonthlyLoad, filterFirstMonthlyLoad,
filterFirstYearlyLoad filterFirstYearlyLoad,
} }
// @ts-check // @ts-check
require('./instrument.js') // Sentry initialization
const { const {
BaseKonnector, BaseKonnector,
hydrateAndFilter, hydrateAndFilter,
errors, errors,
log, log,
updateOrCreate updateOrCreate,
} = require('cozy-konnector-libs') } = require('cozy-konnector-libs')
const getDataGenericErrors = require('./helpers/getDataGenericErrors') const getDataGenericErrors = require('./helpers/getDataGenericErrors')
const { isDev } = require('./helpers/env')
const moment = require('moment') const moment = require('moment')
require('moment-timezone') require('moment-timezone')
moment.locale('fr') // set the language moment.locale('fr') // set the language
moment.tz.setDefault('Europe/Paris') // set the timezone moment.tz.setDefault('Europe/Paris') // set the timezone
const Sentry = require('@sentry/node') const Sentry = require('@sentry/node')
// eslint-disable-next-line
const Tracing = require('@sentry/tracing') // Needed for tracking performance in Sentry
const { version } = require('../package.json')
const { getAuthToken, getConsents } = require('./requests/grdf') const { getAuthToken, getConsents } = require('./requests/grdf')
const { handleConsents, createConsent } = require('./core/core') const { handleConsents, createConsent } = require('./core/core')
const { rangeDate } = require('./constants') const { rangeDate } = require('./constants')
...@@ -23,36 +20,15 @@ const { ...@@ -23,36 +20,15 @@ const {
aggregateMonthlyLoad, aggregateMonthlyLoad,
filterFirstMonthlyLoad, filterFirstMonthlyLoad,
aggregateYearlyLoad, aggregateYearlyLoad,
filterFirstYearlyLoad filterFirstYearlyLoad,
} = require('./helpers/utils') } = require('./helpers/utils')
const { formatData } = require('./helpers/format') const { formatData } = require('./helpers/format')
Sentry.init({
dsn:
'https://fa503fe00434433f805d1c715999b7f5@grandlyon.errors.cozycloud.cc/3',
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
release: version,
environment: isDev() ? 'development' : 'production',
debug: isDev(),
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true })
]
})
Sentry.setTag('method', 'TIERS-DIRECT')
const NO_DATA = process.env.NO_DATA === 'true' const NO_DATA = process.env.NO_DATA === 'true'
const manualExecution = process.env.COZY_JOB_MANUAL_EXECUTION === 'true' const manualExecution = process.env.COZY_JOB_MANUAL_EXECUTION === 'true'
// dates related to consents // dates related to consents
const startDate = moment().subtract(3, 'year') const startDate = moment().subtract(3, 'year')
const endDate = moment() const endDate = moment().startOf('day').add(1, 'year')
.startOf('day')
.add(1, 'year')
// dates related to getting data // dates related to getting data
const dataStartDate = moment().subtract(manualExecution ? 1 : 3, 'year') const dataStartDate = moment().subtract(manualExecution ? 1 : 3, 'year')
const dataEndDate = moment().startOf('day') const dataEndDate = moment().startOf('day')
...@@ -87,11 +63,6 @@ async function start(fields, cozyParameters) { ...@@ -87,11 +63,6 @@ async function start(fields, cozyParameters) {
log('info', `OAuth callback result found, using pce ${pce}`) log('info', `OAuth callback result found, using pce ${pce}`)
} }
const transaction = Sentry.startTransaction({
op: 'konnector',
name: 'start',
tags: { pce }
})
let boToken = '' let boToken = ''
let boBaseUrl = '' let boBaseUrl = ''
let grdfId = '' let grdfId = ''
...@@ -132,7 +103,7 @@ async function start(fields, cozyParameters) { ...@@ -132,7 +103,7 @@ async function start(fields, cozyParameters) {
startDate, startDate,
endDate, endDate,
boUrlGRDF, boUrlGRDF,
boToken boToken,
}) })
} }
...@@ -144,8 +115,6 @@ async function start(fields, cozyParameters) { ...@@ -144,8 +115,6 @@ async function start(fields, cozyParameters) {
) )
if (grdfData.length == 0) { if (grdfData.length == 0) {
log('debug', 'No data found') log('debug', 'No data found')
transaction.setStatus(Tracing.SpanStatus.Ok)
transaction.finish()
return return
} }
...@@ -154,7 +123,7 @@ async function start(fields, cozyParameters) { ...@@ -154,7 +123,7 @@ async function start(fields, cozyParameters) {
grdfData, grdfData,
rangeDate.day.doctype, rangeDate.day.doctype,
{ {
keys: ['year', 'month', 'day', 'load'] keys: ['year', 'month', 'day', 'load'],
} }
) )
log('debug', 'Store GRDF daily load data') log('debug', 'Store GRDF daily load data')
...@@ -198,18 +167,14 @@ async function start(fields, cozyParameters) { ...@@ -198,18 +167,14 @@ async function start(fields, cozyParameters) {
rangeDate.year.doctype, rangeDate.year.doctype,
rangeDate.year.keys rangeDate.year.keys
) )
transaction.setStatus(Tracing.SpanStatus.Ok)
transaction.finish()
} catch (error) { } catch (error) {
log('error', 'Start failed', error) log('error', 'Start failed', error)
Sentry.captureException(error, { Sentry.captureException(error, {
tags: { tags: {
section: 'start', section: 'start',
pce pce,
} },
}) })
transaction.finish()
await Sentry.flush() await Sentry.flush()
throw error throw error
} }
...@@ -234,11 +199,6 @@ function buildGetDataUrl(idPCE, startDate, endDate) { ...@@ -234,11 +199,6 @@ function buildGetDataUrl(idPCE, startDate, endDate) {
* @param {string} endDate 'YYYY-MM-DD' * @param {string} endDate 'YYYY-MM-DD'
*/ */
async function getData(token, idPCE, startDate, endDate) { async function getData(token, idPCE, startDate, endDate) {
const transaction = Sentry.startTransaction({
op: 'konnector',
name: 'getData',
tags: { pce: idPCE }
})
log('debug', `getData from ${startDate} to ${endDate}`) log('debug', `getData from ${startDate} to ${endDate}`)
const url = buildGetDataUrl(idPCE, startDate, endDate) const url = buildGetDataUrl(idPCE, startDate, endDate)
...@@ -247,9 +207,9 @@ async function getData(token, idPCE, startDate, endDate) { ...@@ -247,9 +207,9 @@ async function getData(token, idPCE, startDate, endDate) {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/x-ndjson', 'Content-Type': 'application/x-ndjson',
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`,
}, },
redirect: 'follow' redirect: 'follow',
}) })
if (response.status !== 200) { if (response.status !== 200) {
...@@ -298,12 +258,11 @@ async function getData(token, idPCE, startDate, endDate) { ...@@ -298,12 +258,11 @@ async function getData(token, idPCE, startDate, endDate) {
`Get data threw an error: ${result.statut_restitution.code} - ${result.statut_restitution.message}`, `Get data threw an error: ${result.statut_restitution.code} - ${result.statut_restitution.message}`,
{ {
tags: { tags: {
section: 'getData' section: 'getData',
} },
} }
) )
throw genError throw genError
} }
transaction.finish()
return formattedData return formattedData
} }
const Sentry = require('@sentry/node')
const { version } = require('../package.json')
const { isDev } = require('./helpers/env')
Sentry.init({
dsn: 'https://fa503fe00434433f805d1c715999b7f5@grandlyon.errors.cozycloud.cc/3',
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
release: version,
environment: isDev() ? 'development' : 'production',
debug: isDev(),
autoSessionTracking: true,
})
Sentry.setTag('method', 'TIERS-DIRECT')
...@@ -22,8 +22,8 @@ onDeleteAccount().then( ...@@ -22,8 +22,8 @@ onDeleteAccount().then(
log('error', errorMessage) log('error', errorMessage)
Sentry.captureException(errorMessage, { Sentry.captureException(errorMessage, {
tags: { tags: {
section: 'onDeleteAccount' section: 'onDeleteAccount',
} },
}) })
} }
) )
......
...@@ -20,13 +20,13 @@ async function createBoConsent({ ...@@ -20,13 +20,13 @@ async function createBoConsent({
lastname, lastname,
firstname, firstname,
postalCode, postalCode,
endDate endDate,
}) { }) {
log('info', `Query createBoConsent`) log('info', `Query createBoConsent`)
const headers = { const headers = {
headers: { headers: {
Authorization: `Bearer ${boToken}` Authorization: `Bearer ${boToken}`,
} },
} }
try { try {
...@@ -37,7 +37,7 @@ async function createBoConsent({ ...@@ -37,7 +37,7 @@ async function createBoConsent({
firstname, firstname,
pce, pce,
postalCode, postalCode,
endDate: endDate.toISOString() endDate: endDate.toISOString(),
}, },
headers headers
) )
...@@ -47,11 +47,11 @@ async function createBoConsent({ ...@@ -47,11 +47,11 @@ async function createBoConsent({
log('error', errorMessage) log('error', errorMessage)
Sentry.captureException(errorMessage, { Sentry.captureException(errorMessage, {
tags: { tags: {
section: 'createBoConsent' section: 'createBoConsent',
}, },
extra: { extra: {
pce pce,
} },
}) })
throw new Error(errors.MAINTENANCE) throw new Error(errors.MAINTENANCE)
} }
...@@ -67,8 +67,8 @@ async function deleteBoConsent({ boUrlGRDF, boToken, consentId }) { ...@@ -67,8 +67,8 @@ async function deleteBoConsent({ boUrlGRDF, boToken, consentId }) {
log('info', `Query deleteBoConsent ${consentId}`) log('info', `Query deleteBoConsent ${consentId}`)
const headers = { const headers = {
headers: { headers: {
Authorization: `Bearer ${boToken}` Authorization: `Bearer ${boToken}`,
} },
} }
try { try {
const { data } = await axios.delete( const { data } = await axios.delete(
...@@ -81,11 +81,11 @@ async function deleteBoConsent({ boUrlGRDF, boToken, consentId }) { ...@@ -81,11 +81,11 @@ async function deleteBoConsent({ boUrlGRDF, boToken, consentId }) {
log('error', errorMessage) log('error', errorMessage)
Sentry.captureException(errorMessage, { Sentry.captureException(errorMessage, {
tags: { tags: {
section: 'deleteBoConsent' section: 'deleteBoConsent',
}, },
extra: { extra: {
consentId: consentId consentId: consentId,
} },
}) })
// Don't throw an error, just log it // Don't throw an error, just log it
} }
...@@ -93,5 +93,5 @@ async function deleteBoConsent({ boUrlGRDF, boToken, consentId }) { ...@@ -93,5 +93,5 @@ async function deleteBoConsent({ boUrlGRDF, boToken, consentId }) {
module.exports = { module.exports = {
createBoConsent, createBoConsent,
deleteBoConsent deleteBoConsent,
} }
...@@ -25,7 +25,7 @@ async function saveAccountData(accountId, accountData) { ...@@ -25,7 +25,7 @@ async function saveAccountData(accountId, accountData) {
'info', 'info',
`saveAccountData account: ${JSON.stringify({ `saveAccountData account: ${JSON.stringify({
...account, ...account,
data: accountData data: accountData,
})}` })}`
) )
...@@ -33,7 +33,7 @@ async function saveAccountData(accountId, accountData) { ...@@ -33,7 +33,7 @@ async function saveAccountData(accountId, accountData) {
'info', 'info',
`saveAccountData account after id: ${JSON.stringify({ `saveAccountData account after id: ${JSON.stringify({
...account, ...account,
data: accountData data: accountData,
})}` })}`
) )
account = await updateOrCreate( account = await updateOrCreate(
......
...@@ -16,15 +16,14 @@ async function getAuthToken(client_id, client_secret) { ...@@ -16,15 +16,14 @@ async function getAuthToken(client_id, client_secret) {
scope: '/adict/v2', scope: '/adict/v2',
grant_type: 'client_credentials', grant_type: 'client_credentials',
client_id: client_id, client_id: client_id,
client_secret: client_secret client_secret: client_secret,
} }
try { try {
const response = await Axios({ const response = await Axios({
method: 'POST', method: 'POST',
url: url: 'https://adict-connexion.grdf.fr/oauth2/aus5y2ta2uEHjCWIR417/v1/token',
'https://adict-connexion.grdf.fr/oauth2/aus5y2ta2uEHjCWIR417/v1/token',
headers: { 'content-type': 'application/x-www-form-urlencoded' }, headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify(body) data: qs.stringify(body),
}) })
return response.data return response.data
...@@ -32,8 +31,8 @@ async function getAuthToken(client_id, client_secret) { ...@@ -32,8 +31,8 @@ async function getAuthToken(client_id, client_secret) {
log('error', 'Error inside getAuthToken', error) log('error', 'Error inside getAuthToken', error)
Sentry.captureException('Error while getting auth token', { Sentry.captureException('Error while getting auth token', {
tags: { tags: {
section: 'getAuthToken' section: 'getAuthToken',
} },
}) })
throw errors.VENDOR_DOWN throw errors.VENDOR_DOWN
} }
...@@ -51,9 +50,9 @@ async function getConsents(bearerToken, pce) { ...@@ -51,9 +50,9 @@ async function getConsents(bearerToken, pce) {
method: 'POST', method: 'POST',
headers: { headers: {
Authorization: `Bearer ${bearerToken}`, Authorization: `Bearer ${bearerToken}`,
'Content-Type': 'application/json' 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ id_pce: [pce] }) body: JSON.stringify({ id_pce: [pce] }),
}) })
const rawData = await response.text() const rawData = await response.text()
const consents = [] const consents = []
...@@ -76,8 +75,8 @@ async function getConsents(bearerToken, pce) { ...@@ -76,8 +75,8 @@ async function getConsents(bearerToken, pce) {
log('error', error) log('error', error)
Sentry.captureException('Error while getting consent', { Sentry.captureException('Error while getting consent', {
tags: { tags: {
section: 'getConsents' section: 'getConsents',
} },
}) })
throw errors.VENDOR_DOWN throw errors.VENDOR_DOWN
} }
...@@ -90,7 +89,7 @@ async function createGRDFConsent({ ...@@ -90,7 +89,7 @@ async function createGRDFConsent({
lastname, lastname,
postalCode, postalCode,
startDate, startDate,
endDate endDate,
}) { }) {
try { try {
log('info', `Creating GRDF consent from ${startDate} to ${endDate}`) log('info', `Creating GRDF consent from ${startDate} to ${endDate}`)
...@@ -112,8 +111,8 @@ async function createGRDFConsent({ ...@@ -112,8 +111,8 @@ async function createGRDFConsent({
perim_donnees_contractuelles: 'Vrai', perim_donnees_contractuelles: 'Vrai',
perim_donnees_techniques: 'Vrai', perim_donnees_techniques: 'Vrai',
perim_donnees_informatives: 'Vrai', perim_donnees_informatives: 'Vrai',
perim_donnees_publiees: 'Vrai' perim_donnees_publiees: 'Vrai',
} },
}) })
log('info', response.data.message_retour_traitement) log('info', response.data.message_retour_traitement)
} catch (error) { } catch (error) {
...@@ -121,8 +120,8 @@ async function createGRDFConsent({ ...@@ -121,8 +120,8 @@ async function createGRDFConsent({
log('error', error.response.data) log('error', error.response.data)
Sentry.captureException('Failed to create GRDF consent', { Sentry.captureException('Failed to create GRDF consent', {
tags: { tags: {
section: 'createGRDFConsent' section: 'createGRDFConsent',
} },
}) })
throw errors.USER_ACTION_NEEDED_CGU_FORM throw errors.USER_ACTION_NEEDED_CGU_FORM
} }
......
var path = require('path') module.exports = require('cozy-konnector-build/webpack.config')
const CopyPlugin = require('copy-webpack-plugin')
const webpack = require('webpack')
const fs = require('fs')
const SvgoInstance = require('svgo')
const index = require('./package.json').main
const readManifest = () =>
JSON.parse(fs.readFileSync(path.join(__dirname, './manifest.konnector')))
const svgo = new SvgoInstance({
plugins: [
{
inlineStyles: { onlyMatchedOnce: false }
}
]
})
let iconName
try {
iconName = JSON.parse(fs.readFileSync('manifest.konnector', 'utf8')).icon
// we run optimize only on SVG
if (!iconName.match(/\.svg$/)) iconName = null
} catch (e) {
// console.error(`Unable to read the icon path from manifest: ${e}`)
}
const appIconRX = iconName && new RegExp(`[^/]*/${iconName}`)
module.exports = {
entry: {
index,
onDeleteAccount: './src/onDeleteAccount.js'
},
target: 'node',
mode: 'none',
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js'
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'manifest.konnector' },
{ from: 'package.json' },
{ from: 'README.md' },
{ from: 'assets', transform: optimizeSVGIcon },
{ from: '.travis.yml' },
{ from: 'LICENSE' }
]
}),
new webpack.DefinePlugin({
__WEBPACK_PROVIDED_MANIFEST__: JSON.stringify(readManifest())
})
],
module: {
// to ignore the warnings like :
// WARNING in ../libs/node_modules/bindings/bindings.js 76:22-40
// Critical dependency: the request of a dependency is an expression
// Since we cannot change this dependency. I think it won't hide more important messages
exprContextCritical: false
}
}
function optimizeSVGIcon(buffer, path) {
if (appIconRX && path.match(appIconRX)) {
return svgo.optimize(buffer).then(resp => resp.data)
} else {
return buffer
}
}
yarn.lock 100755 → 100644
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment