{"_id":"@avaya/axp-omni-sdk-core","_rev":"16-a5e0f6bb02e9ff9e35485abc5007e2e7","name":"@avaya/axp-omni-sdk-core","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@avaya/axp-omni-sdk-core","version":"1.0.0","license":"SEE LICENSE IN LICENSE.txt","_id":"@avaya/axp-omni-sdk-core@1.0.0","maintainers":[{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},{"name":"kahagerman","email":"kahagerman@avaya.com"},{"name":"amarasescu","email":"amarasescu@avaya.com"},{"name":"digitalpipeline","email":"bvishwakarma@avaya.com"},{"name":"enrique-prado","email":"enriquep@avaya.com"},{"name":"jonathanavaya","email":"jonathanr@avaya.com"},{"name":"yangatavaya","email":"chungguangy@avaya.com"},{"name":"joe-s-avaya","email":"joe.sebast.avaya@gmail.com"},{"name":"mrazian","email":"mrazian@avaya.com"},{"name":"cpaas.devops","email":"cpaasops@avaya.com"},{"name":"bvazmer","email":"bvazmer@avaya.com"}],"dist":{"shasum":"fd4f4e3b6fc4cfc808b133bead2f7da5b8b42b73","tarball":"https://registry.npmjs.org/@avaya/axp-omni-sdk-core/-/axp-omni-sdk-core-1.0.0.tgz","fileCount":5,"integrity":"sha512-7Ci++2eQc7+2al0m/PyHJbvYPKifu1VnVBZKeUsjl6ZcNwrObfqQ7uwwDN0PNj2a69QudgtQ3qHdGRdifrSXIw==","signatures":[{"sig":"MEYCIQCB5ysYi9D2SXnxR/OkVkosatEZWXlxW7rdfDDzy7TPDAIhAM17vg5Ho+h2Rflz/yzljYyzyHgDdixDV/Sl0OWPnek+","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":100706},"type":"module","_from":"file:candidate/avaya-axp-omni-sdk-core-1.0.0.tgz","exports":{".":{"types":"./lib/axp-omni-sdk-core-types.d.ts","import":"./lib/axp-omni-sdk-core.js"}},"_npmUser":{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},"_resolved":"/home/runner/work/sdk/sdk/candidate/avaya-axp-omni-sdk-core-1.0.0.tgz","_integrity":"sha512-7Ci++2eQc7+2al0m/PyHJbvYPKifu1VnVBZKeUsjl6ZcNwrObfqQ7uwwDN0PNj2a69QudgtQ3qHdGRdifrSXIw==","_npmVersion":"10.7.0","description":"Common and core functionality of AXP Omni SDKs, this is required by other packages.","directories":{},"_nodeVersion":"20.15.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/axp-omni-sdk-core_1.0.0_1722296814639_0.2664962245064335","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@avaya/axp-omni-sdk-core","version":"1.1.0","license":"SEE LICENSE IN LICENSE.txt","_id":"@avaya/axp-omni-sdk-core@1.1.0","maintainers":[{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},{"name":"kahagerman","email":"kahagerman@avaya.com"},{"name":"amarasescu","email":"amarasescu@avaya.com"},{"name":"digitalpipeline","email":"bvishwakarma@avaya.com"},{"name":"enrique-prado","email":"enriquep@avaya.com"},{"name":"jonathanavaya","email":"jonathanr@avaya.com"},{"name":"yangatavaya","email":"chungguangy@avaya.com"},{"name":"joe-s-avaya","email":"joe.sebast.avaya@gmail.com"},{"name":"mrazian","email":"mrazian@avaya.com"},{"name":"cpaas.devops","email":"cpaasops@avaya.com"},{"name":"bvazmer","email":"bvazmer@avaya.com"}],"dist":{"shasum":"1c5bbd1a7ed73547b4a014ffe10ab3e7c80b07d8","tarball":"https://registry.npmjs.org/@avaya/axp-omni-sdk-core/-/axp-omni-sdk-core-1.1.0.tgz","fileCount":5,"integrity":"sha512-F8U6iX7XabPVijniAmgG+iReL4jSRnO03ntPKKe2nPwAFxU/Q6vO9cv4MXzwoiGKJMsaL7L1XKZodFRvK+nOrg==","signatures":[{"sig":"MEYCIQDeW2lKywThsQJrYFaXlHdKmh82c/IYaErfqCnRUalHBwIhAKytLbRHixjAS4vLhh62xlV1n8FeNFifZn7wSpXBYbqi","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":107016},"type":"module","_from":"file:candidate/avaya-axp-omni-sdk-core-1.1.0.tgz","exports":{".":{"types":"./lib/axp-omni-sdk-core-types.d.ts","import":"./lib/axp-omni-sdk-core.js"}},"_npmUser":{"name":"axp-sdk-automation","email":"axp-sdk-automation@avaya.com"},"_resolved":"/home/runner/work/sdk/sdk/candidate/avaya-axp-omni-sdk-core-1.1.0.tgz","_integrity":"sha512-F8U6iX7XabPVijniAmgG+iReL4jSRnO03ntPKKe2nPwAFxU/Q6vO9cv4MXzwoiGKJMsaL7L1XKZodFRvK+nOrg==","_npmVersion":"10.8.2","description":"Common and core functionality of AXP Omni SDKs, this is required by other packages.","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/axp-omni-sdk-core_1.1.0_1728419016704_0.8523324709728162","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-07-29T23:46:54.505Z","modified":"2026-02-04T12:58:18.006Z","0.0.0":"2024-07-25T21:05:39.819Z","1.0.0":"2024-07-29T23:46:54.837Z","1.1.0":"2024-10-08T20:23:36.945Z"},"license":"SEE LICENSE IN LICENSE.txt","description":"Common and core functionality of AXP Omni SDKs, this is required by other packages.","maintainers":[{"email":"mrazian@avaya.com","name":"mrazian"},{"email":"cpaasops@avaya.com","name":"cpaas.devops"},{"email":"bvazmer@avaya.com","name":"bvazmer"},{"email":"gaffara@avaya.com","name":"gaffara"},{"email":"amarasescu@avaya.com","name":"amarasescu"},{"email":"bvishwakarma@avaya.com","name":"digitalpipeline"},{"email":"kahagerman@avaya.com","name":"kahagerman"},{"email":"axp-sdk-automation@avaya.com","name":"axp-sdk-automation"},{"email":"raziandev@gmail.com","name":"raziandev"},{"email":"ptognini@avaya.com","name":"ptognini77"},{"email":"kamau3@avaya.com","name":"kamau3"},{"email":"lancecramlet@avaya.com","name":"lcramlet-avaya"},{"email":"jmidd@avaya.com","name":"jmiddd"},{"email":"ggoulet@avaya.com","name":"ggoulet_avaya"},{"email":"peter.c.schuelke@gmail.com","name":"shulkdog"}],"readme":"# AXP Core\n\n## Overview\n\nThe AXP Core module provides a set of basic functionalities to initialize, shutdown the SDK, and get the default conversation of the end user. The AXP Core establishes the session with Avaya Experience Platform™ for the end user, manages the session inactivity, and participants involved in the conversation.\n\n## Installation\n\nTo install the AXP Core, run the following command:\n\n```bash\nnpm install --save @avaya/axp-omni-sdk-core\n```\n\nAXP Core exports a set of types and classes. Out of all the exports, the class `AxpOmniSdk` is the origin point of the AXP Core usage flow. It can be imported as follows:\n\n```typescript\nimport { AxpOmniSdk } from \"@avaya/axp-omni-sdk-core\";\n```\n\n## Usage\n\n### Prerequisites\n\nBefore using the AXP Omni SDK refer to [this page](https://developers.avayacloud.com/avaya-experience-platform/docs/omni-sdk-introduction#next-steps) for a list of prerequisites.\n\n### Using additional functionalities\n\nThe [Conversation](#conversation) of Core module is extended by other modules of AXP Omni SDK. This extensibility is achieved using the concept of [Mixins](https://www.typescriptlang.org/docs/handbook/mixins.html).\n\nEach additional functionality exports a mixin which enhances the conversation object with its own set of properties and methods. For example, if you use AXP Messaging module, then the conversation object will have additional properties and methods to send and receive messages.\n\nPlease refer to the documentation of the additional functionality module that you are using to know more about the methods that it adds on the Conversation.\n\nList of currently available additional functionalities:\n\n- [AXP Messaging](https://github.com/AvayaExperiencePlatform/omni-sdk-js/blob/v1.1.0/messaging.md)\n\n#### How to use the additional functionalities\n\nTo use the additional functionalities, the Client has to install the additional functionality module (refer to the installation instructions of each additional functionality module for more details).\n\nEach additional functionality module exports a mixin function. The base conversation from AXP Core module can be enhanced by applying this mixin. This will come in handy when we add new functionalities in future releases.\n\nExample of adding AXP Messaging functionality to the AXP Core Conversation:\n\n```ts\n// TS/JS\nimport { AxpOmniSdk } from '@avaya/axp-omni-sdk-core';\nimport { AxpMessagingConversation } from '@avaya/axp-omni-sdk-messaging';\n\nconst EnhancedConversationClass = AxpMessagingConversation();\n\n// All arguments are not shown for brevity, refer to the Initialization section for the complete initialization example.\nconst userSession = await AxpOmniSdk.init(..., EnhancedConversationClass);\n```\n\n### Authentication\n\nThe AXP Omni SDK uses JSON Web Tokens (JWT) for client authentication and requires a valid JWT to function. The JWT is obtained from your own backend web application that communicates with AXP's authentication API.\n\nThe SDK expects an implementation of the `JwtProvider` interface to be provided during [initialization](#initialization). The `JwtProvider` implementation must have two methods:\n\n1. `onExpiryWarning`: This method is called when the JWT is about to expire. In the argument of this method, the remaining time in milliseconds before the JWT expires is provided.\n2. `onExpiry`: This method is called when the JWT has expired.\n\n**The consumers of SDK should call the `AxpOmniSdk.setJwt()` to provide a new JWT to the SDK.**\n\nJWT Provider example (in TypeScript):\n\n```typescript\nimport { JwtProvider } from \"@avaya/axp-omni-sdk-core\";\n\nclass MyJwtProvider implements JwtProvider {\n\tonExpiryWarning(timeToExpiry: number): void {\n\t\t// ...\n\t}\n\n\tonExpiry(): void {\n\t\t// ...\n\t}\n}\n```\n\nJWT Provider example (in JavaScript):\n\n```js\nclass MyJwtProviderJS {\n    onExpiryWarning(timeToExpiry) {\n        // ...\n    }\n\n    onExpiry(): void {\n        // ...\n    }\n}\n```\n\n### Initialization\n\nBefore any operation can be performed with the SDK, it must be initialized. The initialization process creates a new session for the current user (identified by the JWT) and returns a `UserSession` object that contains the Conversation object corresponding to the User's ongoing conversation. For more details see the [Conversation](#conversation) section.\n\nInitialization can be done by calling the static method `init()` on the class `AxpOmniSdk`. The `init()` method takes two arguments:\n\n1. `initParams`: An object which has all the initialization parameters and configurations.\n2. `AdditionalFunctionality`: A Conversation class enhanced by applying the [additional functionalities](#using-additional-functionalities) using mixins.\n\nInitialization Example:\n\n```typescript\nimport { AxpOmniSdk } from '@avaya/axp-omni-sdk-core';\nimport { AxpMessagingConversation } from '@avaya/axp-omni-sdk-messaging';\n\nconst EnhancedConversationClass = AxpMessagingConversation();\n\nconst initParams = {\n    host: 'na'\n    integrationId: '<integrationId>',\n    appKey: '<appKey>',\n    token: '<JWT>',\n    JwtProvider: new MyJwtProvider(),\n    displayName: 'John Doe',\n    logLevel: 'debug',\n    idleTimeoutDuration: 5 * 60 * 1000, // in milliseconds\n    idleShutdownGraceTimeoutDuration: 1 * 60 * 1000, // in milliseconds\n}\n\nconst userSession = await AxpOmniSdk.init(initParams, EnhancedConversationClass);\n```\n\nThe `init()` method returns a `Promise` that resolves to a `UserSession` object. The `UserSession` object contains the conversation object(s) that can be used for further operations.\n\n#### Waiting for initialization to complete\n\nBeing an `async` method, the Client can `await` on the promise returned by the `init()` (as shown in above example) method to wait for the SDK initialization to complete.\n\nAlternatively, the SDK emits an initialized event after the SDK initialization has completed. The Client can listen to these events by providing a listener function to SDK.\n\n**Important: In order to receive the initialized event, it is imperative to provide the listener function before calling the `init()` method.**\n\n```ts\nAxpOmniSdk.addSdkInitializedListener((userSession) => {\n\t// userSession object contains the conversation object that can be used for further operations. More details on the conversation object are below.\n\n\tconsole.log(\"SDK Initialized\");\n\t// ... your code.\n});\n```\n\n### Conversation\n\nA conversation object represents the conversation of the current user with the Contact Center.\n\nThe AXP Core Conversation contains -\n\n- Method to get the details of the participants involved in the conversation.\n- Method to provide listeners for the participant change events.\n- Method to set the context parameters used for routing.\n- Property `conversationId`.\n\n**💡 INFO: Based on [additional functionality](#using-additional-functionalities) that is included, the conversation will have additional properties and methods. Check out the documentation of each functionality that has been added to know more about the methods that it adds on to the Conversation.**\n\n**❗ NOTE: On initialization, the default Conversation for the user gets automatically created on AXP. The default conversation of the user never ends and currently the only conversation that the user can use.**\n\nThe default conversation can be accessed from the `UserSession` object returned by the `init()` method.\n\n```ts\n// Arguments are not shown for brevity, refer to the Initialization section for the complete initialization example.\nconst userSession = await AxpOmniSdk.init(...);\n\nconst conversation = userSession.conversations[0];\n```\n\nAlternatively, the `AxpOmniSdk` class exposes another method `getDefaultConversation()` which returns the default conversation object. Important thing to note here is that this method can be called only after the SDK has been initialized.\n\n```ts\nconst userSession = await AxpOmniSdk.init(...);\n\nconst conversation = AxpOmniSdk.getDefaultConversation();\n```\n\n#### Context Parameters\n\nContext parameters are used to provide routing information to the AXP platform. These parameters are used to route the conversation to the appropriate agent or queue. The context parameters can be set using the `setContextParameters()` method on the conversation object.\n\n```ts\nconversation.setContextParameters({\n\tkey1: \"value1\",\n\tkey2: \"value2\",\n\t// ...\n});\n```\n\n#### Participants\n\nThe Client can get the list of participants involved in the conversation by using the property `participants` on the conversation object. The `participants` property is an array of `Participant` objects. Each `Participant` object contains that participant's details like id of the participant, their display name, their role and the channel on which they are participating in the conversation.\n\n```ts\nconst participants = conversation.participants;\n```\n\n#### Events\n\nApart from the initialized and shutdown events, the SDK emits a few more events that the consumers can listen to. These events are specific to the Conversation and hence the APIs to listen to these events are provided on the Conversation object.\n\n| Event Name          | Description                                                  | API to provide listener                             |\n| ------------------- | ------------------------------------------------------------ | --------------------------------------------------- |\n| Participant Added   | Emitted when a new participant is added to the conversation. | `conversation.addParticipantAddedListener()`        |\n| Participant Removed | Emitted when a participant is removed from the conversation. | `conversation.addParticipantDisconnectedListener()` |\n\nThe APIs to provide listeners returns a handlerId for that listener. This handleId can be used to remove the listener for that event.\n\n```ts\nconst participantAddedHandlerId = conversation.addParticipantAddedListener((participant) => {\n\tconsole.log(\"Participant Added:\", participant);\n\t// ... your code.\n});\n\n// To remove the listener\nconversation.removeParticipantAddedListener(participantAddedHandlerId);\n\n// Similarly for Participant Removed event\n\nconst participantDisconnectedHandlerId = conversation.addParticipantDisconnectedListener((participant) => {\n\tconsole.log(\"Participant Removed:\", participant);\n\t// ... your code.\n});\n\n// To remove the listener\nconversation.removeParticipantDisconnectedListener(participantDisconnectedHandlerId);\n```\n\n### User Activity\n\nThe SDK provides mechanism to automatically clear up the session if the User's session has not been active for the configured amount of time. The following sections explain what is considered as User Activity along with various timers and events that support this feature.\n\n#### Timeouts\n\nThe AXP Core provides two timeouts to manage the session inactivity:\n\nThe first timer is the idle timer which is started right after the session is created. Any activity from the User or Client (mentioned below) resets this timer. This timer expires when there are no activities for the configured duration. Once this timer expires the SDK will emit the Idle Timeout event and provide the configured grace period duration in the event's payload. The Client can show an appropriate message on the UI, warning the User about inactivity, by handling this event.\n\nThe second timer is idle shutdown grace timer which runs after the idle timer has expired. This timer provides additional grace period for User or the Client to extend the session. After this timer expires, the session is terminated automatically and the SDK will raise the shutdown event and shut itself down (see [shutdown](#shutting-down-the-sdk) section for more details). If the Client wants to continue it must be reinitialize the SDK to do so.\n\nBoth the timeout values can be configured during the initialization by providing their values in the init params object passed as the first argument to the `AxpOmniSdk.init()` method.\n\n```ts\nawait AxpOmniSdk.init({\n\t// Other init params\n\tidleTimeoutDuration: 5 * 60 * 1000, // in milliseconds\n\tidleShutdownGraceTimeoutDuration: 1 * 60 * 1000, // in milliseconds\n});\n```\n\nThe Idle Timeout event can be listened to by providing a listener for the same.\n\n```ts\nfunction warnUser(message) {\n\t// Show warning on UI.\n}\n\nconst handlerId = AxpOmniSdk.addIdleTimeOutInvokedListener((eventPayload) => {\n\twarnUser(\"You have been inactive for a while. Do you want to continue?\");\n});\n\n// It can be removed by calling the removeIdleTimeoutListener method.\nAxpOmniSdk.removeIdleTimeOutInvokedListener(handlerId);\n```\n\n#### Extending the session\n\nThe `AxpOmniSdk` provides a method called `resetIdleTimeout()` which can be used to reset the idle timer or the grace timer. This method can be called whenever there is any activity from the User or the Client.\n\nThis method also helps the Client to extend the session in scenarios where the Client is aware that the User is active based on events from its UI.\n\nApart from this method, calling a subset of other methods provided by the Additional Functionalities is also considered as User activities. The list of methods that are considered as User Activity are provided in the documentation of the respective Additional Functionality.\n\nThe `resetIdleTimeout()` method only impacts the timers as opposed to calling methods of Additional Functionalities which also perform the operation that the method is supposed to do.\n\n```js\nfunction showWarningBox(eventPayload) {\n\tconst continueChatButton = document.getElementById(\"inactivity-warning-continue-chat\");\n\n\tcontinueChatButton.onclick = () => {\n\t\tAxpOmniSdk.resetIdleTimeout();\n\t};\n\t// ...\n\tsetTimeout(hideWarningBox, eventPayload.gracePeriod);\n}\n\nfunction hideWarningBox() {\n\t// ...\n}\n```\n\n### Shutting down the SDK\n\nThe current user's session can be terminated by calling the `shutdown()` method of `AxpOmniSdk`. This will end the session and cleanup all the corresponding data within the SDK. **Irrespective of the success or failure of the termination operation, the SDK cleanup will be performed.**\n\nTo shut down the SDK, call the `shutdown()` method on the `AxpOmniSdk` class. The `shutdown()` method returns a `Promise` that resolves when the SDK has been successfully shut down.\n\n```typescript\nawait AxpOmniSdk.shutdown();\n```\n\n> **! Important**\n>\n> Once the SDK is shutdown the Conversation object(s) are also removed, hence the Client must re-initialize the SDK incase it wants to start again. However, this doesn't close the conversation of the User. Post re-initialization, the User can continue the conversation from where it was left.\n\nSimilar to the initialization process, the SDK emits a shutdown event after the SDK has been successfully shut down. The consumers can listen to these events by providing a listener function to SDK.\n\n```ts\nAxpOmniSdk.addSdkShutdownListener(() => {\n\tconsole.log(\"SDK Shutdown\");\n\t// ... your cleanup code.\n});\n```\n","readmeFilename":"README.md"}