diff --git a/README.md b/README.md index 686a337..4c688d6 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,12 @@ npm i cmcd.js ``` ## Usage -All CMCD properties are optional. Properties that are with nullish values will not be serialized. +All CMCD properties are optional. Properties that with nullish values will not be serialized. ```typescript import { Cmcd, + CmcdHeaader, CmcdObjectType, CmcdStreamingFormat, CmcdStreamType, @@ -41,10 +42,10 @@ const headers = toHeaders(data); console.log(headers); /* { - 'cmcd-request': 'mtp=10000', - 'cmcd-object': 'br=200,ot=m', - 'cmcd-session': 'sf=d,cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",st=v', - 'cmcd-status': 'bs', + 'CMCD-Object': 'br=200,ot=m', + 'CMCD-Request': 'mtp=10000', + 'CMCD-Session': 'sf=d,cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",st=v', + 'CMCD-Status': 'bs', } */ @@ -53,6 +54,30 @@ console.log(json); /* '{"mtp":10000,"su":false,"br":200,"ot":"m","sf":"d","cid":"9f7f349b-baba-43d7-bbe7-b0dc8a65af0d","st":"v","bs":true}' */ + +/* Custom Fields */ +data['com.example-a'] = 'hello'; +data['com.example-b']: 1234; +data['com.example-c']: true; +data['com.example-d']: Symbol('s'); + +const headerMap = { + ['com.example-a']: CmcdHeader.Object, + ['com.example-b']: CmcdHeader.Session, + ['com.example-c']: CmcdHeader.Status, + // Unmapped custom fields are added to the CMCD-Request header +}; + +const headers = toHeaders(data, headerMap); +console.log(headers); +/* +{ + 'CMCD-Object': 'br=200,com.example-a="hello",ot=m', + 'CMCD-Request': 'mtp=10000', + 'CMCD-Session': 'cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",com.example-b=1234,sf=d,st=v', + 'CMCD-Status': 'bs,com.example-c', +} +*/ ``` ## API Docs diff --git a/package-lock.json b/package-lock.json index b40022b..e4b632f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cmcd.js", - "version": "0.6.0", + "version": "0.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cmcd.js", - "version": "0.6.0", + "version": "0.6.1", "license": "ISC", "devDependencies": { "@types/jest": "27.0.2", diff --git a/package.json b/package.json index 7f532f1..860739b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cmcd.js", - "version": "0.6.0", + "version": "0.6.1", "description": "CMCD (Common Media Client Data) library with Typescript definitions", "main": "dist/cmcd.min.js", "types": "dist/types/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 0a67ecd..5efcaf5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export * from './Cmcd'; +export * from './CmcdCustomKey'; export * from './CmcdHeader'; export * from './CmcdKey'; export * from './CmcdObjectType';