@financial-times/cmp-client 0.0.0-backup.1

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.
Files changed (78) hide show
  1. package/README.md +273 -0
  2. package/dist/index.cjs +862 -0
  3. package/dist/index.js +862 -0
  4. package/dist/scripts/cmp-static.js +8 -0
  5. package/dist/src/__tests__/index.test.d.ts +2 -0
  6. package/dist/src/__tests__/index.test.d.ts.map +1 -0
  7. package/dist/src/client.d.ts +3 -0
  8. package/dist/src/client.d.ts.map +1 -0
  9. package/dist/src/consent-parsers/__fixtures__/gpp.d.ts +20 -0
  10. package/dist/src/consent-parsers/__fixtures__/gpp.d.ts.map +1 -0
  11. package/dist/src/consent-parsers/__tests__/index.test.d.ts +2 -0
  12. package/dist/src/consent-parsers/__tests__/index.test.d.ts.map +1 -0
  13. package/dist/src/consent-parsers/gpp/__tests__/parse-gpp-consent.test.d.ts +2 -0
  14. package/dist/src/consent-parsers/gpp/__tests__/parse-gpp-consent.test.d.ts.map +1 -0
  15. package/dist/src/consent-parsers/gpp/index.d.ts +3 -0
  16. package/dist/src/consent-parsers/gpp/index.d.ts.map +1 -0
  17. package/dist/src/consent-parsers/index.d.ts +6 -0
  18. package/dist/src/consent-parsers/index.d.ts.map +1 -0
  19. package/dist/src/consent-parsers/tcfv2/__tests__/check-consent.test.d.ts +2 -0
  20. package/dist/src/consent-parsers/tcfv2/__tests__/check-consent.test.d.ts.map +1 -0
  21. package/dist/src/consent-parsers/tcfv2/index.d.ts +10 -0
  22. package/dist/src/consent-parsers/tcfv2/index.d.ts.map +1 -0
  23. package/dist/src/consent-ready/index.d.ts +5 -0
  24. package/dist/src/consent-ready/index.d.ts.map +1 -0
  25. package/dist/src/consent-ready/utils/__fixtures__/helpers.d.ts +28 -0
  26. package/dist/src/consent-ready/utils/__fixtures__/helpers.d.ts.map +1 -0
  27. package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts +5 -0
  28. package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts.map +1 -0
  29. package/dist/src/consent-ready/utils/__tests__/consent.test.d.ts +2 -0
  30. package/dist/src/consent-ready/utils/__tests__/consent.test.d.ts.map +1 -0
  31. package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts +2 -0
  32. package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts.map +1 -0
  33. package/dist/src/consent-ready/utils/consent.d.ts +6 -0
  34. package/dist/src/consent-ready/utils/consent.d.ts.map +1 -0
  35. package/dist/src/consent-ready/utils/get-consent-payload.d.ts +18 -0
  36. package/dist/src/consent-ready/utils/get-consent-payload.d.ts.map +1 -0
  37. package/dist/src/consent-ready/utils/validators.d.ts +15 -0
  38. package/dist/src/consent-ready/utils/validators.d.ts.map +1 -0
  39. package/dist/src/html/__tests__/cmp-manage-cookies-links.test.d.ts +2 -0
  40. package/dist/src/html/__tests__/cmp-manage-cookies-links.test.d.ts.map +1 -0
  41. package/dist/src/html/__tests__/cmp-scripts.test.d.ts +2 -0
  42. package/dist/src/html/__tests__/cmp-scripts.test.d.ts.map +1 -0
  43. package/dist/src/html/cmp-manage-cookies-link.d.ts +8 -0
  44. package/dist/src/html/cmp-manage-cookies-link.d.ts.map +1 -0
  45. package/dist/src/html/cmp-scripts.d.ts +7 -0
  46. package/dist/src/html/cmp-scripts.d.ts.map +1 -0
  47. package/dist/src/index.d.ts +5 -0
  48. package/dist/src/index.d.ts.map +1 -0
  49. package/dist/src/lib/configurators/ft-dot-com.d.ts +7 -0
  50. package/dist/src/lib/configurators/ft-dot-com.d.ts.map +1 -0
  51. package/dist/src/lib/configurators/index.d.ts +14 -0
  52. package/dist/src/lib/configurators/index.d.ts.map +1 -0
  53. package/dist/src/lib/constants.d.ts +40 -0
  54. package/dist/src/lib/constants.d.ts.map +1 -0
  55. package/dist/src/lib/debug.d.ts +15 -0
  56. package/dist/src/lib/debug.d.ts.map +1 -0
  57. package/dist/src/lib/properties.d.ts +132 -0
  58. package/dist/src/lib/properties.d.ts.map +1 -0
  59. package/dist/src/scripts/cmp-static.d.ts +3 -0
  60. package/dist/src/scripts/cmp-static.d.ts.map +1 -0
  61. package/dist/src/tracking/__tests__/state.test.d.ts +2 -0
  62. package/dist/src/tracking/__tests__/state.test.d.ts.map +1 -0
  63. package/dist/src/tracking/constants.d.ts +3 -0
  64. package/dist/src/tracking/constants.d.ts.map +1 -0
  65. package/dist/src/tracking/index.d.ts +3 -0
  66. package/dist/src/tracking/index.d.ts.map +1 -0
  67. package/dist/src/tracking/state.d.ts +15 -0
  68. package/dist/src/tracking/state.d.ts.map +1 -0
  69. package/dist/src/utils/__tests__/url.test.d.ts +2 -0
  70. package/dist/src/utils/__tests__/url.test.d.ts.map +1 -0
  71. package/dist/src/utils/dom.d.ts +3 -0
  72. package/dist/src/utils/dom.d.ts.map +1 -0
  73. package/dist/src/utils/url.d.ts +127 -0
  74. package/dist/src/utils/url.d.ts.map +1 -0
  75. package/package.json +42 -0
  76. package/typings/globals.d.ts +20 -0
  77. package/typings/modules.d.ts +1 -0
  78. package/typings/types.d.ts +280 -0
