@microsoft/omnichannel-chat-sdk 2.0.1 → 2.0.2-main.355218f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,6 +35,7 @@ Please make sure you have a chat widget configured before using this package or
35
35
  - [Send Messages](#send-messages)
36
36
  - [On New Message](#on-new-message)
37
37
  - [On Streaming Message](#on-streaming-message)
38
+ - [On Chat Token Renewed](#on-chat-token-renewed)
38
39
  - [On Typing Event](#on-typing-event)
39
40
  - [On Agent End Session](#on-agent-end-session)
40
41
  - [Send Typing Event](#send-typing-event)
@@ -113,10 +114,14 @@ For a detailed tracking of the releases, please refer to the [Changelog document
113
114
 
114
115
  _**Important Note:**_ Versions below 1.11.0 are no longer supported after November 1st, 2025. Please update to recent versions to ensure you have the latest features and bug fixes.
115
116
 
117
+ _**Known issue:**_ Versions earlier than 1.11.6 can start duplicate conversations when an application calls `startChat()` again before the previous call is complete. Upgrade to 1.11.8 or later. See [Concurrent `startChat()` calls in versions before 1.11.6](docs/KNOWN_ISSUE_CONCURRENT_STARTCHAT.md).
118
+
116
119
  | Version | Docs | Release Date | End of Support | Deprecated |
117
120
  | -- | -- | -- | -- | -- |
121
+ | 2.0.2 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v2.0.2) | Oct 20th 2026 | Oct 20th 2027 | |
118
122
  | 2.0.1 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v2.0.1) | Oct 1st 2026 | Oct 1st 2027 | |
119
123
  | 2.0.0 | [Migration Guide](docs/MIGRATION_2.0.md) / [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v2.0.0) | Aug 13th 2026 | Aug 13th 2027 | |
124
+ | 1.11.8 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.8) | Feb 2nd 2026 | Feb 2nd 2027 | |
120
125
  | 1.11.4 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.4) | Jul 17th 2025 | Jul 17th 2026 | |
121
126
  | 1.11.3 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.3) | Jul 14th 2025 | Jul 14th 2026 | |
122
127
  | 1.11.2 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.2) | Jun 24th 2025 | Jun 24th 2026 | |
@@ -512,6 +517,26 @@ await chatSDK.onStreamingMessage((message) => {
512
517
 
513
518
  Calling this method before `startChat()` throws `UninitializedConversation`. If the conversation does not use ACS, this method throws `UnsupportedLiveChatVersion`.
514
519
 
520
+ ### On Chat Token Renewed
521
+
522
+ Subscribes to notifications after the SDK renews the chat token and updates the current live chat context.
523
+ If your application caches this context for page refresh or reconnect, save the updated context in the callback
524
+ so subsequent restores use the renewed credentials.
525
+
526
+ Register before `startChat()` to capture renewals during startup, including when restoring a saved chat.
527
+
528
+ ```ts
529
+ const unsubscribe = chatSDK.onChatTokenRenewed(async () => {
530
+ const liveChatContext = await chatSDK.getCurrentLiveChatContext();
531
+ cache.saveChatContext(liveChatContext); // Custom logic to save chat context to cache
532
+ });
533
+
534
+ await chatSDK.startChat();
535
+ ```
536
+
537
+ The listener remains registered across chats on the same SDK instance; call `unsubscribe()` during cleanup.
538
+ Token renewal works without a subscription.
539
+
515
540
  ### On Typing Event
516
541
 
517
542
  It subscribes to an agent typing event.
@@ -57,6 +57,8 @@ declare class OmnichannelChatSDK {
57
57
  private coreServicesOrgUrl;
58
58
  private dynamicsLocationCode;
59
59
  private chatToken;
60
+ private chatTokenUnauthorizedRecovery;
61
+ private chatTokenRenewedListeners;
60
62
  private liveChatConfig;
61
63
  private widgetSnippetBaseUrl;
62
64
  private liveChatVersion;
@@ -77,6 +79,7 @@ declare class OmnichannelChatSDK {
77
79
  private isPersistentChat;
78
80
  private isChatReconnect;
79
81
  private reconnectId;
82
+ private endedChatSessionKey;
80
83
  private refreshTokenTimer;
81
84
  private AMSClientLoadCurrentState;
82
85
  private isMaskingDisabled;
@@ -155,6 +158,15 @@ declare class OmnichannelChatSDK {
155
158
  private waitForMessageTags;
156
159
  private waitForSurveyStart;
157
160
  private waitForConversationalSurveyEnd;
161
+ /**
162
+ * Subscribes to usable chat token renewals after the current SDK context has been updated.
163
+ * No token or other payload is passed. Read getCurrentLiveChatContext() to persist the updated context.
164
+ * Returns an idempotent unsubscribe function. Listener failures never affect renewal.
165
+ * Subscriptions belong to this SDK instance and survive endChat()/startChat().
166
+ * Subscribe before startChat() to observe restoration renewals; past notifications are not replayed.
167
+ * Unsubscribe on host teardown or before replacing a per-chat subscription.
168
+ */
169
+ onChatTokenRenewed(listener: () => void): () => void;
158
170
  getCurrentLiveChatContext(): Promise<GetCurrentLiveChatContextResponse>;
159
171
  getConversationDetails(optionalParams?: GetConversationDetailsOptionalParams): Promise<LiveWorkItemDetails>;
160
172
  /**
@@ -165,6 +177,31 @@ declare class OmnichannelChatSDK {
165
177
  getLiveChatConfig(optionalParams?: GetLiveChatConfigOptionalParams): Promise<ChatConfig>;
166
178
  getChatToken(cached?: boolean, optionalParams?: GetChatTokenOptionalParams): Promise<IChatToken>;
167
179
  setChatToken(chatToken: FetchChatTokenResponse): void;
180
+ /**
181
+ * Creates the ACS token refresher used to renew the chat token before it expires. Returns undefined, which keeps
182
+ * the existing behavior, unless renewal is enabled in the chat config, not disabled in the SDK config and
183
+ * supported by the installed OCSDK. The refresher never throws and falls back to the current token on failure.
184
+ */
185
+ private createChatTokenRefresher;
186
+ private notifyChatTokenRenewed;
187
+ /**
188
+ * Gives the renewed chat token to the attachment client, which keeps the token it was initialized with and uses
189
+ * it for every upload and download. Runs in the background and never throws: on failure, attachments keep using
190
+ * the previous token as they did before renewal existed.
191
+ */
192
+ private refreshAttachmentClientToken;
193
+ /**
194
+ * Creates the recovery for chat requests that fail with 401 while the chat token has not
195
+ * expired. Returns null, which keeps the existing behavior, unless chat token renewal is enabled and recovery is
196
+ * not disabled in the SDK config.
197
+ */
198
+ private createChatTokenUnauthorizedRecovery;
199
+ /**
200
+ * Returns the token of the authenticated user to renew the chat token with, refreshed from the auth token
201
+ * provider when possible because the token used to start the chat may have expired. Returns undefined for
202
+ * unauthenticated chats.
203
+ */
204
+ private getAuthenticatedUserTokenForChatTokenRenewal;
168
205
  getCallingToken(): Promise<string>;
169
206
  private recordMessages;
170
207
  getMessages(): Promise<GetMessagesResponse>;
@@ -208,6 +245,15 @@ declare class OmnichannelChatSDK {
208
245
  downloadFileAttachment(fileMetadata: FileMetadata | IFileMetadata): Promise<Blob>;
209
246
  emailLiveChatTranscript(body: ChatTranscriptBody, optionalParams?: EmailLiveChatTranscriptOptionaParams): Promise<void>;
210
247
  getLiveChatTranscript(optionalParams?: GetLiveChatTranscriptOptionalParams): Promise<GetLiveChatTranscriptResponse>;
248
+ /**
249
+ * Returns the ended chat's session key when the call targets that chat, or null.
250
+ */
251
+ private getEndedChatSessionKey;
252
+ /**
253
+ * Sends the session key on one OCSDK request without leaving it on the shared client. OCSDK copies the
254
+ * key into the request headers before its first await, so the previous key is restored before the HTTP wait.
255
+ */
256
+ private withRequestSessionKey;
211
257
  createChatAdapter(optionalParams?: ChatAdapterOptionalParams): Promise<ChatAdapter>;
212
258
  isVoiceVideoCallingEnabled(): boolean;
213
259
  getVoiceVideoCalling(voiceVideoCallingOptionalParams?: VoiceVideoCallingOptionalParams): Promise<GetVoiceVideoCallingResponse>;