/*! * Copyright 2017 - 2020 by ChartIQ, Inc. * All rights reserved. */ /** * This client provides run-time access to Finsemble's configuration. * The Config Client functions similar to a global store created with the Distributed Store Client and offers many of the same methods. * Values modified at runtime are not persisted. * * * See the [Configuration tutorial](/docs/customize/customize-with-SDK/configuration) for a configuration overview. * * @module ConfigClient */ /** This is how we want our API to work going forward, the way the world does it: import { processAndSet } from "configClient" ``` export const processAndSet = () => { ... } ``` This module's single exported object gives us backward compatibility when our core code does this: import { ConfigClient } from "configClient" and provides the object that is attached to FSBL.Clients. This export should be kept as clean and simple as possible. ``` export const ConfigClient = { processAndSet } ``` The default export gives us backward compatibility where our core code does this: import ConfigClient from "configClient" This can be eliminated when our core core is converted to normal imports as in the first example. ``` export default ConfigClient; ``` */ import { QueryResponse } from "./routerClient"; import { StandardErrorCallback, StandardPromise, StandardError, Manifest, FieldPathArrayAndValue, FieldOnlyParam, FieldAndValueParam, FieldAndValueParams, PathArray, ListenerFunction, ListenerParam, RemoveListenersType, PathArrayListenerParam } from "../types"; export { PathArray, ListenerFunction, ListenerParam, PathArrayListenerParam, FieldOnlyParam, RemoveListenersType, FieldPathArrayAndValue, FieldAndValueParam, FieldAndValueParams, }; export { FieldPathArray } from "../types"; export type ProcessAndSetCallback = StandardErrorCallback>; /** * @language javascript, dotnet * Retrieves the entire manifest * * ```javascript * FSBL.Clients.ConfigClient.getManifest(function(err, value){ }); * const {err, data} = await FSBL.Clients.ConfigClient.getManifest(); * ``` */ export declare const getManifest: (cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * Get a value from the config. * * If a field does not exists in the configuration, `data` will be undefined and `err` will * be null. * * If you pass path as null or an empty path the entire config is returned. * * ```javascript * FSBL.Clients.ConfigClient.get( * ['field1', 'property1'], // field1.property1 * function(err,value){ } * ); * * const {err, data} = await FSBL.Clients.ConfigClient.get( * ['field1', 'property1'] // field1.property1 * ); * ``` * * :::note * In Java, this method is named `getValue`. * ::: * @param {Function} cb Will return the value if found. */ export declare const get: (path: PathArray | null, cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * * Get multiple values from the config. * * If a field does not exists in the configuration, `data` will be undefined and `err` will * be null. * * ```javascript * FSBL.Clients.ConfigClient.getMultiple( * [ * // field1.property1.subproperty1 * ["field1", "property1", "subproperty1"], * * // field1.property2 * ["field1", "property2"] * ], (err, values) => { * if(!err){ * console.log("Values: ", values); * } * }); * * const {err, data} = await FSBL.Clients.ConfigClient.getMultiple([ * // field1.property1.subproperty1 * ["field1", "property1", "subproperty1"], * * // field1.property2 * ["field1", "property2"] // field1.property2 * ]); * if(!err){ * console.log("Values: ", data); * } * ``` * @param {Function} cb Will return the value if found. */ export declare const getMultiple: (paths: PathArray[], cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * @deprecated - Use [ `FSBL.Clients.ConfigClient.get()`](#get) instead. * * Get a value from the config. * * ```javascript * FSBL.Clients.ConfigClient.getValue({ field:'field1' }, function(err,value){ }); * FSBL.Clients.ConfigClient.getValue('field1', function(err,value){ }); * const {err, data} = await FSBL.Clients.ConfigClient.getValue({ field:'field1' }); * const {err, data} = await FSBL.Clients.ConfigClient.getValue('field1'); * ``` * @param {Function} cb Will return the value if found. * */ export declare const getValue: (params: FieldOnlyParam | string, cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * @deprecated - Use [`FSBL.Clients.ConfigClient.getMultiple()`](#getmultiple) instead. * * Get multiple values from the config. * * :::caution * **Deprecated functionality**: If there are no fields provided, the complete configuration manifest * is returned (use [getManifest()](#getmanifest)). * ::: * * ```javascript * FSBL.Clients.ConfigClient.getValues(['field1','field2'], function(err,values){ }); * FSBL.Clients.ConfigClient.getValues(null, callback); // returns the complete manifest containing the finsemble property * const {err, data} = await FSBL.Clients.ConfigClient.getValues(['field1', 'field2']); * ``` * @param {fieldOnlyParam[] | string[]} fields An array of objects containing a field property or an array of string field names. * @param {Function} cb Will return the value if found. */ export declare const getValues: (fields?: FieldOnlyParam[] | string[] | null, cb?: StandardErrorCallback>) => StandardPromise>; /** * @language javascript, java, dotnet * Sets a value in the config. * * Setting a value will trigger events that you can listen to using [`addListener()`](#addlistener). * * ```javascript * // Set field1.property1 = "foo" * FSBL.Clients.ConfigClient.set( * ['field1', 'property1'], * "foo", * function(err,value){ } * ); * * // Set field1.property1 = "foo" * const {err, data} = await FSBL.Clients.ConfigClient.set(['field1', 'property1'], "foo"); * ``` * :::note * In Java, this method is named `setValue`. * ::: * @param {Function} cb Optional callback. */ export declare const set: (path: PathArray, value: any, cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * Sets multiple values in the config. * * Setting a value will trigger events that you can listen to using `addListener()`. * * ```javascript * // Set both field1.property1 = "foo" AND field2.property2 = "bar" * FSBL.Clients.ConfigClient.setMultiple( * [ * {field: ['field1', 'property1'], value: "foo"}, * {field: ['field2', 'property2'], value: "bar"} * ], * function(err,value){ } * ); * * // Set both field1.property1 = "foo" AND field2.property2 = "bar" * const {err, data} = await FSBL.Clients.ConfigClient.setMultiple([ * {field: ['field1', 'property1'], value: "foo"}, * {field: ['field2', 'property2'], value: "bar"} * ]); * ``` * * * :::note * In Java, this method is named `setValues`. * ::: * @param {Function} cb Optional callback. */ export declare const setMultiple: (pathsAndValues: FieldPathArrayAndValue[], cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * @deprecated - Use [`FSBL.Clients.ConfigClient.set()`](#set) instead. * * Set a value in the config. Setting a value will trigger events that you can listen to using `addListener()`. * * ```javascript * FSBL.Clients.ConfigClient.setValue({ field:'field1', value:"new value" }, function(err){ }); * const {err} = await FSBL.Clients.ConfigClient.setValue({ field:'field1', value:'new value' }) * ``` * @param {function} cb Optional callback */ export declare const setValue: (params: FieldAndValueParam, cb?: StandardErrorCallback) => Promise<{ err: string | null | undefined; }>; /** * @language javascript, java, dotnet * @deprecated - Use [FSBL.Clients.ConfigClient.setMultiple()](#setmultiple) instead. * * Set multiple values in the config. * * ```javascript * FSBL.Clients.ConfigClient.setValues([{ field:'field1', value: "new value" }]); * const {err} = await FSBL.Clients.ConfigClient.setValues([{ field:'field1', value: "new value" }]); * ``` * @param {function} cb Optional callback */ export declare const setValues: (fields: FieldAndValueParams, cb?: StandardErrorCallback) => Promise<{ err: string | null | undefined; }>; /** * @language javascript, java, dotnet * Remove a value (and its key) from the config. * * Removing a value will trigger events that you can listen to using `addListener()`. * * ```javascript * FSBL.Clients.ConfigClient.remove( ['field1', 'property1'], // field1.property1 function(err,value){ } ); * * const {err, data} = await FSBL.Clients.ConfigClient.remove( ['field1', 'property1']); // field1.property1 * ``` * * :::note * In Java, this method is named `removeValue`. * ::: * @param {Function} cb Optional callback. */ export declare const remove: (path: PathArray, cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * Remove multiple values (and their keys) from the config. * * Removing a value will trigger events that you can listen to using `addListener()`. * * ```javascript * // Remove field1.property1 AND field2.property2 * FSBL.Clients.ConfigClient.removeMultiple( * [ * ['field1', 'property1'], * ['field2', 'property2'] * ], * function(err,value){ } * ); * * // Remove field1.property1 AND field2.property2 * const {err, data} = await FSBL.Clients.ConfigClient.removeMultiple([ * ['field1', 'property1'], * ['field2', 'property2'] * ]); * ``` * * :::note * In Java, this method is named `removeValues`. * ::: * @param {Function} cb Optional callback. */ export declare const removeMultiple: (paths: PathArray[], cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * @deprecated - Use [`FSBL.Clients.ConfigClient.remove()`](#remove) instead. * * Remove a value from the config. * * ```javascript * FSBL.Clients.ConfigClient.removeValue({ field:'field1' }, function(err){ }); * FSBL.Clients.ConfigClient.removeValue('field1', function(err){ }); * * const {err} = await FSBL.Clients.ConfigClient.removeValue({ field:'field1' }); * const {err} = await FSBL.Clients.ConfigClient.removeValue('field1'); * ``` * @param {String} field - Name of field to remove * @param {Function} cb - Returns an error if there is one */ export declare const removeValue: (params: FieldOnlyParam | string, cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * @deprecated - Use [`FSBL.Clients.ConfigClient.removeMultiple()`](#removemultiple) instead. * * Removes multiple values from the config. * * ```javascript * FSBL.Clients.ConfigClient.removeValues(['field1'], function(err){ }); * const {err} = await FSBL.Clients.ConfigClient.removeValues(['field1']) * ``` * @param {FieldOnlyParam[] | string[]} fields - An array of objects containing a field property or an array of string field names. * @param {Function} cb - Returns an error if there is one. */ export declare const removeValues: (fields: FieldOnlyParam[] | string[], cb?: StandardErrorCallback) => Promise<{ err: string | null | undefined; }>; /** * @language javascript, java, dotnet * Add a listener to the config at either the root config level or field level. * If no field is given, the root config level is used. You can also listen for changes to config fields any number of levels deep -- finsemble.configitem.deeperconfigitem.evendeeperconfigitem * * ```javascript * const myFunction = function(err,data){ }; * * FSBL.Clients.ConfigClient.addListener({ field:'field1' }, myFunction, cb); * FSBL.Clients.ConfigClient.addListener(['field1', 'property1'], myFunction, cb); // field1.property1 * ``` * @param {{ field: string | null } | PathArray} params The piece of data that you want to listen on. If this is empty it listens to all changes of the store. * @param {ListenerFunction} fn The function to be called when the observed piece of config is modified. * @param {Function} cb Callback to be invoked after the listener is added. */ export declare const addListener: (params: { field: string | null; } | PathArray, fn: ListenerFunction, cb?: () => void) => Promise; /** * @language javascript, java, dotnet * Add an array of listeners as objects, strings or path arrays. * If using strings, you must provide a function callback as the second parameter. * * ```javascript * const myFunction = function(err,data){} * FSBL.Clients.ConfigClient.addListeners( * [ * { field: "field1", listener: myFunction }, * { field: "field2", listener: myFunction } * ], * null, * cb * ); * * FSBL.Clients.ConfigClient.addListeners( * [{ field: "field1" }, { field: "field2", listener: myFunction }], * myFunction, * cb * ); * * FSBL.Clients.ConfigClient.addListeners(["field1", "field2"], myFunction, cb); * ``` * @param {listenerParam[] | string[] | PathArrayListenerParam[]} params.field The piece of data that you want listen on. If this is empty it listen to all config changes. * @param {ListenerFunction} params.listener The function to call when the piece of data is modified. If this is empty, fn is used. * @param {function} fn The function to be called when the observed piece of config is modified. * @param {function} cb Callback to be invoked after the listeners are added. */ export declare const addListeners: (params: ListenerParam[] | string[] | PathArrayListenerParam[], fn: ListenerFunction, cb?: () => void) => Promise | undefined; /** * @language javascript, java, dotnet * Remove a listener from config. If no field is given, we look for a config root listener * * ```javascript * let myFunction = function(err,data){ } * * FSBL.Clients.ConfigClient.removeListener({field:'field1'}, myFunction, function(err, bool){ }); * FSBL.Clients.ConfigClient.removeListener(myFunction, function(err, bool){ }); * FSBL.Clients.ConfigClient.removeListener(['field1'], myFunction, function(err, bool){ }); * ``` * @param {function} fn The listener to remove. * @param {function} cb Returns true if it was successful in removing the listener. * */ export declare const removeListener: (params: { field: string | null; } | PathArray, fn: ListenerFunction, cb?: Function) => void; /** * @language javascript, java, dotnet * Remove an array of listeners from the config * * ```javascript * let myFunction = function(err,data){ }; * FSBL.Clients.ConfigClient.removeListeners( * { * field: 'field1' * }, * MyFunction, * function(bool){ } * ); * * FSBL.Clients.ConfigClient.removeListeners( * [{ field:'field1', listener: MyFunction }], * function(bool){ } * ); * * FSBL.Clients.ConfigClient.removeListeners( * ['field1'], * MyFunction, * function(bool) { } * ); * ``` * @param {removeListenersType} params * @param {function} fn The listener to remove * @param {function} cb Returns true if it was successful in removing the listener. * */ export declare const removeListeners: (params: RemoveListenersType, fn?: ListenerFunction, cb?: StandardErrorCallback) => void; /** * @language javascript, java, dotnet * Dynamically set config values within the Finsemble configuration. You can set new config properties * or modify existing ones. Note that configuration changes will not necessarily dynamically modify * the components or services that use the corresponding configuration -- it depends if the component * or service handles the corresponding change notifications (either though PubSub or the config's * DataStore). Also, these changes do not persist in any config files. * * Only services and components that reside on the same domain as Finsemble can use `proessAndSet`. * If you want to use it from a domain other than Finsemble, you can't do so directly. Instead, * you need to set up a proxy service that is hosted on the same domain as Finsemble. * Because this proxy server is on the same domain as Finsemble, it can use `processAndSet`. * Now, you can have an externally hosted service or app communicate with this proxy service. * * Here is an example: * 1. Create a proxy app service on the Finsemble domain and make it subscribe to a channel * (for example, "customerName.app.config"). * 2. The cross domain app publishes the new config on that same channel ("customerName.app.config"). * 3. When the proxy app service receives this request, it invokes `ConfigClient.processAndSet(...)` using * the payload from the router message. * * :::note * Any time you set config by using this API, the newConfig along with the updated manifest will by * published to the PubSub topic "Config.changeNotification". To get these notifications any * component or service you can subscribe to the topic. See an example below. * ::: * * :::note * Anytime you set config by using this API, the dataStore underlying configuration * 'Finsemble-Configuration-Store' will also be updated. To get these dataStore events, you can set * a listener as shown in the example below. However, any config modifications made directly though * the DataStore will not result in corresponding PubSub notifications. * ::: * * :::caution * During dynamic configuration, Finsemble can overwrite components already in the configuration when * `ConfigClient.processAndSet` is called. To prevent this from happening, set * `manifest.component.category = "system"` in the config of the component. For example, use this setting * to prevent system UI components from being dropped out of the config. * ::: * * ```javascript * // Examples using processAndSet() * FSBL.Clients.ConfigClient.processAndSet({ newConfig: { myNewConfigField: 12345 }, overwrite: false }); * FSBL.Clients.ConfigClient.processAndSet( * { * newConfig: { * "myNewConfigField": 12345, * "myNewConfigObject": { * A: "this is a test", * B: "more test" * }, * "importConfig": [ * "$applicationRoot/configs/application/test.json", * ] * }, * overwrite: true, * replace: false, * }, * function (err, finsemble) { * if (err) { * console.error("ConfigClient.set", err); * } else { * console.log("new finsemble config", finsemble); * } * } * ); * * // example subscribing to PubSub to get notifications of dynamic updates * RouterClient.subscribe("Config.changeNotification", function (err, notify) { * console.log("set notification", notify.data.newConfig, notify.data.finsemble); * }); * * // example using DataStore to get notifications of dynamic updates * DistributedStoreClient.getStore({ store: 'Finsemble-Configuration-Store', global: true }, function (err, configStore) { * configStore.addListener({ field: "finsemble" }, function (err, newFinsembleConfig) { * console.log("new manifest.finsemble configuration", newFinsembleConfig); * }); * }); * ``` * * @param {object} params * @param {object} params.newConfig Provides the configuration properties to add into the existing configuration under manifest.finsemble. This config must match the Finsemble config requirements as described in the [Configuration tutorial](/docs/customize/customize-with-SDK/configuration). It can include importConfig references to dynamically fetch additional configuration files. * @param {boolean} params.overwrite If true then overwrite any preexisting config with new config (can only set to true when running from same origin, not cross-domain); if false then newConfig must not match properties of existing config, including service and component configuration. * @param {boolean} params.replace True specifies any component, app, or service definitions in the new config will place all existing non-system component and service configuration * @param {StandardErrorCallback} callback Callback to be invoked upon task completion. * */ export declare const processAndSet: (params: { newConfig: Record; overwrite: boolean; replace: boolean; }, cb?: ProcessAndSetCallback) => StandardPromise; /** * @language javascript, java, dotnet * Sets a value on the configStore and persists that value to storage. On application restart, this value will overwrite any application defaults. * * ```javascript * FSBL.Clients.ConfigClient.setPreference({ * field: "finsemble.initialWorkspace", * value: "Workspace 2" * }, (err, response) => { * // preference has been set * }); * * const {err, data} = await FSBL.Clients.ConfigClient.setPreference({ * field: "finsemble.initialWorkspace", * value: "Workspace 2" * }); * ``` * @param {fieldAndValueParam} params * @param {StandardErrorCallback} callback Callback to be invoked when preferences have been retrieved from the service or on error. */ export declare const setPreference: (params: FieldAndValueParam, cb?: StandardErrorCallback) => StandardPromise; /** * @language javascript, java, dotnet * Retrieves all of the preferences set for the application. * * ```javascript * FSBL.Clients.ConfigClient.getPreferences((err, preferences)=> { * if (!err) { * console.log(preferences); // an object containing the entire user preferences. * } * }); * const {err, data} = await FSBL.Clients.ConfigClient.getPreferences(); * ``` * * @param {StandardErrorCallback} callback Callback to be invoked when preferences have been retrieved from the service. */ export declare const getPreferences: (cb?: StandardErrorCallback | null>) => StandardPromise | null>; /** * @language javascript, dotnet * Reset a user preference value to default. On application restart, the application default value will be used instead of the preference. * * ```javascript * FSBL.Clients.ConfigClient.unsetPreference({ * field: "finsemble.initialWorkspace", * }, (err, response) => { * //preference has been unset * }); * const {err, data} = await FSBL.Clients.ConfigClient.unsetPreference({ * field: "finsemble.initialWorkspace" * }); * ``` * @param params The preference field to unset. * @param callback The callback to be invoked after the preference is removed or on error. */ export declare const unsetPreference: (params: FieldOnlyParam, cb?: StandardErrorCallback) => StandardPromise; /** * @ignore */ export declare const ConfigClient: { /** * For backward compatibility * @private * @deprecated */ initialize(): void; /** * For backward compatibility * @private * @deprecated */ onReady: (cb?: any) => void; /** * @private * @deprecated */ triggerListeners(listenerKey: string, data: any): void; /** * @private * @deprecated */ handleChanges(err: StandardError, response: { data: { store: string; storeData: any; field: string | null; value: any; }; }): void; /** * @private * @deprecated */ changeSub(change: string): Promise; addListener: (params: { field: string | null; } | PathArray, fn: ListenerFunction, cb?: () => void) => Promise; addListeners: (params: ListenerParam[] | string[] | PathArrayListenerParam[], fn: ListenerFunction, cb?: () => void) => Promise | undefined; getManifest: (cb?: StandardErrorCallback) => StandardPromise; getPreferences: (cb?: StandardErrorCallback | null>) => StandardPromise | null>; getValue: (params: FieldOnlyParam | string, cb?: StandardErrorCallback) => StandardPromise; getValues: (fields?: FieldOnlyParam[] | string[] | null, cb?: StandardErrorCallback>) => StandardPromise>; processAndSet: (params: { newConfig: Record; overwrite: boolean; replace: boolean; }, cb?: ProcessAndSetCallback) => StandardPromise; removeListener: (params: { field: string | null; } | PathArray, fn: ListenerFunction, cb?: Function) => void; removeListeners: (params: RemoveListenersType, fn?: ListenerFunction, cb?: StandardErrorCallback) => void; removeValue: (params: FieldOnlyParam | string, cb?: StandardErrorCallback) => StandardPromise; removeValues: (fields: FieldOnlyParam[] | string[], cb?: StandardErrorCallback) => Promise<{ err: string | null | undefined; }>; setPreference: (params: FieldAndValueParam, cb?: StandardErrorCallback) => StandardPromise; setValue: (params: FieldAndValueParam, cb?: StandardErrorCallback) => Promise<{ err: string | null | undefined; }>; setValues: (fields: FieldAndValueParams, cb?: StandardErrorCallback) => Promise<{ err: string | null | undefined; }>; unsetPreference: (params: FieldOnlyParam, cb?: StandardErrorCallback) => StandardPromise; get: (path: PathArray | null, cb?: StandardErrorCallback) => StandardPromise; getMultiple: (paths: PathArray[], cb?: StandardErrorCallback) => StandardPromise; set: (path: PathArray, value: any, cb?: StandardErrorCallback) => StandardPromise; setMultiple: (pathsAndValues: FieldPathArrayAndValue[], cb?: StandardErrorCallback) => StandardPromise; remove: (path: PathArray, cb?: StandardErrorCallback) => StandardPromise; removeMultiple: (paths: PathArray[], cb?: StandardErrorCallback) => StandardPromise; }; /** * @ignore */ export default ConfigClient; //# sourceMappingURL=configClient.d.ts.map