package/README.md ADDED
@@ -0,0 +1,273 @@
1
+ # CMP Client
2
+
3
+ A client-side library to help you add a CMP (currently provided by Sourcepoint) to your application.
4
+
5
+ <details>
6
+ <summary>How it works</summary>
7
+
8
+ [(Source on Confluence)](https://financialtimes.atlassian.net/wiki/spaces/ADS/pages/8151990292/New+Consent+Migration+Guide+for+teams#What-happens-when-a-user-visits-%5BinlineCard%5D--in-the-new-consent-framework%3F)
9
+
10
+ ![CMP Client Overview](docs/overview.jpg)
11
+
12
+ </details>
13
+
14
+ ## Installation
15
+
16
+ Install as a \<script> tag (**recommended**):
17
+
18
+ ```copy
19
+ <script async src="https://consent-notice.ft.com/cmp.js"></script>
20
+ ```
21
+
22
+ Install the library from NPM:
23
+
24
+ ```copy
25
+ npm install @financial-times/cmp-client
26
+ ```
27
+
28
+ ## Using the script tag
29
+
30
+ The `src` attribute of the `script` tag points to an immediately invoked function expression (IIFE) that sets up the CMP client on the host page. When the CMP client is installed this way, no additional work needs to be done.
31
+
32
+ The primary benefit of using this integration method is that your users will automatically get new updates to the CMP client as soon as they are available, as opposed to requiring a version bump and application release. However, for this method to work successfully, the host page must be one of our [registered properties](#available-properties-constantly-being-updated). Please reach out to the Ads & Privacy team if you are not sure or you would like to register a property.
33
+
34
+ By default the source link integrates the latest version of the CMP client. If you would like to pin a different version, you can append a `version` query parameter to the source link as follows:
35
+
36
+ ```copy
37
+ <script async src="https://consent-notice.ft.com/cmp.js?version=4.0.0"></script>
38
+ ```
39
+
40
+ ## Using the NPM package
41
+
42
+ > [!Note]
43
+ > We will be adding new properties (i.e. websites under FT group) and their configs as we start rolling out.
44
+ >
45
+ > Please reach out to the Ads & Privacy team if you think your domain needs a new property config
46
+
47
+ ### Usage on non-FT.com properties
48
+
49
+ ```js
50
+ import {
51
+ initSourcepointCmp,
52
+ properties,
53
+ interceptManageCookiesLinks,
54
+ debug,
55
+ } from "@financial-times/cmp-client";
56
+
57
+ /**
58
+ * Optionally enable debug mode to see CMP events in the console
59
+ */
60
+ debug.logCmpEvents();
61
+
62
+ /**
63
+ * Import your domain's CMP configuration from the `properties` module:
64
+ * e.g. properties.MM_IGNITES_ASIA, properties.SP_THE_BANKER, etc.
65
+ *
66
+ * We will add more domains as we create new properties in Sourcepoint
67
+ *
68
+ * See below for the full list of initialisation options
69
+ */
70
+ initSourcepointCmp({
71
+ propertyConfig: properties["YOUR_PROPERTY_CONFIG_KEY"],
72
+ useConsentStore: false, // Specialist Titles _must_ opt out of Single Consent Store
73
+ });
74
+ /**
75
+ * Optionally enable "Manage Cookies" link util
76
+ */
77
+ interceptManageCookiesLinks(properties["YOUR_PROPERTY_CONFIG_KEY"]);
78
+ ```
79
+
80
+ ### Usage on FT.com
81
+
82
+ ```js
83
+ import {
84
+ initSourcepointCmp,
85
+ properties,
86
+ interceptManageCookiesLinks,
87
+ debug,
88
+ } from "@financial-times/cmp-client";
89
+
90
+ /**
91
+ * Optionally enable debug mode to see CMP events in the console
92
+ */
93
+ debug.logCmpEvents();
94
+
95
+ /**
96
+ * We suggest using a feature flag to disable the existing cookie banner
97
+ * and enable the new one
98
+ */
99
+ if (flagsClient.get("adsDisableInternalCMP")) {
100
+ initSourcepointCmp({
101
+ propertyConfig: FT_DOTCOM_TEST,
102
+ });
103
+ interceptManageCookiesLinks();
104
+ }
105
+ ```
106
+
107
+ ### CMP configuration options:
108
+
109
+ <table>
110
+ <thead>
111
+ <tr>
112
+ <th>Option</th>
113
+ <th>Description</th>
114
+ </tr>
115
+ <thead/>
116
+ <tbody>
117
+ <tr>
118
+ <td><code>propertyConfig</code> (SourcepointConfig)</td>
119
+ <td>This config object is directly passed to Sourcepoint (our external CMP) and presets (imported like example usage) will be made available for different properties/titles under the FT group. This currently defaults to the <code>FT_DOTCOM_PROD</code> preset</td>
120
+ </tr>
121
+ <tr>
122
+ <td><code>userId</code> (string)</td>
123
+ <td>Please provide a userId if the user is a logged in user. If your app uses the FT Secure Session token, you can leave empty and set <code>useFTSession</code> to true instead. Defaults to <code>undefined</code> for anonymous users</td>
124
+ </tr>
125
+ <tr>
126
+ <td><code>useFTSession</code> (boolean)</td>
127
+ <td>Set this flag if you want the user's Id to be automatically derived from their FT Secure Session. Set to <code>false</code> if your app doesn't use FT Secure Session. Defaults to <code>true</code></td>
128
+ </tr>
129
+ <tr>
130
+ <td><code>consentProxyHost</code> (string)</td>
131
+ <td>The fully qualified domain name for your consent proxy instance e.g <code>https://consent.thebanker.com</code>. Defaults to <code>https://consent.ft.com</code></td>
132
+ </tr>
133
+ <tr>
134
+ <td><code>cookieDomain</code> (string)</td>
135
+ <td>The domain (and subdomains) that the FTConsent cookie will apply to e.g <code>.thebanker.com</code>. Defaults to <code>.ft.com</code></td>
136
+ </tr>
137
+ <tr>
138
+ <td><code>formOfWordsId</code> (string)</td>
139
+ <td>The IAB custom categories that you have adapted might be tracked under a different FOW ID. At the moment, all custom categories are tracked under the <code>sourcepointCmp</code> form-of-words and it defaults to <code>sourcepointCmp/VngD.XycZut.595cp9fWdp5XYP9vlFvk</code>. Properties using the consent banner as presented should use the default value</td>
140
+ </tr>
141
+ <tr>
142
+ <td><code>useConsentStore</code> (boolean)</td>
143
+ <td>Specifies whether the user's consent record should also be backed by the Single Consent Store. Properties like Specialist titles will need to explicitly set this to <code>false</code> as <code>true</code> is the default behavior</td>
144
+ </tr>
145
+ <tr>
146
+ <td><code>disableFTCookies</code> (boolean)</td>
147
+ <td>Specifies whether the user's consent record should be saved to FT Cookies. Properties like Specialist titles that don't utilize FT cookies will need to explicitly set this to <code>true</code> as <code>false</code> is the default behavior</td>
148
+ </tr>
149
+ <tr>
150
+ <td><code>events</code> (object)</td>
151
+ <td>Used internally to define handlers for events emitted by the Vendor-supplied CMP module. See notes on "Responding to CMP events" below for details on how to define custom event handlers</td>
152
+ </tr>
153
+ </tbody>
154
+ <table/>
155
+
156
+ ### Available Properties (constantly being updated)
157
+
158
+ <table>
159
+ <thead>
160
+ <tr>
161
+ <th>Property Key</th>
162
+ <th>Details</th>
163
+ </tr>
164
+ <thead/>
165
+ <tbody>
166
+ <tr>
167
+ <td><code>FT_DOTCOM_TEST</code></td>
168
+ <td>
169
+ <p>Use this configuration preset for testing the CMP on a property that has not yet been registered in the Sourcepoint portal.</p>
170
+ <p>All <code>*.ft.com</code> are currently registered and this config will spoof your request as coming from <code>https://local.ft.com</code>
171
+ </p>
172
+ </td>
173
+ </tr>
174
+ <tr>
175
+ <td><code>FT_DOTCOM_PROD</code></td>
176
+ <td>Configuration preset for all properties on FT.com domain operating in a production environment - <code>https://*.ft.com</code></td>
177
+ </tr>
178
+ <tr>
179
+ <td><code>SP_THE_BANKER</code></td>
180
+ <td>Configuration preset for properties on thebanker.com domain</td>
181
+ </tr>
182
+ <tr>
183
+ <td><code>SP_PWMNET</code></td>
184
+ <td>Configuration preset for properties on pwmnet.com domain</td>
185
+ </tr>
186
+ <tr>
187
+ <td><code>SP_FDI_INTELLIGENCE</code></td>
188
+ <td>Configuration preset for properties on fdiintelligence.com domain</td>
189
+ </tr>
190
+ <tr>
191
+ <td><code>SP_BANKING_RR</code></td>
192
+ <td>Configuration preset for properties on bankingriskandregulation.com domain</td>
193
+ </tr>
194
+ <tr>
195
+ <td><code>SP_SUSTAINABLE_VIEWS</code></td>
196
+ <td>Configuration preset for properties on sustainableviews.com domain</td>
197
+ </tr>
198
+ <tr>
199
+ <td><code>SP_FT_ADVISER</code></td>
200
+ <td>Configuration preset for properties on ftadviser.com domain</td>
201
+ </tr>
202
+ <tr>
203
+ <td><code>SP_INVESTORS_CHRONICLE</code></td>
204
+ <td>Configuration preset for properties on investorschronicle.co.uk domain</td>
205
+ </tr>
206
+ <tr>
207
+ <td><code>MM_IGNITES_ASIA</code></td>
208
+ <td>Configuration preset for properties on ignitesasia.com domain</td>
209
+ </tr>
210
+ <tr>
211
+ <td><code>MM_IGNITES_EUROPE</code></td>
212
+ <td>Configuration preset for properties on igniteseurope.com domain</td>
213
+ </tr>
214
+ </tbody>
215
+ <table/>
216
+
217
+ ## Responding to CMP events
218
+
219
+ If you need to do additional work in response to events emitted by the CMP Vendor module – e.g. initialising vendor packages that match the purposes granted by the user – you can do so via the `window._sp_.addEventListener` method:
220
+
221
+ ```js
222
+ window._sp_.addEventListener("onMessageReady", (messageType) => {... });
223
+ window._sp_.addEventListener("onConsentReady", (legislation, consentUUID, consentString, consentMeta) => { ... });
224
+ ```
225
+
226
+ > [!Note]
227
+ > The `onConsentReady` event is fired
228
+ >
229
+ > 1. As soon as the CMP has finished loading and the user's consent choices are available
230
+ > 1. Subsequently, whenever the user's consent choices change
231
+
232
+ See the [Sourcepoint docs](https://docs.sourcepoint.com/hc/en-us/articles/4412176150035-Queue-event-callbacks) for a full listing of the events you can listen for and the arguments passed to the callbacks.
233
+
234
+ ## Debugging
235
+
236
+ You can verify that the CMP is correctly configured using the `logCmpEvents` method exported from the `debug` module:
237
+
238
+ ```js
239
+ import { debug } from "@financial-times/cmp-client";
240
+
241
+ debug.logCmpEvents();
242
+ ```
243
+
244
+ If everything's working then you'll see the CMP Module log its lifecycle events to the console, _even if its UI isn't displayed_.
245
+
246
+ This can easily happen when you've made a previous consent choice and the CMP is now picking it up from local storage. For this reason we recommend running in an incognito window during development.
247
+
248
+ > [!Note]
249
+ > Please ensure that your app always uses the latest version of the CMP Client library.
250
+ >
251
+ > You can check the version your live app is using by running the following in the browser console:
252
+ >
253
+ > ```copy
254
+ > window.FT_CMP_CLIENT_VERSION
255
+ > ```
256
+
257
+ ## Development
258
+
259
+ If you have access to the source on Github you can take a look at [the reference implementations in `src/examples/cmp-client`](https://github.com/Financial-Times/privacy/tree/main/src/examples).
260
+
261
+ To see a demo in action in your browser, run:
262
+
263
+ ```copy
264
+ npm run dev -w src/examples/cmp-client
265
+ ```
266
+
267
+ Visit https://localhost:5173 (see setup details in `src/examples/cmp-client`) to interact with the banner and see how cookies are set accordingly
268
+
269
+ > For resetting your consent cookies/record and other common troubleshooting issues, see the [Troubleshooting Guide](./docs/troubleshooting.md)
270
+
271
+ #### Resources
272
+
273
+ For a detailed deep-dive (internal only) of how the static deployment process works, the design is [documented here](https://financialtimes.atlassian.net/wiki/spaces/ADS/pages/8293711881/How+the+CMP+static+loader+works). If you need to be granted access, please reach out to the Ads & Privacy team.