@financial-times/cmp-client 0.0.0-beta.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 (45) hide show
  1. package/README.md +195 -0
  2. package/dist/index.cjs +2993 -0
  3. package/dist/index.js +2993 -0
  4. package/dist/src/client.d.ts +3 -0
  5. package/dist/src/client.d.ts.map +1 -0
  6. package/dist/src/consent-ready/index.d.ts +5 -0
  7. package/dist/src/consent-ready/index.d.ts.map +1 -0
  8. package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts +9 -0
  9. package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts.map +1 -0
  10. package/dist/src/consent-ready/utils/__tests__/check-consent.test.d.ts +2 -0
  11. package/dist/src/consent-ready/utils/__tests__/check-consent.test.d.ts.map +1 -0
  12. package/dist/src/consent-ready/utils/__tests__/get-parsed-consent.test.d.ts +2 -0
  13. package/dist/src/consent-ready/utils/__tests__/get-parsed-consent.test.d.ts.map +1 -0
  14. package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts +2 -0
  15. package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts.map +1 -0
  16. package/dist/src/consent-ready/utils/get-consent-payload.d.ts +18 -0
  17. package/dist/src/consent-ready/utils/get-consent-payload.d.ts.map +1 -0
  18. package/dist/src/consent-ready/utils/get-parsed-consent.d.ts +14 -0
  19. package/dist/src/consent-ready/utils/get-parsed-consent.d.ts.map +1 -0
  20. package/dist/src/consent-ready/utils/has-consent-changed.d.ts +3 -0
  21. package/dist/src/consent-ready/utils/has-consent-changed.d.ts.map +1 -0
  22. package/dist/src/consent-ready/utils/validators.d.ts +16 -0
  23. package/dist/src/consent-ready/utils/validators.d.ts.map +1 -0
  24. package/dist/src/html/__tests__/cmp-footer-links.test.d.ts +2 -0
  25. package/dist/src/html/__tests__/cmp-footer-links.test.d.ts.map +1 -0
  26. package/dist/src/html/__tests__/cmp-scripts.test.d.ts +2 -0
  27. package/dist/src/html/__tests__/cmp-scripts.test.d.ts.map +1 -0
  28. package/dist/src/html/cmp-footer-link.d.ts +8 -0
  29. package/dist/src/html/cmp-footer-link.d.ts.map +1 -0
  30. package/dist/src/html/cmp-scripts.d.ts +7 -0
  31. package/dist/src/html/cmp-scripts.d.ts.map +1 -0
  32. package/dist/src/index.d.ts +5 -0
  33. package/dist/src/index.d.ts.map +1 -0
  34. package/dist/src/lib/constants.d.ts +13 -0
  35. package/dist/src/lib/constants.d.ts.map +1 -0
  36. package/dist/src/lib/debug.d.ts +15 -0
  37. package/dist/src/lib/debug.d.ts.map +1 -0
  38. package/dist/src/lib/properties.d.ts +94 -0
  39. package/dist/src/lib/properties.d.ts.map +1 -0
  40. package/dist/src/utils/dom.d.ts +3 -0
  41. package/dist/src/utils/dom.d.ts.map +1 -0
  42. package/package.json +40 -0
  43. package/typings/globals.d.ts +12 -0
  44. package/typings/modules.d.ts +1 -0
  45. package/typings/types.d.ts +98 -0
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # CMP Client
2
+
3
+ A client-side package 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 the package from npm:
17
+
18
+ ```copy
19
+ npm install @financial-times/cmp-client
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ import { initSourcepointCmp } from "@financial-times/cmp-client/client";
26
+ import { FT_DOTCOM_TEST } from "@financial-times/cmp-client/properties";
27
+
28
+ // we suggest using a feature flag to disable the existing cookie banner and enable the new one
29
+ if (flagsClient.get("adsDisableInternalCMP")) {
30
+ initSourcepointCmp({
31
+ propertyConfig: FT_DOTCOM_TEST,
32
+ // useConsentStore: false (set to false for non-FT.com properties or websites)
33
+ });
34
+ }
35
+ ```
36
+
37
+ We will be adding new properties (websites under FT group) and their configs as we start rolling out. Please reach out to the Ads & Privacy team if you think you need to create a new property for your domain - for example, if it is on a different domain from the `ft.com` domain.
38
+
39
+ ### CMP configuration options:
40
+
41
+ <table>
42
+ <thead>
43
+ <tr>
44
+ <th>Option</th>
45
+ <th>Description</th>
46
+ </tr>
47
+ <thead/>
48
+ <tbody>
49
+ <tr>
50
+ <td><code>propertyConfig</code> (SourcepointConfig)</td>
51
+ <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>
52
+ </tr>
53
+ <tr>
54
+ <td><code>userId</code> (string)</td>
55
+ <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>
56
+ </tr>
57
+ <tr>
58
+ <td><code>useFTSession</code> (boolean)</td>
59
+ <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>
60
+ </tr>
61
+ <tr>
62
+ <td><code>consentProxyHost</code> (string)</td>
63
+ <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>
64
+ </tr>
65
+ <tr>
66
+ <td><code>cookieDomain</code> (string)</td>
67
+ <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>
68
+ </tr>
69
+ <tr>
70
+ <td><code>formOfWordsId</code> (string)</td>
71
+ <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>
72
+ </tr>
73
+ <tr>
74
+ <td><code>useConsentStore</code> (boolean)</td>
75
+ <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>
76
+ </tr>
77
+ <tr>
78
+ <td><code>events</code> (object)</td>
79
+ <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>
80
+ </tr>
81
+ </tbody>
82
+ <table/>
83
+
84
+ ### Available Properties (constantly being updated)
85
+
86
+ <table>
87
+ <thead>
88
+ <tr>
89
+ <th>Property Key</th>
90
+ <th>Details</th>
91
+ </tr>
92
+ <thead/>
93
+ <tbody>
94
+ <tr>
95
+ <td><code>FT_DOTCOM_TEST</code></td>
96
+ <td>
97
+ <p>Use this configuration preset for testing the CMP on a property that has not yet been registered in the Sourcepoint portal.</p>
98
+ <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>
99
+ </p>
100
+ </td>
101
+ </tr>
102
+ <tr>
103
+ <td><code>FT_DOTCOM_PROD</code></td>
104
+ <td>Configuration preset for all properties on FT.com domain operating in a production environment - <code>https://*.ft.com</code></td>
105
+ </tr>
106
+ <tr>
107
+ <td><code>SP_THE_BANKER</code></td>
108
+ <td>Configuration preset for properties on thebanker.com domain</td>
109
+ </tr>
110
+ <tr>
111
+ <td><code>SP_PWMNET</code></td>
112
+ <td>Configuration preset for properties on pwmnet.com domain</td>
113
+ </tr>
114
+ <tr>
115
+ <td><code>SP_FDI_INTELLIGENCE</code></td>
116
+ <td>Configuration preset for properties on fdiintelligence.com domain</td>
117
+ </tr>
118
+ <tr>
119
+ <td><code>SP_BANKING_RR</code></td>
120
+ <td>Configuration preset for properties on bankingriskandregulation.com domain</td>
121
+ </tr>
122
+ <tr>
123
+ <td><code>SP_SUSTAINABLE_VIEWS</code></td>
124
+ <td>Configuration preset for properties on sustainableviews.com domain</td>
125
+ </tr>
126
+ <tr>
127
+ <td><code>SP_FT_ADVISER</code></td>
128
+ <td>Configuration preset for properties on ftadviser.com domain</td>
129
+ </tr>
130
+ <tr>
131
+ <td><code>SP_INVESTORS_CHRONICLE</code></td>
132
+ <td>Configuration preset for properties on investorschronicle.co.uk domain</td>
133
+ </tr>
134
+ <tr>
135
+ <td><code>MM_IGNITES_ASIA</code></td>
136
+ <td>Configuration preset for properties on ignitesasia.com domain</td>
137
+ </tr>
138
+ <tr>
139
+ <td><code>MM_IGNITES_EUROPE</code></td>
140
+ <td>Configuration preset for properties on igniteseurope.com domain</td>
141
+ </tr>
142
+ </tbody>
143
+ <table/>
144
+
145
+ ## Responding to CMP events
146
+
147
+ 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:
148
+
149
+ ```js
150
+ window._sp_.addEventListener("onMessageReady", (messageType) => {... });
151
+ window._sp_.addEventListener("onConsentReady", (legislation, consentUUID, consentString, consentMeta) => { ... });
152
+ ```
153
+
154
+ > [!Note]
155
+ > The `onConsentReady` event is fired
156
+ >
157
+ > 1. As soon as the CMP has finished loading and the user's consent choices are available
158
+ > 1. Subsequently, whenever the user's consent choices change
159
+
160
+ 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.
161
+
162
+ ## Debugging
163
+
164
+ You can verify that the CMP is correctly configured using the `logCmpEvents` method exported from the `debug` module:
165
+
166
+ ```js
167
+ import { debug } from "@financial-times/cmp-client";
168
+
169
+ debug.logCmpEvents();
170
+ ```
171
+
172
+ 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_.
173
+
174
+ 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.
175
+
176
+ > [!Note]
177
+ > Please ensure that your app always uses the latest version of the CMP Client package.
178
+ >
179
+ > You can check the version your live app is using by running the following in the browser console:
180
+ >
181
+ > ```copy
182
+ > window.FT_CMP_CLIENT_VERSION
183
+ > ```
184
+
185
+ ## Development
186
+
187
+ 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).
188
+
189
+ To see a demo in action in your browser, run:
190
+
191
+ ```copy
192
+ npm run dev -w src/examples/cmp-client
193
+ ```
194
+
195
+ Visit https://localhost:5173 (see setup details in `src/examples/cmp-client`) to interact with the banner and see how cookies are set accordingly