NodeJS Example

The following are NodeJS samples.

Create a Consent

This example creates a consent.

First, this is the package.json:

📘

SDK Version

Update the version below to match the latest release of @wirewheelio/cmp-javascript-sdk located here.

{
  "name": "sdkwirewheel",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "type": "module",
  "scripts": {
    "start:mjs": "node index.mjs"
  },
  "dependencies": {
    "@wirewheelio/cmp-javascript-sdk": "^0.4.1"
  }
}

To run this app, run:

npm run start:mjs

import { WireWheelSDK, Subject,  ActionType, Scopes} from '@wirewheelio/cmp-javascript-sdk'

const scopes = [Scopes.ConsentWrite, Scopes.ConsentRead, Scopes.SubjectProfileManage];
 
const accessToken = await WireWheelSDK.getToken(
  {
    issuer: process.env.issuerURL,
    clientId: process.env.clientId,
    clientSecret: process.env.clientSecret
  },
  scopes

)

scopes.sort()

console.log(accessToken);

const client = await WireWheelSDK.createClient({
  token: accessToken,
  apiUrl: https://api.upcp.wirewheel.io',
})

const subject = Subject.anonymous()

let cs = await client.createConsent({
  subject: Subject.verified('some-verified-id'),
  actions: [{ action: ActionType.Accept, target: 'target', vendor: 'vendor' }],
  attributes: {  },
  tags: ['sample-app'],
  compliance: { privacyPolicy: {
        version: "1",
         url: "http://foo.com/privacy.html" 
  }}
});

console.log("consent " + cs + "subject Id " + subject.anonymousId);

Responds with the subject anonymous Id.

consent Createdsubject Id a4dad4ef-aa58-4c3a-8701-85b3bee151a9

Create a Subject the Client Directly

As an alternative to using CreateConsentPayloadBuilder.newFor(subject), you can provide a subjectId when you instantiate the client to create a subject.

import { WireWheelSDK, Subject, Scopes, CreateConsentPayloadBuilder} from '@wirewheelio/cmp-javascript-sdk'
 
const scopes = ['consent-insert-api consent-get-api subject-profile-manage']


const accessToken = await WireWheelSDK.getToken(
  {
    issuer: process.env.issuerURL,
    clientId: process.env.clientId,
    clientSecret: process.env.clientSecret
  },
  scopes
)

const subject = Subject.anonymous()

const client = await WireWheelSDK.createClient({
  subject: subject,
  token: accessToken,
  apiUrl: 'https://api.upcp.wirewheel.io',
})

 
console.log("subject created ", client.subject);

Responds:

{
  verifiedId: undefined,
  anonymousId: '3bf9b86a-17cb-44cc-bd95-d9ad0349ff91'
}

Didn’t find what you were looking for?

Email our team: [email protected]?subject=UPCP