diff --git a/src/privacy_compliance.js b/src/privacy_compliance.js index b3a3fdb..1677d6c 100644 --- a/src/privacy_compliance.js +++ b/src/privacy_compliance.js @@ -20,10 +20,32 @@ class PrivacyCompliance { }; } + /** + * useConfig is a convenient way to pass configuration values to all frameworks. + * When a useConfig is called, every loaded framework will have their own + * useConfig methods called. + * + * The ideal pattern is to use keys to type the configs, for example: + * PrivacyCompliance.useConfig({ + * usp: "1TFT" + * }) + * Which could signal to any listening capabiltiy-frameworks to use the new + * US Privacy String + * + * @param {Object} someConfigs any config to share with all frameworks + */ useConfig(someConfigs) { this.frameworks.forEach(f => f.useConfig(someConfigs)); } + /** + * Allows this libraries internal logs to be accessible to including libraries. + * The default is to also insert any missed logs. Because this is setup as a singleton, + * it is easy to miss the initial setup logs, that happened, before a logger was setup. + * + * @param {Function} logFunction to be called everytime a new log entry is generated + * @param {Boolean} relogMissedEntries when true will relog missed entries from before the logger was wired up + */ useLogger(logFunction, relogMissedEntries = true) { this.logger = logFunction; if (relogMissedEntries) { @@ -35,12 +57,6 @@ class PrivacyCompliance { this.logger(...args); } - // For use with testing only - reset() { - this.frameworks = []; - this.supportedCapabilities = new Set(); - } - addFramework(frameworkInstance) { this.log('Adding new framework: ', frameworkInstance.name); frameworkInstance.setPrivacyComplianceInstance(privacyComplianceSingleton); @@ -48,14 +64,33 @@ class PrivacyCompliance { frameworkInstance.supportedCapabilities().forEach(c => this.supportedCapabilities.add(c)); } + /** + * Checks if a given Capability (as a string) can be answered by the loaded + * frameworks. + * + * Caution: not all frameworks will be applicable and able to + * answer this capability for all environments. + * + * @param {String} capability the method name of the capability + * @returns Boolean true if the capability can be answered + */ hasFrameworkLoadedToAnswerCapability(capability) { return this.supportedCapabilities.has(capability); } + /** + * Returns a list of applicable frameworks for this environment. + */ applicableFrameworks() { return this.frameworks.filter(f => f.isApplicable()); } + // For use with testing only + reset() { + this.frameworks = []; + this.supportedCapabilities = new Set(); + } + /** * This method will take a string, translate it into a method and call it * on the added frameworks. If all applicable frameworks support this capability