3.0.0 • Published 8 months ago

@financial-times/n-consent-proxy-client v3.0.0

Weekly downloads
20
License
MIT
Repository
github
Last release
8 months ago

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 as CONSENT_PROXY_SERVICE_KEY in your env vars
    • OR a valid secure session (will be passed through via CORS)
  • Optionally
    • The host (including protocol) for next-consent-proxy set as CONSENT_PROXY_SERVICE_HOST in your env vars - defaults to https://consent.ft.com

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 user
  • category - the consent group like enhancement
  • channel - the individual option like byEmail
  • silentMode - if true, returns an object with an error property rather than throwing; defaults to false

getAllConsent

Gets the full consent record (all channels and categories) for the user.

Arguments

An object containing:

  • userId: ID for the user
  • silentMode - if true, returns an object with an error property rather than throwing; defaults to false

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.

3.0.0

8 months ago

2.0.0

2 years ago

1.0.0

6 years ago

0.0.2

6 years ago