@pubtech-ai/core 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +527 -0
- package/lib/cjs/Cloneable.d.ts +27 -0
- package/lib/cjs/Cloneable.js +1 -0
- package/lib/cjs/GVL.d.ts +295 -0
- package/lib/cjs/GVL.js +1 -0
- package/lib/cjs/Json.d.ts +20 -0
- package/lib/cjs/Json.js +1 -0
- package/lib/cjs/TCModel.d.ts +337 -0
- package/lib/cjs/TCModel.js +1 -0
- package/lib/cjs/TCString.d.ts +27 -0
- package/lib/cjs/TCString.js +1 -0
- package/lib/cjs/encoder/Base64Url.d.ts +29 -0
- package/lib/cjs/encoder/Base64Url.js +1 -0
- package/lib/cjs/encoder/BitLength.d.ts +32 -0
- package/lib/cjs/encoder/BitLength.js +1 -0
- package/lib/cjs/encoder/EncodingOptions.d.ts +6 -0
- package/lib/cjs/encoder/EncodingOptions.js +1 -0
- package/lib/cjs/encoder/SegmentEncoder.d.ts +8 -0
- package/lib/cjs/encoder/SegmentEncoder.js +1 -0
- package/lib/cjs/encoder/SemanticPreEncoder.d.ts +6 -0
- package/lib/cjs/encoder/SemanticPreEncoder.js +1 -0
- package/lib/cjs/encoder/field/BooleanEncoder.d.ts +4 -0
- package/lib/cjs/encoder/field/BooleanEncoder.js +1 -0
- package/lib/cjs/encoder/field/DateEncoder.d.ts +4 -0
- package/lib/cjs/encoder/field/DateEncoder.js +1 -0
- package/lib/cjs/encoder/field/FieldEncoderMap.d.ts +1 -0
- package/lib/cjs/encoder/field/FieldEncoderMap.js +1 -0
- package/lib/cjs/encoder/field/FixedVectorEncoder.d.ts +5 -0
- package/lib/cjs/encoder/field/FixedVectorEncoder.js +1 -0
- package/lib/cjs/encoder/field/IntEncoder.d.ts +4 -0
- package/lib/cjs/encoder/field/IntEncoder.js +1 -0
- package/lib/cjs/encoder/field/LangEncoder.d.ts +4 -0
- package/lib/cjs/encoder/field/LangEncoder.js +1 -0
- package/lib/cjs/encoder/field/PurposeRestrictionVectorEncoder.d.ts +5 -0
- package/lib/cjs/encoder/field/PurposeRestrictionVectorEncoder.js +1 -0
- package/lib/cjs/encoder/field/VectorEncodingType.d.ts +4 -0
- package/lib/cjs/encoder/field/VectorEncodingType.js +1 -0
- package/lib/cjs/encoder/field/VendorVectorEncoder.d.ts +6 -0
- package/lib/cjs/encoder/field/VendorVectorEncoder.js +1 -0
- package/lib/cjs/encoder/field/index.d.ts +9 -0
- package/lib/cjs/encoder/field/index.js +1 -0
- package/lib/cjs/encoder/index.d.ts +7 -0
- package/lib/cjs/encoder/index.js +1 -0
- package/lib/cjs/encoder/sequence/FieldSequence.d.ts +5 -0
- package/lib/cjs/encoder/sequence/FieldSequence.js +1 -0
- package/lib/cjs/encoder/sequence/SegmentSequence.d.ts +9 -0
- package/lib/cjs/encoder/sequence/SegmentSequence.js +1 -0
- package/lib/cjs/encoder/sequence/SequenceVersionMap.d.ts +7 -0
- package/lib/cjs/encoder/sequence/SequenceVersionMap.js +1 -0
- package/lib/cjs/encoder/sequence/index.d.ts +3 -0
- package/lib/cjs/encoder/sequence/index.js +1 -0
- package/lib/cjs/errors/DecodingError.d.ts +15 -0
- package/lib/cjs/errors/DecodingError.js +1 -0
- package/lib/cjs/errors/EncodingError.d.ts +15 -0
- package/lib/cjs/errors/EncodingError.js +1 -0
- package/lib/cjs/errors/GVLError.d.ts +15 -0
- package/lib/cjs/errors/GVLError.js +1 -0
- package/lib/cjs/errors/TCModelError.d.ts +16 -0
- package/lib/cjs/errors/TCModelError.js +1 -0
- package/lib/cjs/errors/index.d.ts +4 -0
- package/lib/cjs/errors/index.js +1 -0
- package/lib/cjs/index.d.ts +8 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/model/BinarySearchTree.d.ts +30 -0
- package/lib/cjs/model/BinarySearchTree.js +1 -0
- package/lib/cjs/model/ConsentLanguages.d.ts +6 -0
- package/lib/cjs/model/ConsentLanguages.js +1 -0
- package/lib/cjs/model/DeviceDisclosure.d.ts +9 -0
- package/lib/cjs/model/DeviceDisclosure.js +1 -0
- package/lib/cjs/model/DeviceDisclosureStorageAccessType.d.ts +5 -0
- package/lib/cjs/model/DeviceDisclosureStorageAccessType.js +1 -0
- package/lib/cjs/model/Fields.d.ts +29 -0
- package/lib/cjs/model/Fields.js +1 -0
- package/lib/cjs/model/IntMap.d.ts +13 -0
- package/lib/cjs/model/IntMap.js +1 -0
- package/lib/cjs/model/KeyMap.d.ts +12 -0
- package/lib/cjs/model/KeyMap.js +1 -0
- package/lib/cjs/model/PurposeRestriction.d.ts +33 -0
- package/lib/cjs/model/PurposeRestriction.js +1 -0
- package/lib/cjs/model/PurposeRestrictionVector.d.ts +100 -0
- package/lib/cjs/model/PurposeRestrictionVector.js +1 -0
- package/lib/cjs/model/RestrictionType.d.ts +19 -0
- package/lib/cjs/model/RestrictionType.js +1 -0
- package/lib/cjs/model/Segment.d.ts +6 -0
- package/lib/cjs/model/Segment.js +1 -0
- package/lib/cjs/model/SegmentIDs.d.ts +12 -0
- package/lib/cjs/model/SegmentIDs.js +1 -0
- package/lib/cjs/model/Vector.d.ts +72 -0
- package/lib/cjs/model/Vector.js +1 -0
- package/lib/cjs/model/gvl/ByPurposeVendorMap.d.ts +7 -0
- package/lib/cjs/model/gvl/ByPurposeVendorMap.js +1 -0
- package/lib/cjs/model/gvl/DataCategory.d.ts +4 -0
- package/lib/cjs/model/gvl/DataCategory.js +1 -0
- package/lib/cjs/model/gvl/DataRetention.d.ts +6 -0
- package/lib/cjs/model/gvl/DataRetention.js +1 -0
- package/lib/cjs/model/gvl/Declarations.d.ts +13 -0
- package/lib/cjs/model/gvl/Declarations.js +1 -0
- package/lib/cjs/model/gvl/Feature.d.ts +5 -0
- package/lib/cjs/model/gvl/Feature.js +1 -0
- package/lib/cjs/model/gvl/GVLMapItem.d.ts +4 -0
- package/lib/cjs/model/gvl/GVLMapItem.js +1 -0
- package/lib/cjs/model/gvl/IDSetMap.d.ts +2 -0
- package/lib/cjs/model/gvl/IDSetMap.js +1 -0
- package/lib/cjs/model/gvl/Purpose.d.ts +5 -0
- package/lib/cjs/model/gvl/Purpose.js +1 -0
- package/lib/cjs/model/gvl/Stack.d.ts +6 -0
- package/lib/cjs/model/gvl/Stack.js +1 -0
- package/lib/cjs/model/gvl/Vendor.d.ts +24 -0
- package/lib/cjs/model/gvl/Vendor.js +1 -0
- package/lib/cjs/model/gvl/VendorList.d.ts +10 -0
- package/lib/cjs/model/gvl/VendorList.js +1 -0
- package/lib/cjs/model/gvl/VendorUrl.d.ts +5 -0
- package/lib/cjs/model/gvl/VendorUrl.js +1 -0
- package/lib/cjs/model/gvl/index.d.ts +10 -0
- package/lib/cjs/model/gvl/index.js +1 -0
- package/lib/cjs/model/index.d.ts +14 -0
- package/lib/cjs/model/index.js +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/mjs/Cloneable.d.ts +27 -0
- package/lib/mjs/Cloneable.js +76 -0
- package/lib/mjs/GVL.d.ts +295 -0
- package/lib/mjs/GVL.js +591 -0
- package/lib/mjs/Json.d.ts +20 -0
- package/lib/mjs/Json.js +74 -0
- package/lib/mjs/TCModel.d.ts +337 -0
- package/lib/mjs/TCModel.js +512 -0
- package/lib/mjs/TCString.d.ts +27 -0
- package/lib/mjs/TCString.js +71 -0
- package/lib/mjs/encoder/Base64Url.d.ts +29 -0
- package/lib/mjs/encoder/Base64Url.js +80 -0
- package/lib/mjs/encoder/BitLength.d.ts +32 -0
- package/lib/mjs/encoder/BitLength.js +32 -0
- package/lib/mjs/encoder/EncodingOptions.d.ts +6 -0
- package/lib/mjs/encoder/EncodingOptions.js +1 -0
- package/lib/mjs/encoder/SegmentEncoder.d.ts +8 -0
- package/lib/mjs/encoder/SegmentEncoder.js +106 -0
- package/lib/mjs/encoder/SemanticPreEncoder.d.ts +6 -0
- package/lib/mjs/encoder/SemanticPreEncoder.js +133 -0
- package/lib/mjs/encoder/field/BooleanEncoder.d.ts +4 -0
- package/lib/mjs/encoder/field/BooleanEncoder.js +9 -0
- package/lib/mjs/encoder/field/DateEncoder.d.ts +4 -0
- package/lib/mjs/encoder/field/DateEncoder.js +15 -0
- package/lib/mjs/encoder/field/FieldEncoderMap.d.ts +1 -0
- package/lib/mjs/encoder/field/FieldEncoderMap.js +39 -0
- package/lib/mjs/encoder/field/FixedVectorEncoder.d.ts +5 -0
- package/lib/mjs/encoder/field/FixedVectorEncoder.js +25 -0
- package/lib/mjs/encoder/field/IntEncoder.d.ts +4 -0
- package/lib/mjs/encoder/field/IntEncoder.js +25 -0
- package/lib/mjs/encoder/field/LangEncoder.d.ts +4 -0
- package/lib/mjs/encoder/field/LangEncoder.js +36 -0
- package/lib/mjs/encoder/field/PurposeRestrictionVectorEncoder.d.ts +5 -0
- package/lib/mjs/encoder/field/PurposeRestrictionVectorEncoder.js +109 -0
- package/lib/mjs/encoder/field/VectorEncodingType.d.ts +4 -0
- package/lib/mjs/encoder/field/VectorEncodingType.js +5 -0
- package/lib/mjs/encoder/field/VendorVectorEncoder.d.ts +6 -0
- package/lib/mjs/encoder/field/VendorVectorEncoder.js +156 -0
- package/lib/mjs/encoder/field/index.d.ts +9 -0
- package/lib/mjs/encoder/field/index.js +9 -0
- package/lib/mjs/encoder/index.d.ts +7 -0
- package/lib/mjs/encoder/index.js +7 -0
- package/lib/mjs/encoder/sequence/FieldSequence.d.ts +5 -0
- package/lib/mjs/encoder/sequence/FieldSequence.js +53 -0
- package/lib/mjs/encoder/sequence/SegmentSequence.d.ts +9 -0
- package/lib/mjs/encoder/sequence/SegmentSequence.js +52 -0
- package/lib/mjs/encoder/sequence/SequenceVersionMap.d.ts +7 -0
- package/lib/mjs/encoder/sequence/SequenceVersionMap.js +1 -0
- package/lib/mjs/encoder/sequence/index.d.ts +3 -0
- package/lib/mjs/encoder/sequence/index.js +4 -0
- package/lib/mjs/errors/DecodingError.d.ts +15 -0
- package/lib/mjs/errors/DecodingError.js +18 -0
- package/lib/mjs/errors/EncodingError.d.ts +15 -0
- package/lib/mjs/errors/EncodingError.js +18 -0
- package/lib/mjs/errors/GVLError.d.ts +15 -0
- package/lib/mjs/errors/GVLError.js +18 -0
- package/lib/mjs/errors/TCModelError.d.ts +16 -0
- package/lib/mjs/errors/TCModelError.js +19 -0
- package/lib/mjs/errors/index.d.ts +4 -0
- package/lib/mjs/errors/index.js +4 -0
- package/lib/mjs/index.d.ts +8 -0
- package/lib/mjs/index.js +9 -0
- package/lib/mjs/model/BinarySearchTree.d.ts +30 -0
- package/lib/mjs/model/BinarySearchTree.js +267 -0
- package/lib/mjs/model/ConsentLanguages.d.ts +6 -0
- package/lib/mjs/model/ConsentLanguages.js +42 -0
- package/lib/mjs/model/DeviceDisclosure.d.ts +9 -0
- package/lib/mjs/model/DeviceDisclosure.js +1 -0
- package/lib/mjs/model/DeviceDisclosureStorageAccessType.d.ts +5 -0
- package/lib/mjs/model/DeviceDisclosureStorageAccessType.js +6 -0
- package/lib/mjs/model/Fields.d.ts +29 -0
- package/lib/mjs/model/Fields.js +29 -0
- package/lib/mjs/model/IntMap.d.ts +13 -0
- package/lib/mjs/model/IntMap.js +1 -0
- package/lib/mjs/model/KeyMap.d.ts +12 -0
- package/lib/mjs/model/KeyMap.js +1 -0
- package/lib/mjs/model/PurposeRestriction.d.ts +33 -0
- package/lib/mjs/model/PurposeRestriction.js +69 -0
- package/lib/mjs/model/PurposeRestrictionVector.d.ts +100 -0
- package/lib/mjs/model/PurposeRestrictionVector.js +286 -0
- package/lib/mjs/model/RestrictionType.d.ts +19 -0
- package/lib/mjs/model/RestrictionType.js +20 -0
- package/lib/mjs/model/Segment.d.ts +6 -0
- package/lib/mjs/model/Segment.js +7 -0
- package/lib/mjs/model/SegmentIDs.d.ts +12 -0
- package/lib/mjs/model/SegmentIDs.js +21 -0
- package/lib/mjs/model/Vector.d.ts +72 -0
- package/lib/mjs/model/Vector.js +161 -0
- package/lib/mjs/model/gvl/ByPurposeVendorMap.d.ts +7 -0
- package/lib/mjs/model/gvl/ByPurposeVendorMap.js +1 -0
- package/lib/mjs/model/gvl/DataCategory.d.ts +4 -0
- package/lib/mjs/model/gvl/DataCategory.js +1 -0
- package/lib/mjs/model/gvl/DataRetention.d.ts +6 -0
- package/lib/mjs/model/gvl/DataRetention.js +1 -0
- package/lib/mjs/model/gvl/Declarations.d.ts +13 -0
- package/lib/mjs/model/gvl/Declarations.js +1 -0
- package/lib/mjs/model/gvl/Feature.d.ts +5 -0
- package/lib/mjs/model/gvl/Feature.js +2 -0
- package/lib/mjs/model/gvl/GVLMapItem.d.ts +4 -0
- package/lib/mjs/model/gvl/GVLMapItem.js +1 -0
- package/lib/mjs/model/gvl/IDSetMap.d.ts +2 -0
- package/lib/mjs/model/gvl/IDSetMap.js +1 -0
- package/lib/mjs/model/gvl/Purpose.d.ts +5 -0
- package/lib/mjs/model/gvl/Purpose.js +1 -0
- package/lib/mjs/model/gvl/Stack.d.ts +6 -0
- package/lib/mjs/model/gvl/Stack.js +1 -0
- package/lib/mjs/model/gvl/Vendor.d.ts +24 -0
- package/lib/mjs/model/gvl/Vendor.js +1 -0
- package/lib/mjs/model/gvl/VendorList.d.ts +10 -0
- package/lib/mjs/model/gvl/VendorList.js +1 -0
- package/lib/mjs/model/gvl/VendorUrl.d.ts +5 -0
- package/lib/mjs/model/gvl/VendorUrl.js +1 -0
- package/lib/mjs/model/gvl/index.d.ts +10 -0
- package/lib/mjs/model/gvl/index.js +11 -0
- package/lib/mjs/model/index.d.ts +14 -0
- package/lib/mjs/model/index.js +14 -0
- package/lib/mjs/package.json +3 -0
- package/package.json +95 -0
package/README.md
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@pubtech-ai/core)
|
|
2
|
+
[](https://www.npmjs.org/package/@pubtech-ai/core)
|
|
3
|
+
[](https://circleci.com/gh/InteractiveAdvertisingBureau/pubtech-ai-es)
|
|
4
|
+
|
|
5
|
+
# @pubtech-ai/core
|
|
6
|
+
|
|
7
|
+
Ensures consistent encoding and decoding of [IAB's Transparency and Consent Framework (TCF)](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework) [TC Strings](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) and the stateful persistence of the Transparency and Consent information while providing tools for the handling and manipulation of the [TCF](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework) [Global Vendor List](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#the-global-vendor-list) data all free and open sourced ([License](LICENSE)).
|
|
8
|
+
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Including in your project](#including-in-your-project)
|
|
11
|
+
- [`TCModel`](#tcmodel) - Creates a stateful model to store a Transparency and Consent user interaction with all the fields specifed in the [TC string](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) encoding schema.
|
|
12
|
+
- [Information that is stored in a TC string (specification)](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#what-information-is-stored-in-a-tc-string)
|
|
13
|
+
- [GVL](#gvl) - The [Global Vendor List](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#the-global-vendor-list) contains all of the information about vendors and legal language to display to users in a CMP user interface, this component helps manage it.
|
|
14
|
+
+ [Autoload latest vendor-list.json](#autoload-latest-vendor-listjson)
|
|
15
|
+
+ [Autoload specific version vendor-list.json](#autoload-specific-version-vendor-listjson)
|
|
16
|
+
+ [Pass vendor-list.json object](#pass-vendor-listjson-object)
|
|
17
|
+
+ [Change GVL Language](#change-gvl-language)
|
|
18
|
+
+ [Cloning a GVL with a Non-Default language](#cloning-a-gvl-with-a-non-default-language)
|
|
19
|
+
+ [Get only vendors with a specific feature or purpose under legal basis](#get-only-vendors-with-a-specific-feature-or-purpose-under-legal-basis)
|
|
20
|
+
+ [Narrow the list of vendors](#narrow-the-list-of-vendors)
|
|
21
|
+
+ [filtering](#narrow-the-list-of-vendors) vendors for subsets of the GVL.
|
|
22
|
+
+ [sorting of vendors based on purpose legal bases](#get-only-vendors-with-a-specific-feature-or-purpose-under-legal-basis) that the CMP will need to show the vendors in.
|
|
23
|
+
+ loading [GVL JSON files](#autoload-specific-vendor-listjson)
|
|
24
|
+
+ loading [language translations](#change-gvl-language) of Purposes, Features, Special Features, Special Purposes, and Stacks
|
|
25
|
+
- [TCString](#tcstring) - Encodes a [`TCModel`](#tcmodel) into a [TC string](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) and decodes a [TC string](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) into a [`TCModel`](#tcmodel)
|
|
26
|
+
+ [Decode an IAB TC String](#decode-an-iab-tc-string)
|
|
27
|
+
+ [Encode an IAB TC String](#encode-an-iab-tc-string)
|
|
28
|
+
|
|
29
|
+
#### Installation
|
|
30
|
+
|
|
31
|
+
npm
|
|
32
|
+
```
|
|
33
|
+
npm install @pubtech-ai/core --save
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
yarn
|
|
37
|
+
```
|
|
38
|
+
yarn add @pubtech-ai/core
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Using
|
|
42
|
+
|
|
43
|
+
This example demonstrates the basic use case of a CMP creating a "default all-no" TC string.
|
|
44
|
+
```javascript
|
|
45
|
+
import {TCModel, TCString, GVL} from '@pubtech-ai/core';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* the IAB requires CMPs to host their own vendor-list.json files. This must
|
|
49
|
+
* be set before creating any instance of the GVL class.
|
|
50
|
+
*/
|
|
51
|
+
GVL.baseUrl = "http://mydomain.com/cmp/vendorlist";
|
|
52
|
+
|
|
53
|
+
// create a new TC string
|
|
54
|
+
const tcModel = new TCModel(new GVL());
|
|
55
|
+
|
|
56
|
+
// Some fields will not be populated until a GVL is loaded
|
|
57
|
+
tcModel.gvl.readyPromise.then(() => {
|
|
58
|
+
|
|
59
|
+
// Set values on tcModel...
|
|
60
|
+
|
|
61
|
+
const encodedString = TCString.encode(tcModel);
|
|
62
|
+
|
|
63
|
+
console.log(encodedString); // TC string encoded begins with 'C'
|
|
64
|
+
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// take an encoded TC string and decode into a TCModel
|
|
68
|
+
const decodedTCModel = TCString.decode(encodedString);
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
# TCModel
|
|
73
|
+
|
|
74
|
+
### Creating a new TCModel
|
|
75
|
+
|
|
76
|
+
To encode a `TCModel` a `GVL` must be included.
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
import {TCModel} from '@pubtech-ai/core';
|
|
80
|
+
|
|
81
|
+
// creates a TCModel
|
|
82
|
+
const tcModel = new TCModel();
|
|
83
|
+
|
|
84
|
+
// to encode you must have a cmpId and cmpVersion
|
|
85
|
+
tcModel.cmpId = //{myCMPID}
|
|
86
|
+
tcModel.cmpVersion = //{myCMPVersion}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* we now have a TCString assigned with a GVL which will set vendorListVersion,
|
|
90
|
+
* tcfPolicyVersion and consentLanguage
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### CMP Meta Fields
|
|
96
|
+
|
|
97
|
+
This exmple shows how to set the basic fields that all TC strings need to have set.
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import {TCModel} from '@pubtech-ai/core';
|
|
101
|
+
|
|
102
|
+
const tcModel = new TCModel();
|
|
103
|
+
tcModel.cmpId = // my CMP ID
|
|
104
|
+
tcModel.cmpVersion = // my CMP Version
|
|
105
|
+
tcModel.consentScreen = // On which 'screen' consent was captured; this is a cmp proprietary number encoded into the TC string
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Vectors
|
|
109
|
+
|
|
110
|
+
The `TCModel` leverages a [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) style `Vector` data structure to set consents, optins, allowed, disclosed, and legitimate interest establishment. Properties that leverage this data structure are:
|
|
111
|
+
- **Vendors**
|
|
112
|
+
- `vendorConsents`
|
|
113
|
+
- `vendorLegitimateInterests`
|
|
114
|
+
- `vendorsAllowed`
|
|
115
|
+
- `vendorsDisclosed`
|
|
116
|
+
- **Global Purposes**
|
|
117
|
+
- `purposeConsents`
|
|
118
|
+
- `purposeLegitimateInterests`
|
|
119
|
+
- **Special Feature Opt-Ins**
|
|
120
|
+
- `specialFeatureOptins`
|
|
121
|
+
- **Publisher**
|
|
122
|
+
- `publisherConsents`
|
|
123
|
+
- `publisherCustomConsents`
|
|
124
|
+
- `publisherLegitimateInterests`
|
|
125
|
+
- `publisherCustomLegitimateInterests`
|
|
126
|
+
- `publisherRestrictions`
|
|
127
|
+
- This Vector is a special `PurposeRestrictionVector` of `PurposeRestrictions`
|
|
128
|
+
|
|
129
|
+
**Example with `vendorConsents`**
|
|
130
|
+
|
|
131
|
+
The `vendorConsents` property on the `TCModel` is a `Vector`. This example illustrates the methods of a `Vector`. With the exception of the `publisherRestrictions`, which implements a different type of `PurposeRestrictionVector`, all of the above Vectors will have this interface and functionality.
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
// Give Vendor ID 24 consent
|
|
135
|
+
tcModel.vendorConsents.set(24);
|
|
136
|
+
|
|
137
|
+
console.log(tcModel.vendorConsents.has(24)); // true
|
|
138
|
+
console.log(tcModel.vendorConsents.maxId); // 24
|
|
139
|
+
console.log(tcModel.vendorConsents.size); // 1
|
|
140
|
+
|
|
141
|
+
// remove vendor 24
|
|
142
|
+
tcModel.vendorConsents.unset(24);
|
|
143
|
+
console.log(tcModel.vendorConsents.has(24)); // false
|
|
144
|
+
console.log(tcModel.vendorConsents.maxId); // 0
|
|
145
|
+
console.log(tcModel.vendorConsents.size); // 0
|
|
146
|
+
|
|
147
|
+
// give a group of vendors consent
|
|
148
|
+
tcModel.vendorConsents.set([24, 14, 24, 100, 102]);
|
|
149
|
+
console.log(tcModel.vendorConsents.has(24)); // true
|
|
150
|
+
console.log(tcModel.vendorConsents.has(14)); // true
|
|
151
|
+
console.log(tcModel.vendorConsents.has(200)); // false
|
|
152
|
+
console.log(tcModel.vendorConsents.maxId); // 102
|
|
153
|
+
console.log(tcModel.vendorConsents.size); // 5
|
|
154
|
+
|
|
155
|
+
// loop through all ids 1 to maxId (102 loops)
|
|
156
|
+
tcModel.vendorConsents.forEach((hasConsent, vendorId) => {
|
|
157
|
+
|
|
158
|
+
// check each id for consent
|
|
159
|
+
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// empty everything
|
|
163
|
+
tcModel.vendorConsents.empty();
|
|
164
|
+
|
|
165
|
+
console.log(tcModel.vendorConsents.has(24)); // false
|
|
166
|
+
console.log(tcModel.vendorConsents.maxId); // 0
|
|
167
|
+
console.log(tcModel.vendorConsents.size); // 0
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Setting Publisher Restrictions
|
|
171
|
+
|
|
172
|
+
A [Publisher Restriction](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#what-are-publisher-restrictions) is a restriction placed on a Vendor by a publisher limiting the purposes for which that Vendor is allowed to process personal data. The `TCModel.publisherRestrictions` is an instance of the `PurposeRestrictionVector`, which is a vector containing `PurposeRestrictions`'s.
|
|
173
|
+
|
|
174
|
+
**Example of setting publisher restrictions**
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
|
|
178
|
+
import {TCModel, PurposeRestriction, RestrictionType} from '@pubtech-ai/core';
|
|
179
|
+
|
|
180
|
+
// first you must create a PurposeRestriction
|
|
181
|
+
const purposeRestriction = new PurposeRestriction();
|
|
182
|
+
|
|
183
|
+
purposeRestriction.purposeId = 2;
|
|
184
|
+
purposeRestriction.restrictionType = RestrictionType.NOT_ALLOWED;
|
|
185
|
+
|
|
186
|
+
// vendorID and restriction
|
|
187
|
+
tcModel.publisherRestrictions.add(2000, purposeRestriction);
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# GVL
|
|
193
|
+
|
|
194
|
+
* [Autoload latest vendor-list.json](#autoload-latest-vendor-listjson)
|
|
195
|
+
* [Autoload specific vendor-list.json](#autoload-specific-vendor-listjson)
|
|
196
|
+
* [Pass vendor-list.json object](#pass-vendor-list.json-object)
|
|
197
|
+
* [Change GVL Language](#change-gvl-language)
|
|
198
|
+
* [Cloning a GVL with a Non-Default language](#cloning-a-gvl-with-a-non-default-language)
|
|
199
|
+
* [Get only vendors with a specific feature or purpose under legal basis](#get-only-vendors-with-a-specific-feature-or-purpose-under-legal-basis)
|
|
200
|
+
* [Narrow the list of vendors](#narrow-the-list-of-vendors)
|
|
201
|
+
|
|
202
|
+
The `GVL` class provides two ways to instantiate. Either by passing in a vendor-list.json object to populate it or autoloading a vendor-list.json from a url.
|
|
203
|
+
|
|
204
|
+
### Autoload latest vendor-list.json
|
|
205
|
+
Autoloading a vendor-list.json will accept into the constructor a vendor list version number or if nothing or "LATEST" is passed it will load the latest version of the vendor list. NOTE. You must set the `GVL.baseUrl` parameter before instantiating a GVL instance. If desired the `GVL.latestFilename` may be set if `vendor-list.json` is not used.
|
|
206
|
+
|
|
207
|
+
**Loading default filename**
|
|
208
|
+
```javascript
|
|
209
|
+
import {GVL} from '@pubtech-ai/core';
|
|
210
|
+
|
|
211
|
+
// only needs to be set once per application as this is a static variable
|
|
212
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';
|
|
213
|
+
|
|
214
|
+
// loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json'
|
|
215
|
+
const gvl = new GVL();
|
|
216
|
+
|
|
217
|
+
gvl.readyPromise.then(() => {
|
|
218
|
+
|
|
219
|
+
// GVL has loaded and it's ready to use
|
|
220
|
+
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Loading with custom filename**
|
|
225
|
+
```javascript
|
|
226
|
+
import {GVL} from '@pubtech-ai/core';
|
|
227
|
+
|
|
228
|
+
// only needs to be set once per application as this is a static variable
|
|
229
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';
|
|
230
|
+
|
|
231
|
+
GVL.latestFilename = 'latest/vendorlist.js';
|
|
232
|
+
|
|
233
|
+
// loads 'http://cmp.mysupercoolcmp.com/cmp/latest/vendorlist.json'
|
|
234
|
+
const gvl = new GVL();
|
|
235
|
+
|
|
236
|
+
gvl.readyPromise.then(() => {
|
|
237
|
+
|
|
238
|
+
// GVL has loaded and it's ready to use
|
|
239
|
+
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Autoload specific version vendor-list.json
|
|
244
|
+
Autoloading a specific version requires that you both set the `GVL.baseUrl` static variable and pass into the constructor the version number you wish to load. Optionally if your filename has a version other than `vendor-list-v[VERSION].json` you may set a different filename with version as `GVL.versionedFilename = 'vendorlist[VERSION].json';` and the token `[version]` will be replaced with the version number you pass into the constructor.
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
**Loading default filename for version**
|
|
248
|
+
```javascript
|
|
249
|
+
import {GVL} from '@pubtech-ai/core';
|
|
250
|
+
|
|
251
|
+
// only needs to be set once per application as this is a static variable
|
|
252
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';
|
|
253
|
+
|
|
254
|
+
// loads 'http://cmp.mysupercoolcmp.com/cmp/archives/vendor-list-v23.json'
|
|
255
|
+
const gvl = new GVL(23);
|
|
256
|
+
|
|
257
|
+
gvl.readyPromise.then(() => {
|
|
258
|
+
|
|
259
|
+
// GVL has loaded and it's ready to use
|
|
260
|
+
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Changing version name scheme**
|
|
265
|
+
```javascript
|
|
266
|
+
import {GVL} from '@pubtech-ai/core';
|
|
267
|
+
|
|
268
|
+
// only needs to be set once per application as this is a static variable
|
|
269
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';
|
|
270
|
+
|
|
271
|
+
GVL.versionedFilename = 'vendorlist[VERSION].json';
|
|
272
|
+
|
|
273
|
+
// loads 'http://cmp.mysupercoolcmp.com/cmp/vendorlist23.json'
|
|
274
|
+
const gvl = new GVL(23);
|
|
275
|
+
|
|
276
|
+
gvl.readyPromise.then(() => {
|
|
277
|
+
|
|
278
|
+
// GVL has loaded and it's ready to use
|
|
279
|
+
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Pass vendor-list.json object
|
|
284
|
+
You may also just pass in the json object (not strigified)
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
import {GVL} from '@pubtech-ai/core';
|
|
288
|
+
|
|
289
|
+
const gvl = new GVL(gvljson);
|
|
290
|
+
|
|
291
|
+
// no need for ready promise because no asynchronous action has occurred
|
|
292
|
+
// gvl is ready to use
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Change GVL Language
|
|
296
|
+
All vendorlists are published by default as english. There are alternate languages that the iab publishes which are essetnailly a vendor list without the vendors. `GVL.baseUrl` must be set for langauges changes. To load an alternate you simply call `gvl.changeLanguage(/**language*/);` langauge is the iso639-1 two-letter langauge code. [For the full list of iab provided language translations click here](https://register.consensu.org/Translation). If desired the `GVL.languageFilename` may be set if `purposes-[LANG].json` is not used.
|
|
297
|
+
|
|
298
|
+
**Default filename load**
|
|
299
|
+
```javascript
|
|
300
|
+
import {GVL} from '@pubtech-ai/core';
|
|
301
|
+
|
|
302
|
+
// only needs to be set once per application as this is a static variable
|
|
303
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/';
|
|
304
|
+
|
|
305
|
+
const gvl = new GVL(gvljson);
|
|
306
|
+
|
|
307
|
+
// loads the French langauge
|
|
308
|
+
gvl.changeLanguage('fr').then(() => {
|
|
309
|
+
|
|
310
|
+
// French Language GVL is ready for use
|
|
311
|
+
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Changing filename load**
|
|
316
|
+
```javascript
|
|
317
|
+
import {GVL} from '@pubtech-ai/core';
|
|
318
|
+
|
|
319
|
+
const gvl = new GVL(gvljson);
|
|
320
|
+
|
|
321
|
+
// only needs to be set once per application as this is a static variable
|
|
322
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/';
|
|
323
|
+
|
|
324
|
+
GVL.langaugeFilename = 'langauges/purp[LANG].json';
|
|
325
|
+
|
|
326
|
+
// loads the French langauge from 'http://cmp.mysupercoolcmp.com/purpfr.json'
|
|
327
|
+
gvl.changeLanguage('fr').then(() => {
|
|
328
|
+
|
|
329
|
+
// French Language GVL is ready for use
|
|
330
|
+
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Cloning a GVL with a Non-Default language
|
|
335
|
+
|
|
336
|
+
When cloning a GVL with a non-default language, make sure that any prior `changeLanguage` call is resolved. If changeLanguage has not yet resolved, `clone` will make an http request for the current language but will have no indication of resolving that request since it is synchronous.
|
|
337
|
+
|
|
338
|
+
```javascript
|
|
339
|
+
import {GVL} from '@pubtech-ai/core';
|
|
340
|
+
|
|
341
|
+
const gvl = new GVL();
|
|
342
|
+
|
|
343
|
+
// Resolving changeLanguage promise using thenables.
|
|
344
|
+
gvl.changeLanguage('fr').then(() => {
|
|
345
|
+
|
|
346
|
+
const clone = gvl.clone();
|
|
347
|
+
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
// Resolving changeLanguage through async/await
|
|
351
|
+
const someAsyncFunction = async () => {
|
|
352
|
+
|
|
353
|
+
await gvl.changeLanguage('fr');
|
|
354
|
+
const clone = gvl.clone();
|
|
355
|
+
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
### Get only vendors with a specific feature or purpose under legal basis
|
|
361
|
+
A CMP UI may want to group vendors by what purpose they use under what legal basis and/or features. This can be accomplished quite easily by using one of the 6 grouping methods:
|
|
362
|
+
* `getVendorsWithConsentPurpose(purposeId)`
|
|
363
|
+
* `getVendorsWithFeature(featureId)`
|
|
364
|
+
* `getVendorsWithFlexiblePurpose(purposId)`
|
|
365
|
+
* `getVendorsWithLegIntPurpose(purposId)`
|
|
366
|
+
* `getVendorsWithSpecialFeature(featureId)`
|
|
367
|
+
* `getVendorsWithSpecialPurpose(purposId)`
|
|
368
|
+
|
|
369
|
+
All 6 grouping methods return an `IntMap<Vendor>` object
|
|
370
|
+
|
|
371
|
+
```javascript
|
|
372
|
+
import {GVL} from '@pubtech-ai/core';
|
|
373
|
+
|
|
374
|
+
// only needs to be set once per application as this is a static variable
|
|
375
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';
|
|
376
|
+
|
|
377
|
+
// loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json'
|
|
378
|
+
const gvl = new GVL();
|
|
379
|
+
|
|
380
|
+
gvl.readyPromise.then(() => {
|
|
381
|
+
|
|
382
|
+
const vendorMap = gvl.getVendorsWithConsentPurpose(1);
|
|
383
|
+
|
|
384
|
+
// logs all vendor ids who have specified they require consent for purpose 1
|
|
385
|
+
Object.keys(vendorMap).forEach(console.log);
|
|
386
|
+
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
### Narrow the list of vendors
|
|
391
|
+
If loading a CMP would like to show a subset of the Vendor List a filter may be passed to only work with those vendors on the list.
|
|
392
|
+
|
|
393
|
+
```javascript
|
|
394
|
+
import {GVL} from '@pubtech-ai/core';
|
|
395
|
+
|
|
396
|
+
// only needs to be set once per application as this is a static variable
|
|
397
|
+
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';
|
|
398
|
+
|
|
399
|
+
// loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json'
|
|
400
|
+
const gvl = new GVL();
|
|
401
|
+
|
|
402
|
+
gvl.readyPromise.then(() => {
|
|
403
|
+
|
|
404
|
+
// now this gvl instance only has these 3 vendors
|
|
405
|
+
gvl.narrowVendorsTo([1,2,3]);
|
|
406
|
+
|
|
407
|
+
// will only show the Vendor objects for 1, 2, and 3
|
|
408
|
+
console.log(gvl.vendors);
|
|
409
|
+
|
|
410
|
+
// will only return the vendors within the narrowed vendor list
|
|
411
|
+
const vendorsWithLegInt2 = gvl.getVendorsWithLegIntPurpose(2);
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
# TCString
|
|
419
|
+
|
|
420
|
+
- [Decode](#decode-an-iab-tc-string)
|
|
421
|
+
- [Encode](#encode-an-iab-tc-string)
|
|
422
|
+
- [Encoding Options](#encoding-options)
|
|
423
|
+
- [Encoding a Publisher TC Segment](#encoding-a-publisher-tc-segment)
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
### Decode an IAB TC String
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
|
|
430
|
+
import {TCString, TCModel} from '@pubtech-ai/core';
|
|
431
|
+
|
|
432
|
+
const myTCModel = TCString.decode(encodedTCString);
|
|
433
|
+
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
*returns:* [`TCModel`](#tcmodel)
|
|
437
|
+
|
|
438
|
+
### Encode an IAB TC String
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
import {TCString, TCModel, GVL} from '@pubtech-ai/core';
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* With v2.0 of the TCF, CMPs are required to host their own vendor-list.json for
|
|
445
|
+
* their client-side scripts to consume. This GVL class follows the convention
|
|
446
|
+
* outlined in the GVL URL Version scheme. (latest at vendor-list.json and
|
|
447
|
+
* version specific at archives/vendor-list-v{vendor-list-version}.json
|
|
448
|
+
*/
|
|
449
|
+
GVL.baseUrl = "http://mydomain.com/cmp/vendorlist";
|
|
450
|
+
|
|
451
|
+
// we'll get the latest GVL to encode this TCString to
|
|
452
|
+
const gvl = new GVL("LATEST");
|
|
453
|
+
|
|
454
|
+
// have to wait for it to fetch the json
|
|
455
|
+
gvl.readyPromise.then(() => {
|
|
456
|
+
|
|
457
|
+
const tcModel = new TCModel(gvl);
|
|
458
|
+
const encodedTCString = TCString.encode(tcModel);
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* this will output a default all "no" encoded string to the console at the
|
|
462
|
+
* lastest GVL version.
|
|
463
|
+
*/
|
|
464
|
+
console.log(encodedTCString);
|
|
465
|
+
|
|
466
|
+
});
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Decoding A Segment At A Time
|
|
470
|
+
|
|
471
|
+
It is possible to pass a reference to an already created `TCModel` and add individual segments to the model. An important use case for this is if using a globally-scoped TC string and storing the Publisher TC Segment separately in a first-party cookie.
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
|
|
475
|
+
import {TCString, Segment} from '@pubtech-ai/core';
|
|
476
|
+
|
|
477
|
+
// if you had a getCookie function that returned just that segment
|
|
478
|
+
const publisherTCSegment = getCookie('euconsent-ptc');
|
|
479
|
+
|
|
480
|
+
let tcModel;
|
|
481
|
+
|
|
482
|
+
// if you had an asynchronous function to get the cookie from global
|
|
483
|
+
getGlobalTCString().then((encodedTCString) => {
|
|
484
|
+
|
|
485
|
+
tcModel = TCString.decode(encodedTCString);
|
|
486
|
+
TCString.decode(publisherTCSegment, tcModel);
|
|
487
|
+
|
|
488
|
+
// now you have a combined TCModel
|
|
489
|
+
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### Encoding Options
|
|
496
|
+
|
|
497
|
+
Options may be passed to the encoder to override defaults. In most cases the encoder can figure out what segments to include but if the string is surfaced to vendors or for storing in a cookie the encoding is slightly different. The `@pubtech-ai/cmpapi` handles this difference and CMPs don't need to worry about it.
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
import {TCString, Segment} from '@pubtech-ai/core';
|
|
501
|
+
|
|
502
|
+
// produces the version of the string for the __tcfapi function
|
|
503
|
+
const cmpApiEncodedString = TCString.encode(tcModel, { isForVendors: true });
|
|
504
|
+
|
|
505
|
+
// Overrides default segments (not recommended unless you know what you're doing)
|
|
506
|
+
const encodingOptions = {
|
|
507
|
+
segments: [
|
|
508
|
+
Segment.CORE,
|
|
509
|
+
Segment.VENDORS_DISCLOSED,
|
|
510
|
+
Segment.VENDORS_ALLOWED,
|
|
511
|
+
Segment.PUBLISHER_TC,
|
|
512
|
+
]
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const customEncodedString = TCString.encode(tcModel, encodingOptions);
|
|
516
|
+
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Encoding a Publisher TC Segment
|
|
520
|
+
By default if the `TCModel.isServiceSpecific = true` then encoding a string will include the publisherTC segment. But if `TCModel.isServiceSpecific = false` then the segment should only be surfaced through the `__tcfapi` interface and not saved to the global cookie. However, one will need a way to access and save the publisher TC segment separately from the main TC String to store as a first-party cookie. In that case you can use the `EncodingOptions` to generate only a Publisher TC segment.
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
const encodingOptions = {
|
|
524
|
+
segments: [Segment.PUBLISHER_TC]
|
|
525
|
+
}
|
|
526
|
+
const publisherTCSegment = TCString.encode(tcModel, encodingOptions);
|
|
527
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract Class Cloneable<T> can be extended to give the child class the ability to clone its self.
|
|
3
|
+
* The child class must pass its class to super. You can then pass any needed arguments to help build
|
|
4
|
+
* the cloned class to the protected _clone() method.
|
|
5
|
+
*
|
|
6
|
+
* Example:
|
|
7
|
+
*
|
|
8
|
+
* class Example extends Cloneable<Example> {
|
|
9
|
+
*
|
|
10
|
+
* }
|
|
11
|
+
* Todo: There must be more non primitive build in types to check. But for our current purposes, this works great.
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class Cloneable<T> {
|
|
14
|
+
/**
|
|
15
|
+
* clone - returns a copy of the classes with new values and not references
|
|
16
|
+
*
|
|
17
|
+
* @return {T}
|
|
18
|
+
*/
|
|
19
|
+
clone(): T;
|
|
20
|
+
/**
|
|
21
|
+
* deepClone - recursive function that makes copies of reference values
|
|
22
|
+
*
|
|
23
|
+
* @param {unknown} item
|
|
24
|
+
* @return {unknown}
|
|
25
|
+
*/
|
|
26
|
+
private deepClone;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __values=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cloneable=void 0;var Cloneable=function(){function e(){}return e.prototype.clone=function(){var e=this,r=new this.constructor;return Object.keys(this).forEach((function(t){var n=e.deepClone(e[t]);void 0!==n&&(r[t]=n)})),r},e.prototype.deepClone=function(e){var r,t,n=typeof e;if("number"===n||"string"===n||"boolean"===n)return e;if(null!==e&&"object"===n){if("function"==typeof e.clone)return e.clone();if(e instanceof Date)return new Date(e.getTime());if(void 0!==e[Symbol.iterator]){var o=[];try{for(var i=__values(e),l=i.next();!l.done;l=i.next()){var a=l.value;o.push(this.deepClone(a))}}catch(e){r={error:e}}finally{try{l&&!l.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return e instanceof Array?o:new e.constructor(o)}var u={};for(var f in e)e.hasOwnProperty(f)&&(u[f]=this.deepClone(e[f]));return u}},e}();exports.Cloneable=Cloneable;
|