diff --git a/sdk/communication/communication-messages-rest/api-extractor.json b/sdk/communication/communication-messages-rest/api-extractor.json index e4a0816f672e..301ff7669556 100644 --- a/sdk/communication/communication-messages-rest/api-extractor.json +++ b/sdk/communication/communication-messages-rest/api-extractor.json @@ -1,18 +1,31 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", "mainEntryPointFilePath": "./types/src/index.d.ts", - "docModel": { "enabled": true }, - "apiReport": { "enabled": true, "reportFolder": "./review" }, + "docModel": { + "enabled": true + }, + "apiReport": { + "enabled": true, + "reportFolder": "./review" + }, "dtsRollup": { "enabled": true, "untrimmedFilePath": "", "publicTrimmedFilePath": "./types/communication-messages.d.ts" }, "messages": { - "tsdocMessageReporting": { "default": { "logLevel": "none" } }, + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, "extractorMessageReporting": { - "ae-missing-release-tag": { "logLevel": "none" }, - "ae-unresolved-link": { "logLevel": "none" } + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } } } -} +} \ No newline at end of file diff --git a/sdk/communication/communication-messages-rest/karma.conf.js b/sdk/communication/communication-messages-rest/karma.conf.js index cf0000f9e90b..a9d5f1b5fc59 100644 --- a/sdk/communication/communication-messages-rest/karma.conf.js +++ b/sdk/communication/communication-messages-rest/karma.conf.js @@ -53,12 +53,11 @@ module.exports = function (config) { envPreprocessor: [ "TEST_MODE", + "ENDPOINT", "AZURE_CLIENT_SECRET", "AZURE_CLIENT_ID", "AZURE_TENANT_ID", - "CHANNEL_ID", - "RECIPIENT_PHONE_NUMBER", - "COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING", + "SUBSCRIPTION_ID", "RECORDINGS_RELATIVE_PATH", ], diff --git a/sdk/communication/communication-messages-rest/package.json b/sdk/communication/communication-messages-rest/package.json index 140a54c2bbcb..5f819f9fc6ea 100644 --- a/sdk/communication/communication-messages-rest/package.json +++ b/sdk/communication/communication-messages-rest/package.json @@ -121,4 +121,4 @@ "azure-communication-services" ] } -} +} \ No newline at end of file diff --git a/sdk/communication/communication-messages-rest/review/communication-messages.api.md b/sdk/communication/communication-messages-rest/review/communication-messages.api.md index d5c468dcb3c7..6634fdfa483b 100644 --- a/sdk/communication/communication-messages-rest/review/communication-messages.api.md +++ b/sdk/communication/communication-messages-rest/review/communication-messages.api.md @@ -19,14 +19,13 @@ import { StreamableMethod } from '@azure-rest/core-client'; import { TokenCredential } from '@azure/core-auth'; // @public -export interface ClientRequestIdHeaderOutput { -} +export type CommunicationMessageKind = string | "text" | "image" | "template"; // @public -function createClient(connectionString: string, options?: ClientOptions): MessagesServiceClient; +export type CommunicationMessagesChannelOutput = string | "whatsApp"; // @public -function createClient(endpoint: string, credential: KeyCredential | TokenCredential, options?: ClientOptions): MessagesServiceClient; +function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): MessagesServiceClient; export default createClient; // @public @@ -184,10 +183,13 @@ export interface MessageTemplate { // @public export type MessageTemplateBindings = MessageTemplateBindingsParent | WhatsAppMessageTemplateBindings; +// @public +export type MessageTemplateBindingsKind = string | "whatsApp"; + // @public export interface MessageTemplateBindingsParent { // (undocumented) - kind: string; + kind: MessageTemplateBindingsKind; } // @public @@ -212,10 +214,10 @@ export type MessageTemplateItemOutput = MessageTemplateItemOutputParent | WhatsA // @public export interface MessageTemplateItemOutputParent { // (undocumented) - kind: string; + kind: CommunicationMessagesChannelOutput; language: string; readonly name: string; - status: string; + status: MessageTemplateStatusOutput; } // @public @@ -234,6 +236,9 @@ export interface MessageTemplateQuickAction extends MessageTemplateValueParent { text?: string; } +// @public +export type MessageTemplateStatusOutput = string | "approved" | "rejected" | "pending" | "paused"; + // @public export interface MessageTemplateText extends MessageTemplateValueParent { kind: "text"; @@ -243,10 +248,13 @@ export interface MessageTemplateText extends MessageTemplateValueParent { // @public export type MessageTemplateValue = MessageTemplateValueParent | MessageTemplateText | MessageTemplateImage | MessageTemplateDocument | MessageTemplateVideo | MessageTemplateLocation | MessageTemplateQuickAction; +// @public +export type MessageTemplateValueKind = string | "text" | "image" | "document" | "video" | "location" | "quickAction"; + // @public export interface MessageTemplateValueParent { // (undocumented) - kind: string; + kind: MessageTemplateValueKind; name: string; } @@ -265,7 +273,7 @@ export type NotificationContent = NotificationContentParent | TextNotificationCo export interface NotificationContentParent { channelRegistrationId: string; // (undocumented) - kind: string; + kind: CommunicationMessageKind; to: string[]; } @@ -287,14 +295,6 @@ export interface PagingOptions { customGetPage?: GetPage[]>; } -// @public -export interface RepeatabilityRequestHeadersOutput { -} - -// @public -export interface RepeatabilityResponseHeadersOutput { -} - // @public export type RepeatabilityResultOutput = "accepted" | "rejected"; @@ -307,7 +307,7 @@ export interface Routes { // @public (undocumented) export interface Send { - post(options?: SendParameters): StreamableMethod; + post(options: SendParameters): StreamableMethod; } // @public (undocumented) @@ -328,8 +328,7 @@ export interface Send202Response extends HttpResponse { // @public (undocumented) export interface SendBodyParam { - // (undocumented) - body?: NotificationContent; + body: NotificationContent; } // @public (undocumented) @@ -380,6 +379,9 @@ export interface TextNotificationContent extends NotificationContentParent { kind: "text"; } +// @public +export type WhatsAppMessageButtonSubType = string | "quickReply" | "url"; + // @public export interface WhatsAppMessageTemplateBindings extends MessageTemplateBindingsParent { body?: Array; @@ -392,7 +394,7 @@ export interface WhatsAppMessageTemplateBindings extends MessageTemplateBindings // @public export interface WhatsAppMessageTemplateBindingsButton { refValue: string; - subType: string; + subType: WhatsAppMessageButtonSubType; } // @public diff --git a/sdk/communication/communication-messages-rest/src/generated/src/clientDefinitions.ts b/sdk/communication/communication-messages-rest/src/clientDefinitions.ts similarity index 95% rename from sdk/communication/communication-messages-rest/src/generated/src/clientDefinitions.ts rename to sdk/communication/communication-messages-rest/src/clientDefinitions.ts index 4fe414ce154d..72f9c8405e2f 100644 --- a/sdk/communication/communication-messages-rest/src/generated/src/clientDefinitions.ts +++ b/sdk/communication/communication-messages-rest/src/clientDefinitions.ts @@ -5,7 +5,7 @@ import { GetMediaParameters, SendParameters, ListTemplatesParameters, -} from "./parameters"; +} from "./parameters.js"; import { GetMedia200Response, GetMediaDefaultResponse, @@ -13,7 +13,7 @@ import { SendDefaultResponse, ListTemplates200Response, ListTemplatesDefaultResponse, -} from "./responses"; +} from "./responses.js"; import { Client, StreamableMethod } from "@azure-rest/core-client"; export interface GetMedia { @@ -26,7 +26,7 @@ export interface GetMedia { export interface Send { /** Sends a notification message from Business to User. */ post( - options?: SendParameters, + options: SendParameters, ): StreamableMethod; } diff --git a/sdk/communication/communication-messages-rest/src/generated/src/index.ts b/sdk/communication/communication-messages-rest/src/generated/src/index.ts deleted file mode 100644 index 364ed4e15b3d..000000000000 --- a/sdk/communication/communication-messages-rest/src/generated/src/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import MessagesServiceClient from "./messagesServiceClient"; - -export * from "./messagesServiceClient"; -export * from "./parameters"; -export * from "./responses"; -export * from "./clientDefinitions"; -export * from "./isUnexpected"; -export * from "./models"; -export * from "./outputModels"; -export * from "./paginateHelper"; - -export default MessagesServiceClient; diff --git a/sdk/communication/communication-messages-rest/src/generated/src/messagesServiceClient.ts b/sdk/communication/communication-messages-rest/src/generated/src/messagesServiceClient.ts deleted file mode 100644 index 1bfe62266af9..000000000000 --- a/sdk/communication/communication-messages-rest/src/generated/src/messagesServiceClient.ts +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { getClient, ClientOptions } from "@azure-rest/core-client"; -import { logger } from "./logger"; -import { TokenCredential, KeyCredential } from "@azure/core-auth"; -import { MessagesServiceClient } from "./clientDefinitions"; - -/** - * Initialize a new instance of `MessagesServiceClient` - * @param endpoint - The communication resource, for example https://my-resource.communication.azure.com - * @param credentials - uniquely identify client credential - * @param options - the parameter for all optional parameters - */ -export default function createClient( - endpoint: string, - credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, -): MessagesServiceClient { - const baseUrl = options.baseUrl ?? `${endpoint}`; - options.apiVersion = options.apiVersion ?? "2024-02-01"; - const userAgentInfo = `azsdk-js-communication-messages-rest/1.1.0-beta.1`; - const userAgentPrefix = - options.userAgentOptions && options.userAgentOptions.userAgentPrefix - ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` - : `${userAgentInfo}`; - options = { - ...options, - userAgentOptions: { - userAgentPrefix, - }, - loggingOptions: { - logger: options.loggingOptions?.logger ?? logger.info, - }, - credentials: { - scopes: options.credentials?.scopes ?? [ - "https://communication.azure.com/.default", - ], - apiKeyHeaderName: - options.credentials?.apiKeyHeaderName ?? "Authorization", - }, - }; - - const client = getClient( - baseUrl, - credentials, - options, - ) as MessagesServiceClient; - - return client; -} diff --git a/sdk/communication/communication-messages-rest/src/index.ts b/sdk/communication/communication-messages-rest/src/index.ts index 3de8a39de43f..2569b5d40254 100644 --- a/sdk/communication/communication-messages-rest/src/index.ts +++ b/sdk/communication/communication-messages-rest/src/index.ts @@ -1,13 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import MessagesServiceClient from "./messagesServiceClient"; -export * from "./generated/src/messagesServiceClient"; -export * from "./generated/src/parameters"; -export * from "./generated/src/responses"; -export * from "./generated/src/clientDefinitions"; -export * from "./generated/src/isUnexpected"; -export * from "./generated/src/models"; -export * from "./generated/src/outputModels"; -export * from "./generated/src/paginateHelper"; +import MessagesServiceClient from "./messagesServiceClient.js"; + +export * from "./messagesServiceClient.js"; +export * from "./parameters.js"; +export * from "./responses.js"; +export * from "./clientDefinitions.js"; +export * from "./isUnexpected.js"; +export * from "./models.js"; +export * from "./outputModels.js"; +export * from "./paginateHelper.js"; + export default MessagesServiceClient; diff --git a/sdk/communication/communication-messages-rest/src/generated/src/isUnexpected.ts b/sdk/communication/communication-messages-rest/src/isUnexpected.ts similarity index 99% rename from sdk/communication/communication-messages-rest/src/generated/src/isUnexpected.ts rename to sdk/communication/communication-messages-rest/src/isUnexpected.ts index 1b41010bd3cc..8e6c1aef68a8 100644 --- a/sdk/communication/communication-messages-rest/src/generated/src/isUnexpected.ts +++ b/sdk/communication/communication-messages-rest/src/isUnexpected.ts @@ -8,7 +8,7 @@ import { SendDefaultResponse, ListTemplates200Response, ListTemplatesDefaultResponse, -} from "./responses"; +} from "./responses.js"; const responseMap: Record = { "GET /messages/streams/{id}": ["200"], diff --git a/sdk/communication/communication-messages-rest/src/generated/src/logger.ts b/sdk/communication/communication-messages-rest/src/logger.ts similarity index 100% rename from sdk/communication/communication-messages-rest/src/generated/src/logger.ts rename to sdk/communication/communication-messages-rest/src/logger.ts diff --git a/sdk/communication/communication-messages-rest/src/messagesServiceClient.ts b/sdk/communication/communication-messages-rest/src/messagesServiceClient.ts index feff126d926c..1315881917ca 100644 --- a/sdk/communication/communication-messages-rest/src/messagesServiceClient.ts +++ b/sdk/communication/communication-messages-rest/src/messagesServiceClient.ts @@ -1,64 +1,51 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { - TokenCredential, - isTokenCredential, - KeyCredential, - isKeyCredential, -} from "@azure/core-auth"; -import { ClientOptions } from "@azure-rest/core-client"; -import { parseClientArguments, createCommunicationAuthPolicy } from "@azure/communication-common"; -import { MessagesServiceClient } from "./generated/src/clientDefinitions"; -import GeneratedAzureCommunicationMessageServiceClient from "./generated/src/messagesServiceClient"; +import { getClient, ClientOptions } from "@azure-rest/core-client"; +import { logger } from "./logger.js"; +import { TokenCredential, KeyCredential } from "@azure/core-auth"; +import { MessagesServiceClient } from "./clientDefinitions.js"; /** * Initialize a new instance of `MessagesServiceClient` - * @param connectionString - The connectionString or url of your Communication Services resource. - * @param options - the parameter for all optional parameters - */ -export default function createClient( - connectionString: string, - options?: ClientOptions, -): MessagesServiceClient; - -/** - * Initialize a new instance of `MessagesServiceClient` - * @param endpoint - The endpoint of your Communication Services resource. - * @param credential - The key or token credential. - * @param options - the parameter for all optional parameters - */ -export default function createClient( - endpoint: string, - credential: KeyCredential | TokenCredential, - options?: ClientOptions, -): MessagesServiceClient; - -/** - * Initialize a new instance of `MessagesServiceClient` - * @param endpoint - The communication resource, for example https://my-resource.communication.azure.com + * @param endpointParam - The communication resource, for example https://my-resource.communication.azure.com * @param credentials - uniquely identify client credential * @param options - the parameter for all optional parameters */ export default function createClient( - endpointOrConnectionString: string, - credentialOrOptions?: ClientOptions | (TokenCredential | KeyCredential), - options?: ClientOptions, + endpointParam: string, + credentials: TokenCredential | KeyCredential, + options: ClientOptions = {}, ): MessagesServiceClient { - if (!(isTokenCredential(credentialOrOptions) || isKeyCredential(credentialOrOptions))) { - options = credentialOrOptions as ClientOptions; - } - - if (options === undefined) { - options = {}; - } - - const { url, credential } = parseClientArguments(endpointOrConnectionString, credentialOrOptions); - const baseUrl = options.baseUrl ?? `${url}`; - - const client = GeneratedAzureCommunicationMessageServiceClient(baseUrl, credential, options); - const authPolicy = createCommunicationAuthPolicy(credential); - client.pipeline.addPolicy(authPolicy); + const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; + options.apiVersion = options.apiVersion ?? "2024-02-01"; + const userAgentInfo = `azsdk-js-communication-messages-rest/1.0.0-beta.2`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` + : `${userAgentInfo}`; + options = { + ...options, + userAgentOptions: { + userAgentPrefix, + }, + loggingOptions: { + logger: options.loggingOptions?.logger ?? logger.info, + }, + credentials: { + scopes: options.credentials?.scopes ?? [ + "https://communication.azure.com/.default", + ], + apiKeyHeaderName: + options.credentials?.apiKeyHeaderName ?? "Authorization", + }, + }; + + const client = getClient( + endpointUrl, + credentials, + options, + ) as MessagesServiceClient; return client; } diff --git a/sdk/communication/communication-messages-rest/src/generated/src/models.ts b/sdk/communication/communication-messages-rest/src/models.ts similarity index 89% rename from sdk/communication/communication-messages-rest/src/generated/src/models.ts rename to sdk/communication/communication-messages-rest/src/models.ts index c9a50032ba22..5184d548b9b6 100644 --- a/sdk/communication/communication-messages-rest/src/generated/src/models.ts +++ b/sdk/communication/communication-messages-rest/src/models.ts @@ -7,7 +7,7 @@ export interface NotificationContentParent { channelRegistrationId: string; /** The native external platform user identifiers of the recipient. */ to: string[]; - kind: string; + kind: CommunicationMessageKind; } /** A request to send a text notification. */ @@ -52,7 +52,7 @@ export interface MessageTemplate { export interface MessageTemplateValueParent { /** Template binding reference name */ name: string; - kind: string; + kind: MessageTemplateValueKind; } /** The message template's text value information. */ @@ -125,7 +125,7 @@ export interface MessageTemplateQuickAction extends MessageTemplateValueParent { /** The binding object to link values to the template specific locations */ export interface MessageTemplateBindingsParent { - kind: string; + kind: MessageTemplateBindingsKind; } /** The template bindings for WhatsApp */ @@ -151,12 +151,8 @@ export interface WhatsAppMessageTemplateBindingsComponent { /** The template bindings component button for WhatsApp */ export interface WhatsAppMessageTemplateBindingsButton { - /** - * The WhatsApp button sub type - * - * Possible values: "quickReply", "url" - */ - subType: string; + /** The WhatsApp button sub type */ + subType: WhatsAppMessageButtonSubType; /** The name of the referenced item in the template values. */ refValue: string; } @@ -180,3 +176,18 @@ export type MessageTemplateValue = export type MessageTemplateBindings = | MessageTemplateBindingsParent | WhatsAppMessageTemplateBindings; +/** Alias for CommunicationMessageKind */ +export type CommunicationMessageKind = string | "text" | "image" | "template"; +/** Alias for MessageTemplateValueKind */ +export type MessageTemplateValueKind = + | string + | "text" + | "image" + | "document" + | "video" + | "location" + | "quickAction"; +/** Alias for MessageTemplateBindingsKind */ +export type MessageTemplateBindingsKind = string | "whatsApp"; +/** Alias for WhatsAppMessageButtonSubType */ +export type WhatsAppMessageButtonSubType = string | "quickReply" | "url"; diff --git a/sdk/communication/communication-messages-rest/src/generated/src/outputModels.ts b/sdk/communication/communication-messages-rest/src/outputModels.ts similarity index 73% rename from sdk/communication/communication-messages-rest/src/generated/src/outputModels.ts rename to sdk/communication/communication-messages-rest/src/outputModels.ts index 318d2111df1c..0f4ba9311c4a 100644 --- a/sdk/communication/communication-messages-rest/src/generated/src/outputModels.ts +++ b/sdk/communication/communication-messages-rest/src/outputModels.ts @@ -3,15 +3,6 @@ import { Paged } from "@azure/core-paging"; -/** Provides the 'Repeatability-*' headers to enable repeatable requests. */ -export interface RepeatabilityRequestHeadersOutput {} - -/** Provides the 'Repeatability-*' headers to enable repeatable requests. */ -export interface RepeatabilityResponseHeadersOutput {} - -/** Provides the 'x-ms-client-request-id' header to enable request correlation in requests and responses. */ -export interface ClientRequestIdHeaderOutput {} - /** Result of the send message operation. */ export interface SendMessageResultOutput { /** Receipts of the send message operation. */ @@ -32,13 +23,9 @@ export interface MessageTemplateItemOutputParent { readonly name: string; /** The template's language, in the ISO 639 format, consist of a two-letter language code followed by an optional two-letter country code, e.g., 'en' or 'en_US'. */ language: string; - /** - * The aggregated template status. - * - * Possible values: "approved", "rejected", "pending", "paused" - */ - status: string; - kind: string; + /** The aggregated template status. */ + status: MessageTemplateStatusOutput; + kind: CommunicationMessagesChannelOutput; } /** The WhatsApp-specific template response contract */ @@ -58,3 +45,12 @@ export type MessageTemplateItemOutput = export type RepeatabilityResultOutput = "accepted" | "rejected"; /** Paged collection of MessageTemplateItem items */ export type PagedMessageTemplateItemOutput = Paged; +/** Alias for MessageTemplateStatusOutput */ +export type MessageTemplateStatusOutput = + | string + | "approved" + | "rejected" + | "pending" + | "paused"; +/** Alias for CommunicationMessagesChannelOutput */ +export type CommunicationMessagesChannelOutput = string | "whatsApp"; diff --git a/sdk/communication/communication-messages-rest/src/generated/src/paginateHelper.ts b/sdk/communication/communication-messages-rest/src/paginateHelper.ts similarity index 100% rename from sdk/communication/communication-messages-rest/src/generated/src/paginateHelper.ts rename to sdk/communication/communication-messages-rest/src/paginateHelper.ts diff --git a/sdk/communication/communication-messages-rest/src/generated/src/parameters.ts b/sdk/communication/communication-messages-rest/src/parameters.ts similarity index 94% rename from sdk/communication/communication-messages-rest/src/generated/src/parameters.ts rename to sdk/communication/communication-messages-rest/src/parameters.ts index 304bc53ff1d6..4b0e1a9ddebf 100644 --- a/sdk/communication/communication-messages-rest/src/generated/src/parameters.ts +++ b/sdk/communication/communication-messages-rest/src/parameters.ts @@ -3,7 +3,7 @@ import { RawHttpHeadersInput } from "@azure/core-rest-pipeline"; import { RequestParameters } from "@azure-rest/core-client"; -import { NotificationContent } from "./models"; +import { NotificationContent } from "./models.js"; export interface GetMediaHeaders { /** An opaque, globally-unique, client-generated string identifier for the request. */ @@ -26,7 +26,8 @@ export interface SendHeaders { } export interface SendBodyParam { - body?: NotificationContent; + /** Body parameter. */ + body: NotificationContent; } export interface SendHeaderParam { diff --git a/sdk/communication/communication-messages-rest/src/generated/src/responses.ts b/sdk/communication/communication-messages-rest/src/responses.ts similarity index 98% rename from sdk/communication/communication-messages-rest/src/generated/src/responses.ts rename to sdk/communication/communication-messages-rest/src/responses.ts index 405592b5e00b..ab5c33ce14cb 100644 --- a/sdk/communication/communication-messages-rest/src/generated/src/responses.ts +++ b/sdk/communication/communication-messages-rest/src/responses.ts @@ -7,7 +7,7 @@ import { RepeatabilityResultOutput, SendMessageResultOutput, PagedMessageTemplateItemOutput, -} from "./outputModels"; +} from "./outputModels.js"; export interface GetMedia200Headers { /** An opaque, globally-unique, client-generated string identifier for the request. */ diff --git a/sdk/communication/communication-messages-rest/test/public/sampleTest.spec.ts b/sdk/communication/communication-messages-rest/test/public/sampleTest.spec.ts new file mode 100644 index 000000000000..344657d6f17e --- /dev/null +++ b/sdk/communication/communication-messages-rest/test/public/sampleTest.spec.ts @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { createRecorder } from "./utils/recordedClient.js"; +import { assert, beforeEach, afterEach, it, describe } from "vitest"; + +describe("My test", () => { + // let recorder: Recorder; + + beforeEach(async function () { + // recorder = await createRecorder(this); + }); + + afterEach(async function () { + // await recorder.stop(); + }); + + it("sample test", async function () { + assert.equal(1, 1); + }); +}); diff --git a/sdk/communication/communication-messages-rest/test/public/utils/recordedClient.ts b/sdk/communication/communication-messages-rest/test/public/utils/recordedClient.ts index 9a8780971948..6cc58bc15e11 100644 --- a/sdk/communication/communication-messages-rest/test/public/utils/recordedClient.ts +++ b/sdk/communication/communication-messages-rest/test/public/utils/recordedClient.ts @@ -1,53 +1,20 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Context, Test } from "mocha"; -import { Recorder, RecorderStartOptions, SanitizerOptions, env } from "@azure-tools/test-recorder"; -import MessageClient, { MessagesServiceClient } from "../../../src"; -import { parseConnectionString } from "@azure/communication-common"; -import { TokenCredential } from "@azure/core-auth"; -import { createTestCredential } from "@azure-tools/test-credential"; - -export interface RecordedMessageClient { - client: MessagesServiceClient; - recorder: Recorder; -} +import { Context } from "mocha"; +import { Recorder, RecorderStartOptions } from "@azure-tools/test-recorder"; +import "./env"; const envSetupForPlayback: Record = { - COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING: - "endpoint=https://someEndpoint/;accesskey=someAccessKeyw==", - CHANNEL_ID: "test_channel_id", - RECIPIENT_PHONE_NUMBER: "+14255550123", + ENDPOINT: "https://endpoint", AZURE_CLIENT_ID: "azure_client_id", AZURE_CLIENT_SECRET: "azure_client_secret", AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", -}; - -const sanitizerOptions: SanitizerOptions = { - connectionStringSanitizers: [ - { - actualConnString: env.COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING, - fakeConnString: envSetupForPlayback["COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING"], - }, - ], - generalSanitizers: [ - { regex: true, target: `"access_token"\\s?:\\s?"[^"]*"`, value: `"access_token":"sanitized"` }, - { - regex: true, - target: `"repeatabilityRequestId"\\s?:\\s?"[^"]*"`, - value: `"repeatabilityRequestId":"sanitized"`, - }, - { - regex: true, - target: `"repeatabilityFirstSent"\\s?:\\s?"[^"]*"`, - value: `"repeatabilityFirstSent":"Thu, 01 Jan 1970 00:00:00 GMT"`, - }, - ], + SUBSCRIPTION_ID: "azure_subscription_id", }; const recorderEnvSetup: RecorderStartOptions = { envSetupForPlayback, - sanitizerOptions: sanitizerOptions, }; /** @@ -55,43 +22,8 @@ const recorderEnvSetup: RecorderStartOptions = { * Should be called first in the test suite to make sure environment variables are * read before they are being used. */ -export async function createRecorder(context: Test | undefined): Promise { - const recorder = new Recorder(context); +export async function createRecorder(context: Context): Promise { + const recorder = new Recorder(context.currentTest); await recorder.start(recorderEnvSetup); - await recorder.setMatcher("CustomDefaultMatcher", { - excludedHeaders: [ - "Accept-Language", // This is env-dependent - "x-ms-content-sha256", // This is dependent on the current datetime - "sec-ch-ua", // This is browser dependent - // https://developer.mozilla.org/docs/Web/HTTP/Headers/Sec-CH-UA - ], - }); return recorder; } - -export async function createRecorderWithToken(context: Context): Promise { - const recorder = await createRecorder(context.currentTest); - - const credential: TokenCredential = createTestCredential(); - const endpoint = parseConnectionString( - env.COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING ?? "", - ).endpoint; - - return { - client: MessageClient(endpoint, credential, recorder.configureClientOptions({})), - recorder, - }; -} - -export async function createRecorderWithConnectionString( - context: Context, -): Promise { - const recorder = await createRecorder(context.currentTest); - - const client = MessageClient( - env.COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING ?? "", - recorder.configureClientOptions({}), - ); - - return { client, recorder }; -} diff --git a/sdk/communication/communication-messages-rest/tsconfig.json b/sdk/communication/communication-messages-rest/tsconfig.json index 331b03eb9cd9..4666d8f33037 100644 --- a/sdk/communication/communication-messages-rest/tsconfig.json +++ b/sdk/communication/communication-messages-rest/tsconfig.json @@ -4,8 +4,14 @@ "outDir": "./dist-esm", "declarationDir": "./types", "paths": { - "@azure-rest/communication-messages": ["./src/index"] + "@azure-rest/communication-messages": [ + "./src/index" + ] } }, - "include": ["src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] -} + "include": [ + "src/**/*.ts", + "./test/**/*.ts", + "samples-dev/**/*.ts" + ] +} \ No newline at end of file diff --git a/sdk/communication/communication-messages-rest/tsp-location.yaml b/sdk/communication/communication-messages-rest/tsp-location.yaml index 786cc1bd3d15..15249fca6e91 100644 --- a/sdk/communication/communication-messages-rest/tsp-location.yaml +++ b/sdk/communication/communication-messages-rest/tsp-location.yaml @@ -1,4 +1,5 @@ directory: specification/communication/Communication.Messages -commit: c1a6baa03bc5861ade8be93e4ad0a7673732ad2d repo: Azure/azure-rest-api-specs -additionalDirectories: \ No newline at end of file +commit: 228acac22c34fa19cd629ba2df005822ab8ba959 +additionalDirectories: [] +