# GPP JS Integration

## What is this? 

This is a small Typescript module that provides some functions that wrap functionality implemented by the IAB's CMP API npm package, `@iabgpp/cmpapi`. 
`gpp-encoder.ts` provides utilities for encoding and decoding GPP strings for Fides PrivacyExperiences. This module does NOT contain any UI components,
and is meant to be run in a Node runtime. This allows it to be called from the Fidesplus backend!

## How to run it

To execute a function from the `gpp-encoder` script, you first need to compile the TypeScript code into JavaScript. You can run `npm run build` on this folder, or alternatively `npm run dev` to have the script auto-compile every time you make a change to the TypeScript code. 

Then, use the  `node` command to run the file, with the `-e` flag (to "eval" the code); you'll need to `require` the JS file (which lives in the `/compiled` folder), and call the function:

`node -e require('./compiled/gpp-encoder.js').encodePrivacyExperienceIntoGppString(...arguments go here...)`

You can also call the methods defined in `gpp-encoder.ts` from a Python file. An example can be found in `src/fidesplus/api/gpp_utils.py` , in the function `encode_gpp_string_for_experience`.

### Hot reloading 

If you're calling the JS script from a Python file within Fidesplus, and want changes to the TS script to be automatically picked up by Fidesplus, you need to follow these steps:

1. In the Fidesplus `docker-compose` file, look for the line `- /fidesplus/src/fidesplus/gpp_js_integration/compiled` and comment it out (remember to uncomment it before merging). Restart Fidesplus.
2. In a separate shell from where you're running Fidesplus, cd into this directory (`src/fidesplus/gpp_js_integration`), and run `npm run dev`. This will
automatically re-compile the JS files every time you make a change in the TS file.
3. Enjoy the hot reloading!
