Commit 02cfc704 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat(dacc): add indicators sending to cozy dacc.

parent b378a39a
......@@ -7,6 +7,7 @@ yarn-error.log
scripts/AAAA*
scripts/config.js
scripts/data/
.token.json
# Report
public/report.html
......
......@@ -53,7 +53,7 @@ build-dev:
- apk add bash
script:
- yarn
- yarn build
- yarn build-dev
- git config --global user.name build-pipeline
- git config --global user.email "$GIT_USER"
- git config --global user.password "$GIT_PWD"
......
'use strict'
/**
* This file overrides the default cozy webpack config to specify a custom react config.
* This react config enables the use of TypeScript.
*
* @override node_modules/cozy-scripts/config/webpack.bundle.default.js
*/
const merge = require('webpack-merge')
const { target, addAnalyzer } = require('cozy-scripts/config/webpack.vars')
const configs = [
require('cozy-scripts/config/webpack.config.base'),
require('cozy-scripts/config/webpack.config.chunks'),
//require('cozy-scripts/config/webpack.config.react'),
require('./app.config.react'), // Override the react config
require('cozy-scripts/config/webpack.config.cozy-ui'),
require('cozy-scripts/config/webpack.config.cozy-ui.react'),
require('cozy-scripts/config/webpack.config.intents'),
require('cozy-scripts/config/webpack.config.public'),
require('cozy-scripts/config/webpack.config.pictures'),
require('cozy-scripts/config/webpack.config.vendors'),
require('cozy-scripts/config/webpack.config.manifest'),
require('cozy-scripts/config/webpack.config.progress'),
addAnalyzer ? require('cozy-scripts/config/webpack.config.analyzer') : null,
// require('cozy-scripts/config/webpack.config.services'),
require('./app.config.services'), // Override the services config
require(`cozy-scripts/config/webpack.target.${target}`),
]
configs.push(require('./app.config.environment.alpha'))
//module.exports = merge.apply(null, configs)
module.exports = [merge.apply(null, configs)] // cozy builder expects an array
'use strict'
const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const { target } = require('cozy-scripts/config/webpack.vars')
module.exports = {
mode: 'none',
plugins: [
// use a hash as chunk id to avoid id changes of not changing chunk
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'), // to compile on production mode (redux)
__DEVELOPMENT__: false,
__DEVTOOLS__: false,
__STACK_ASSETS__: target !== 'mobile',
}),
],
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
//To fix a SAfari 10 bug : https://github.com/zeit/next.js/issues/5630
terserOptions: {
safari10: true,
},
}),
],
},
}
......@@ -17,6 +17,7 @@ let plugins = [
const stackProvidedLibsConfig = {
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
__STACK_ASSETS__: true,
}),
],
......
......@@ -30,7 +30,7 @@ const configs = [
addAnalyzer ? require('cozy-scripts/config/webpack.config.analyzer') : null,
// require('cozy-scripts/config/webpack.config.services'),
require('./app.config.services'), // Override the services config
require(`cozy-scripts/config/webpack.target.${target}`)
require(`cozy-scripts/config/webpack.target.${target}`),
]
if (environment === 'production') {
......
......@@ -41,6 +41,12 @@
},
"settings": {
"description": "Requis pour afficher les paramètres Cozy dans la barre Cozy."
},
"dacc-dev": {
"description": "Requis pour envoyer des statistiques d'utilisation anonymisées."
},
"dacc": {
"description": "Requis pour envoyer des statistiques d'utilisation anonymisées."
}
}
},
......@@ -77,6 +83,12 @@
},
"settings": {
"description": "Required to display Cozy settings in the Cozy bar."
},
"dacc-dev": {
"description": "Required for sending cozy anonymized stats."
},
"dacc": {
"description": "Required for sending cozy anonymized stats."
}
}
}
......@@ -98,6 +110,11 @@
"type": "node",
"file": "services/monthlyReportNotification/ecolyo.js",
"trigger": "@cron 0 0 10 3 * *"
},
"aggregatorUsageEvents": {
"type": "node",
"file": "services/aggregatorUsageEvents/ecolyo.js",
"trigger": "@cron 0 1 * * *"
}
},
"permissions": {
......@@ -132,6 +149,14 @@
"settings": {
"type": "io.cozy.settings",
"verbs": ["GET"]
},
"dacc": {
"type": "cc.cozycloud.dacc",
"verbs": ["ALL"]
},
"dacc-dev": {
"type": "cc.cozycloud.dacc.dev",
"verbs": ["ALL"]
}
}
}
......@@ -8,6 +8,8 @@
"lint:styles": "stylint src/styles --config ./.stylintrc",
"prebuild": "yarn lint",
"build:cs": "build:browser",
"build-dev:browser": "cs build --browser --config app.config.alpha.js",
"build-dev:mobile": "cs build --mobile --config app.config.alpha.js",
"build:browser": "cs build --browser ",
"build:mobile": "cs build --mobile",
"watch": "yarn watch:browser",
......@@ -23,6 +25,7 @@
"watch:css": "yarn run build:css && node-sass -c -w ./src/styles -o src/styles",
"start": "npm-run-all -p start:cs",
"build": "yarn run build:css && yarn run build:browser",
"build-dev": "yarn run build:css && yarn run build-dev:browser",
"release": "standard-version --no-verify",
"winstack": "start powershell -command docker run --rm -it -p 8080:8080 -p 5984:5984 -p 8025:8025 -v $PWD/build:/data/cozy-app/ecolyo -v $PWD/data:/usr/local/couchdb/data -v $PWD/docker/disableCSP.yaml:/etc/cozy/cozy.yaml registry.forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/cozy-env",
"linuxstack": "docker run --rm -it -p 8080:8080 -p 5984:5984 -p 8025:8025 -v $(pwd)/build:/data/cozy-app/ecolyo -v ~/cozy/data/db:/usr/local/couchdb/data -v ~/cozy/data/storage:/data/cozy-storage -v $(pwd)/docker/disableCSP.yaml:/etc/cozy/cozy.yaml registry.forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/cozy-env",
......
const http = require('http')
const process = (request, response) => {
setTimeout(() => {
response.end()
}, 100)
}
console.log('Listening on port 8081...')
http
.createServer(function(request, response) {
const requestStart = Date.now()
let errorMessage = null
let body = []
request.on('data', chunk => {
body.push(chunk)
})
request.on('end', () => {
body = Buffer.concat(body)
body = body.toString()
})
request.on('error', error => {
errorMessage = error.message
})
response.on('finish', () => {
const { rawHeaders, httpVersion, method, socket, url } = request
const { remoteAddress, remoteFamily } = socket
// console.log(
// JSON.stringify({
// timestamp: Date.now(),
// processingTime: Date.now() - requestStart,
// rawHeaders,
// errorMessage,
// httpVersion,
// method,
// remoteAddress,
// remoteFamily,
// url,
// })
// )
console.log(JSON.parse(body))
})
process(request, response)
})
.listen(8081)
export enum DaccEvent {
CONNECTION_COUNT_DAILY = 'connection-count-daily',
KONNECTOR_EVENT_DAILY = 'konnector-event-daily',
KONNECTOR_CONNECTED_PER_DAY = 'konnector-connected-daily',
NAVIGATION_COUNT_DAILY = 'navigation-count-daily',
CHALLENGE_LAUNCH_EVENT_DAILY = 'challenge-launch-daily',
CONSUMPTION_VARIATION_MONTHLY = 'consumption-variation-monthly',
SESSION_DURATION = 'session-duration',
NAVIGATION_ACTION_DAILY = 'navigation-action-daily',
EVENT_DURATION = 'event-duration',
QUIZ_STARS = 'quiz-stars',
}
export enum UsageEventType {
CONNECTION_EVENT = 'ConnectionEvent',
KONNECTOR_CONNECT_EVENT = 'KonnectorConnectEvent',
KONNECTOR_REFRESH_EVENT = 'KonnectorRefreshEvent',
NAVIGATION_EVENT = 'NavigationEvent',
CONSUMPTION_COMPARE_EVENT = 'ConsumptionCompareEvent',
CONSUMPTION_CHANGE_TIMESTEP_EVENT = 'ConsumptionChangeTimeStepEvent',
CHALLENGE_LAUNCH_EVENT = 'ChallengeLaunchEvent',
CHALLENGE_END_EVENT = 'ChallengeEndEvent',
DUEL_LAUNCH_EVENT = 'DuelLaunchEvent',
DUEL_END_EVENT = 'DuelEndEvent',
QUIZ_END_EVENT = 'QuizEndEvent',
EXPLORATION_END_EVENT = 'ExplorationEndEvent',
ACTION_CHANGE_EVENT = 'ActionChangeEvent',
ACTION_END_EVENT = 'ActionEndEvent',
PROFILE_SET_EVENT = 'ProfileSetEvent',
}
export enum UsageEventType {
CONNECTION_EVENT = 'ConnectionEvent',
KONNECTOR_CONNECT_EVENT = 'KonnectorConnectEvent',
KONNECTOR_REFRESH_EVENT = 'KonnectorRefreshEvent',
NAVIGATION_EVENT = 'NavigationEvent',
CONSUMPTION_COMPARE_EVENT = 'ConsumptionCompareEvent',
CONSUMPTION_CHANGE_TIMESTEP_EVENT = 'ConsumptionChangeTimeStepEvent',
CHALLENGE_LAUNCH_EVENT = 'ChallengeLaunchEvent',
CHALLENGE_END_EVENT = 'ChallengeEndEvent',
DUEL_LAUNCH_EVENT = 'DuelLaunchEvent',
DUEL_END_EVENT = 'DuelEndEvent',
QUIZ_END_EVENT = 'QuizEndEvent',
EXPLORATION_END_EVENT = 'ExplorationEndEvent',
ACTION_CHANGE_EVENT = 'ActionChangeEvent',
ACTION_END_EVENT = 'ActionEndEvent',
PROFILE_SET_EVENT = 'ProfileSetEvent',
}
export enum UsageEventProperties {
TARGET = 1,
RESULT = 2,
CONTEXT = 3,
}
import EnvironementService from './environement.service'
describe('Environement service', () => {
const OLD_ENV = process.env
beforeEach(() => {
jest.resetModules() // Most important - it clears the cache
process.env = { ...OLD_ENV } // Make a copy
})
afterAll(() => {
process.env = OLD_ENV // Restore old environment
})
const environementService = new EnvironementService()
describe('isProduction method', () => {
it('should return true', async () => {
process.env.NODE_ENV = 'production'
const result = environementService.isProduction()
expect(result).toEqual(true)
})
it('should return false, developement case', async () => {
process.env.NODE_ENV = 'development'
const result = environementService.isProduction()
expect(result).toEqual(false)
})
it('should return false, non existing case', async () => {
process.env.NODE_ENV = 'toto'
const result = environementService.isProduction()
expect(result).toEqual(false)
})
})
})
export default class EnvironementService {
private getEnvironement() {
return process.env.NODE_ENV
}
public isProduction() {
if (this.getEnvironement() === 'production') {
return true
}
return false
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment