Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Task/move to advui #77

Merged
merged 2 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Build status](https://travis-ci.org/scm-spain/Boros-CMP.svg?branch=master)](https://travis-ci.org/scm-spain/Boros-CMP)
[![codecov](https://codecov.io/gh/scm-spain/Boros-CMP/branch/master/graph/badge.svg)](https://codecov.io/gh/scm-spain/Boros-CMP)
[![GitHub license](https://img.shields.io/github/license/scm-spain/Boros-CMP.svg)](https://github.com/scm-spain/Boros-CMP/blob/master/LICENSE)
[![npm version](https://img.shields.io/npm/v/@schibstedspain/boros-cmp.svg)](https://www.npmjs.com/package/@schibstedspain/boros-cmp)
[![npm version](https://img.shields.io/npm/v/@adv-ui/boros-cmp.svg)](https://www.npmjs.com/package/@adv-ui/boros-cmp)

## Table of Contents

Expand Down Expand Up @@ -41,18 +41,18 @@

## Usage

**Boros CMP** is available as [npm](https://www.npmjs.com/package/@schibstedspain/boros-cmp) package named **@schibstedspain/boros-cmp**.
**Boros CMP** is available as [npm](https://www.npmjs.com/package/@adv-ui/boros-cmp) package named **@adv-ui/boros-cmp**.

To install the last stable version:

```bash
npm install --save @schibstedspain/boros-cmp
npm install --save @adv-ui/boros-cmp
```

To initialize Boros CMP using [default configuration](#configuration-properties-and-default-values) values:

```javascript
import boroscmp from '@schibstedspain/boros-cmp'
import boroscmp from '@adv-ui/boros-cmp'

boroscmp.init()
.then(()=>{
Expand All @@ -63,7 +63,7 @@ boroscmp.init()
To initialize Boros CMP using customized configuration values:

```javascript
import boroscmp from '@schibstedspain/boros-cmp'
import boroscmp from '@adv-ui/boros-cmp'

const customConfig = {
gdpr: {
Expand All @@ -84,7 +84,7 @@ boroscmp.init({config: customConfig})

Notice that **init** method is returning a _Promise_ but you can subscribe to *cmpReady* event instead:
```javascript
import boroscmp from '@schibstedspain/boros-cmp'
import boroscmp from '@adv-ui/boros-cmp'

window.document.addEventListener("cmpReady", (event) => {
// do your stuff ...
Expand All @@ -98,7 +98,7 @@ boroscmp.init()
**You could also import directly the library instead the bundled version.** By using this, it will assume you're providing the @babel/runtime dependency, helpers and polyfills needed to get it working but it will give you a better size by reusing your packages.

```javascript
import boroscmp from '@schibstedspain/boros-cmp/lib'
import boroscmp from '@adv-ui/boros-cmp/lib'

boroscmp.init()
.then(()=>{
Expand All @@ -110,7 +110,7 @@ boroscmp.init()

Boros should be initialized with at least this custom configuration
```javascript
import boroscmp from '@schibstedspain/boros-cmp'
import boroscmp from '@adv-ui/boros-cmp'

const customConfig = {
gdpr: {
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@schibstedspain/boros-cmp",
"name": "@adv-ui/boros-cmp",
"version": "1.5.0",
"description": "Schibsted GDPR - Consent Management Provider - Standalone",
"description": "Adevinta GDPR - Consent Management Provider - Standalone",
"main": "dist/cmp.pro.js",
"scripts": {
"prepack": "rm -Rf dist && rm -Rf lib && npm run build:cmp",
Expand Down Expand Up @@ -30,6 +30,7 @@
"ads",
"advertising",
"schibsted",
"adevinta",
"gdpr",
"cmp",
"consent-string",
Expand All @@ -44,7 +45,7 @@
"@babel/plugin-transform-modules-commonjs": "7.2.0",
"@babel/polyfill": "7.2.5",
"@babel/register": "7.0.0",
"@s-ui/lint": "2",
"@s-ui/lint": "3",
"babel-loader": "8.0.5",
"babel-plugin-transform-define": "1.3.1",
"babel-preset-sui": "3.0.0",
Expand All @@ -56,7 +57,7 @@
"jsdom": "11.11.0",
"mocha": "5.2.0",
"sinon": "2.3.4",
"versiona": "^4.2.1",
"versiona": "4",
"webpack": "4.12.0",
"webpack-cli": "3.0.8",
"webpack-dev-server": "3.10.1"
Expand Down Expand Up @@ -89,5 +90,9 @@
"consent-string": "1.4.2",
"isomorphic-unfetch": "3.0.0",
"uuid": "3.3.2"
},
"prettier": "./node_modules/@s-ui/lint/.prettierrc.js",
"stylelint": {
"extends": "./node_modules/@s-ui/lint/stylelint.config.js"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export default class GetConsentStatusUseCase {
getConsentStatus() {
return Promise.resolve()
.then(() => this._consentRepository.getConsent())
.then(
consent =>
consent ? CONSENT_STATUS_ACCEPTED : CONSENT_STATUS_NOT_ACCEPTED
.then(consent =>
consent ? CONSENT_STATUS_ACCEPTED : CONSENT_STATUS_NOT_ACCEPTED
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default class GetVendorListUseCase {
constructor({vendorListRepository}) {
this._vendorListRepository = vendorListRepository
}

/**
* The result will be the GlobalVendorList being the vendor list object of the requested version.
* If the vendorListVersion is null, the vendor list for the VendorListVersion in the current consent string is returned.
Expand Down
2 changes: 1 addition & 1 deletion src/cmp/domain/consent/UpdateConsentVendorsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class UpdateConsentVendorsService {
newIdsNotInOldGlobalVendors
]) => {
// TODO fn remove ids accepted in the consent that they are not anymore in the new global list
let newAcceptedVendorIds = acceptedVendorIds.filter(
const newAcceptedVendorIds = acceptedVendorIds.filter(
id => oldIdsNotInNewGlobalVendors.indexOf(id) < 0
)

Expand Down
1 change: 1 addition & 0 deletions src/cmp/domain/vendor_consents/NewVendorsStatusService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class NewVendorsStatusService {
constructor({option = OPTION_USE_SAME_THAN_ALL_CUSTOM_IS_TRUE} = {}) {
this._option = option
}

getNewVendorsStatus({acceptedVendorIds, globalVendorIds, allowedVendorIds}) {
return Promise.resolve()
.then(() =>
Expand Down
31 changes: 18 additions & 13 deletions src/cmp/domain/vendor_consents/VendorConsentsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class VendorConsentsFactory {
this._gdprApplies = gdprApplies
this._storeConsentGlobally = storeConsentGlobally
}

createVendorConsents({consent, globalVendorList, allowedVendorIds} = {}) {
return Promise.resolve().then(() =>
Promise.all([
Expand Down Expand Up @@ -35,12 +36,14 @@ const filterAllowedVendorIdsFromGlobalList = ({
allowedVendorIds
}) =>
Promise.resolve().then(() =>
globalVendorList.vendors.map(v => v.id).filter(id =>
isWhitelisted({
whitelist: allowedVendorIds,
id
})
)
globalVendorList.vendors
.map(v => v.id)
.filter(id =>
isWhitelisted({
whitelist: allowedVendorIds,
id
})
)
)

const createVendorConsents = ({consent, vendorIds = []} = {}) =>
Expand All @@ -56,11 +59,13 @@ const createVendorConsents = ({consent, vendorIds = []} = {}) =>

const createPurposeConsents = ({consent, globalVendorList}) =>
Promise.resolve().then(() =>
globalVendorList.purposes.map(p => p.id).reduce(
(accumulator, id) => ({
...accumulator,
[`${id}`]: consent.isPurposeAllowed(id)
}),
{}
)
globalVendorList.purposes
.map(p => p.id)
.reduce(
(accumulator, id) => ({
...accumulator,
[`${id}`]: consent.isPurposeAllowed(id)
}),
{}
)
)
2 changes: 1 addition & 1 deletion src/cmp/infrastructure/bootstrap/GlobalStorageBootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class GlobalStorageBootstrap {
registerIframeCommunication(container)
])
)
.then(([cmp, undefined]) => registerWindowCMP({cmp, window}))
.then(([cmp, any]) => registerWindowCMP({cmp, window}))
.then(() => createEvent({window, name: 'cmpReady'}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmp/infrastructure/build/webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getMajorVersionFromPackageJsonVersion = () => {
return JSON.stringify(process.env.npm_package_version.split('.')[0])
}

let webpackConfig = {
const webpackConfig = {
entry: ['@s-ui/polyfills', ENTRY_PATH],
output: {
path: path.resolve(OUTPUT_DIST_FOLDER),
Expand Down
2 changes: 1 addition & 1 deletion src/cmp/infrastructure/build/webpack.config.cmp.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getMajorVersionFromPackageJsonVersion = () => {
return parseInt(JSON.stringify(process.env.npm_package_version.split('.')[0]))
}

let webpackConfig = {
const webpackConfig = {
devtool: 'inline-source-map',
entry: ENTRY_PATH,
output: {
Expand Down
4 changes: 4 additions & 0 deletions src/cmp/infrastructure/configuration/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ export default class Configuration {
this._log = {}
this._log.level = log.level || DEFAULT_LOG_LEVEL
}

get gdpr() {
return this._gdpr
}

get vendorList() {
return this._vendorList
}

get consent() {
return this._consent
}

get log() {
return this._log
}
Expand Down
1 change: 1 addition & 0 deletions src/cmp/infrastructure/container/BaseConsentContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export default class BaseConsentContainer {
option: this._config.consent.newVendorsStatusOption
})
}

_buildGlobalVendorListVersionChangedObserver() {
return globalVendorListVersionChangedObserverFactory({
updateConsentVendorsService: this.getInstance({
Expand Down
2 changes: 1 addition & 1 deletion src/cmp/infrastructure/event-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (typeof window !== 'undefined' && typeof window.CustomEvent !== 'function') {
cancelable: false,
detail: undefined
}
let evt = document.createEvent('CustomEvent')
const evt = document.createEvent('CustomEvent')
evt.initCustomEvent(
event,
eventParams.bubbles,
Expand Down
11 changes: 6 additions & 5 deletions src/cmp/infrastructure/repository/ChainedVendorListRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export default class ChainedVendorListRepository {
.then(
globalVendorList =>
globalVendorList ||
this._getRemoteVendorList({vendorListVersion}).then(
globalVendorList =>
this._saveRemoteVendorListToLocal({globalVendorList}).then(
() => globalVendorList
)
this._getRemoteVendorList({
vendorListVersion
}).then(globalVendorList =>
this._saveRemoteVendorListToLocal({globalVendorList}).then(
() => globalVendorList
)
)
)
this._requested.set(vendorListVersion, request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class ConsentStringVendorConsentsRepository {
}

_mapVendorConsentsToConsent({vendorConsents, purposeConsents}) {
let consent = new ConsentString()
const consent = new ConsentString()
consent.setVendorsAllowed(vendorConsents)
consent.setPurposesAllowed(purposeConsents)
consent.setCmpId(this._cmpId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export default class HttpTranslationVendorListRepository {
return Promise.all([
this._vendorListRepository.getGlobalVendorList({vendorListVersion}),
this._acceptedLanguage ? this._getTranslation({vendorListVersion}) : null
]).then(
([vendorList, translation]) =>
translation
? this._mergeTranslation({vendorList, translation})
: vendorList
]).then(([vendorList, translation]) =>
translation
? this._mergeTranslation({vendorList, translation})
: vendorList
)
}

Expand Down
1 change: 1 addition & 0 deletions src/cmp/infrastructure/service/UUIDV4Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class UUIDV4Generator {
constructor({uuidv4}) {
this._uuidv4 = uuidv4
}

generate() {
return this._uuidv4()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class IframeCommunicationClient {

_timeout({transactionId}) {
return new Promise((resolve, reject) => {
let wait = setTimeout(() => {
const wait = setTimeout(() => {
clearTimeout(wait)
reject(new RequestTimeoutError(transactionId))
}, POST_MESSAGE_DEFAULT_REQUEST_TIMEOUT)
Expand Down
8 changes: 8 additions & 0 deletions src/cmp/infrastructure/service/log/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,40 @@ class Log {
this._level = (this._isValidLevel({level}) && level) || LEVEL.off
this._console = console || NO_CONSOLE
}

changeLevel({level}) {
this._level = (this._isValidLevel({level}) && level) || this._level
}

get level() {
return this._level
}

debug(...args) {
this._level <= LEVEL.debug &&
this._print({logMethod: this._console.log, level: 'DEBUG', args})
}

info(...args) {
this._level <= LEVEL.info &&
this._print({logMethod: this._console.info, level: 'INFO', args})
}

warn(...args) {
this._level <= LEVEL.warn &&
this._print({logMethod: this._console.warn, level: 'WARN', args})
}

error(...args) {
this._level <= LEVEL.error &&
this._print({logMethod: this._console.error, level: 'ERROR', args})
}

_print({logMethod, level, args}) {
const [message, ...rest] = [...args]
logMethod(`[${level}] CMP - ${message}`, ...rest)
}

_isValidLevel({level}) {
return level >= LEVEL.debug && level <= LEVEL.off
}
Expand Down
4 changes: 1 addition & 3 deletions src/cmp/infrastructure/service/log/loggerDebugHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export const debugHandler = logger => ({
case 'function':
return (...args) => {
logger.debug(
`Function ${propKey} called from class ${
target.constructor.name
} with arguments:`,
`Function ${propKey} called from class ${target.constructor.name} with arguments:`,
Object.entries(args)
)
return target[propKey].apply(target, args)
Expand Down
11 changes: 4 additions & 7 deletions src/globalstorage/application/globalStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ const filterEventFormatIsValid = event =>
const filterCommandIsValid = event => commands =>
Promise.resolve(event)
.then(event => event.data.__cmpCall.command)
.then(
command =>
typeof commands[command] === 'function'
? command
: Promise.reject(
new CommandNotFoundError(event.data.__cmpCall.callId)
)
.then(command =>
typeof commands[command] === 'function'
? command
: Promise.reject(new CommandNotFoundError(event.data.__cmpCall.callId))
)

const sendError = ({error, event}) =>
Expand Down
Loading