From 3632c58dca6859056358468b008c0139550ffcfd Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Wed, 13 Nov 2024 12:52:09 +0000 Subject: [PATCH 1/2] Document settings methods --- injected/src/content-feature.js | 39 ++++++++++++++++++++ injected/src/features/element-hiding.js | 2 + injected/src/features/navigator-interface.js | 1 + 3 files changed, 42 insertions(+) diff --git a/injected/src/content-feature.js b/injected/src/content-feature.js index 4ffa13141..e2b97ab0f 100644 --- a/injected/src/content-feature.js +++ b/injected/src/content-feature.js @@ -146,6 +146,26 @@ export default class ContentFeature { /** * Return a specific setting from the feature settings + * If the "settings" key within the config has a "domains" key, it will be used to override the settings. + * This uses JSONPatch to apply the patches to settings before getting the setting value. + * For example.conm getFeatureSettings('val') will return 1: + * ```json + * { + * "settings": { + * "domains": [ + * { + * "domain": "example.com", + * "patchSettings": [ + * { "op": "replace", "path": "/val", "value": 1 } + * ] + * } + * ] + * } + * } + * ``` + * "domain" can either be a string or an array of strings. + + * For boolean states you should consider using getFeatureSettingEnabled. * @param {string} featureKeyName * @param {string} [featureName] * @returns {any} @@ -184,6 +204,23 @@ export default class ContentFeature { /** * For simple boolean settings, return true if the setting is 'enabled' * For objects, verify the 'state' field is 'enabled'. + * This allows for future forwards compatibility with more complex settings if required. + * For example: + * ```json + * { + * "toggle": "enabled" + * } + * ``` + * Could become later (without breaking changes): + * ```json + * { + * "toggle": { + * "state": "enabled", + * "someOtherKey": 1 + * } + * } + * ``` + * This also supports domain overrides as per `getFeatureSetting`. * @param {string} featureKeyName * @param {string} [featureName] * @returns {boolean} @@ -198,8 +235,10 @@ export default class ContentFeature { /** * Given a config key, interpret the value as a list of domain overrides, and return the elements that match the current page + * Consider using patchSettings instead as per `getFeatureSetting`. * @param {string} featureKeyName * @return {any[]} + * @private */ matchDomainFeatureSetting(featureKeyName) { const domain = this.#args?.site.domain; diff --git a/injected/src/features/element-hiding.js b/injected/src/features/element-hiding.js index ded7c38a2..84974ff62 100644 --- a/injected/src/features/element-hiding.js +++ b/injected/src/features/element-hiding.js @@ -320,10 +320,12 @@ export default class ElementHiding extends ContentFeature { // determine whether strict hide rules should be injected as a style tag if (shouldInjectStyleTag) { + // @ts-expect-error: Accessing private method shouldInjectStyleTag = this.matchDomainFeatureSetting('styleTagExceptions').length === 0; } // collect all matching rules for domain + // @ts-expect-error: Accessing private method const activeDomainRules = this.matchDomainFeatureSetting('domains').flatMap((item) => item.rules); const overrideRules = activeDomainRules.filter((rule) => { diff --git a/injected/src/features/navigator-interface.js b/injected/src/features/navigator-interface.js index 42bcc8128..87243261e 100644 --- a/injected/src/features/navigator-interface.js +++ b/injected/src/features/navigator-interface.js @@ -3,6 +3,7 @@ import ContentFeature from '../content-feature'; export default class NavigatorInterface extends ContentFeature { load(args) { + // @ts-expect-error: Accessing private method if (this.matchDomainFeatureSetting('privilegedDomains').length) { this.injectNavigatorInterface(args); } From a55b6804f3aa0dadac0888789a63fcd1a30b23db Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Wed, 13 Nov 2024 14:24:18 +0000 Subject: [PATCH 2/2] Update injected/src/content-feature.js --- injected/src/content-feature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/injected/src/content-feature.js b/injected/src/content-feature.js index e2b97ab0f..9cec5ffb7 100644 --- a/injected/src/content-feature.js +++ b/injected/src/content-feature.js @@ -148,7 +148,7 @@ export default class ContentFeature { * Return a specific setting from the feature settings * If the "settings" key within the config has a "domains" key, it will be used to override the settings. * This uses JSONPatch to apply the patches to settings before getting the setting value. - * For example.conm getFeatureSettings('val') will return 1: + * For example.com getFeatureSettings('val') will return 1: * ```json * { * "settings": {