@financial-times/n-consent-proxy-client v3.0.0
n-consent-proxy-client
A client library to talk to the next-consent-proxy.
NOTE - it's not necessary to use this module if your app is downstream of next-preflight
and uses n-ui
or n-express
with the withConsent
option (true
by default in n-ui
, false
by default in n-express
)". In those cases, your app will automatically receive the user's consent record in res.locals.consent.
Requirements
- Node 8+
- Either
- An API key for
next-consent-proxy
set asCONSENT_PROXY_SERVICE_KEY
in your env vars - OR a valid secure session (will be passed through via CORS)
- An API key for
- Optionally
- The host (including protocol) for
next-consent-proxy
set asCONSENT_PROXY_SERVICE_HOST
in your env vars - defaults to https://consent.ft.com
- The host (including protocol) for
Install
Server-side:
npm install @financial-times/n-consent-proxy-client --save
This will make HEAD requests and return normalised data
Client-side:
bower install n-consent-proxy-client --save
This will make GET requests and return normalised data
Usage
import {getConsent} from '@financial-times/n-consent-proxy-client';
const someFn = async () => {
await getConsent({
userId,
category,
channel
});
}
Scope
doesn't need set - it defaults to FTPINK
.
Public methods
getConsent
Gets a granular consent item for the user, e.g. has this user opted out of marketing by email?
Arguments
An object containing:
userId
- ID for the usercategory
- the consent group likeenhancement
channel
- the individual option likebyEmail
silentMode
- iftrue
, returns an object with anerror
property rather than throwing; defaults tofalse
getAllConsent
Gets the full consent record (all channels and categories) for the user.
Arguments
An object containing:
userId
: ID for the usersilentMode
- iftrue
, returns an object with an error property rather than throwing; defaults tofalse
Returned Object
The returned object will always be in the following format
{
"consent": {
"mycategoryMychannel": true,
"mycategoryAnotherchannel": false
}
}
Note that 'myCategory' gets changed to 'mycategory' and 'myChannel' gets changed to 'Mychannel' - categories and channels are lower-cased, joined and the resulting string is camel-cased. This is because use of case can vary between what we receive in the headers and the body (e.g. Bypost
vs byPost
).
Contributing
Set up the component locally by first installing dependencies and running build to transpile Typescript (in the src
directory) to JavaScript (in the dist
directory) and run tests to confirm everything works
make install
make build
make test
Use the #ft-next-gdpr-dev
Slack channel to communicate with the team.