Skip to content

Commit

Permalink
Feature/iab core update (#50)
Browse files Browse the repository at this point in the history
* update iab library

* add concrete GVL data for version&lang

* add consent generation utility to prepare tests

* add decoding consent utility

* add decoding consent utility

* refactor cookie fixtures

* update consent factory

* update vendorlist test

* mock GVLFactory by default in tests

* fix gettcdata test

* fix iabconsentencoderservice test

* reemove only clause

* fix save consent use test

* fix initialization test

* fix boros api facade tests

* fix tcfapi tests

* fix eslint timeouts

* check coverage

* add dependabot

* update consent helper

* better consent update vendors
  • Loading branch information
alextremp authored Nov 4, 2020
1 parent 2b2613d commit 1fb68e4
Show file tree
Hide file tree
Showing 34 changed files with 43,002 additions and 20,585 deletions.
15 changes: 15 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 1
update_configs:
# Keep package.json (& lockfiles) up to date as soon as
# new versions are published to the npm registry
- package_manager: "javascript"
directory: "/"
update_schedule: "weekly"
# Apply default reviewer and label to created
# pull requests
default_reviewers:
- "github-alextremp"
- "github-paulusrex"
- "github-oscarramirez23"
- "github-oscarraigscmspain"
- "github-maryammdot"
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ coverage
.idea
.eslintignore
.github
.dependabot
resources
package
*.tgz
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"extends": "./node_modules/@s-ui/lint/stylelint.config.js"
},
"dependencies": {
"@iabtcf/core": "1.0.1",
"@iabtcf/core": "1.1.4",
"brusc": "1",
"core-js": "3"
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/application/BorosTcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {ChangeUiVisibleUseCase} from './services/ui/ChangeUiVisibleUseCase'
import {GetTCDataUseCase} from './services/tcdata/GetTCDataUseCase'
import {StatusRepository} from '../domain/status/StatusRepository'
import {Status} from '../domain/status/Status'
import {DomainEventBus} from '../domain/service/DomainEventBus'

class BorosTcf {
/**
Expand All @@ -17,24 +16,21 @@ class BorosTcf {
* @param {SaveUserConsentUseCase} param.saveUserConsentUseCase
* @param {ChangeUiVisibleUseCase} param.changeUiVisibleUseCase
* @param {GetTCDataUseCase} param.getTCDataUseCase
* @param {DomainEventBus} param.domainEventBus
*/
constructor({
getVendorListUseCase = inject(GetVendorListUseCase),
loadUserConsentUseCase = inject(LoadUserConsentUseCase),
saveUserConsentUseCase = inject(SaveUserConsentUseCase),
getTCDataUseCase = inject(GetTCDataUseCase),
changeUiVisibleUseCase = inject(ChangeUiVisibleUseCase),
statusRepository = inject(StatusRepository),
domainEventBus = inject(DomainEventBus)
statusRepository = inject(StatusRepository)
} = {}) {
this._getVendorListUseCase = getVendorListUseCase
this._loadUserConsentUseCase = loadUserConsentUseCase
this._saveUserConsentUseCase = saveUserConsentUseCase
this._getTCDataUseCase = getTCDataUseCase
this._changeUiVisibleUseCase = changeUiVisibleUseCase
this._statusRepository = statusRepository
this._domainEventBus = domainEventBus
}

ready() {
Expand Down
1 change: 1 addition & 0 deletions src/main/application/services/AsyncUseCase.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
/**
* @interface
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/application/services/SyncUseCase.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
/**
* @interface
*/
Expand Down
32 changes: 32 additions & 0 deletions src/main/domain/consent/Consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PUBLISHER_CC,
TCF_API_VERSION
} from '../../core/constants'
import {VendorAcceptanceStatus} from '../vendorlist/VendorAcceptanceStatus'

export class Consent {
/**
Expand All @@ -28,6 +29,7 @@ export class Consent {
cmpId = BOROS_TCF_ID,
cmpVersion = BOROS_TCF_VERSION,
policyVersion = TCF_API_VERSION,
vendorListVersion,
publisherCC = PUBLISHER_CC,
isServiceSpecific = true,
useNonStandardStacks = false,
Expand All @@ -47,6 +49,7 @@ export class Consent {
this._cmpId = cmpId
this._cmpVersion = cmpVersion
this._policyVersion = policyVersion
this._vendorListVersion = vendorListVersion
this._publisherCC = publisherCC
this._isServiceSpecific = isServiceSpecific
this._useNonStandardStacks = useNonStandardStacks
Expand All @@ -59,6 +62,30 @@ export class Consent {
this._isNew = isNew
}

updateVendors({oldVendorList, newVendorList}) {
const updated = {
consents: {},
legitimateInterests: {}
}
const consentVendorsAcceptanceStatus = new VendorAcceptanceStatus({
consent: this,
vendorList: oldVendorList
})
Object.keys(newVendorList.vendors).forEach(key => {
updated.consents[key] = consentVendorsAcceptanceStatus.resolveConsent({
current: this._vendor.consents[key]
})
updated.legitimateInterests[
key
] = consentVendorsAcceptanceStatus.resolveLegitimateInterest({
current: this._vendor.legitimateInterests[key]
})
})
this._vendor = updated
this._vendorListVersion = newVendorList.version
this._valid = consentVendorsAcceptanceStatus.isValid()
}

get vendor() {
return this._vendor
}
Expand Down Expand Up @@ -91,11 +118,16 @@ export class Consent {
return this._policyVersion
}

get vendorListVersion() {
return this._vendorListVersion
}

toJSON() {
return {
cmpId: this._cmpId,
cmpVersion: this._cmpVersion,
policyVersion: this._policyVersion,
vendorListVersion: this._vendorListVersion,
publisherCC: this._publisherCC,
isServiceSpecific: this._isServiceSpecific,
useNonStandardStacks: this._useNonStandardStacks,
Expand Down
2 changes: 1 addition & 1 deletion src/main/domain/consent/ConsentEncoderService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @interface
*/
class ConsentEncoderService {
encode({vendor, purpose, specialFeatures, previousEncodedConsent}) {}
encode({consent}) {}
}

export {ConsentEncoderService}
120 changes: 24 additions & 96 deletions src/main/domain/consent/LoadConsentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {ConsentFactory} from '../consent/ConsentFactory'
import {ConsentDecoderService} from '../consent/ConsentDecoderService'
import {VendorListRepository} from '../vendorlist/VendorListRepository'
import {ConsentEncoderService} from './ConsentEncoderService'
import {VendorListHelper} from '../vendorlist/VendorListHelper'
import {Version} from '../vendorlist/Version'

export class LoadConsentService {
Expand All @@ -13,124 +12,53 @@ export class LoadConsentService {
consentFactory = inject(ConsentFactory),
consentDecoderService = inject(ConsentDecoderService),
consentEncoderService = inject(ConsentEncoderService),
vendorListRepository = inject(VendorListRepository),
vendorListHelper = inject(VendorListHelper)
vendorListRepository = inject(VendorListRepository)
} = {}) {
this._consentRepository = consentRepository
this._consentFactory = consentFactory
this._consentDecoderService = consentDecoderService
this._consentEncoderService = consentEncoderService
this._vendorListRepository = vendorListRepository
this._vendorListHelper = vendorListHelper
}

async loadConsent() {
const encodedConsent = this._consentRepository.loadUserConsent()

if (!encodedConsent) {
return this._consentFactory.createEmptyConsent()
}
const existingConsent = this._consentDecoderService.decode({encodedConsent})

const decodedConsent = this._consentDecoderService.decode({encodedConsent})
const newVendorList = await this._vendorListRepository.getVendorList()

if (newVendorList.policyVersion !== existingConsent.policyVersion) {
if (newVendorList.policyVersion !== decodedConsent.policyVersion) {
return this._consentFactory.createEmptyConsent()
}

const result = await this._isValid({
newVendorList,
consent: existingConsent
})

return result
? this._createValidConsentWithTheSavedOne({savedConsent: existingConsent})
: this._createAnInValidConsentAndMergeListVendors({
existingConsent,
newVendorList
})
}

_createAnInValidConsentAndMergeListVendors({existingConsent, newVendorList}) {
existingConsent.valid = false
existingConsent.vendor = this._vendorListHelper.mergeVendors({
newVendorList: newVendorList.value.vendors,
oldVendors: existingConsent.vendor
})
return this._consentFactory.createConsent(existingConsent)
}

async _createValidConsentWithTheSavedOne({savedConsent}) {
const consent = await this._renewSavedConsent({savedConsent})
consent.valid = true
return this._consentFactory.createConsent(consent)
}

async _renewSavedConsent({savedConsent}) {
const encodedConsent = await this._consentEncoderService.encode({
consent: savedConsent
})
this._consentRepository.saveUserConsent({
encodedConsent: encodedConsent,
decodedConsent: savedConsent
})
const renewedEncodedConsent = this._consentRepository.loadUserConsent()
const consent = this._consentDecoderService.decode({
encodedConsent: renewedEncodedConsent
})
return consent
}

async _isValid({newVendorList, consent}) {
if (newVendorList.version === consent.vendorListVersion) {
return true
let consent
if (newVendorList.version === decodedConsent.vendorListVersion) {
decodedConsent.valid = true
consent = this._consentFactory.createConsent(decodedConsent)
} else {
consent = this._consentFactory.createConsent(decodedConsent)
const oldVendorList = await this._vendorListRepository.getVendorList({
version: new Version(consent.vendorListVersion)
})
consent.updateVendors({
oldVendorList,
newVendorList
})
}

const oldVendorList = await this._vendorListRepository.getVendorList({
version: new Version(consent.vendorListVersion)
})

return (
(await this._consentHaveConsentsAndLIForAllVendorsWithTheSameValue({
consent,
newVendorList,
value: true,
oldVendorList: oldVendorList.value.vendors
})) ||
this._consentHaveConsentsAndLIForAllVendorsWithTheSameValue({
if (consent.valid) {
const encodedConsent = await this._consentEncoderService.encode({
consent,
newVendorList,
value: false,
oldVendorList: oldVendorList.value.vendors
vendorListVersion: consent.vendorListVersion
})
)
}

async _consentHaveConsentsAndLIForAllVendorsWithTheSameValue({
consent,
newVendorList,
value,
oldVendorList
}) {
let isValid = false
if (
this._vendorListHelper.haveAllValuesTo({
object: consent.vendor.consents,
valueToVerify: value,
oldVendorList
}) &&
this._vendorListHelper.haveAllValuesTo({
object: consent.vendor.legitimateInterests,
valueToVerify: value,
oldVendorList
})
) {
consent.vendor = this._vendorListHelper.setAllVendorsTo({
vendorList: newVendorList.value.vendors,
valueToSet: value
this._consentRepository.saveUserConsent({
encodedConsent: encodedConsent,
decodedConsent: consent
})
isValid = true
}
return isValid

return consent
}
}
Loading

0 comments on commit 1fb68e4

Please sign in to comment.