) => {
const existingLocaleUtilApis = this.getLocaleUtils();
Object.keys(customLocaleUtilApis).forEach((customLocaleUtilsApiKey) => {
// override existing apis with custom apis
(existingLocaleUtilApis[customLocaleUtilsApiKey as keyof LocaleUtils] as unknown) =
customLocaleUtilApis[customLocaleUtilsApiKey as keyof LocaleUtils];
});
};
/**
* Access for a runtime environment to set some flags to override some
* default behaviors. Note that this action replaces
* any previous overrides. To add to the existing overrides, use
* setBehaviorOverride
* @param overridesObj The JSON object containing any behavior override flags
* Supported override flag:
* dynamicLoadComponents - when false, do not attempt to load components dynamically
* @example PCore.setBehaviorOverrides( { "dynamicLoadComponents": false } );
* @function
*/
setBehaviorOverrides = (overridesObj: { [key: string]: boolean }) => {
PCore.behaviorOverrides = overridesObj;
};
/**
* Access for a runtime environment to set/update a flag to override some
* default behaviors. Note that this action adds or updates
* the override key value. Other keys/values are left intact.
* To replace the existing overrides, use
* setBehaviorOverrides
* @param overrideKey The key value for the behavior override flag. (Ex: "dynamicLoadComponents")
* @param overrideValue the desired value of the override. (Ex: true, false)
* Supported override flags:
* dynamicLoadComponents - when false, do not attempt to load components dynamically
* dynamicSemanticUrl - when false, do not attempt to update the app's semantic URL dynamically
* dynamicSetCookie - when false, do not attempt to set the app's C11n cookie dynamically
*
* @example PCore.setBehaviorOverride("dynamicLoadComponents", true);
* @function
*/
setBehaviorOverride = (overrideKey: string, overrideValue: boolean) => {
PCore.behaviorOverrides[overrideKey] = overrideValue;
};
/**
* Returns the current JSON object of behavior overrides.
* @example PCore.getBehaviorOverrides() could return { "dynamicLoadComponents": false }
* @returns The current JSON object of behavior overrides.
* @function
*/
getBehaviorOverrides = () => {
return PCore.behaviorOverrides;
};
/**
* Returns the current value of the requested behavior override flag.
* If the requested flag has not been sent, this returns undefined.
* @param theOverride The requested override flag. Ex: dynamicLoadComponents
* @example PCore.getBehaviorOverride("dynamicLoadComponents") could return false
* @function
*/
getBehaviorOverride = (theOverride: string) => {
return PCore.behaviorOverrides[theOverride];
};
/**
* This API obtains an entry point to the AsynchronousUtils object that contains utility APIs that perform asynchronous operations using Observable patterns.
* To view the APIs in the AsynchronousUtils class, see {@link AsynchronousUtils} Class.
* @example In this example, the API returns the AsynchronousUtils object.
* const asyncUtils = PCore.getAsynchronousUtils();
* @function
*/
getAsynchronousUtils = () => {
return AsynchronousUtils;
};
/**
* Creates a PConnect object from the input configuration of a component.
* The PConnect object represents a newly created component context for the given input configuration and has access to all public PConnect APIs.
*
* Use the createPConnect(config) API if you need to explicitly create a PConnect object for a component.
*
* For example, in a table, each column has its own type and configuration. To render the cells in the table, you can use the createPConnect(config) API to create
* a PConnect object by passing the config object that contains the details of the cells along with the context and pageReference of the parent component.
*
* The configuration object passed to this API should include:
* - meta.type: Denotes the type of the component. In the example, the type is "DropDown". This is a required property
* - options.context: The name of the context under which the component is rendered. context must be passed if the component has to render on a context that is different from the parent component's context.
* - options.pageReference: The data reference path of the store where the data value is stored for the current component. pageReference must be passed if the component has to render on a page reference that is different from the parent component's page reference.
*
* These three properties are of type string.
*
* @example Example usage of createPConnect
* Example:
* const config = {
* "meta": {
* "type": "DropDown",
* "config": {
* label: "@L Type"
* }
* },
* "options": {
* context: "contextName",
* pageReference: "pageRef"
* }
* }
*
* const dropDownPConn = createPConnect(config);
* In this example, the API creates a PConnect object for a dropdown component based on the input configuration of the config object.
*
* @param config payload to create a PConnect Object
* @returns A PConnect object created from the configuration object.
* @function
*/
createPConnect = (config: {
meta?: {
type: string;
config?: Record;
};
options?: {
context?: string;
pageReference?: string;
referenceList?: string;
hasForm?: boolean;
contextName?: string;
};
}) => {
return createC11nEnv(config);
};
/**
* This API provides an entry point to the PubSubUtils object that is used to access the
* utility APIs in the Constellation Core that publish and subscribe events
* This exposes the Event PubSub UtilsAPIs like
*
*
* @example Example for getPubSubUtils()
* Example usage - PCore.getPubSubUtils();
* // returns the PubSubUtils object containing the utility APIs that publish and subscribe events
* @function
*/
getPubSubUtils = () => {
return PubSubUtils;
};
/**
* Call registerComponentCreator with component creator function, such that it will be registered and receives the C11nEnv object.
*
* @param creator function which is called to register a component creator.
* This function will receive the C11nEnv as first argument
* and if there are any additionalProps object as second argument.
*
* @example Example for registerComponentCreator()
* Example Usage:
* PCore.registerComponentCreator((c11nEnv, additionalProps = {}) => {
* return React.createElement(PConnectHOC(), {
* ...c11nEnv,
* ...c11nEnv.getPConnect().getConfigProps(),
* ...c11nEnv.getPConnect().getActions(),
* ...{ additionalProps }
* });
*
* All the components, which render will be using this registered component create function to create the component instance
* Note: Here the usage shows React.createElement which indicates, the components are created using React.
* @function
*/
registerComponentCreator = (creator: Function) => {
registerComponentCreator(creator);
};
/**
* Call getConstants function to get the public constants
* which are supposed to be used at appropriate places.
*
* @example Example for getConstants()
* Example Usage:
* const constants = PCore.getConstants();
*
* constants will have un-modifiable constants object which you can use at places Infra expects.
* for example: you have to use constants.MESSAGES.MESSAGES_TYPE_ERROR if you want to add or delete error messages in the application state.
*
* @function
*/
getConstants = () => {
return Object.freeze(publicConstants);
};
/**
* Call getResolvedConstantValue function to get the resolved constant value for objects.
*
* @example Example for getResolvedConstantValue()
* Example Usage:
* const property = PCore.getResolvedConstantValue('property');
*
* @function
*/
getResolvedConstantValue = (key: string) => {
return constants.getProperty(key);
};
/**
* Call getEvents function to get all the case related events
* which are supposed to be used to subscribe using getPubSubUtils.
* This exposes Events like:
*
*
* @example Example for getEvents()
* Example Usage:
* const CaseEvent = PCore.getEvents().getCaseEvent();
*
* @function
*/
getEvents = () => {
return Events;
};
/**
* This API provides an entry point to the {@link module:RestClient|REST Client} API object.
* This exposes APIs that include:
*
* - invokeRestApi
* - getCancelTokenSource
* - isRequestCanceled
*
*
* @example Example for invokeRestApi api
* const { invokeRestApi } = PCore.getRestClient();
* const cancelTokenSource = getCancelTokenSource();
* invokeRestApi('getFeedMessages', {
* queryPayload: {
* filterForContext: 'DATA-PORTAL $SpaceTra',
* filterByContext: 'context'
* },
* body: {},
* headers: {},
* // passing cancel token so that we can cancel the request using cancelTokenSource
* cancelTokenSource: cancelTokenSource.token
* })
* .then(() => {
* // handle the response
* })
* .catch((error) => {
* // handle error
* if(isRequestCanceled(error)) {
* // handle the canceled request using cancelTokenSource.cancel();
* }
* });
* // above example shows how to use invokeRestApi api to make REST API call to get Feed messages.
*
* @example Example for getCancelTokenSource api
* const { getCancelTokenSource } = PCore.getRestClient();
* const cancelTokenSource = getCancelTokenSource();
* // cancel the ongoing request using the cancelTokenSource
* cancelTokenSource.cancel();
* // above example shows how to use getCancelTokenSource api to get the cancel token source using which we can cancel the ongoing request.
*
* @example Example for isRequestCanceled api
* const { isRequestCanceled } = PCore.getRestClient();
* if(isRequestCanceled(error)) {
* // handle the canceled request using cancelTokenSource.cancel();
* }
* // above example shows how to use isRequestCanceled api to know if the request is canceled using cancel token source.
*
*
* @returns the REST Client API object
* @function
*/
getRestClient = () => {
return RestClient;
};
/**
* This api provides api to mashup cases and views.
* @example Example for getMashupApi()
* Example usage - PCore.getMashupApi();
* // returns the MashupApi object containing the utility APIs to work with cases and pages
*
* @returns - the {@link MashupApi} API object
* @function
*/
getMashupApi = () => {
return MashupApi;
};
/**
* Call getEnvironmentInfo function to get the Environment Information
* such as Locale, Operator info, Application info.
*
* @example Example for getEnvironmentInfo
* Example Usage:
* const envInfo = PCore.getEnvironmentInfo();
* // to get application name
* const appName = envInfo.getApplicationName();
*
* @function
* @returns - the {@link EnvironmentInfo} API object
*/
// This is a stub for getEnvironmentInfo function
getEnvironmentInfo = (): typeof EnvironmentInfo => {
return EnvironmentInfo;
};
/**
* Call getRuntimeParamsAPI to get RuntimeParamsAPI
* which is used to set parameters object while authoring and to be made available in runtime
*
* @example Example for getRuntimeParamsAPI
* Example Usage:
* const runtimeParamsAPI = PCore.getRuntimeParamsAPI();
* // to set runtimeParams
* runtimeParamsAPI.setRuntimeParams({});
*
* @function
* @private
* @returns - the {@link RuntimeParamsAPI} API object
*/
getRuntimeParamsAPI = () => {
return RuntimeParamsAPI;
};
/**
* This api provides utilities to build semantic URLs.
* @example Example for getSemanticUrlUtils()
* // this example will return the SemanticUrlUtils API object
* const semanticUrlUtils = PCore.getSemanticUrlUtils();
*
* @returns - the {@link SemanticUrlUtils} API object
* @function
*/
getSemanticUrlUtils = () => SemanticUrlUtils;
/**
* This api provides remote case utils.
* @example Example for getRemoteCaseUtils()
* Example usage - PCore.getRemoteCaseUtils();
*
* @returns - the {@link RemoteCase} API object
* @function
* @private
*/
getRemoteCaseUtils = () => RemoteCase;
/**
* This api provides NavigationUtils
* @example Example for getNavigationUtils()
* Example usage - PCore.getNavigationUtils();
* @returns - the {@link NavigationUtils} API object
* @function
*/
getNavigationUtils = () => NavigationUtils;
/**
* This api provides registering module on demand.
* @example Example for registerModule()
* Example usage - PCore.registerModule("getFollowersApi", {
* getFollowers: () => {}
* });
*
* @param moduleName Name of the module to be exposed
* eq., getFollowersApi()
* @param module module object to be returned
* @function
* @private
*/
registerModule = (moduleName: string, module: { [key: string]: unknown }) => {
return ModuleRegistry.registerModule(moduleName, module, this);
};
/**
* This api provides Error Handling
* @example Example for getErrorHandler()
* Example usage - PCore.getErrorHandler().setGenericFailedMessage('Failed to load preview');
* Example usage - PCore.getErrorHandler().getGenericFailedMessage();
* @returns - the {@link ErrorHandler} API object
* @function
*/
getErrorHandler = () => ErrorHandler;
/**
* Obtains an entry point to the {@link FormUtils} object that contains APIs that handle form related cases.
* @example In this example, the getFormUtils is used to obtain the getChanges API.
* // To access getChanges API
* const formUtils = PCore.getFormUtils();
* const changes = formUtils.getChanges('app/primary_1');
* @returns - the {@link FormUtils} API object
* @function
*/
getFormUtils = () => FormUtils;
/**
* This api provides messaging service (web sockets) related APIs
* @example Example getMessagingServiceManager()
* Example usage - PCore.getMessagingServiceManager().subscribe({matcher: "interaction"}, message => {
* // Do process message here
* }));
* PCore.getMessagingServiceManager().unsubscribe(subId);
* @returns - the {@link MessagingServiceManager} API object
* @function
*/
getMessagingServiceManager = () => MessagingServiceManager;
/**
* This api provides metadata access like views, data-pages, fields etc.,
* @example Example getMetadataUtils()
* Example usage - PCore.getMetadataUtils().getDatapageMetadata("D_TestPage")
* @returns - the {@link RuleStore} API object
* @function
* @private
*/
getMetadataUtils = () => MetadataUtils;
/**
* This API contains utility methods to retrieve data from data pages.
* @example Example getDataPageUtils()
* Example usage - PCore.getDataPageUtils()
* @returns - the {@link DataStore} API object
* @function
*/
getDataPageUtils = (): typeof DataStore => DataStore;
/**
* This API contains utility methods to retrieve information about data types.
* @example Example getDataTypeUtils()
* Example usage - PCore.getDataTypeUtils().getSavableDataPage();
* @returns - the {@link DataTypeUtils} API object
* @function
*/
getDataTypeUtils = () => DataTypeUtils;
/**
* This api is to register Datapage parameters for callback subscription
* @example Example getCascadeManager()
* Example usage - PCore.getCascadeManager()
* @returns - the {@link CascadeManager} API object
* @function
*/
getCascadeManager = () => CascadeManager;
/**
* Determines if the values of two objects are the same by performing a deep comparison.
* @example In this example isDeepEqual is used to compare 2 objects
* Example usage - PCore.isDeepEqual({'a': '123'}, {'a': '123'});
* @param oldValue The value of the first object.
* @param newValue The value of the second object.
* @returns returns true if both object are same in terms to value else return false
* @function
*/
isDeepEqual = (oldValue: object, newValue: object) => _isEqual(oldValue, newValue);
/**
* This API provides an entry point to the {@link AuthUtils} API object that contains utility APIs to
* to handle authentication tokens utilized for REST API calls.
*
*
* @example Example for getAuthUtils()
* Example usage - PCore.getAuthUtils().setTokens(tokenObj)
* Example usage - PCore.getAuthUtils().revokeTokens().then()
* Example usage - PCore.getAuthUtils().getAuthInstance(authConfig)
*
* @returns - the {@link AuthUtils} Object
* @function
*/
getAuthUtils = (): typeof AuthUtils => {
return AuthUtils;
};
/**
* This API provides an entry point to the {@link module:Debugger} API object that contains utility APIs to
* to enable Xray.
*
* @example Example for getDebugger()
* Example usage - PCore.getDebugger().toggleXRay(true)
*
* @returns - the {@link module:Debugger} Object
* @function
* @private
*/
getDebugger = () => Debugger;
/**
* This API provides an entry point to the {@link module:DeferLoadManager} API object that exposes methods to
* manager defer loaded components
*
*
* @example Example for getDeferLoadManager()
* Example usage - PCore.getDeferLoadManager().start(viewName, caseKey, pageReference, contextName, uniqueId)
* Example usage - PCore.getDeferLoadManager().stop(uniqueId, contextName)
*
* @returns - the {@link DeferLoadManager} Object
* @function
* @private
*/
getDeferLoadManager = () => DeferLoadManager;
/**
* Obtains an entry point to the {@link ExpressionEngine} object that contains API to evaluate expression on given data
*
* @example Example for getExpressionEngine
* Example Usage:
* const expressionEngine = PCore.getExpressionEngine();
* // to evaluate an expression on localData
* const result = expressionEngine.evaluate();
*
* @function
* @returns - the {@link ExpressionEngine} API object
*/
getExpressionEngine = () => ExpressionEngine;
/**
* Obtains an entry point to the ActionsSequencer object that contains APIs to sequence different type of actions in the Constellation Infrastructure.
* To view the APIs in the ActionsSequencer class, see {@link ActionsSequencer|APIs in the ActionsSequencer class}
*
* @example In this example , the API returns the ActionsSequencer object containing the utility APIs
* PCore.getActionsSequencer();
*
* @returns The ActionsSequencer Object
* @function
*/
getActionsSequencer = () => ActionsSequencer;
/**
* This API create unique id and registers given property in passed context
* @example Example for RefreshManager
* const callback = refreshCaseView.bind(params);
* PCore.getRefreshManager().registerForRefresh('PROP_CHANGE',callback,'caseInfo.content.Name','app/modal_1/caseInfo.content','app/modal_1');
*
* options parameter is optional
* @returns return the RefreshManager instance
* @private
*/
getRefreshManager = () => RefreshManager;
getInitialiser = () => Initialiser;
getBootstrapUtils = (): typeof BootstrapUtils => BootstrapUtils;
/**
* Obtains an entry point to the ContextTreeManager object which provides apis to register and handle mutations confined to a view and its children.
* @example Example for getContextTreeManager
* PCore.getContextTreeManager().onViewMutate(
* tab.getPConnect().getContextName(),
* tab.getPConnect().getPageReference(),
* tab.getPConnect()._rawConfig.config?.name,
* (errors) => {
* setTabErrors((tabErrors) => {
* const errors = [...tabErrors];
* ...
* }
* @returns return the ContextTreeManager instance
*/
getContextTreeManager = (): typeof ContextTreeManager => ContextTreeManager;
/**
* This API provides with access related information
* @example Example for AccessPrivilege
* if(PCore.getAccessPrivilege().hasCreateAccess("Person")){
* hasAccess = true;
* }
* @returns {object} return the AccessPrivilege instance
* @private
*/
getAccessPrivilege = () => AccessPrivilege.getInstance();
/**
* Obtains an entry point to the ObjectTransformer object that contains APIs to transform keys
*
* @example In this example , the API returns the ObjectTransformer object containing the utility APIs
* PCore.getObjectTransformer();
*
* @returns The ObjectTransformer Object
* @private
*/
getObjectTransformer = () => ObjectTransformer;
/**
* This API returns all the stateMachines for the given
* context, pageReference & target
* @example Example for getAllStateMachines
* getAllStateMachines("app/primary/workarea_2", "caseInfo.content", ".var1")
* @returns {object} return the available stateMachines
* @private
*/
getAllStateMachines = (context: string, pageReference?: string, target?: string) => {
if (!pageReference || !target) {
return stateMachineManager.getAllStateMachinesByContext(context);
}
return stateMachineManager.getAllStateMachines(context, pageReference, target);
};
/**
* Determines whether namespacing is enabled for the current application.
*
* @example Example for isNamespaceEnabled()
* Example usage - PCore.isNamespaceEnabled();
* // returns -- false (namespacing disabled)
* @returns {boolean} `true` if namespacing is enabled; otherwise, `false`.
* @private
*/
isNamespaceEnabled = () => false;
/**
* Returns the fully qualified rule name with the given namespace.
*
* @example Example for getQualifiedName()
* Example usage - PCore.getQualifiedName('TestRule', 'AgileStudio');
* // returns -- 'AgileStudio__TestRule'
* @param {string} ruleName - The name of the rule to be qualified.
* @param {string} namespace - The namespace to prefix to the rule name.
* @returns {string} The namespace-qualified rule name.
* @public
*/
/* eslint-disable @typescript-eslint/no-unused-vars */
getQualifiedName = (ruleName: string, namespace: string) => ruleName;
/**
* Returns the rule name qualified with the default namespace `"PegaPlatform"`.
*
* @example Example for getDefaultQualifiedName()
* Example usage - PCore.getDefaultQualifiedName('TestRule');
* // returns -- 'PegaPlatform__TestRule'
* @param {string} ruleName - The name of the rule to be qualified.
* @returns {string} The namespace-qualified rule name using `"PegaPlatform"` as the default namespace.
* @public
*/
getDefaultQualifiedName = (ruleName: string) => this.getQualifiedName(ruleName, 'PegaPlatform');
}
export type { PCore };
export default PCore;