diff --git a/bin/publish-version b/bin/publish-version index 38479d88..695e678d 100755 --- a/bin/publish-version +++ b/bin/publish-version @@ -3,7 +3,7 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD) DIFF=$(git diff HEAD) ROOT=$(git rev-parse --show-toplevel) -npm_package_version=2.7.1 +npm_package_version=2.8.0 #if [[ -n $DIFF ]]; then # diff --git a/bin/version b/bin/version index 87c3fb3c..4382c59a 100755 --- a/bin/version +++ b/bin/version @@ -1,7 +1,7 @@ #!/bin/bash ROOT=$(git rev-parse --show-toplevel) -npm_package_version=2.7.1 +npm_package_version=2.8.0 cd $ROOT diff --git a/modules/cli/package.json b/modules/cli/package.json index 3cc672ef..0e332405 100644 --- a/modules/cli/package.json +++ b/modules/cli/package.json @@ -1,6 +1,6 @@ { "name": "@pubtech-ai/cli", - "version": "2.7.1", + "version": "2.8.0", "description": "Decode a iab TCF (Transparency and Consent Framework) TC String via the command line", "author": "Mayank Mishra ", "homepage": "https://iabtcf.com/", @@ -27,7 +27,7 @@ "lint": "eslint `find src -name '*.ts'`" }, "dependencies": { - "@pubtech-ai/core": "2.7.1" + "@pubtech-ai/core": "2.8.0" }, "devDependencies": { "@types/node": "18.17.4", diff --git a/modules/cmpapi/package.json b/modules/cmpapi/package.json index 70f22e10..1b72c102 100644 --- a/modules/cmpapi/package.json +++ b/modules/cmpapi/package.json @@ -1,6 +1,6 @@ { "name": "@pubtech-ai/cmpapi", - "version": "2.7.1", + "version": "2.8.0", "description": "Ensures other in-page digital marketing technologies have access to CMP transparency and consent information for the iab. Transparency and Consent Framework (TCF).", "author": "Mayank Mishra ", "homepage": "https://iabtcf.com/", @@ -31,8 +31,8 @@ "@pubtech-ai/core": ">=1.0.0" }, "devDependencies": { - "@pubtech-ai/stub": "2.7.1", - "@pubtech-ai/testing": "2.7.1", + "@pubtech-ai/stub": "2.8.0", + "@pubtech-ai/testing": "2.8.0", "@istanbuljs/nyc-config-typescript": "^0.1.3", "@types/mocha": "^9.1.0", "@types/sinon": "10.0.11", diff --git a/modules/core/package.json b/modules/core/package.json index fecf3eb9..f3bbcaa1 100644 --- a/modules/core/package.json +++ b/modules/core/package.json @@ -1,6 +1,6 @@ { "name": "@pubtech-ai/core", - "version": "2.7.1", + "version": "2.8.0", "description": "Ensures consistent encoding and decoding of TC Signals for the iab. Transparency and Consent Framework (TCF).", "author": "Mayank Mishra ", "homepage": "https://iabtcf.com/", @@ -28,7 +28,7 @@ "test-cov": "rm -rf coverage; nyc --reporter=html mocha" }, "devDependencies": { - "@pubtech-ai/testing": "2.7.1", + "@pubtech-ai/testing": "2.8.0", "@istanbuljs/nyc-config-typescript": "^0.1.3", "@types/sinon": "^10.0.11", "@types/sinon-chai": "3.2.8", diff --git a/modules/core/src/TCString.ts b/modules/core/src/TCString.ts index d1491e45..ea148648 100644 --- a/modules/core/src/TCString.ts +++ b/modules/core/src/TCString.ts @@ -69,13 +69,14 @@ export class TCString { * @param {string} encodedTCString - base64url encoded Transparency and * Consent String to decode - can also be a single or group of segments of * the string - * @param {string} [tcModel] - model to enhance with the information. If + * @param {TCModel} tcModel - model to enhance with the information. If * none is passed a new instance of TCModel will be created. + * @param {boolean} useCached - if true it will return a reference to the same TCModel already created previously. * @return {TCModel} - Returns populated TCModel */ - public static decode(encodedTCString: string, tcModel?: TCModel): TCModel { + public static decode(encodedTCString: string, tcModel?: TCModel, useCached = false): TCModel { - if (decodeCachedResults[encodedTCString]) { + if (useCached && decodeCachedResults[encodedTCString]) { return decodeCachedResults[encodedTCString]; diff --git a/modules/core/src/encoder/field/PurposeRestrictionVectorEncoder.ts b/modules/core/src/encoder/field/PurposeRestrictionVectorEncoder.ts index 82476494..66d2ccf9 100644 --- a/modules/core/src/encoder/field/PurposeRestrictionVectorEncoder.ts +++ b/modules/core/src/encoder/field/PurposeRestrictionVectorEncoder.ts @@ -16,7 +16,7 @@ export class PurposeRestrictionVectorEncoder { const gvlVendorIds = Array.from(prVector.gvl.vendorIds); - const nextGvlVendor = (vendorId, lastVendorId): number => { + const nextGvlVendor = (vendorId, lastVendorId) => { const firstIndex = gvlVendorIds.indexOf(vendorId); const lastIndex = gvlVendorIds.indexOf(lastVendorId); @@ -24,11 +24,18 @@ export class PurposeRestrictionVectorEncoder { if (lastIndex - firstIndex > 0) { const nextIndex = gvlVendorIds.indexOf(vendorId + 1); - return gvlVendorIds[nextIndex]; + + return { + nextVendorId: gvlVendorIds[nextIndex], + index: gvlVendorIds[firstIndex + 1], + }; } - return vendorId; + return { + nextVendorId: vendorId, + index: vendorId, + }; }; @@ -73,10 +80,28 @@ export class PurposeRestrictionVectorEncoder { } + let isRangeEncodeRequired = i === len - 1; + + if (!isRangeEncodeRequired) { + + const {nextVendorId, index} = nextGvlVendor(vendorId, vendors[len - 1]); + + if (vendors[i + 1] > nextVendorId) { + + isRangeEncodeRequired = true; + + } else if (index > i && index < len) { + + i = index; + + } + + } + /** * either end of the loop or there are GVL vendor IDs before the next one */ - if (i === len - 1 || vendors[i + 1] > nextGvlVendor(vendorId, vendors[len - 1])) { + if (isRangeEncodeRequired) { /** * it's a range entry if we've got something other than the start @@ -109,7 +134,7 @@ export class PurposeRestrictionVectorEncoder { } /** - * now that the range encoding is built, encode the number of ranges + * now that the range encoding is built, encode the number of ranges * and then append the range field to the bitString. */ bitString += IntEncoder.encode(numEntries, BitLength.numEntries); diff --git a/modules/stub/package.json b/modules/stub/package.json index 7a2dac54..e11562c3 100644 --- a/modules/stub/package.json +++ b/modules/stub/package.json @@ -1,6 +1,6 @@ { "name": "@pubtech-ai/stub", - "version": "2.7.1", + "version": "2.8.0", "description": "CMP API Stub code", "author": "Mayank Mishra ", "homepage": "https://iabtcf.com/", diff --git a/modules/testing/package.json b/modules/testing/package.json index 7f9e9968..2ab4e291 100644 --- a/modules/testing/package.json +++ b/modules/testing/package.json @@ -1,6 +1,6 @@ { "name": "@pubtech-ai/testing", - "version": "2.7.1", + "version": "2.8.0", "description": "Shared testing utilities", "author": "Mayank Mishra ", "homepage": "https://iabtcf.com/",