-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from voxmedia/simplified
Version 1!
- Loading branch information
Showing
15 changed files
with
524 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install modules | ||
run: yarn | ||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true, | ||
"printWidth": 80 | ||
"printWidth": 120, | ||
"arrowParens": "avoid" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class FrameworkBase { | ||
constructor() {} | ||
|
||
get name() { | ||
return this.constructor.name; | ||
} | ||
|
||
static isAutoLoaded() { | ||
return true; | ||
} | ||
|
||
isApplicable() { | ||
return true; | ||
} | ||
|
||
useConfig(someConfigs = {}) {} | ||
|
||
supportedCapabilities() { | ||
return []; | ||
} | ||
|
||
canAnswerCapability(capability) { | ||
return this.supportedCapabilities().includes(capability); | ||
} | ||
} | ||
|
||
module.exports = FrameworkBase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const FrameworkBase = require('./base'); | ||
|
||
/** | ||
* Implements usprivacy string framework | ||
* for more information on the US Privacy string see: | ||
* https://github.com/InteractiveAdvertisingBureau/USPrivacy/blob/master/CCPA/US%20Privacy%20String.md#us-privacy-string-format | ||
*/ | ||
class CCPAFromUSPrivacyString extends FrameworkBase { | ||
constructor() { | ||
super(); | ||
this.usPrivacyString = ''; | ||
} | ||
|
||
useConfig({ usp }) { | ||
if (usp) { | ||
this.usPrivacyString = ('' + usp).toUpperCase(); | ||
} | ||
} | ||
|
||
isApplicable() { | ||
return !!this.usPrivacyString; | ||
} | ||
|
||
supportedCapabilities() { | ||
return ['canUsePersonalInformationForTargeting', 'hasBeenNotifiedOfRights']; | ||
} | ||
|
||
canUsePersonalInformationForTargeting() { | ||
return this.consentStringAllowsPersonalDataSale(); | ||
} | ||
|
||
hasBeenNotifiedOfRights() { | ||
return this.consentStringAcknowledgesUserHasBeenNotifiedOfRights(); | ||
} | ||
|
||
consentStringAllowsPersonalDataSale() { | ||
if (!this.supportedUsPrivacyStringVersion()) return true; | ||
if (!this.consentStringAcknowledgesUserHasBeenNotifiedOfRights()) return true; | ||
return this.usPrivacyString[2] !== 'Y'; | ||
} | ||
|
||
consentStringAcknowledgesUserHasBeenNotifiedOfRights() { | ||
return this.supportedUsPrivacyStringVersion() && this.usPrivacyString[1] === 'Y'; | ||
} | ||
|
||
supportedUsPrivacyStringVersion() { | ||
return this.usPrivacyString.length === 4 && this.usPrivacyString[0] === '1'; | ||
} | ||
} | ||
|
||
module.exports = CCPAFromUSPrivacyString; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Cookie = require('../lib/cookie'); | ||
const FrameworkBase = require('./base'); | ||
|
||
class CcpaOnChorus extends FrameworkBase { | ||
isApplicable() { | ||
return !!window && !!window.Chorus; | ||
} | ||
|
||
supportedCapabilities() { | ||
return ['canUsePersonalInformationForTargeting', 'hasBeenNotifiedOfRights']; | ||
} | ||
|
||
canUsePersonalInformationForTargeting() { | ||
return !Cookie.hasCookie('_chorus_ccpa_consent_donotsell'); | ||
} | ||
|
||
hasBeenNotifiedOfRights() { | ||
// see https://github.com/voxmedia/sbn/commit/ce74ab006c89afe799afffa2a31137454d9e5bb3 | ||
return Cookie.hasCookie('_chorus_ccpa_consent'); | ||
} | ||
} | ||
|
||
module.exports = CcpaOnChorus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const CcpaOnChorus = require('./ccpa_on_chorus'); | ||
const CcpaFromUsPrivacyString = require('./ccpa_from_us_privacy_string'); | ||
|
||
const defaultFrameworks = [CcpaOnChorus, CcpaFromUsPrivacyString]; | ||
|
||
module.exports = defaultFrameworks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,5 @@ | ||
class FrameworkBase { | ||
canPersonalizeContent() { | ||
return true; | ||
} | ||
canSendMetrics() { | ||
return true; | ||
} | ||
canSendThirdPartyMetrics() { | ||
return true; | ||
} | ||
} | ||
const PrivacyCompliance = require('./privacy_compliance'); | ||
|
||
class GDPRFramework extends FrameworkBase { | ||
canPersonalizeContent() { | ||
return false; | ||
} | ||
} | ||
|
||
class CCPAFramework extends FrameworkBase { | ||
canPerformPersonalizedAdvertiserTargeting() { | ||
return true; | ||
} | ||
} | ||
|
||
const areAllTrue = (collection) => { | ||
return collection.filter((capability) => !capability).length == 0; | ||
module.exports = { | ||
PrivacyCompliance, | ||
}; | ||
|
||
class PrivacyCompliance { | ||
constructor() { | ||
this.frameworks = []; | ||
this.frameworks.push(new CCPAFramework()); | ||
this.frameworks.push(new GDPRFramework()); | ||
} | ||
|
||
canPerform(functionalities = []) { | ||
return areAllTrue( | ||
this.frameworks.map((f) => f.canPerform(functionalities)) | ||
); | ||
} | ||
|
||
canPerformPersonalizedAdvertiserTargeting() { | ||
return areAllTrue( | ||
this.frameworks.map((f) => f.canPerformPersonalizedAdvertiserTargeting()) | ||
); | ||
} | ||
canPersonalizeContent() {} | ||
canSendMetrics() {} | ||
canSendThirdPartyMetrics() {} | ||
} | ||
|
||
export default new PrivacyCompliance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Gets all the cookies as a Map | ||
* | ||
* @returns Map of cookie values | ||
*/ | ||
function getAllCookies() { | ||
return new Map(document.cookie.split(';').map(cookie => cookie.trim().split('='))); | ||
} | ||
|
||
/** | ||
* Checks if cookie exists | ||
* | ||
* @param {String} name name of cookie | ||
* @return {Boolean} true of cookie is present | ||
*/ | ||
function hasCookie(name) { | ||
return getAllCookies().has(name); | ||
} | ||
|
||
/** | ||
* Gets the cookie value | ||
* | ||
* @param {String} name name of cookie | ||
* @return {String} the value of the cookie | ||
*/ | ||
function getCookie(name) { | ||
return getAllCookies().get(name); | ||
} | ||
|
||
module.exports = { | ||
getAllCookies, | ||
hasCookie, | ||
getCookie, | ||
}; |
Oops, something went wrong.