From c44618b8306ee2ab78bade40afebd27d944d277d Mon Sep 17 00:00:00 2001 From: luc <44377201+LuChen-Microsoft@users.noreply.github.com> Date: Tue, 24 Aug 2021 18:32:49 -0700 Subject: [PATCH] Chat Core2 Migration (#17045) * migrate to core client * add tests recordings * revert rollup change * remove commented code * fix dependency * fix rush lint * format files * update swagger version * update sdk version * update pacakge version * update the constants path * revert recording files --- common/config/rush/pnpm-lock.yaml | 4 +- .../communication-chat/CHANGELOG.md | 8 +- .../communication-chat/package.json | 18 +- .../review/communication-chat.api.md | 16 +- .../communication-chat/src/chatClient.ts | 51 ++-- .../src/chatThreadClient.ts | 84 +++---- .../communication-chat/src/constants.ts | 4 - .../communicationTokenCredentialPolicy.ts | 18 +- .../src/generated/src/chatApiClient.ts | 7 +- .../src/generated/src/chatApiClientContext.ts | 38 +-- .../src/generated/src/index.ts | 1 + .../src/generated/src/models/index.ts | 199 +++++---------- .../src/generated/src/models/mappers.ts | 54 ++--- .../src/generated/src/models/parameters.ts | 2 +- .../src/generated/src/operations/chat.ts | 59 ++--- .../generated/src/operations/chatThread.ts | 226 +++++++----------- .../src/operationsInterfaces/chat.ts | 56 +++++ .../src/operationsInterfaces/chatThread.ts | 214 +++++++++++++++++ .../src/operationsInterfaces/index.ts | 10 + .../communication-chat/src/models/options.ts | 4 +- .../communication-chat/src/models/uuid.ts | 14 ++ .../communication-chat/swagger/README.md | 8 +- .../test/internal/chatClient.mocked.spec.ts | 2 +- .../internal/chatThreadClient.mocked.spec.ts | 12 +- .../test/internal/utils/mockClient.ts | 13 +- .../test/public/chatClient.spec.ts | 2 +- .../test/public/utils/connectionUtils.ts | 4 +- .../test/public/utils/recordedClient.ts | 33 +-- 28 files changed, 615 insertions(+), 546 deletions(-) delete mode 100644 sdk/communication/communication-chat/src/constants.ts create mode 100644 sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts create mode 100644 sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts create mode 100644 sdk/communication/communication-chat/src/generated/src/operationsInterfaces/index.ts create mode 100644 sdk/communication/communication-chat/src/models/uuid.ts diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 580820464d99..1731ee27a924 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -9064,6 +9064,7 @@ packages: '@types/mocha': 7.0.2 '@types/node': 12.20.20 '@types/sinon': 9.0.11 + '@types/uuid': 8.3.1 assert: 1.5.0 chai: 4.3.4 cross-env: 7.0.3 @@ -9099,13 +9100,14 @@ packages: typedoc: 0.15.2 typescript: 4.2.4 util: 0.12.4 + uuid: 8.3.2 dev: false id: file:projects/communication-chat.tgz name: '@rush-temp/communication-chat' peerDependencies: debug: '*' resolution: - integrity: sha512-J9pI+zoofrbGE5JN7f+ylcCtejg5cfDEU6YCkj+vA8SlDhmatprWeHy33GDEArTjc+09EK8ZUQVmXXz1DUcm/Q== + integrity: sha512-iK/tanehdcoDEh8n3iLnc33ancPWTq92R7tTT6KpXhhj/j/cw77w0GXJEjPo0NOAIxFn8lGLZYq0Grkrr8lg2g== tarball: file:projects/communication-chat.tgz version: 0.0.0 file:projects/communication-common.tgz_debug@4.3.2: diff --git a/sdk/communication/communication-chat/CHANGELOG.md b/sdk/communication/communication-chat/CHANGELOG.md index 7d0f948411cb..fd56e76baf9e 100644 --- a/sdk/communication/communication-chat/CHANGELOG.md +++ b/sdk/communication/communication-chat/CHANGELOG.md @@ -1,14 +1,10 @@ # Release History -## 1.1.0-beta.2 (Unreleased) - -### Features Added +## 1.1.0 (Unreleased) ### Breaking Changes -### Bugs Fixed - -### Other Changes +- Migrated from using `@azure/core-http` to `@azure/core-rest-pipeline` for the handling of HTTP requests. See [Azure Core v1 vs v2](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-rest-pipeline/documentation/core2.md) for more on the difference and benefits of the move. ## 1.1.0-beta.1 (2021-08-10) diff --git a/sdk/communication/communication-chat/package.json b/sdk/communication/communication-chat/package.json index 3e99517a6973..ea903b458d89 100644 --- a/sdk/communication/communication-chat/package.json +++ b/sdk/communication/communication-chat/package.json @@ -1,6 +1,6 @@ { "name": "@azure/communication-chat", - "version": "1.1.0-beta.2", + "version": "1.1.0", "description": "Azure client library for Azure Communication Chat services", "sdk-type": "client", "main": "dist/index.js", @@ -8,7 +8,7 @@ "types": "types/communication-chat.d.ts", "scripts": { "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", - "build:autorest": "autorest ./swagger/README.md --typescript --version=3.0.6267 --v3 && rushx format", + "build:autorest": "autorest ./swagger/README.md --typescript --v3 && rushx format", "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo Obsolete.", @@ -68,14 +68,17 @@ "@azure/communication-common": "^1.1.0", "@azure/communication-signaling": "1.0.0-beta.7", "@azure/core-auth": "^1.3.0", - "@azure/core-http": "^2.0.0", + "@azure/core-client": "^1.0.0", + "@azure/core-rest-pipeline": "^1.1.0", "@azure/core-tracing": "1.0.0-preview.13", "@azure/logger": "^1.0.0", "events": "^3.0.0", "tslib": "^2.2.0", - "@azure/core-paging": "^1.1.1" + "@azure/core-paging": "^1.1.1", + "uuid": "^8.3.0" }, "devDependencies": { + "@azure/core-util": "^1.0.0-beta.1", "@azure/communication-identity": "^1.0.0", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", @@ -90,6 +93,7 @@ "@types/mocha": "^7.0.2", "@types/node": "^12.0.0", "@types/sinon": "^9.0.4", + "@types/uuid": "^8.0.0", "assert": "^1.4.1", "chai": "^4.2.0", "cross-env": "^7.0.2", @@ -128,11 +132,7 @@ "constantPaths": [ { "path": "src/generated/src/chatApiClientContext.ts", - "prefix": "packageVersion" - }, - { - "path": "src/constants.ts", - "prefix": "SDK_VERSION" + "prefix": "packageDetails" }, { "path": "swagger/README.md", diff --git a/sdk/communication/communication-chat/review/communication-chat.api.md b/sdk/communication/communication-chat/review/communication-chat.api.md index 7c28cb354527..cc49698cabde 100644 --- a/sdk/communication/communication-chat/review/communication-chat.api.md +++ b/sdk/communication/communication-chat/review/communication-chat.api.md @@ -10,15 +10,15 @@ import { ChatMessageReceivedEvent } from '@azure/communication-signaling'; import { ChatThreadCreatedEvent } from '@azure/communication-signaling'; import { ChatThreadDeletedEvent } from '@azure/communication-signaling'; import { ChatThreadPropertiesUpdatedEvent } from '@azure/communication-signaling'; +import { CommonClientOptions } from '@azure/core-client'; import { CommunicationIdentifier } from '@azure/communication-common'; import { CommunicationIdentifierKind } from '@azure/communication-common'; import { CommunicationTokenCredential } from '@azure/communication-common'; -import * as coreHttp from '@azure/core-http'; -import { OperationOptions } from '@azure/core-http'; +import * as coreClient from '@azure/core-client'; +import { OperationOptions } from '@azure/core-client'; import { PagedAsyncIterableIterator } from '@azure/core-paging'; import { ParticipantsAddedEvent } from '@azure/communication-signaling'; import { ParticipantsRemovedEvent } from '@azure/communication-signaling'; -import { PipelineOptions } from '@azure/core-http'; import { ReadReceiptReceivedEvent } from '@azure/communication-signaling'; import { TypingIndicatorReceivedEvent } from '@azure/communication-signaling'; @@ -67,7 +67,7 @@ export class ChatClient { } // @public -export interface ChatClientOptions extends PipelineOptions { +export interface ChatClientOptions extends CommonClientOptions { } // @public @@ -209,25 +209,25 @@ export type ListReadReceiptsOptions = RestListReadReceiptsOptions; export type RemoveParticipantOptions = OperationOptions; // @public -export interface RestListChatThreadsOptions extends coreHttp.OperationOptions { +export interface RestListChatThreadsOptions extends coreClient.OperationOptions { maxPageSize?: number; startTime?: Date; } // @public -export interface RestListMessagesOptions extends coreHttp.OperationOptions { +export interface RestListMessagesOptions extends coreClient.OperationOptions { maxPageSize?: number; startTime?: Date; } // @public -export interface RestListParticipantsOptions extends coreHttp.OperationOptions { +export interface RestListParticipantsOptions extends coreClient.OperationOptions { maxPageSize?: number; skip?: number; } // @public -export interface RestListReadReceiptsOptions extends coreHttp.OperationOptions { +export interface RestListReadReceiptsOptions extends coreClient.OperationOptions { maxPageSize?: number; skip?: number; } diff --git a/sdk/communication/communication-chat/src/chatClient.ts b/sdk/communication/communication-chat/src/chatClient.ts index 0cf6c4e6eb69..93984cb4c3a5 100644 --- a/sdk/communication/communication-chat/src/chatClient.ts +++ b/sdk/communication/communication-chat/src/chatClient.ts @@ -4,7 +4,6 @@ import { logger } from "./models/logger"; import { EventEmitter } from "events"; -import { SDK_VERSION } from "./constants"; import { CommunicationTokenCredential } from "@azure/communication-common"; import { SignalingClient, @@ -21,13 +20,6 @@ import { ParticipantsRemovedEvent } from "@azure/communication-signaling"; import { getSignalingClient } from "./signaling/signalingClient"; -import { - InternalPipelineOptions, - createPipelineFromOptions, - operationOptionsToRequestOptionsBase, - generateUuid -} from "@azure/core-http"; -import "@azure/core-paging"; import { PagedAsyncIterableIterator } from "@azure/core-paging"; import { SpanStatusCode } from "@azure/core-tracing"; import { createSpan } from "./tracing"; @@ -44,9 +36,11 @@ import { mapToCreateChatThreadResultSdkModel } from "./models/mappers"; import { ChatThreadItem, CreateChatThreadResult, ListPageSettings } from "./models/models"; -import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy"; +import { InternalPipelineOptions } from "@azure/core-rest-pipeline"; import { ChatApiClient } from "./generated/src"; import { CreateChatThreadRequest } from "./models/requests"; +import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy"; +import { generateUuid } from "./models/uuid"; /** * The client to do chat operations @@ -54,7 +48,6 @@ import { CreateChatThreadRequest } from "./models/requests"; export class ChatClient { private readonly tokenCredential: CommunicationTokenCredential; private readonly clientOptions: ChatClientOptions; - // private readonly api: Chat; private readonly client: ChatApiClient; private readonly signalingClient: SignalingClient | undefined = undefined; private readonly emitter = new EventEmitter(); @@ -75,21 +68,8 @@ export class ChatClient { this.tokenCredential = credential; this.clientOptions = { ...options }; - const libInfo = `azsdk-js-communication-chat/${SDK_VERSION}`; - - if (!options.userAgentOptions) { - options.userAgentOptions = {}; - } - - const userAgentOptions = { ...options.userAgentOptions }; - if (options.userAgentOptions.userAgentPrefix) { - userAgentOptions.userAgentPrefix = `${options.userAgentOptions.userAgentPrefix} ${libInfo}`; - } else { - userAgentOptions.userAgentPrefix = libInfo; - } - const internalPipelineOptions: InternalPipelineOptions = { - ...{ ...options, userAgentOptions }, + ...options, ...{ loggingOptions: { logger: logger.info @@ -97,10 +77,13 @@ export class ChatClient { } }; - const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential); - const pipeline = createPipelineFromOptions(internalPipelineOptions, authPolicy); + this.client = new ChatApiClient(this.endpoint, { + endpoint: this.endpoint, + ...internalPipelineOptions + }); - this.client = new ChatApiClient(this.endpoint, pipeline); + const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential); + this.client.pipeline.addPolicy(authPolicy); this.signalingClient = getSignalingClient(credential, logger); } @@ -130,14 +113,14 @@ export class ChatClient { updatedOptions.idempotencyToken = updatedOptions.idempotencyToken ?? generateUuid(); const updatedRestModelOptions = mapToCreateChatThreadOptionsRestModel(updatedOptions); - const { _response, ...result } = await this.client.chat.createChatThread( + const result = await this.client.chat.createChatThread( { topic: request.topic, participants: options.participants?.map((participant) => mapToChatParticipantRestModel(participant) ) }, - operationOptionsToRequestOptionsBase(updatedRestModelOptions) + updatedRestModelOptions ); return mapToCreateChatThreadResultSdkModel(result); } catch (e) { @@ -155,9 +138,8 @@ export class ChatClient { continuationState: ListPageSettings, options: ListChatThreadsOptions = {} ): AsyncIterableIterator { - const requestOptions = operationOptionsToRequestOptionsBase(options); if (!continuationState.continuationToken) { - const currentSetResponse = await this.client.chat.listChatThreads(requestOptions); + const currentSetResponse = await this.client.chat.listChatThreads(options); continuationState.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { yield currentSetResponse.value; @@ -167,7 +149,7 @@ export class ChatClient { while (continuationState.continuationToken) { const currentSetResponse = await this.client.chat.listChatThreadsNext( continuationState.continuationToken, - requestOptions + options ); continuationState.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { @@ -230,10 +212,7 @@ export class ChatClient { const { span, updatedOptions } = createSpan("ChatClient-DeleteChatThread", options); try { - await this.client.chat.deleteChatThread( - threadId, - operationOptionsToRequestOptionsBase(updatedOptions) - ); + await this.client.chat.deleteChatThread(threadId, updatedOptions); } catch (e) { span.setStatus({ code: SpanStatusCode.ERROR, diff --git a/sdk/communication/communication-chat/src/chatThreadClient.ts b/sdk/communication/communication-chat/src/chatThreadClient.ts index cb9876351261..d5715a872814 100644 --- a/sdk/communication/communication-chat/src/chatThreadClient.ts +++ b/sdk/communication/communication-chat/src/chatThreadClient.ts @@ -2,17 +2,11 @@ // Licensed under the MIT license. import { logger } from "./models/logger"; -import { SDK_VERSION } from "./constants"; import { CommunicationIdentifier, CommunicationTokenCredential, serializeCommunicationIdentifier } from "@azure/communication-common"; -import { - InternalPipelineOptions, - createPipelineFromOptions, - operationOptionsToRequestOptionsBase -} from "@azure/core-http"; import { PagedAsyncIterableIterator } from "@azure/core-paging"; import { SpanStatusCode } from "@azure/core-tracing"; import { createSpan } from "./tracing"; @@ -56,6 +50,7 @@ import { } from "./models/options"; import { ChatApiClient } from "./generated/src"; import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy"; +import { InternalPipelineOptions } from "@azure/core-rest-pipeline"; const minimumTypingIntervalInMilliSeconds: number = 8000; /** @@ -81,21 +76,8 @@ export class ChatThreadClient { this.threadId = threadId; this.tokenCredential = credential; - const libInfo = `azsdk-js-communication-chat/${SDK_VERSION}`; - - if (!options.userAgentOptions) { - options.userAgentOptions = {}; - } - - const userAgentOptions = { ...options.userAgentOptions }; - if (options.userAgentOptions.userAgentPrefix) { - userAgentOptions.userAgentPrefix = `${options.userAgentOptions.userAgentPrefix} ${libInfo}`; - } else { - userAgentOptions.userAgentPrefix = libInfo; - } - const internalPipelineOptions: InternalPipelineOptions = { - ...{ ...options, userAgentOptions }, + ...options, ...{ loggingOptions: { logger: logger.info @@ -103,10 +85,13 @@ export class ChatThreadClient { } }; - const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential); - const pipeline = createPipelineFromOptions(internalPipelineOptions, authPolicy); + this.client = new ChatApiClient(this.endpoint, { + endpoint: this.endpoint, + ...internalPipelineOptions + }); - this.client = new ChatApiClient(this.endpoint, pipeline); + const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential); + this.client.pipeline.addPolicy(authPolicy); } /** @@ -118,9 +103,9 @@ export class ChatThreadClient { const { span, updatedOptions } = createSpan("ChatClient-GetProperties", options); try { - const { _response, ...result } = await this.client.chatThread.getChatThreadProperties( + const result = await this.client.chatThread.getChatThreadProperties( this.threadId, - operationOptionsToRequestOptionsBase(updatedOptions) + updatedOptions ); return mapToChatThreadPropertiesSdkModel(result); } catch (e) { @@ -146,7 +131,7 @@ export class ChatThreadClient { await this.client.chatThread.updateChatThreadProperties( this.threadId, { topic: topic }, - operationOptionsToRequestOptionsBase(updatedOptions) + updatedOptions ); } catch (e) { span.setStatus({ @@ -175,10 +160,10 @@ export class ChatThreadClient { // reset typing notification clock this.timeOfLastTypingRequest = undefined; - const { _response, ...result } = await this.client.chatThread.sendChatMessage( + const result = await this.client.chatThread.sendChatMessage( this.threadId, { ...request, ...options }, - operationOptionsToRequestOptionsBase(updatedOptions) + updatedOptions ); return result; } catch (e) { @@ -205,10 +190,10 @@ export class ChatThreadClient { const { span, updatedOptions } = createSpan("ChatThreadClient-GetMessage", options); try { - const { _response, ...result } = await this.client.chatThread.getChatMessage( + const result = await this.client.chatThread.getChatMessage( this.threadId, messageId, - operationOptionsToRequestOptionsBase(updatedOptions) + updatedOptions ); return mapToChatMessageSdkModel(result); } catch (e) { @@ -226,11 +211,10 @@ export class ChatThreadClient { pageSettings: ListPageSettings, options: ListMessagesOptions = {} ): AsyncIterableIterator { - const requestOptions = operationOptionsToRequestOptionsBase(options); if (!pageSettings.continuationToken) { const currentSetResponse = await this.client.chatThread.listChatMessages( this.threadId, - requestOptions + options ); pageSettings.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { @@ -242,7 +226,7 @@ export class ChatThreadClient { const currentSetResponse = await this.client.chatThread.listChatMessagesNext( this.threadId, pageSettings.continuationToken, - requestOptions + options ); pageSettings.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { @@ -300,11 +284,7 @@ export class ChatThreadClient { const { span, updatedOptions } = createSpan("ChatThreadClient-DeleteMessage", options); try { - await this.client.chatThread.deleteChatMessage( - this.threadId, - messageId, - operationOptionsToRequestOptionsBase(updatedOptions) - ); + await this.client.chatThread.deleteChatMessage(this.threadId, messageId, updatedOptions); } catch (e) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -329,7 +309,7 @@ export class ChatThreadClient { this.threadId, messageId, options, - operationOptionsToRequestOptionsBase(updatedOptions) + updatedOptions ); } catch (e) { span.setStatus({ @@ -354,10 +334,10 @@ export class ChatThreadClient { const { span, updatedOptions } = createSpan("ChatThreadClient-AddParticipants", options); try { - const { _response, ...result } = await this.client.chatThread.addChatParticipants( + const result = await this.client.chatThread.addChatParticipants( this.threadId, mapToAddChatParticipantsRequestRestModel(request), - operationOptionsToRequestOptionsBase(updatedOptions) + updatedOptions ); return result; } catch (e) { @@ -375,11 +355,10 @@ export class ChatThreadClient { continuationState: ListPageSettings, options: ListParticipantsOptions = {} ): AsyncIterableIterator { - const requestOptions = operationOptionsToRequestOptionsBase(options); if (!continuationState.continuationToken) { const currentSetResponse = await this.client.chatThread.listChatParticipants( this.threadId, - requestOptions + options ); continuationState.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { @@ -391,7 +370,7 @@ export class ChatThreadClient { const currentSetResponse = await this.client.chatThread.listChatParticipantsNext( this.threadId, continuationState.continuationToken, - requestOptions + options ); continuationState.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { @@ -459,7 +438,7 @@ export class ChatThreadClient { await this.client.chatThread.removeChatParticipant( this.threadId, serializeCommunicationIdentifier(participant), - operationOptionsToRequestOptionsBase(updatedOptions) + updatedOptions ); } catch (e) { span.setStatus({ @@ -485,9 +464,7 @@ export class ChatThreadClient { try { const dateNow = new Date(); - const { senderDisplayName, ...restOptions } = operationOptionsToRequestOptionsBase( - updatedOptions - ); + const { senderDisplayName, ...restOptions } = updatedOptions; if (this.canPostTypingNotification(dateNow)) { await this.client.chatThread.sendTypingNotification(this.threadId, { sendTypingNotificationRequest: { senderDisplayName: senderDisplayName }, @@ -524,11 +501,7 @@ export class ChatThreadClient { const { span, updatedOptions } = createSpan("ChatThreadClient-SendReadReceipt", options); try { - await this.client.chatThread.sendChatReadReceipt( - this.threadId, - request, - operationOptionsToRequestOptionsBase(updatedOptions) - ); + await this.client.chatThread.sendChatReadReceipt(this.threadId, request, updatedOptions); } catch (e) { span.setStatus({ code: SpanStatusCode.ERROR, @@ -544,11 +517,10 @@ export class ChatThreadClient { continuationState: ListPageSettings, options: ListReadReceiptsOptions = {} ): AsyncIterableIterator { - const requestOptions = operationOptionsToRequestOptionsBase(options); if (!continuationState.continuationToken) { const currentSetResponse = await this.client.chatThread.listChatReadReceipts( this.threadId, - requestOptions + options ); continuationState.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { @@ -560,7 +532,7 @@ export class ChatThreadClient { const currentSetResponse = await this.client.chatThread.listChatReadReceiptsNext( this.threadId, continuationState.continuationToken, - requestOptions + options ); continuationState.continuationToken = currentSetResponse.nextLink; if (currentSetResponse.value) { diff --git a/sdk/communication/communication-chat/src/constants.ts b/sdk/communication/communication-chat/src/constants.ts deleted file mode 100644 index b16463d7a868..000000000000 --- a/sdk/communication/communication-chat/src/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -export const SDK_VERSION: string = "1.1.0-beta.2"; diff --git a/sdk/communication/communication-chat/src/credential/communicationTokenCredentialPolicy.ts b/sdk/communication/communication-chat/src/credential/communicationTokenCredentialPolicy.ts index de393fb17205..92636cf9b1b6 100644 --- a/sdk/communication/communication-chat/src/credential/communicationTokenCredentialPolicy.ts +++ b/sdk/communication/communication-chat/src/credential/communicationTokenCredentialPolicy.ts @@ -2,7 +2,11 @@ // Licensed under the MIT license. import { CommunicationTokenCredential } from "@azure/communication-common"; -import { RequestPolicyFactory, bearerTokenAuthenticationPolicy } from "@azure/core-http"; +import { + bearerTokenAuthenticationPolicy, + BearerTokenAuthenticationPolicyOptions, + PipelinePolicy +} from "@azure/core-rest-pipeline"; /** * Creates a new CommunicationTokenCredentialPolicy factory. @@ -11,11 +15,13 @@ import { RequestPolicyFactory, bearerTokenAuthenticationPolicy } from "@azure/co */ export const createCommunicationTokenCredentialPolicy = ( credential: CommunicationTokenCredential -): RequestPolicyFactory => { - return bearerTokenAuthenticationPolicy( - { +): PipelinePolicy => { + const policyOptions: BearerTokenAuthenticationPolicyOptions = { + credential: { getToken: (_scopes, options) => credential.getToken({ abortSignal: options?.abortSignal }) }, - [] - ); + scopes: [] + }; + + return bearerTokenAuthenticationPolicy(policyOptions); }; diff --git a/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts b/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts index 9763e0db47b1..0d7c9e93a07a 100644 --- a/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts +++ b/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts @@ -6,7 +6,8 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { ChatThread, Chat } from "./operations"; +import { ChatThreadImpl, ChatImpl } from "./operations"; +import { ChatThread, Chat } from "./operationsInterfaces"; import { ChatApiClientContext } from "./chatApiClientContext"; import { ChatApiClientOptionalParams } from "./models"; @@ -18,8 +19,8 @@ export class ChatApiClient extends ChatApiClientContext { */ constructor(endpoint: string, options?: ChatApiClientOptionalParams) { super(endpoint, options); - this.chatThread = new ChatThread(this); - this.chat = new Chat(this); + this.chatThread = new ChatThreadImpl(this); + this.chat = new ChatImpl(this); } chatThread: ChatThread; diff --git a/sdk/communication/communication-chat/src/generated/src/chatApiClientContext.ts b/sdk/communication/communication-chat/src/generated/src/chatApiClientContext.ts index 94f9dd6e92ec..bc2ed3743349 100644 --- a/sdk/communication/communication-chat/src/generated/src/chatApiClientContext.ts +++ b/sdk/communication/communication-chat/src/generated/src/chatApiClientContext.ts @@ -6,13 +6,10 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; import { ChatApiClientOptionalParams } from "./models"; -const packageName = "azure-communication-chat"; -const packageVersion = "1.1.0-beta.2"; - -export class ChatApiClientContext extends coreHttp.ServiceClient { +export class ChatApiClientContext extends coreClient.ServiceClient { endpoint: string; apiVersion: string; @@ -30,18 +27,25 @@ export class ChatApiClientContext extends coreHttp.ServiceClient { if (!options) { options = {}; } - - if (!options.userAgent) { - const defaultUserAgent = coreHttp.getDefaultUserAgentValue(); - options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`; - } - - super(undefined, options); - - this.requestContentType = "application/json; charset=utf-8"; - - this.baseUri = options.endpoint || "{endpoint}"; - + const defaults: ChatApiClientOptionalParams = { + requestContentType: "application/json; charset=utf-8" + }; + + const packageDetails = `azsdk-js-azure-communication-chat/1.1.0`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` + : `${packageDetails}`; + + const optionsWithDefaults = { + ...defaults, + ...options, + userAgentOptions: { + userAgentPrefix + }, + baseUri: options.endpoint || "{endpoint}" + }; + super(optionsWithDefaults); // Parameter assignments this.endpoint = endpoint; diff --git a/sdk/communication/communication-chat/src/generated/src/index.ts b/sdk/communication/communication-chat/src/generated/src/index.ts index 89e0cfaf6b86..4d7079f3241d 100644 --- a/sdk/communication/communication-chat/src/generated/src/index.ts +++ b/sdk/communication/communication-chat/src/generated/src/index.ts @@ -9,3 +9,4 @@ export * from "./models"; export { ChatApiClient } from "./chatApiClient"; export { ChatApiClientContext } from "./chatApiClientContext"; +export * from "./operationsInterfaces"; diff --git a/sdk/communication/communication-chat/src/generated/src/models/index.ts b/sdk/communication/communication-chat/src/generated/src/models/index.ts index dd22c5a1d444..5bbfa164a154 100644 --- a/sdk/communication/communication-chat/src/generated/src/models/index.ts +++ b/sdk/communication/communication-chat/src/generated/src/models/index.ts @@ -6,7 +6,7 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; /** A paged collection of chat message read receipts. */ export interface ChatMessageReadReceiptsCollection { @@ -281,7 +281,7 @@ export interface SendTypingNotificationRequest { } /** Known values of {@link CommunicationCloudEnvironmentModel} that the service accepts. */ -export const enum KnownCommunicationCloudEnvironmentModel { +export enum KnownCommunicationCloudEnvironmentModel { Public = "public", Dod = "dod", Gcch = "gcch" @@ -291,7 +291,7 @@ export const enum KnownCommunicationCloudEnvironmentModel { * Defines values for CommunicationCloudEnvironmentModel. \ * {@link KnownCommunicationCloudEnvironmentModel} can be used interchangeably with CommunicationCloudEnvironmentModel, * this enum contains the known values that the service supports. - * ### Know values supported by the service + * ### Known values supported by the service * **public** \ * **dod** \ * **gcch** @@ -307,7 +307,7 @@ export type ChatMessageType = /** Optional parameters. */ export interface ChatThreadListChatReadReceiptsOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of chat message read receipts to be returned per page. */ maxPageSize?: number; /** Skips chat message read receipts up to a specified position in response. */ @@ -315,32 +315,22 @@ export interface ChatThreadListChatReadReceiptsOptionalParams } /** Contains response data for the listChatReadReceipts operation. */ -export type ChatThreadListChatReadReceiptsResponse = ChatMessageReadReceiptsCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +export type ChatThreadListChatReadReceiptsResponse = ChatMessageReadReceiptsCollection; - /** The response body as parsed JSON or XML */ - parsedBody: ChatMessageReadReceiptsCollection; - }; -}; +/** Optional parameters. */ +export interface ChatThreadSendChatReadReceiptOptionalParams + extends coreClient.OperationOptions {} -/** Contains response data for the sendChatMessage operation. */ -export type ChatThreadSendChatMessageResponse = SendChatMessageResult & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +/** Optional parameters. */ +export interface ChatThreadSendChatMessageOptionalParams + extends coreClient.OperationOptions {} - /** The response body as parsed JSON or XML */ - parsedBody: SendChatMessageResult; - }; -}; +/** Contains response data for the sendChatMessage operation. */ +export type ChatThreadSendChatMessageResponse = SendChatMessageResult; /** Optional parameters. */ export interface ChatThreadListChatMessagesOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of messages to be returned per page. */ maxPageSize?: number; /** The earliest point in time to get messages up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ @@ -348,32 +338,26 @@ export interface ChatThreadListChatMessagesOptionalParams } /** Contains response data for the listChatMessages operation. */ -export type ChatThreadListChatMessagesResponse = ChatMessagesCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +export type ChatThreadListChatMessagesResponse = ChatMessagesCollection; - /** The response body as parsed JSON or XML */ - parsedBody: ChatMessagesCollection; - }; -}; +/** Optional parameters. */ +export interface ChatThreadGetChatMessageOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the getChatMessage operation. */ -export type ChatThreadGetChatMessageResponse = ChatMessage & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +export type ChatThreadGetChatMessageResponse = ChatMessage; - /** The response body as parsed JSON or XML */ - parsedBody: ChatMessage; - }; -}; +/** Optional parameters. */ +export interface ChatThreadUpdateChatMessageOptionalParams + extends coreClient.OperationOptions {} + +/** Optional parameters. */ +export interface ChatThreadDeleteChatMessageOptionalParams + extends coreClient.OperationOptions {} /** Optional parameters. */ export interface ChatThreadListChatParticipantsOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of participants to be returned per page. */ maxPageSize?: number; /** Skips participants up to a specified position in response. */ @@ -381,51 +365,40 @@ export interface ChatThreadListChatParticipantsOptionalParams } /** Contains response data for the listChatParticipants operation. */ -export type ChatThreadListChatParticipantsResponse = ChatParticipantsCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +export type ChatThreadListChatParticipantsResponse = ChatParticipantsCollection; - /** The response body as parsed JSON or XML */ - parsedBody: ChatParticipantsCollection; - }; -}; +/** Optional parameters. */ +export interface ChatThreadRemoveChatParticipantOptionalParams + extends coreClient.OperationOptions {} + +/** Optional parameters. */ +export interface ChatThreadAddChatParticipantsOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the addChatParticipants operation. */ -export type ChatThreadAddChatParticipantsResponse = AddChatParticipantsResult & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +export type ChatThreadAddChatParticipantsResponse = AddChatParticipantsResult; - /** The response body as parsed JSON or XML */ - parsedBody: AddChatParticipantsResult; - }; -}; +/** Optional parameters. */ +export interface ChatThreadUpdateChatThreadPropertiesOptionalParams + extends coreClient.OperationOptions {} -/** Contains response data for the getChatThreadProperties operation. */ -export type ChatThreadGetChatThreadPropertiesResponse = ChatThreadProperties & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +/** Optional parameters. */ +export interface ChatThreadGetChatThreadPropertiesOptionalParams + extends coreClient.OperationOptions {} - /** The response body as parsed JSON or XML */ - parsedBody: ChatThreadProperties; - }; -}; +/** Contains response data for the getChatThreadProperties operation. */ +export type ChatThreadGetChatThreadPropertiesResponse = ChatThreadProperties; /** Optional parameters. */ export interface ChatThreadSendTypingNotificationOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** Details of the typing notification request. */ sendTypingNotificationRequest?: SendTypingNotificationRequest; } /** Optional parameters. */ export interface ChatThreadListChatReadReceiptsNextOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of chat message read receipts to be returned per page. */ maxPageSize?: number; /** Skips chat message read receipts up to a specified position in response. */ @@ -433,20 +406,11 @@ export interface ChatThreadListChatReadReceiptsNextOptionalParams } /** Contains response data for the listChatReadReceiptsNext operation. */ -export type ChatThreadListChatReadReceiptsNextResponse = ChatMessageReadReceiptsCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: ChatMessageReadReceiptsCollection; - }; -}; +export type ChatThreadListChatReadReceiptsNextResponse = ChatMessageReadReceiptsCollection; /** Optional parameters. */ export interface ChatThreadListChatMessagesNextOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of messages to be returned per page. */ maxPageSize?: number; /** The earliest point in time to get messages up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ @@ -454,20 +418,11 @@ export interface ChatThreadListChatMessagesNextOptionalParams } /** Contains response data for the listChatMessagesNext operation. */ -export type ChatThreadListChatMessagesNextResponse = ChatMessagesCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: ChatMessagesCollection; - }; -}; +export type ChatThreadListChatMessagesNextResponse = ChatMessagesCollection; /** Optional parameters. */ export interface ChatThreadListChatParticipantsNextOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of participants to be returned per page. */ maxPageSize?: number; /** Skips participants up to a specified position in response. */ @@ -475,39 +430,21 @@ export interface ChatThreadListChatParticipantsNextOptionalParams } /** Contains response data for the listChatParticipantsNext operation. */ -export type ChatThreadListChatParticipantsNextResponse = ChatParticipantsCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: ChatParticipantsCollection; - }; -}; +export type ChatThreadListChatParticipantsNextResponse = ChatParticipantsCollection; /** Optional parameters. */ export interface ChatCreateChatThreadOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** If specified, the client directs that the request is repeatable; that is, that the client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an opaque string representing a client-generated, globally unique for all time, identifier for the request. It is recommended to use version 4 (random) UUIDs. */ repeatabilityRequestId?: string; } /** Contains response data for the createChatThread operation. */ -export type ChatCreateChatThreadResponse = CreateChatThreadResult & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: CreateChatThreadResult; - }; -}; +export type ChatCreateChatThreadResponse = CreateChatThreadResult; /** Optional parameters. */ export interface ChatListChatThreadsOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of chat threads returned per page. */ maxPageSize?: number; /** The earliest point in time to get chat threads up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ @@ -515,20 +452,15 @@ export interface ChatListChatThreadsOptionalParams } /** Contains response data for the listChatThreads operation. */ -export type ChatListChatThreadsResponse = ChatThreadsItemCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; +export type ChatListChatThreadsResponse = ChatThreadsItemCollection; - /** The response body as parsed JSON or XML */ - parsedBody: ChatThreadsItemCollection; - }; -}; +/** Optional parameters. */ +export interface ChatDeleteChatThreadOptionalParams + extends coreClient.OperationOptions {} /** Optional parameters. */ export interface ChatListChatThreadsNextOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The maximum number of chat threads returned per page. */ maxPageSize?: number; /** The earliest point in time to get chat threads up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ @@ -536,20 +468,11 @@ export interface ChatListChatThreadsNextOptionalParams } /** Contains response data for the listChatThreadsNext operation. */ -export type ChatListChatThreadsNextResponse = ChatThreadsItemCollection & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: ChatThreadsItemCollection; - }; -}; +export type ChatListChatThreadsNextResponse = ChatThreadsItemCollection; /** Optional parameters. */ export interface ChatApiClientOptionalParams - extends coreHttp.ServiceClientOptions { + extends coreClient.ServiceClientOptions { /** Api Version */ apiVersion?: string; /** Overrides client endpoint. */ diff --git a/sdk/communication/communication-chat/src/generated/src/models/mappers.ts b/sdk/communication/communication-chat/src/generated/src/models/mappers.ts index bea3dcbc6a78..be9ab8bfdec5 100644 --- a/sdk/communication/communication-chat/src/generated/src/models/mappers.ts +++ b/sdk/communication/communication-chat/src/generated/src/models/mappers.ts @@ -6,9 +6,9 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; -export const ChatMessageReadReceiptsCollection: coreHttp.CompositeMapper = { +export const ChatMessageReadReceiptsCollection: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatMessageReadReceiptsCollection", @@ -37,7 +37,7 @@ export const ChatMessageReadReceiptsCollection: coreHttp.CompositeMapper = { } }; -export const ChatMessageReadReceipt: coreHttp.CompositeMapper = { +export const ChatMessageReadReceipt: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatMessageReadReceipt", @@ -67,7 +67,7 @@ export const ChatMessageReadReceipt: coreHttp.CompositeMapper = { } }; -export const CommunicationIdentifierModel: coreHttp.CompositeMapper = { +export const CommunicationIdentifierModel: coreClient.CompositeMapper = { type: { name: "Composite", className: "CommunicationIdentifierModel", @@ -103,7 +103,7 @@ export const CommunicationIdentifierModel: coreHttp.CompositeMapper = { } }; -export const CommunicationUserIdentifierModel: coreHttp.CompositeMapper = { +export const CommunicationUserIdentifierModel: coreClient.CompositeMapper = { type: { name: "Composite", className: "CommunicationUserIdentifierModel", @@ -119,7 +119,7 @@ export const CommunicationUserIdentifierModel: coreHttp.CompositeMapper = { } }; -export const PhoneNumberIdentifierModel: coreHttp.CompositeMapper = { +export const PhoneNumberIdentifierModel: coreClient.CompositeMapper = { type: { name: "Composite", className: "PhoneNumberIdentifierModel", @@ -135,7 +135,7 @@ export const PhoneNumberIdentifierModel: coreHttp.CompositeMapper = { } }; -export const MicrosoftTeamsUserIdentifierModel: coreHttp.CompositeMapper = { +export const MicrosoftTeamsUserIdentifierModel: coreClient.CompositeMapper = { type: { name: "Composite", className: "MicrosoftTeamsUserIdentifierModel", @@ -163,7 +163,7 @@ export const MicrosoftTeamsUserIdentifierModel: coreHttp.CompositeMapper = { } }; -export const CommunicationErrorResponse: coreHttp.CompositeMapper = { +export const CommunicationErrorResponse: coreClient.CompositeMapper = { type: { name: "Composite", className: "CommunicationErrorResponse", @@ -179,7 +179,7 @@ export const CommunicationErrorResponse: coreHttp.CompositeMapper = { } }; -export const ChatError: coreHttp.CompositeMapper = { +export const ChatError: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatError", @@ -229,7 +229,7 @@ export const ChatError: coreHttp.CompositeMapper = { } }; -export const SendReadReceiptRequest: coreHttp.CompositeMapper = { +export const SendReadReceiptRequest: coreClient.CompositeMapper = { type: { name: "Composite", className: "SendReadReceiptRequest", @@ -245,7 +245,7 @@ export const SendReadReceiptRequest: coreHttp.CompositeMapper = { } }; -export const SendChatMessageRequest: coreHttp.CompositeMapper = { +export const SendChatMessageRequest: coreClient.CompositeMapper = { type: { name: "Composite", className: "SendChatMessageRequest", @@ -287,7 +287,7 @@ export const SendChatMessageRequest: coreHttp.CompositeMapper = { } }; -export const SendChatMessageResult: coreHttp.CompositeMapper = { +export const SendChatMessageResult: coreClient.CompositeMapper = { type: { name: "Composite", className: "SendChatMessageResult", @@ -303,7 +303,7 @@ export const SendChatMessageResult: coreHttp.CompositeMapper = { } }; -export const ChatMessagesCollection: coreHttp.CompositeMapper = { +export const ChatMessagesCollection: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatMessagesCollection", @@ -332,7 +332,7 @@ export const ChatMessagesCollection: coreHttp.CompositeMapper = { } }; -export const ChatMessage: coreHttp.CompositeMapper = { +export const ChatMessage: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatMessage", @@ -422,7 +422,7 @@ export const ChatMessage: coreHttp.CompositeMapper = { } }; -export const ChatMessageContent: coreHttp.CompositeMapper = { +export const ChatMessageContent: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatMessageContent", @@ -462,7 +462,7 @@ export const ChatMessageContent: coreHttp.CompositeMapper = { } }; -export const ChatParticipant: coreHttp.CompositeMapper = { +export const ChatParticipant: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatParticipant", @@ -490,7 +490,7 @@ export const ChatParticipant: coreHttp.CompositeMapper = { } }; -export const UpdateChatMessageRequest: coreHttp.CompositeMapper = { +export const UpdateChatMessageRequest: coreClient.CompositeMapper = { type: { name: "Composite", className: "UpdateChatMessageRequest", @@ -512,7 +512,7 @@ export const UpdateChatMessageRequest: coreHttp.CompositeMapper = { } }; -export const ChatParticipantsCollection: coreHttp.CompositeMapper = { +export const ChatParticipantsCollection: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatParticipantsCollection", @@ -541,7 +541,7 @@ export const ChatParticipantsCollection: coreHttp.CompositeMapper = { } }; -export const AddChatParticipantsRequest: coreHttp.CompositeMapper = { +export const AddChatParticipantsRequest: coreClient.CompositeMapper = { type: { name: "Composite", className: "AddChatParticipantsRequest", @@ -563,7 +563,7 @@ export const AddChatParticipantsRequest: coreHttp.CompositeMapper = { } }; -export const AddChatParticipantsResult: coreHttp.CompositeMapper = { +export const AddChatParticipantsResult: coreClient.CompositeMapper = { type: { name: "Composite", className: "AddChatParticipantsResult", @@ -585,7 +585,7 @@ export const AddChatParticipantsResult: coreHttp.CompositeMapper = { } }; -export const CreateChatThreadRequest: coreHttp.CompositeMapper = { +export const CreateChatThreadRequest: coreClient.CompositeMapper = { type: { name: "Composite", className: "CreateChatThreadRequest", @@ -613,7 +613,7 @@ export const CreateChatThreadRequest: coreHttp.CompositeMapper = { } }; -export const CreateChatThreadResult: coreHttp.CompositeMapper = { +export const CreateChatThreadResult: coreClient.CompositeMapper = { type: { name: "Composite", className: "CreateChatThreadResult", @@ -642,7 +642,7 @@ export const CreateChatThreadResult: coreHttp.CompositeMapper = { } }; -export const ChatThreadProperties: coreHttp.CompositeMapper = { +export const ChatThreadProperties: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatThreadProperties", @@ -685,7 +685,7 @@ export const ChatThreadProperties: coreHttp.CompositeMapper = { } }; -export const ChatThreadsItemCollection: coreHttp.CompositeMapper = { +export const ChatThreadsItemCollection: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatThreadsItemCollection", @@ -714,7 +714,7 @@ export const ChatThreadsItemCollection: coreHttp.CompositeMapper = { } }; -export const ChatThreadItem: coreHttp.CompositeMapper = { +export const ChatThreadItem: coreClient.CompositeMapper = { type: { name: "Composite", className: "ChatThreadItem", @@ -750,7 +750,7 @@ export const ChatThreadItem: coreHttp.CompositeMapper = { } }; -export const UpdateChatThreadRequest: coreHttp.CompositeMapper = { +export const UpdateChatThreadRequest: coreClient.CompositeMapper = { type: { name: "Composite", className: "UpdateChatThreadRequest", @@ -765,7 +765,7 @@ export const UpdateChatThreadRequest: coreHttp.CompositeMapper = { } }; -export const SendTypingNotificationRequest: coreHttp.CompositeMapper = { +export const SendTypingNotificationRequest: coreClient.CompositeMapper = { type: { name: "Composite", className: "SendTypingNotificationRequest", diff --git a/sdk/communication/communication-chat/src/generated/src/models/parameters.ts b/sdk/communication/communication-chat/src/generated/src/models/parameters.ts index da8ebf7e70ee..428f7764d88e 100644 --- a/sdk/communication/communication-chat/src/generated/src/models/parameters.ts +++ b/sdk/communication/communication-chat/src/generated/src/models/parameters.ts @@ -10,7 +10,7 @@ import { OperationParameter, OperationURLParameter, OperationQueryParameter -} from "@azure/core-http"; +} from "@azure/core-client"; import { SendReadReceiptRequest as SendReadReceiptRequestMapper, SendChatMessageRequest as SendChatMessageRequestMapper, diff --git a/sdk/communication/communication-chat/src/generated/src/operations/chat.ts b/sdk/communication/communication-chat/src/generated/src/operations/chat.ts index eca8a071ce3e..bc012ce80f74 100644 --- a/sdk/communication/communication-chat/src/generated/src/operations/chat.ts +++ b/sdk/communication/communication-chat/src/generated/src/operations/chat.ts @@ -6,29 +6,31 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import { Chat } from "../operationsInterfaces"; +import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; -import { ChatApiClient } from "../chatApiClient"; +import { ChatApiClientContext } from "../chatApiClientContext"; import { CreateChatThreadRequest, ChatCreateChatThreadOptionalParams, ChatCreateChatThreadResponse, ChatListChatThreadsOptionalParams, ChatListChatThreadsResponse, + ChatDeleteChatThreadOptionalParams, ChatListChatThreadsNextOptionalParams, ChatListChatThreadsNextResponse } from "../models"; -/** Class representing a Chat. */ -export class Chat { - private readonly client: ChatApiClient; +/** Class containing Chat operations. */ +export class ChatImpl implements Chat { + private readonly client: ChatApiClientContext; /** * Initialize a new instance of the class Chat class. * @param client Reference to the service client */ - constructor(client: ChatApiClient) { + constructor(client: ChatApiClientContext) { this.client = client; } @@ -41,14 +43,10 @@ export class Chat { createChatThreadRequest: CreateChatThreadRequest, options?: ChatCreateChatThreadOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - createChatThreadRequest, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { createChatThreadRequest, options }, createChatThreadOperationSpec - ) as Promise; + ); } /** @@ -58,13 +56,10 @@ export class Chat { listChatThreads( options?: ChatListChatThreadsOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { options }, listChatThreadsOperationSpec - ) as Promise; + ); } /** @@ -74,16 +69,12 @@ export class Chat { */ deleteChatThread( chatThreadId: string, - options?: coreHttp.OperationOptions - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + options?: ChatDeleteChatThreadOptionalParams + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, options }, deleteChatThreadOperationSpec - ) as Promise; + ); } /** @@ -95,20 +86,16 @@ export class Chat { nextLink: string, options?: ChatListChatThreadsNextOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - nextLink, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { nextLink, options }, listChatThreadsNextOperationSpec - ) as Promise; + ); } } // Operation Specifications -const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); -const createChatThreadOperationSpec: coreHttp.OperationSpec = { +const createChatThreadOperationSpec: coreClient.OperationSpec = { path: "/chat/threads", httpMethod: "POST", responses: { @@ -143,7 +130,7 @@ const createChatThreadOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const listChatThreadsOperationSpec: coreHttp.OperationSpec = { +const listChatThreadsOperationSpec: coreClient.OperationSpec = { path: "/chat/threads", httpMethod: "GET", responses: { @@ -176,7 +163,7 @@ const listChatThreadsOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const deleteChatThreadOperationSpec: coreHttp.OperationSpec = { +const deleteChatThreadOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}", httpMethod: "DELETE", responses: { @@ -203,7 +190,7 @@ const deleteChatThreadOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listChatThreadsNextOperationSpec: coreHttp.OperationSpec = { +const listChatThreadsNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { diff --git a/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts b/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts index e548b19102ac..f15ac568725e 100644 --- a/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts +++ b/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts @@ -6,26 +6,36 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import { ChatThread } from "../operationsInterfaces"; +import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; -import { ChatApiClient } from "../chatApiClient"; +import { ChatApiClientContext } from "../chatApiClientContext"; import { ChatThreadListChatReadReceiptsOptionalParams, ChatThreadListChatReadReceiptsResponse, SendReadReceiptRequest, + ChatThreadSendChatReadReceiptOptionalParams, SendChatMessageRequest, + ChatThreadSendChatMessageOptionalParams, ChatThreadSendChatMessageResponse, ChatThreadListChatMessagesOptionalParams, ChatThreadListChatMessagesResponse, + ChatThreadGetChatMessageOptionalParams, ChatThreadGetChatMessageResponse, UpdateChatMessageRequest, + ChatThreadUpdateChatMessageOptionalParams, + ChatThreadDeleteChatMessageOptionalParams, ChatThreadListChatParticipantsOptionalParams, ChatThreadListChatParticipantsResponse, CommunicationIdentifierModel, + ChatThreadRemoveChatParticipantOptionalParams, AddChatParticipantsRequest, + ChatThreadAddChatParticipantsOptionalParams, ChatThreadAddChatParticipantsResponse, UpdateChatThreadRequest, + ChatThreadUpdateChatThreadPropertiesOptionalParams, + ChatThreadGetChatThreadPropertiesOptionalParams, ChatThreadGetChatThreadPropertiesResponse, ChatThreadSendTypingNotificationOptionalParams, ChatThreadListChatReadReceiptsNextOptionalParams, @@ -36,15 +46,15 @@ import { ChatThreadListChatParticipantsNextResponse } from "../models"; -/** Class representing a ChatThread. */ -export class ChatThread { - private readonly client: ChatApiClient; +/** Class containing ChatThread operations. */ +export class ChatThreadImpl implements ChatThread { + private readonly client: ChatApiClientContext; /** * Initialize a new instance of the class ChatThread class. * @param client Reference to the service client */ - constructor(client: ChatApiClient) { + constructor(client: ChatApiClientContext) { this.client = client; } @@ -57,14 +67,10 @@ export class ChatThread { chatThreadId: string, options?: ChatThreadListChatReadReceiptsOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, options }, listChatReadReceiptsOperationSpec - ) as Promise; + ); } /** @@ -76,17 +82,12 @@ export class ChatThread { sendChatReadReceipt( chatThreadId: string, sendReadReceiptRequest: SendReadReceiptRequest, - options?: coreHttp.OperationOptions - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - sendReadReceiptRequest, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + options?: ChatThreadSendChatReadReceiptOptionalParams + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, sendReadReceiptRequest, options }, sendChatReadReceiptOperationSpec - ) as Promise; + ); } /** @@ -98,17 +99,12 @@ export class ChatThread { sendChatMessage( chatThreadId: string, sendChatMessageRequest: SendChatMessageRequest, - options?: coreHttp.OperationOptions + options?: ChatThreadSendChatMessageOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - sendChatMessageRequest, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, sendChatMessageRequest, options }, sendChatMessageOperationSpec - ) as Promise; + ); } /** @@ -120,14 +116,10 @@ export class ChatThread { chatThreadId: string, options?: ChatThreadListChatMessagesOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, options }, listChatMessagesOperationSpec - ) as Promise; + ); } /** @@ -139,17 +131,12 @@ export class ChatThread { getChatMessage( chatThreadId: string, chatMessageId: string, - options?: coreHttp.OperationOptions + options?: ChatThreadGetChatMessageOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - chatMessageId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, chatMessageId, options }, getChatMessageOperationSpec - ) as Promise; + ); } /** @@ -163,18 +150,12 @@ export class ChatThread { chatThreadId: string, chatMessageId: string, updateChatMessageRequest: UpdateChatMessageRequest, - options?: coreHttp.OperationOptions - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - chatMessageId, - updateChatMessageRequest, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + options?: ChatThreadUpdateChatMessageOptionalParams + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, chatMessageId, updateChatMessageRequest, options }, updateChatMessageOperationSpec - ) as Promise; + ); } /** @@ -186,17 +167,12 @@ export class ChatThread { deleteChatMessage( chatThreadId: string, chatMessageId: string, - options?: coreHttp.OperationOptions - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - chatMessageId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + options?: ChatThreadDeleteChatMessageOptionalParams + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, chatMessageId, options }, deleteChatMessageOperationSpec - ) as Promise; + ); } /** @@ -208,14 +184,10 @@ export class ChatThread { chatThreadId: string, options?: ChatThreadListChatParticipantsOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, options }, listChatParticipantsOperationSpec - ) as Promise; + ); } /** @@ -227,17 +199,12 @@ export class ChatThread { removeChatParticipant( chatThreadId: string, participantCommunicationIdentifier: CommunicationIdentifierModel, - options?: coreHttp.OperationOptions - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - participantCommunicationIdentifier, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + options?: ChatThreadRemoveChatParticipantOptionalParams + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, participantCommunicationIdentifier, options }, removeChatParticipantOperationSpec - ) as Promise; + ); } /** @@ -249,17 +216,12 @@ export class ChatThread { addChatParticipants( chatThreadId: string, addChatParticipantsRequest: AddChatParticipantsRequest, - options?: coreHttp.OperationOptions + options?: ChatThreadAddChatParticipantsOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - addChatParticipantsRequest, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, addChatParticipantsRequest, options }, addChatParticipantsOperationSpec - ) as Promise; + ); } /** @@ -271,17 +233,12 @@ export class ChatThread { updateChatThreadProperties( chatThreadId: string, updateChatThreadRequest: UpdateChatThreadRequest, - options?: coreHttp.OperationOptions - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - updateChatThreadRequest, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + options?: ChatThreadUpdateChatThreadPropertiesOptionalParams + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, updateChatThreadRequest, options }, updateChatThreadPropertiesOperationSpec - ) as Promise; + ); } /** @@ -291,16 +248,12 @@ export class ChatThread { */ getChatThreadProperties( chatThreadId: string, - options?: coreHttp.OperationOptions + options?: ChatThreadGetChatThreadPropertiesOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, options }, getChatThreadPropertiesOperationSpec - ) as Promise; + ); } /** @@ -311,15 +264,11 @@ export class ChatThread { sendTypingNotification( chatThreadId: string, options?: ChatThreadSendTypingNotificationOptionalParams - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, options }, sendTypingNotificationOperationSpec - ) as Promise; + ); } /** @@ -333,15 +282,10 @@ export class ChatThread { nextLink: string, options?: ChatThreadListChatReadReceiptsNextOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - nextLink, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, nextLink, options }, listChatReadReceiptsNextOperationSpec - ) as Promise; + ); } /** @@ -355,15 +299,10 @@ export class ChatThread { nextLink: string, options?: ChatThreadListChatMessagesNextOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - nextLink, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, nextLink, options }, listChatMessagesNextOperationSpec - ) as Promise; + ); } /** @@ -377,21 +316,16 @@ export class ChatThread { nextLink: string, options?: ChatThreadListChatParticipantsNextOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - chatThreadId, - nextLink, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { chatThreadId, nextLink, options }, listChatParticipantsNextOperationSpec - ) as Promise; + ); } } // Operation Specifications -const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); -const listChatReadReceiptsOperationSpec: coreHttp.OperationSpec = { +const listChatReadReceiptsOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/readReceipts", httpMethod: "GET", responses: { @@ -424,7 +358,7 @@ const listChatReadReceiptsOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const sendChatReadReceiptOperationSpec: coreHttp.OperationSpec = { +const sendChatReadReceiptOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/readReceipts", httpMethod: "POST", responses: { @@ -453,7 +387,7 @@ const sendChatReadReceiptOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const sendChatMessageOperationSpec: coreHttp.OperationSpec = { +const sendChatMessageOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/messages", httpMethod: "POST", responses: { @@ -484,7 +418,7 @@ const sendChatMessageOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const listChatMessagesOperationSpec: coreHttp.OperationSpec = { +const listChatMessagesOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/messages", httpMethod: "GET", responses: { @@ -517,7 +451,7 @@ const listChatMessagesOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const getChatMessageOperationSpec: coreHttp.OperationSpec = { +const getChatMessageOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/messages/{chatMessageId}", httpMethod: "GET", responses: { @@ -550,7 +484,7 @@ const getChatMessageOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const updateChatMessageOperationSpec: coreHttp.OperationSpec = { +const updateChatMessageOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/messages/{chatMessageId}", httpMethod: "PATCH", responses: { @@ -583,7 +517,7 @@ const updateChatMessageOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const deleteChatMessageOperationSpec: coreHttp.OperationSpec = { +const deleteChatMessageOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/messages/{chatMessageId}", httpMethod: "DELETE", responses: { @@ -614,7 +548,7 @@ const deleteChatMessageOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listChatParticipantsOperationSpec: coreHttp.OperationSpec = { +const listChatParticipantsOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/participants", httpMethod: "GET", responses: { @@ -647,7 +581,7 @@ const listChatParticipantsOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const removeChatParticipantOperationSpec: coreHttp.OperationSpec = { +const removeChatParticipantOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/participants/:remove", httpMethod: "POST", responses: { @@ -676,7 +610,7 @@ const removeChatParticipantOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const addChatParticipantsOperationSpec: coreHttp.OperationSpec = { +const addChatParticipantsOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/participants/:add", httpMethod: "POST", responses: { @@ -707,7 +641,7 @@ const addChatParticipantsOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const updateChatThreadPropertiesOperationSpec: coreHttp.OperationSpec = { +const updateChatThreadPropertiesOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}", httpMethod: "PATCH", responses: { @@ -736,7 +670,7 @@ const updateChatThreadPropertiesOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const getChatThreadPropertiesOperationSpec: coreHttp.OperationSpec = { +const getChatThreadPropertiesOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}", httpMethod: "GET", responses: { @@ -765,7 +699,7 @@ const getChatThreadPropertiesOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const sendTypingNotificationOperationSpec: coreHttp.OperationSpec = { +const sendTypingNotificationOperationSpec: coreClient.OperationSpec = { path: "/chat/threads/{chatThreadId}/typing", httpMethod: "POST", responses: { @@ -794,7 +728,7 @@ const sendTypingNotificationOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const listChatReadReceiptsNextOperationSpec: coreHttp.OperationSpec = { +const listChatReadReceiptsNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { @@ -831,7 +765,7 @@ const listChatReadReceiptsNextOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listChatMessagesNextOperationSpec: coreHttp.OperationSpec = { +const listChatMessagesNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { @@ -868,7 +802,7 @@ const listChatMessagesNextOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listChatParticipantsNextOperationSpec: coreHttp.OperationSpec = { +const listChatParticipantsNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { diff --git a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts new file mode 100644 index 000000000000..9e8bdddf68da --- /dev/null +++ b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts @@ -0,0 +1,56 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { + CreateChatThreadRequest, + ChatCreateChatThreadOptionalParams, + ChatCreateChatThreadResponse, + ChatListChatThreadsOptionalParams, + ChatListChatThreadsResponse, + ChatDeleteChatThreadOptionalParams, + ChatListChatThreadsNextOptionalParams, + ChatListChatThreadsNextResponse +} from "../models"; + +/** Interface representing a Chat. */ +export interface Chat { + /** + * Creates a chat thread. + * @param createChatThreadRequest Request payload for creating a chat thread. + * @param options The options parameters. + */ + createChatThread( + createChatThreadRequest: CreateChatThreadRequest, + options?: ChatCreateChatThreadOptionalParams + ): Promise; + /** + * Gets the list of chat threads of a user. + * @param options The options parameters. + */ + listChatThreads( + options?: ChatListChatThreadsOptionalParams + ): Promise; + /** + * Deletes a thread. + * @param chatThreadId Id of the thread to be deleted. + * @param options The options parameters. + */ + deleteChatThread( + chatThreadId: string, + options?: ChatDeleteChatThreadOptionalParams + ): Promise; + /** + * ListChatThreadsNext + * @param nextLink The nextLink from the previous successful call to the ListChatThreads method. + * @param options The options parameters. + */ + listChatThreadsNext( + nextLink: string, + options?: ChatListChatThreadsNextOptionalParams + ): Promise; +} diff --git a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts new file mode 100644 index 000000000000..2b92996889ac --- /dev/null +++ b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts @@ -0,0 +1,214 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { + ChatThreadListChatReadReceiptsOptionalParams, + ChatThreadListChatReadReceiptsResponse, + SendReadReceiptRequest, + ChatThreadSendChatReadReceiptOptionalParams, + SendChatMessageRequest, + ChatThreadSendChatMessageOptionalParams, + ChatThreadSendChatMessageResponse, + ChatThreadListChatMessagesOptionalParams, + ChatThreadListChatMessagesResponse, + ChatThreadGetChatMessageOptionalParams, + ChatThreadGetChatMessageResponse, + UpdateChatMessageRequest, + ChatThreadUpdateChatMessageOptionalParams, + ChatThreadDeleteChatMessageOptionalParams, + ChatThreadListChatParticipantsOptionalParams, + ChatThreadListChatParticipantsResponse, + CommunicationIdentifierModel, + ChatThreadRemoveChatParticipantOptionalParams, + AddChatParticipantsRequest, + ChatThreadAddChatParticipantsOptionalParams, + ChatThreadAddChatParticipantsResponse, + UpdateChatThreadRequest, + ChatThreadUpdateChatThreadPropertiesOptionalParams, + ChatThreadGetChatThreadPropertiesOptionalParams, + ChatThreadGetChatThreadPropertiesResponse, + ChatThreadSendTypingNotificationOptionalParams, + ChatThreadListChatReadReceiptsNextOptionalParams, + ChatThreadListChatReadReceiptsNextResponse, + ChatThreadListChatMessagesNextOptionalParams, + ChatThreadListChatMessagesNextResponse, + ChatThreadListChatParticipantsNextOptionalParams, + ChatThreadListChatParticipantsNextResponse +} from "../models"; + +/** Interface representing a ChatThread. */ +export interface ChatThread { + /** + * Gets chat message read receipts for a thread. + * @param chatThreadId Thread id to get the chat message read receipts for. + * @param options The options parameters. + */ + listChatReadReceipts( + chatThreadId: string, + options?: ChatThreadListChatReadReceiptsOptionalParams + ): Promise; + /** + * Sends a read receipt event to a thread, on behalf of a user. + * @param chatThreadId Thread id to send the read receipt event to. + * @param sendReadReceiptRequest Read receipt details. + * @param options The options parameters. + */ + sendChatReadReceipt( + chatThreadId: string, + sendReadReceiptRequest: SendReadReceiptRequest, + options?: ChatThreadSendChatReadReceiptOptionalParams + ): Promise; + /** + * Sends a message to a thread. + * @param chatThreadId The thread id to send the message to. + * @param sendChatMessageRequest Details of the message to send. + * @param options The options parameters. + */ + sendChatMessage( + chatThreadId: string, + sendChatMessageRequest: SendChatMessageRequest, + options?: ChatThreadSendChatMessageOptionalParams + ): Promise; + /** + * Gets a list of messages from a thread. + * @param chatThreadId The thread id of the message. + * @param options The options parameters. + */ + listChatMessages( + chatThreadId: string, + options?: ChatThreadListChatMessagesOptionalParams + ): Promise; + /** + * Gets a message by id. + * @param chatThreadId The thread id to which the message was sent. + * @param chatMessageId The message id. + * @param options The options parameters. + */ + getChatMessage( + chatThreadId: string, + chatMessageId: string, + options?: ChatThreadGetChatMessageOptionalParams + ): Promise; + /** + * Updates a message. + * @param chatThreadId The thread id to which the message was sent. + * @param chatMessageId The message id. + * @param updateChatMessageRequest Details of the request to update the message. + * @param options The options parameters. + */ + updateChatMessage( + chatThreadId: string, + chatMessageId: string, + updateChatMessageRequest: UpdateChatMessageRequest, + options?: ChatThreadUpdateChatMessageOptionalParams + ): Promise; + /** + * Deletes a message. + * @param chatThreadId The thread id to which the message was sent. + * @param chatMessageId The message id. + * @param options The options parameters. + */ + deleteChatMessage( + chatThreadId: string, + chatMessageId: string, + options?: ChatThreadDeleteChatMessageOptionalParams + ): Promise; + /** + * Gets the participants of a thread. + * @param chatThreadId Thread id to get participants for. + * @param options The options parameters. + */ + listChatParticipants( + chatThreadId: string, + options?: ChatThreadListChatParticipantsOptionalParams + ): Promise; + /** + * Remove a participant from a thread. + * @param chatThreadId Thread id to remove the participant from. + * @param participantCommunicationIdentifier Id of the thread participant to remove from the thread. + * @param options The options parameters. + */ + removeChatParticipant( + chatThreadId: string, + participantCommunicationIdentifier: CommunicationIdentifierModel, + options?: ChatThreadRemoveChatParticipantOptionalParams + ): Promise; + /** + * Adds thread participants to a thread. If participants already exist, no change occurs. + * @param chatThreadId Id of the thread to add participants to. + * @param addChatParticipantsRequest Thread participants to be added to the thread. + * @param options The options parameters. + */ + addChatParticipants( + chatThreadId: string, + addChatParticipantsRequest: AddChatParticipantsRequest, + options?: ChatThreadAddChatParticipantsOptionalParams + ): Promise; + /** + * Updates a thread's properties. + * @param chatThreadId The id of the thread to update. + * @param updateChatThreadRequest Request payload for updating a chat thread. + * @param options The options parameters. + */ + updateChatThreadProperties( + chatThreadId: string, + updateChatThreadRequest: UpdateChatThreadRequest, + options?: ChatThreadUpdateChatThreadPropertiesOptionalParams + ): Promise; + /** + * Gets a chat thread's properties. + * @param chatThreadId Id of the thread. + * @param options The options parameters. + */ + getChatThreadProperties( + chatThreadId: string, + options?: ChatThreadGetChatThreadPropertiesOptionalParams + ): Promise; + /** + * Posts a typing event to a thread, on behalf of a user. + * @param chatThreadId Id of the thread. + * @param options The options parameters. + */ + sendTypingNotification( + chatThreadId: string, + options?: ChatThreadSendTypingNotificationOptionalParams + ): Promise; + /** + * ListChatReadReceiptsNext + * @param chatThreadId Thread id to get the chat message read receipts for. + * @param nextLink The nextLink from the previous successful call to the ListChatReadReceipts method. + * @param options The options parameters. + */ + listChatReadReceiptsNext( + chatThreadId: string, + nextLink: string, + options?: ChatThreadListChatReadReceiptsNextOptionalParams + ): Promise; + /** + * ListChatMessagesNext + * @param chatThreadId The thread id of the message. + * @param nextLink The nextLink from the previous successful call to the ListChatMessages method. + * @param options The options parameters. + */ + listChatMessagesNext( + chatThreadId: string, + nextLink: string, + options?: ChatThreadListChatMessagesNextOptionalParams + ): Promise; + /** + * ListChatParticipantsNext + * @param chatThreadId Thread id to get participants for. + * @param nextLink The nextLink from the previous successful call to the ListChatParticipants method. + * @param options The options parameters. + */ + listChatParticipantsNext( + chatThreadId: string, + nextLink: string, + options?: ChatThreadListChatParticipantsNextOptionalParams + ): Promise; +} diff --git a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/index.ts b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/index.ts new file mode 100644 index 000000000000..504f4a5f4ea3 --- /dev/null +++ b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/index.ts @@ -0,0 +1,10 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +export * from "./chatThread"; +export * from "./chat"; diff --git a/sdk/communication/communication-chat/src/models/options.ts b/sdk/communication/communication-chat/src/models/options.ts index 09a711a703fd..e61e19583448 100644 --- a/sdk/communication/communication-chat/src/models/options.ts +++ b/sdk/communication/communication-chat/src/models/options.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { PipelineOptions, OperationOptions } from "@azure/core-http"; +import { CommonClientOptions, OperationOptions } from "@azure/core-client"; import { ChatThreadListChatMessagesOptionalParams as RestListMessagesOptions, ChatListChatThreadsOptionalParams as RestListChatThreadsOptions, @@ -20,7 +20,7 @@ export { /** * Options to create chat client. */ -export interface ChatClientOptions extends PipelineOptions {} +export interface ChatClientOptions extends CommonClientOptions {} /** * Options to create chat thread client. diff --git a/sdk/communication/communication-chat/src/models/uuid.ts b/sdk/communication/communication-chat/src/models/uuid.ts new file mode 100644 index 000000000000..1ea3af6f248d --- /dev/null +++ b/sdk/communication/communication-chat/src/models/uuid.ts @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { v4 as uuidv4 } from "uuid"; + +/** + * Generated Universally Unique Identifier + * + * @returns RFC4122 v4 UUID. + * @internal + */ +export function generateUuid(): string { + return uuidv4(); +} diff --git a/sdk/communication/communication-chat/swagger/README.md b/sdk/communication/communication-chat/swagger/README.md index 563c04ac70a6..17119377385a 100644 --- a/sdk/communication/communication-chat/swagger/README.md +++ b/sdk/communication/communication-chat/swagger/README.md @@ -12,16 +12,14 @@ generate-metadata: false license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../src/generated tag: package-chat-2021-04-05-preview6 -require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/29e0c9624a8e60138127457f2e863bb4a9ba1419/specification/communication/data-plane/Chat/readme.md +require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/communication/data-plane/Chat/readme.md model-date-time-as-string: false optional-response-headers: true -use-extension: - "@autorest/typescript": "6.0.0-dev.20210114.1" - "@autorest/modelerfour": "4.15.442" +typescript: true azure-arm: false add-credentials: false disable-async-iterators: true -package-version: 1.1.0-beta.2 +package-version: 1.1.0 ``` ### Rename CommunicationError to ChatError diff --git a/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts b/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts index 939880cb0603..852906938a7d 100644 --- a/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts +++ b/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts @@ -59,7 +59,7 @@ describe("[Mocked] ChatClient", async () => { assert.equal(request.url, `${baseUri}/chat/threads?api-version=${API_VERSION}`); assert.equal(request.method, "POST"); - assert.deepEqual(JSON.parse(request.body), sendRequest); + assert.deepEqual(JSON.parse(request.body as string), sendRequest); assert.isNotEmpty(request.headers.get("repeatability-request-id")); }); diff --git a/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts b/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts index f69555a61893..780aaf12da1e 100644 --- a/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts +++ b/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts @@ -82,7 +82,7 @@ describe("[Mocked] ChatThreadClient", async () => { const request = spy.getCall(0).args[0]; assert.equal(request.url, `${baseUri}/chat/threads/${threadId}?api-version=${API_VERSION}`); assert.equal(request.method, "PATCH"); - assert.deepEqual(JSON.parse(request.body), { topic: topic }); + assert.deepEqual(JSON.parse(request.body as string), { topic: topic }); }); it("makes successful send message request", async () => { @@ -113,7 +113,7 @@ describe("[Mocked] ChatThreadClient", async () => { `${baseUri}/chat/threads/${threadId}/messages?api-version=${API_VERSION}` ); assert.equal(request.method, "POST"); - assert.deepEqual(JSON.parse(request.body), { + assert.deepEqual(JSON.parse(request.body as string), { ...sendRequest, ...sendOptions }); @@ -224,7 +224,7 @@ describe("[Mocked] ChatThreadClient", async () => { `${baseUri}/chat/threads/${threadId}/messages/${mockMessage.id}?api-version=${API_VERSION}` ); assert.equal(request.method, "PATCH"); - assert.deepEqual(JSON.parse(request.body), { + assert.deepEqual(JSON.parse(request.body as string), { content: mockMessage.content?.message, metadata: mockMessage.metadata }); @@ -265,7 +265,7 @@ describe("[Mocked] ChatThreadClient", async () => { `${baseUri}/chat/threads/${threadId}/participants/:add?api-version=${API_VERSION}` ); assert.equal(request.method, "POST"); - const requestJson = JSON.parse(request.body); + const requestJson = JSON.parse(request.body as string); assert.equal( (sendRequest.participants[0].id as CommunicationUserIdentifier).communicationUserId, requestJson.participants[0].communicationIdentifier.communicationUser.id @@ -323,7 +323,7 @@ describe("[Mocked] ChatThreadClient", async () => { `${baseUri}/chat/threads/${threadId}/participants/:remove?api-version=${API_VERSION}` ); assert.equal(request.method, "POST"); - const requestJson = JSON.parse(request.body); + const requestJson = JSON.parse(request.body as string); assert.deepEqual(mockParticipant.communicationIdentifier, requestJson); }); @@ -360,7 +360,7 @@ describe("[Mocked] ChatThreadClient", async () => { `${baseUri}/chat/threads/${threadId}/typing?api-version=${API_VERSION}` ); assert.equal(request.method, "POST"); - assert.deepEqual(JSON.parse(request.body), options); + assert.deepEqual(JSON.parse(request.body as string), options); }); it("makes successful sent read receipt request", async () => { diff --git a/sdk/communication/communication-chat/test/internal/utils/mockClient.ts b/sdk/communication/communication-chat/test/internal/utils/mockClient.ts index 7bb25152a443..56b6e93fa1ef 100644 --- a/sdk/communication/communication-chat/test/internal/utils/mockClient.ts +++ b/sdk/communication/communication-chat/test/internal/utils/mockClient.ts @@ -2,7 +2,12 @@ // Licensed under the MIT license. import { AzureCommunicationTokenCredential } from "@azure/communication-common"; -import { HttpClient, HttpHeaders, WebResourceLike, HttpOperationResponse } from "@azure/core-http"; +import { + createHttpHeaders, + HttpClient, + PipelineRequest, + PipelineResponse +} from "@azure/core-rest-pipeline"; import * as RestModel from "../../../src/generated/src/models"; import { ChatClient, ChatParticipant, ChatThreadClient } from "../../../src"; import { CommunicationIdentifierModel } from "../../../src/generated/src"; @@ -68,12 +73,12 @@ export const mockChatMessageReadReceipt: RestModel.ChatMessageReadReceipt = { export const generateHttpClient = (status: number, parsedBody?: unknown): HttpClient => { const mockHttpClient: HttpClient = { - async sendRequest(httpRequest: WebResourceLike): Promise { + async sendRequest(httpRequest: PipelineRequest): Promise { return { status: status, - headers: new HttpHeaders(), + headers: createHttpHeaders(), request: httpRequest, - parsedBody: parsedBody + bodyAsText: JSON.stringify(parsedBody) }; } }; diff --git a/sdk/communication/communication-chat/test/public/chatClient.spec.ts b/sdk/communication/communication-chat/test/public/chatClient.spec.ts index 45c4b9957665..cc6526950036 100644 --- a/sdk/communication/communication-chat/test/public/chatClient.spec.ts +++ b/sdk/communication/communication-chat/test/public/chatClient.spec.ts @@ -5,7 +5,7 @@ import { isLiveMode, Recorder } from "@azure/test-utils-recorder"; import { assert } from "chai"; import { ChatClient, ChatThreadClient } from "../../src"; import { createTestUser, createRecorder, createChatClient } from "./utils/recordedClient"; -import { isNode } from "@azure/core-http"; +import { isNode } from "@azure/core-util"; import sinon from "sinon"; import { CommunicationIdentifier } from "@azure/communication-common"; import { Context } from "mocha"; diff --git a/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts b/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts index bbe8a18247b6..829a6230cfdb 100644 --- a/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts +++ b/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { isNode } from "@azure/core-http"; +import { isNode } from "@azure/core-util"; -export const baseUri = "https://contoso.api.fake:443"; +export const baseUri = "https://contoso.api.fake"; declare function btoa(stringToEncode: string): string; diff --git a/sdk/communication/communication-chat/test/public/utils/recordedClient.ts b/sdk/communication/communication-chat/test/public/utils/recordedClient.ts index 60dbf6ba4e1b..5d0a9d292462 100644 --- a/sdk/communication/communication-chat/test/public/utils/recordedClient.ts +++ b/sdk/communication/communication-chat/test/public/utils/recordedClient.ts @@ -5,13 +5,7 @@ import { Context } from "mocha"; import * as dotenv from "dotenv"; import { env, Recorder, record, RecorderEnvironmentSetup } from "@azure/test-utils-recorder"; -import { - DefaultHttpClient, - HttpClient, - HttpOperationResponse, - isNode, - WebResourceLike -} from "@azure/core-http"; +import { isNode } from "@azure/core-util"; import { ChatClient } from "../../../src"; import { CommunicationUserIdentifier, @@ -71,28 +65,5 @@ export function createChatClient(userToken: string): ChatClient { } const { url } = parseClientArguments(env.COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING); - return new ChatClient(url, new AzureCommunicationTokenCredential(userToken), { - httpClient: createTestHttpClient() - }); -} - -function createTestHttpClient(): HttpClient { - const customHttpClient = new DefaultHttpClient(); - - const originalSendRequest = customHttpClient.sendRequest; - customHttpClient.sendRequest = async function( - httpRequest: WebResourceLike - ): Promise { - const requestResponse = await originalSendRequest.apply(this, [httpRequest]); - - console.log( - `MS-CV header for request: ${httpRequest.url} (${ - requestResponse.status - } - ${requestResponse.headers.get("ms-cv")})` - ); - - return requestResponse; - }; - - return customHttpClient; + return new ChatClient(url, new AzureCommunicationTokenCredential(userToken)); }