Skip to content

Commit 69ebd01

Browse files
Document settings methods (#1219)
* Document settings methods * Update injected/src/content-feature.js
1 parent 6761b7f commit 69ebd01

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

injected/src/content-feature.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ export default class ContentFeature {
146146

147147
/**
148148
* Return a specific setting from the feature settings
149+
* If the "settings" key within the config has a "domains" key, it will be used to override the settings.
150+
* This uses JSONPatch to apply the patches to settings before getting the setting value.
151+
* For example.com getFeatureSettings('val') will return 1:
152+
* ```json
153+
* {
154+
* "settings": {
155+
* "domains": [
156+
* {
157+
* "domain": "example.com",
158+
* "patchSettings": [
159+
* { "op": "replace", "path": "/val", "value": 1 }
160+
* ]
161+
* }
162+
* ]
163+
* }
164+
* }
165+
* ```
166+
* "domain" can either be a string or an array of strings.
167+
168+
* For boolean states you should consider using getFeatureSettingEnabled.
149169
* @param {string} featureKeyName
150170
* @param {string} [featureName]
151171
* @returns {any}
@@ -184,6 +204,23 @@ export default class ContentFeature {
184204
/**
185205
* For simple boolean settings, return true if the setting is 'enabled'
186206
* For objects, verify the 'state' field is 'enabled'.
207+
* This allows for future forwards compatibility with more complex settings if required.
208+
* For example:
209+
* ```json
210+
* {
211+
* "toggle": "enabled"
212+
* }
213+
* ```
214+
* Could become later (without breaking changes):
215+
* ```json
216+
* {
217+
* "toggle": {
218+
* "state": "enabled",
219+
* "someOtherKey": 1
220+
* }
221+
* }
222+
* ```
223+
* This also supports domain overrides as per `getFeatureSetting`.
187224
* @param {string} featureKeyName
188225
* @param {string} [featureName]
189226
* @returns {boolean}
@@ -198,8 +235,10 @@ export default class ContentFeature {
198235

199236
/**
200237
* Given a config key, interpret the value as a list of domain overrides, and return the elements that match the current page
238+
* Consider using patchSettings instead as per `getFeatureSetting`.
201239
* @param {string} featureKeyName
202240
* @return {any[]}
241+
* @private
203242
*/
204243
matchDomainFeatureSetting(featureKeyName) {
205244
const domain = this.#args?.site.domain;

injected/src/features/element-hiding.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ export default class ElementHiding extends ContentFeature {
320320

321321
// determine whether strict hide rules should be injected as a style tag
322322
if (shouldInjectStyleTag) {
323+
// @ts-expect-error: Accessing private method
323324
shouldInjectStyleTag = this.matchDomainFeatureSetting('styleTagExceptions').length === 0;
324325
}
325326

326327
// collect all matching rules for domain
328+
// @ts-expect-error: Accessing private method
327329
const activeDomainRules = this.matchDomainFeatureSetting('domains').flatMap((item) => item.rules);
328330

329331
const overrideRules = activeDomainRules.filter((rule) => {

injected/src/features/navigator-interface.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ContentFeature from '../content-feature';
33

44
export default class NavigatorInterface extends ContentFeature {
55
load(args) {
6+
// @ts-expect-error: Accessing private method
67
if (this.matchDomainFeatureSetting('privilegedDomains').length) {
78
this.injectNavigatorInterface(args);
89
}

0 commit comments

Comments
 (0)