/** * @module PCore */ /* * Copyright (c) 2019 Pegasystems Inc. * All rights reserved. */ import _isEqual from 'lodash.isequal'; import Initialiser from './initialiser'; import * as StateManager from './store/state/state-manager'; import * as ContainerUtils from './container/container-utils'; import { LocaleUtils } from './locale/locale-utils'; import Attachment from './attachment'; import ViewRule from './view-rule'; import FollowerApi from './case-follower'; import RelatedCasesApi from './related-cases'; import UserApi from './user'; import FeedUtils from './feed'; import Tags from './tags'; import Stakeholders from './stakeholders'; import EnvironmentInfo from './environment-info'; import RuntimeParamsAPI from './runtime-params'; import getPersonalizationUtils from './personalization'; import DataApi from './data-view/index'; import DataApiUtils from './data-view/data-api-utils'; import AnalyticsUtils from './analytics'; import RoutingUtils from './router/routing-utils'; import RemoteCase from './case/remote-case'; import { createC11nEnv, registerComponentCreator } from './interpreter/c11n-env'; import * as AppRouter from './router/app-router'; import ModuleRegistry from './modules/module-registry'; import MessageManager from './messages'; import CoexistenceManager from './coexistence'; import constants, { publicConstants } from './constants'; import MashupApi from './mashup/apis'; import Events from './events'; import SemanticUrlUtils from './router/semanticurl-utils'; import ErrorHandler from './error-handler'; import FormUtils from './form/form-utils'; import AnnotationUtils from './annotation/utils'; import FieldUtils from './fields/index'; import MessagingServiceManager from './messagingservice/manager'; import * as MetadataUtils from './rules/rules-store'; import DataStore from './datapage/index'; import DataTypeUtils from './datatype'; import CascadeManager from './cascade/manager'; import Debugger from './debug/debugger'; import DeferLoadManager from './deferload/manager'; import CaseUtils from './case/utils'; import StateUtils from './store/state/utils/state-utils'; import * as ExpressionEngine from './expression/expression-engine'; import RefreshManager from './refresh/refresh-manager'; import ActionsSequencer from './actions/sequencer'; import * as RestClient from './rest-client'; import FieldDefaultUtils from './fields/field-default'; import AuthUtils from './utils/authentication-utils'; import NavigationUtils from './utils/navigation-utils'; import * as ViewResources from './utils/view-resources'; import PubSubUtils from './utils/pubsub-utils'; import AsynchronousUtils from './utils/asynchronous-utils'; import ObjectTransformer from './utils/object-transformer'; import AssetLoader from './utils/asset-loader'; import './validation/validators/validators'; import './annotation/handlers'; import BootstrapUtils from './bootstrap/bootstrap-utils'; import ContextTreeManager from './contextree/treemanager'; import GenAIAssistant from './genai-assistant'; import type ComponentsRegistry from './components-registry'; import AccessPrivilege from './access-privilege'; import stateMachineManager from './page-instructions/state-machine-manager'; /** * The PCore object provides access to methods * that are available * for use by Bridge layers that connect the Constellation * Core to a UI Library implementation. (For example, Nebula * is a bridge layer between Constellation Core and React.) * Methods defined on this class are available via the * PCore object. */ class PCore { /** * JSON object that stores any behavior overrides. *

Supported override flag is:

*

dynamicLoadComponents - when false, do not attempt to load components dynamically

* @private */ static behaviorOverrides: { [key: string]: boolean } = {}; /** * This API provides an entry point to the {@link PersonalizationUtils} object that contains utility APIs * to manage the personalization instances of a list component. * To view the APIs in the {@link PersonalizationUtils} module, * see {@link PersonalizationUtils} Module. * * @param listId - A unique ID referencing a list component. The length of the ID should be limited to 32 characters. * * @example In this example, the API obtains the PersonalizationUtils object for the list whose ID is 443533r555. * const listId = "443533r555"; * PCore.getPersonalizationUtils(listId); * * @returns - {@link PersonalizationUtils} object * @function */ getPersonalizationUtils = getPersonalizationUtils; /** * Constructor - Not for use outside of Core! Included for reference only. */ constructor() { // Empty Constructor explicitly provided to control JSDoc output PCore.behaviorOverrides = {}; } /** * Returns the version of the PConnect/PCore APIs for this implementation. * @returns The major/minor/patch version (ex: "8.6.1") * @function */ getPCoreVersion = () => '8.23.0'; /** * This API registers a callback that will be called once the application infrastructure * has established the store and is ready to perform its initial render. * It is expected that the component object and container ID information * passed into the callback will be used to call a * function that will render the component tree specified by the results of the * component object's getPConnect(). * * Example use can be found in src/bridge/react_root.js: * PCore.onPCoreReady((root, target) => { render(root, target)}); * where the incoming root and target arguments are passed along to the method * that renders the application * * @param callback The callback takes 2 arguments: root and target. * root is a JSON * object containing a "props" key. This is the component object that provides * access to the initial getPConnect() for the top-level component * of the application. The root object may also provides a "domContainerID" key. * If that key exists, it used to get the DOM element with the given ID which is * then used as the target element in order the component object will be rendered. * If that key is null, the target argument passed to the callback is used as the * initial point of rendering. * * target will be null when the application is first being rendered and may * be a string such "app/primary" to indicate the target container in which the * application should be rendered. If target is not defined, the component object * is rendered in the DOM's element or in the element with id="app" if * there is no element. * * @function */ onPCoreReady = (callback: Function) => { return BootstrapUtils.onPCoreReady(callback); }; /** * This API registers a callback that will be called once the application infrastructure * is to be dismounted. It is invoked in the Web Embed scenario when the Web Embed * web component receives a disconnectedCallback or when the user explicitly * invokes the logout API. * It is expected that the portalTarget and styleSheetTarget information * passed into the callback will be used to call the proper React methods * to unmount the component tree previously mounted at that target as well * as any stylesheet related cleanup. * * Example use can be found in src/bridge/react_root.js: * PCore.onPCoreCleanup((config) => { unmount(config)}); * where the config object includes portalTarget and styleSheetTarget attributes * which were specified when originally bootstrapping Constellation * * @param callback The callback takes 1 argument: config. * config is a JSON object containing key attributes passed in when initially * rendering the Web Embed via bootstrapping Constellation and invoking the * appropriate MashupAPI. Some relevant attributes include "domContainerID", * "portalTarget" and "styleSheetTarget". * * @function */ onPCoreCleanup = ( callback: (config: { domContainerID: string | null; portalTarget: HTMLDivElement; styleSheetTarget: HTMLDivElement; }) => void ) => BootstrapUtils.onPCoreCleanup(callback); /** * This function returns the component registry bound to core. * It has methods to register or override existing components, this is exposed * so that components from other lib like mobile can replace desktop one. * @example Example for getComponentsRegistry() * const componentRegistry = PCore.getComponentsRegistry(); * @returns the Component registry * @function */ getComponentsRegistry = (): typeof ComponentsRegistry => { return BootstrapUtils.getComponentsRegistry(); }; /** * Utility function to check for a semantic URL * @function */ checkIfSemanticURL = () => { return BootstrapUtils.checkIfSemanticURL(); }; /** * Utility function to check for a valid semantic URL * @function */ isValidSemanticURL = () => { return AppRouter.isValidSemanticURL(); }; /** * This api provides utilities to update routing table. * @example Example for getRoutingUtils() * // this example will return the RoutingUtils API object * const routingUtils = PCore.getRoutingUtils(); * * @returns the API object * @function * @private */ getRoutingUtils = () => RoutingUtils; /** * Obtains an entry point to the {@link ViewResources} object that contains APIs to manage view metadata in rule store * * @example In this example, the getViewResources API is used to obtain the updateViewResources API. * const { updateViewResources } = PCore.getViewResources(); * * @returns An object of {@link ViewResources} APIs * @function */ getViewResources = () => { return ViewResources; }; /** * Utility function to configure for browser bookmarking * @param payload need better description * @function */ configureForBrowserBookmark = (payload: object) => { return BootstrapUtils.configureForBrowserBookmark(payload); }; /** * Returns the Redux Store * @returns the Redux Store * @function * * @example Example for getStore() * const store = PCore.getStore(); */ getStore = () => { return StateManager.getStore(); }; /** * Reset the Store to its initial state. Note: This is typically only * used by Mashups when they are exiting out of their flow and want * to leave the Store in a state that is initialized for the next use. * On the initial loading of the app, the store is automatically * initialized. * @function * @private * @returns object with actionMgrID and promise keys: { actionMgrID: , promise: } * * @example Example for resetStore() * const store = PCore.resetStore(); */ resetStore = () => StateManager.resetStore(); /** * Returns the {@link MessageManager} API's. It exposes below API's *
    *
  • addMessages
  • *
  • getMessages
  • *
  • clearMessages
  • *
* * @example Example for addMessages api * const { addMessages } = PCore.getMessageManager(); * addMessages({ * messages: [ * { * type: 'error', * message: 'Validation Error' * } * ], * category: 'HTTP' * context: 'app/primary_2' * }); * // above example shows how to use addMessages api to add HTTP message * // for the context app/primary_2 * * @example Example for clearMessages api * const { clearMessages } = PCore.getMessageManager(); * clearMessages({ * type: 'error', * property: '.firstName', * context: 'app/primary_2' * }); * // above example shows how to use clearMessages api to clear messages of type error * // on firstName property * * @returns the API object * @function */ getMessageManager = () => { return MessageManager; }; /** * This api provides Coexistence related api. * @example Example for getCoexistenceManager() * Example usage - PCore.getCoexistenceManager(); * * @returns the API object * @function * @private */ getCoexistenceManager = (): typeof CoexistenceManager => CoexistenceManager; /** * Returns the value of prop from Redux Store. This is a syntactical sugar to StateManager.getValue() * * @param propReference property reference e.g. .FirstName or pyWorkPage.FirstName * @param pageReference page reference e.g. .pyWorkPage, D_Accounts.pxResults(1) * @param context context of the property * @returns - value of the prop * @function * */ getStoreValue = (propReference: string, pageReference: string, context: string) => { return StateManager.getValue(propReference, pageReference, context); }; /** * Returns the Container Manager Utils * This exposes the container manager utility APIs like *
    *
  • getContainers
  • *
  • getContainerData
  • *
  • isContainerItemExists
  • *
  • getContainerItemName
  • * and others *
* * @example Example for getContainerUtils() * Example usage - PCore.getContainerUtils() * // returns -- ContainerUtils Object which containers the utility APIs * * @example Example for getContainerUtils().getContainerItemName * Example usage - PCore.getContainerUtils().getContainerItemName('app/primary') * // returns -- container item name if container already exists in store * * @returns {@link ContainerUtils} object * @function */ getContainerUtils = (): typeof ContainerUtils => { return ContainerUtils; }; /** * Obtains an entry point to the {@link AnnotationUtils} class that is used to access utility APIs to handle the annotation to a property. * * @example Example for getAnnotationUtils() * Example usage - PCore.getAnnotationUtils() * // returns -- AnnotationUtils class containing the utility APIs * * @example Example for getAnnotationUtils().isProperty() * Example usage - PCore.getAnnotationUtils().isProperty('@P .EmployeeName') * // returns -- true if the passed argument is property otherwise it returns false * * @returns the AnnotationUtils API object * @function */ getAnnotationUtils = () => { return AnnotationUtils; }; /** * Obtains an entry point to the {@link FieldUtils} class that is used to access utility APIs to handle the field related operations. * * @example Example for getFieldUtils() * Example usage - PCore.getFieldUtils() * // returns -- FieldUtils class containing the utility APIs * * @example Example for getFieldUtils().formatPageReference() * Example usage - PCore.getFieldUtils().formatPageReference('.Questionsets[0].Questions') * // returns -- '.Questionsets(1).Questions' * * @returns the FieldUtils API object * @function */ getFieldUtils = () => { return FieldUtils; }; /** * Obtains an entry point to the {@link FieldDefaultUtils} instance that is used to access APIs to handle the fields default related operations. * * @example Example for getFieldDefaultUtils() * Example usage - PCore.getFieldDefaultUtils() * // returns -- FieldDefaultUtils class instance containing the APIs * * @example Example for getFieldDefaultUtils().getDefaultsforType() * Example usage - PCore.getFieldDefaultUtils().getDefaultsforType("Email") * * @returns the FieldDefaultUtils object * @function * @public */ getFieldDefaultUtils = () => { return FieldDefaultUtils; }; /** * Returns the Asset Loader Class * This exposes the Asset Loader utility APIs including: *
    *
  • getStaticServerUrl
  • *
  • getConstellationServiceUrl
  • *
  • initServer
  • *
  • register
  • *
  • getLoader
  • *
  • loadAssets
  • *
* * @example Example for getAssetLoader() * Example usage - PCore.getAssetLoader() * // returns -- AssetLoader Object which containers the utility APIs * * @example Example for getAssetLoader().getLoader * Example usage - PCore.getAssetLoader().getLoader('font-loader') * // returns -- Font Loader Function to load font assets if font-loader is defined * // else returns default loader * * * @returns the Asset Loader Object * @function */ getAssetLoader = () => { return AssetLoader; }; /** * Obtains an entry point to the {@link module:AttachmentUtils|AttachmentUtils} object that contains utility APIs to handle the attachments of a case. * * @example In this example, the getAttachmentUtils API is used to obtain the uploadAttachment API. * // To access uploadAttachment API * const { uploadAttachment } = PCore.getAttachmentUtils(); * // returns -- An object of Attachment utility APIs * * @returns An object of AttachmentUtils APIs * @function */ getAttachmentUtils = () => { return Attachment; }; /** * Obtains an entry point to the {@link module:ViewRule|ViewRule} object that contains APIs to handle performing * CRUD operations to View Rules * * @example In this example, the getViewRuleApi is used to obtain the getViewRule API. * // To access getViewRule API * const { getViewRule } = PCore.getViewRuleApi(); * // returns -- An object of ViewRule utility APIs * * In particular, the full list of utility APIs are: *
    *
  • createViewRule
  • *
  • getViewRule
  • *
  • updateViewRule
  • *
  • deleteViewRule
  • *
* * @returns An object of ViewRule APIs * @function * @private */ getViewRuleApi = () => { return ViewRule; }; /** * Obtains an entry point to the {@link FeedUtils} object that contains APIs to handle the feeds of a case. * @example In this example, the FeedApi is used to obtain the postMessage API. * // To access postMessage API * const feedUtils = PCore.getFeedUtils(); * feedUtils.postMessage().then(()=>{ * // success case * }).catch(()=>{ * // error case * }) * * @returns An object of FeedUtils APIs * @function */ getFeedUtils = (): typeof FeedUtils => FeedUtils; /** * Obtains an entry point to the {@link TagUtils} object that contains APIs to handle the tags of a case. * * @example In this example, the API returns the tagUtils object containing the APIs that handle the tags of a case. * const { getTaggedCases, getTags, postTags, removeTag , getTagsLandingPageURL } = PCore.getTagUtils(); * * @returns This API returns the {@link TagUtils} object. * @function */ getTagUtils = () => Tags; /** * Obtains an entry point to the {@link module:GenAIAssistantUtils|GenAIAssistantUtils} object that contains APIs to handle the GenAI Assistant. * @example In this example, the API returns the genAiAssistantUtils object containing the APIs that handle the genai functionalities in a case. * const { createConversation, sendMessage, createConversationForAgent, sendMessageForAgent, likeAgentMessage, unLikeAgentMessage, getConversations, getConversationsForAgent, getMessages, getMessagesForAgent } = PCore.getGenAIAssistantUtils(); * * @returns {object} Returns the {@link module:GenAIAssistantUtils|GenAIAssistantUtils} object. * @function */ getGenAIAssistantUtils = () => GenAIAssistant; /** * Obtains an entry point to the {@link module:StakeholderUtils|StakeholderUtils} object that contains APIs to handle the participants of a case. * * @example In this example, the API returns the StakeholderUtils object containing the APIs that handle the participants of a case. * const { getParticipants, getRoleView, getParticipantRoles, getParticipant, createParticipant, updateParticipant, deleteParticipant } = PCore.getStakeholderUtils(); * * @returns This API returns the {@link StakeholderUtils} object. * @function */ getStakeholderUtils = () => Stakeholders; /** * Obtains an entry point to the {@link UserApi} object that contains APIs to handle the user data. * * @example In this example, the getUserApi API is used to obtain the getOperatorDetails API. * // To access Users API * const { getOperatorDetails } = PCore.getUserApi(); * // returns -- An object of User APIs * * @returns An object of {@link UserApi} APIs * @function */ getUserApi = () => { return UserApi; }; /** * Obtains an entry point to the {@link CaseFollowerApi} object that contains APIs to handle the followers of a case. * * @example In this example, the getCaseFollowerApi API is used to obtain the addCaseFollower API. * // To access Followers API * const { addCaseFollower } = PCore.getCaseFollowerApi(); * // returns -- An object of Follower APIs * * @returns An object of {@link CaseFollowerApi} APIs * @function */ getCaseFollowerApi = (): typeof FollowerApi => { return FollowerApi; }; /** * Obtains an entry point to the {@link CaseUtils} object that contains utility APIs for the Case. * * @example In this example, the getCaseUtils API is used to obtain the isCaseActive API. * const CaseUtils = PCore.getCaseUtils(); * * @returns An object of {@link CaseUtils} APIs * @function */ getCaseUtils = () => { return CaseUtils; }; /** * Obtains an entry point to the {@link StateUtils} object that contains utility APIs for the Redux State. * * @example In this example, the getStateUtils API is used to obtain API's like getSharedState, setSharedState. * const StateUtils = PCore.getStateUtils(); * * @returns An object of StateUtils APIs * @function */ getStateUtils = () => { return StateUtils; }; /** * This API provides an entry point to the RelatedCasesApi object that contains APIs to handle the related cases of a case. * To view the APIs in the RelatedCasesApi module, see {@link RelatedCasesApi}. * * @example In this example, the API returns the RelatedCasesApi object containing the APIs that handle the related cases of a case. * PCore.getRelatedCasesApi(); * * @returns This API returns the {@link RelatedCasesApi} object. * @function */ getRelatedCasesApi = () => { return RelatedCasesApi; }; /** * This API obtains the metadata associated with the datasource contained in the config object * * @example Example for getDataApi() * Example usage - PCore.getDataApi().init(dataConfig); * // the API obtains the metadata associated with the data source contained in the dataConfig object. * @function */ getDataApi = () => { return DataApi; }; /** * This API provides an entry point to the {@link DataApiUtils} object that contains utility APIs to retrieve information from data views. * To view the APIs in the {@link DataApiUtils} module, see {@link DataApiUtils} Module. * * @example In this example, the API obtains the entry point to the DataApiUtils object. * PCore.getDataApiUtils(); * * @returns The DataApiUtils object * @function */ getDataApiUtils = (): typeof DataApiUtils => { return DataApiUtils; }; /** * Returns an object of Analytics utils like: *
    *
  • getDataObjects
  • *
  • getDefaultColumns
  • *
  • getInsightIDs
  • *
  • getInsightByID
  • *
  • createInsight
  • *
  • exportToExcel
  • *
  • exportToCSV
  • *
  • translateStrings
  • *
* * All APIs return a Promise. * * @example Examples for getAnalyticsUtils() * // To retrieve a list of all insights * PCore.getAnalyticsUtils().getInsightIDs().then(response => { ... }).catch(() => { ... }); * * // To create an insight * const insightMetadata = { ... }; * PCore.getAnalyticsUtils().createInsight(insightMetadata).then(response => { ... }).catch(() => { ... }); * * @returns An object of {@link AnalyticsUtils} APIs * @function */ getAnalyticsUtils = (): typeof AnalyticsUtils => { return AnalyticsUtils; }; /** * Returns an instance of the LocaleUtils class. * @example PCore.getLocaleUtils() * //Returns the instance of the localeUtils with the following API's on it. *
    *
  • setLocaleForRule
  • *
  • getLocaleForRule
  • *
  • resetLocaleStore
  • *
  • getLocaleValue
  • *
  • setTimezone
  • *
  • getTimeZoneInUse
  • *
* @function * @returns the localeUtils Object */ getLocaleUtils = (locale?: string) => { const languagePackObj = locale ?? EnvironmentInfo.getLocale() ?? 'en-US'; return MetadataUtils.getLocaleUtilsForLanguage(languagePackObj); }; /** * Registers the custom LocaleUtils APIs overriding the existing ones. * @example PCore.getLocaleUtils().registerLocaleManager(customLocaleUtilApis) * customLocaleUtilApis - { * "setLocaleForRule" : function(){ //custom implementation}, * "getLocaleForRule" : function(){ //custom implementation}, * "resetLocaleStore" : function(){ //custom implementation}, * "getLocaleValue" : function(){ //custom implementation}, * "setTimezone" : function(){ //custom implementation}, * "getTimeZoneInUse" : function(){ //custom implementation} * } * @function * @param customLocaleUtilApis An object with the custom implementation if the LocaleUtils API's */ registerLocaleManager = (customLocaleUtilApis: Partial) => { 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 *
    *
  • subscribe
  • *
  • publish
  • *
* * @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: *
    *
  • getCaseEvents
  • *
* * @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. *
    *
  • setTokens
  • *
* * @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 *
    *
  • start
  • *
  • stop
  • *
* * @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;