## Generate DDEX from JSON

Use this to test a way of compiling DDEX fragments without loading the entire XML doc in memory. 

The best way to use this is to simply change runner.ts to run the function you want, then run it (see below)
We download the files we want to disk and as we do that we record in a map product ids and the sound recordings on them 
```javascript 
{ 
    'productId': [ 'filename1.xml', 'filename2.xml', 'filename3.xml'],
    'nextproductId': ['filename1.xml', 'filname7.xml']
}
``` 

I have broken the process down into two sections, so you can run them separately for testing. They can also be run together but you won't get the right results. 

Both sections are based on the code in the DDEX compiler, and use the output of the DDEX generator lambda, which are XML fragements living in S3, one per sound recording. 

 -  buildDDex() will download you the required files and product the map. 

 -  listDirs() will update the downloaded fragments, changing the NumberOfSoundRecordingsClaimedInCarrier in them to be the correct value.

 I have used hard coded values in some places for simplicitiy (e.g. orderId)

 If you want to test this, after you've downloaded the files, you must manually alter then like this: 

 ```<NumberOfSoundRecordingsClaimedInCarrier>#3615930137398#</NumberOfSoundRecordingsClaimedInCarrier>``` 

 where you replace 1 with a hash then the product id of that host sound carrier (product) followed by another hash.
 You don't need to do this on all files.  For this fix to work the DDEX Generator will have to change to generate this 'hash productId hash' value of course. 
 At the end of the process you should see the values updated. 

From the `ddex` root dir run: 
```bash
yarn generate:ddex
```

## DDEX Builder version
Note there is also some code in ddex.ts which tries to do the same thing using the DDEX Builder. 
I didn't quite get it to work. 

## TODO 
Compile the fragments (see publshing example maybe, speak to Jess or Jorge)
Add the header and the footer
Upload to S3


## Graphql
Note you can ignore this section if you're only generating DDEX (see above). 

If you need to do anything involving `graphql`, you'll need to specify the `qa` graphql endpoint. For example:

```bash
GRAPHQL_URL=https://qa-graphql-router.theorchard.io/graphql yarn compile:run
```