From 93000422298b3d77f7568c5128cb9ebdd74cd4ab Mon Sep 17 00:00:00 2001 From: Alex Castells Date: Tue, 23 Jun 2020 09:09:42 +0200 Subject: [PATCH] Feature/stub (#1) * add stub registration * update docs --- .npmignore | 6 +- README.md | 45 +++++++++++-- package.json | 4 +- src/main/index.js | 4 +- .../service/handler/PostMessageHandler.js | 34 ++++++++++ src/main/service/handler/TcfApiHandler.js | 33 +++++++++ .../service/registerIframeMessageHandler.js | 10 +++ src/main/service/registerStub.js | 14 ++++ src/main/service/registerTcfApiHandler.js | 7 ++ src/main/service/registerTcfApiLocator.js | 16 +++++ src/main/service/waitUntil.js | 20 ++++++ src/test/indexTest.js | 67 ++++++++++++++++++- src/webpack/deploy.webpack.config.js | 2 +- src/webpack/dev.index.js | 3 - src/webpack/dev.webpack.config.js | 2 +- src/webpack/standalone.index.js | 3 + versiona.js | 1 - 17 files changed, 255 insertions(+), 16 deletions(-) create mode 100644 src/main/service/handler/PostMessageHandler.js create mode 100644 src/main/service/handler/TcfApiHandler.js create mode 100644 src/main/service/registerIframeMessageHandler.js create mode 100644 src/main/service/registerStub.js create mode 100644 src/main/service/registerTcfApiHandler.js create mode 100644 src/main/service/registerTcfApiLocator.js create mode 100644 src/main/service/waitUntil.js delete mode 100644 src/webpack/dev.index.js create mode 100644 src/webpack/standalone.index.js diff --git a/.npmignore b/.npmignore index 3ba775c..1b2e496 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ src +deploy coverage .nyc_output .travis.yml @@ -8,4 +9,7 @@ coverage resources package *.tgz -versiona.js \ No newline at end of file +versiona.js +deploy.js +mocha.config.js +.babelrc.js \ No newline at end of file diff --git a/README.md b/README.md index d557160..6288837 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -![](/resources/logo/boros_logo.png) - # Boros TCF Stub [![Build status](https://travis-ci.org/scm-spain/boros-tcf-stub.svg?branch=master)](https://travis-ci.org/scm-spain/boros-tcf-stub) @@ -11,19 +9,56 @@ * [About](#about) * [Features](#features) -* [Technical features](#technical-features) -* [Configuration](#configuration) * [Usage](#usage) * [License](#license) ## About +The Boros TCF stub implements the [standard TCF v2 stub](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#how-does-the-cmp-stub-api-work) + ## Features -## Technical features +- Registers the `__tcfapiLocator` frame + +- Stubs the `window.__tcfapi` responding immediately to the commands + - `ping` [See PingReturn in the stubbed __tcfapi](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#requirements-for-the-cmp-stub-api-script) + - `pending` returns the pending calls accumulated while calling `window.__tcfapi` commands + +- Initializes the cross-framee communication via `postMessagee`, [see usage details](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#how-can-vendors-that-use-iframes-call-the-cmp-api-from-an-iframe) ## Usage +### As an importable module + +> Use it this way if you're generating your own initialization + +**Install** +``` +npm i @adv-ui/boros-tcf-stub --save +``` + +**Register the Stub** +``` +import registerStub from '../main' + +// do your magic + +registerStub() +``` + +> Remember that the Stub **must** be registered before any script depending on the TCF is loaded + +### As a standalone script + +**Add it to the `head` tag** + +``` +