Skip to content

Commit

Permalink
fix: [#4204] Fix remaining eslint warnings - final issues (#4240)
Browse files Browse the repository at this point in the history
* Warnings fixed in botbuilder-ai-orchestrator

* Warnings in botbuilder fixed.

* Warnings fixed in adaptive-expressions

* Warnings fixed in botframework-connector

* Suggested changes applied.

* Documentation updated

* Additional warning fixed.

Co-authored-by: Emiliano Quiroga <emiliano.quiroga@7-11.com>
  • Loading branch information
sw-joelmut and Emiliano Quiroga authored Jun 15, 2022
1 parent e339a30 commit 4b1be03
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 21 deletions.
2 changes: 1 addition & 1 deletion libraries/adaptive-expressions/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../.eslintrc.json",
"plugins": ["only-warn"],
"ignorePatterns": ["**/generated/*"]
"ignorePatterns": ["**/generated/*", "expressionProperty.test.js"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export enum LabelType {
Intent = 1
}

// @public (undocumented)
// @public
class OrchestratorBotComponent extends BotComponent {
// (undocumented)
configureServices(services: ServiceCollection, _configuration: Configuration): void;
Expand Down
14 changes: 5 additions & 9 deletions libraries/botbuilder-ai-orchestrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@
}
},
"dependencies": {
"adaptive-expressions": "4.1.6",
"botbuilder-core": "4.1.6",
"botbuilder-dialogs": "4.1.6",
"botbuilder-dialogs-adaptive": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"botbuilder-dialogs-declarative": "4.1.6",
"@microsoft/orchestrator-core": "~4.14.3",
"uuid": "^8.3.2"
},
"peerDependencies": {
"botbuilder-dialogs-declarative": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6"
},
"devDependencies": {
"adaptive-expressions": "4.1.6",
"botbuilder-core": "4.1.6",
"botbuilder-dialogs": "4.1.6"
},
"scripts": {
"build": "tsc -b",
"build-docs": "typedoc --theme markdown --entryPoint botbuilder-ai-orchestrator --excludePrivate --includeDeclarations --ignoreCompilerErrors --module amd --out ..\\..\\doc\\botbuilder-ai-orchestrator .\\lib\\index.d.ts --hideGenerator --name \"Bot Builder SDK - Orchestrator\" --readme none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { ComponentDeclarativeTypes } from 'botbuilder-dialogs-declarative';
import { OrchestratorRecognizer } from './orchestratorRecognizer';
import { ServiceCollection, Configuration } from 'botbuilder-dialogs-adaptive-runtime-core';

/**
* Define component assets for Orchestrator.
*/
export class OrchestratorBotComponent extends BotComponent {
/**
* @param services Services collection.
* @param _configuration Configuration for the bot component.
*/
configureServices(services: ServiceCollection, _configuration: Configuration): void {
services.composeFactory<ComponentDeclarativeTypes[]>('declarativeTypes', (declarativeTypes) =>
declarativeTypes.concat({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
*/
readonly entityProperty = 'entityResult';

/**
* @param property The key of the conditional selector configuration.
* @returns The converter for the selector configuration.
*/
getConverter(property: keyof OrchestratorRecognizerConfiguration): Converter | ConverterFactory {
switch (property) {
case 'modelFolder':
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder/etc/botbuilder.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class HandoffEventNames {

// Warning: (ae-forgotten-export) The symbol "InterceptionMiddleware" needs to be exported by the entry point index.d.ts
//
// @public
// @public @deprecated
export class InspectionMiddleware extends InterceptionMiddleware {
constructor(inspectionState: InspectionState, userState?: UserState, conversationState?: ConversationState, credentials?: Partial<MicrosoftAppCredentials>);
protected inbound(turnContext: TurnContext, traceActivity: Partial<Activity>): Promise<any>;
Expand All @@ -278,7 +278,7 @@ export class InspectionMiddleware extends InterceptionMiddleware {
protected traceState(turnContext: TurnContext): Promise<any>;
}

// @public
// @public @deprecated
export class InspectionState extends BotState {
constructor(storage: Storage_2);
protected getStorageKey(_turnContext: TurnContext): string;
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder/src/inspectionMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ abstract class InterceptionMiddleware implements Middleware {
* @remarks
* InspectionMiddleware for emulator inspection of runtime Activities and BotState.
*
* @obsolete This class will be removed in a future version of the framework.
* @deprecated This class will be removed in a future version of the framework.
*/
export class InspectionMiddleware extends InterceptionMiddleware {
private static readonly command = '/INSPECT';
Expand Down Expand Up @@ -445,7 +445,7 @@ class InspectionSessionsByStatus {
* @remarks
* InspectionState for use by the InspectionMiddleware for emulator inspection of runtime Activities and BotState.
*
* @obsolete This class will be removed in a future version of the framework.
* @deprecated This class will be removed in a future version of the framework.
*/
export class InspectionState extends BotState {
/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder/src/teamsActivityHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function teamsGetChannelId(activity: Activity): string | null {
*/
export function teamsNotifyUser(
activity: Partial<Activity>,
alertInMeeting: boolean = false,
alertInMeeting = false,
externalResourceUrl?: string
): void {
validateActivity(activity);
Expand Down
8 changes: 8 additions & 0 deletions libraries/botframework-connector/src/auth/appCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export abstract class AppCredentials implements msrest.ServiceClientCredentials
* @param {Date} expiration? The expiration date after which this service url is not trusted anymore
*/
public static trustServiceUrl(serviceUrl: string, expiration?: Date): void;
/**
* Adds the host of service url to MicrosoftAppCredentials trusted hosts.
*/
public static trustServiceUrl(): void {
// no-op
}
Expand All @@ -130,6 +133,11 @@ export abstract class AppCredentials implements msrest.ServiceClientCredentials
* @returns {boolean} True if the host of the service url is trusted; False otherwise.
*/
public static isTrustedServiceUrl(serviceUrl: string): boolean;
/**
* Checks if the service url is for a trusted host or not.
*
* @returns True if the host of the service url is trusted; False otherwise.
*/
public static isTrustedServiceUrl(): boolean {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ export class BotFrameworkAuthenticationFactory {
connectorClientOptions?: ConnectorClientOptions
): BotFrameworkAuthentication;

/**
* @param maybeChannelService The Channel Service.
* @param maybeValidateAuthority The validate authority value to use.
* @param maybeToChannelFromBotLoginUrl The to Channel from bot login url.
* @param maybeToChannelFromBotOAuthScope The to Channel from bot oauth scope.
* @param maybeToBotFromChannelTokenIssuer The to bot from Channel Token Issuer.
* @param maybeOAuthUrl The oAuth url.
* @param maybeToBotFromChannelOpenIdMetadataUrl The to bot from Channel Open Id Metadata url.
* @param maybeToBotFromEmulatorOpenIdMetadataUrl The to bot from Emulator Open Id Metadata url.
* @param maybeCallerId The callerId set on on authenticated [Activities](xref:botframework-schema.Activity).
* @param maybeCredentialFactory The [ServiceClientCredentialsFactory](xref:botframework-connector.ServiceClientCredentialsFactory) to use to create credentials.
* @param maybeAuthConfiguration The [AuthenticationConfiguration](xref:botframework-connector.AuthenticationConfiguration) to use.
* @param maybeBotFrameworkClientFetch The fetch to use in BotFrameworkClient.
* @param maybeConnectorClientOptions The [ConnectorClientOptions](xref:botframework-connector.ConnectorClientOptions) to use when creating ConnectorClients.
* @returns A new [BotFrameworkAuthentication](xref:botframework-connector.BotFrameworkAuthentication) instance.
*/
static create(
maybeChannelService?: string,
maybeValidateAuthority?: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ const botFrameworkClientFetchImpl: typeof fetch = async (input, init) => {
} as Response;
};

// Internal
/**
* @internal
* Implementation of [BotFrameworkClient](xref:botframework-connector.BotFrameworkClient).
*/
export class BotFrameworkClientImpl implements BotFrameworkClient {
/**
* @param credentialsFactory A [ServiceClientCredentialsFactory](xref:botframework-connector.ServiceClientCredentialsFactory) instance.
* @param loginEndpoint The login url.
* @param botFrameworkClientFetch A custom Fetch implementation to be used in the [BotFrameworkClient](xref:botframework-connector.BotFrameworkClient).
*/
constructor(
private readonly credentialsFactory: ServiceClientCredentialsFactory,
private readonly loginEndpoint: string,
Expand All @@ -36,6 +44,16 @@ export class BotFrameworkClientImpl implements BotFrameworkClient {
ok(typeof botFrameworkClientFetch === 'function');
}

/**
* @template T The type of body in the InvokeResponse.
* @param fromBotId The MicrosoftAppId of the bot sending the activity.
* @param toBotId The MicrosoftAppId of the bot receiving the activity.
* @param toUrl The URL of the bot receiving the activity.
* @param serviceUrl The callback Url for the skill host.
* @param conversationId A conversation ID to use for the conversation with the skill.
* @param activity The Activity to send to forward.
* @returns {Promise<InvokeResponse<T>>} A promise representing the asynchronous operation.
*/
async postActivity<T>(
fromBotId: string,
toBotId: string,
Expand Down
5 changes: 5 additions & 0 deletions libraries/botframework-connector/src/auth/claimsIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class ClaimsIdentity {
*/
constructor(public readonly claims: Claim[], private readonly authenticationType?: string | boolean) {}

/**
* Returns authentication status.
*
* @returns True if is authenticated.
*/
public get isAuthenticated(): boolean {
if (typeof this.authenticationType === 'boolean') {
return this.authenticationType;
Expand Down
3 changes: 3 additions & 0 deletions libraries/botframework-connector/src/auth/connectorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import { ConnectorClient } from '../connectorApi/connectorClient';

/**
* A factory class used to create ConnectorClients with appropriate credentials for the current appId.
*/
export abstract class ConnectorFactory {
/**
* A factory method used to create [ConnectorClient](xref:botframework-connector.ConnectorClient) instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ export const USER_AGENT = `Microsoft-BotFramework/3.1 ${packageInfo.name}/${
packageInfo.version
} ${getDefaultUserAgentValue()} `;

// Internal
/**
* @internal
* Implementation of [ConnectorFactory](xref:botframework-connector.ConnectorFactory).
*/
export class ConnectorFactoryImpl extends ConnectorFactory {
/**
* @param appId The AppID.
* @param toChannelFromBotOAuthScope The to Channel from bot oauth scope.
* @param loginEndpoint The login url.
* @param validateAuthority The validate authority value to use.
* @param credentialFactory A ServiceClientCredentialsFactory to use.
* @param connectorClientOptions The [ConnectorClientOptions](xref:botframework-connector.ConnectorClientOptions) to use when creating ConnectorClients.
*/
constructor(
private readonly appId: string,
private readonly toChannelFromBotOAuthScope: string,
Expand All @@ -26,6 +37,11 @@ export class ConnectorFactoryImpl extends ConnectorFactory {
super();
}

/**
* @param serviceUrl The client's service URL.
* @param audience The audience to use for outbound communication. It will vary by cloud environment.
* @returns The new instance of the ConnectorClient class.
*/
async create(serviceUrl: string, audience?: string): Promise<ConnectorClient> {
// Use the credentials factory to create credentails specific to this particular cloud environment.
const credentials = await this.credentialFactory.createCredentials(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { StatusCodes } from 'botframework-schema';
* Licensed under the MIT License.
*/

/**
* Contains helper methods for verifying JWT endorsements.
*/
export class EndorsementsValidator {
/**
* Verify that the set of ChannelIds, which come from the incoming activities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ManagedIdentityAppCredentials } from './managedIdentityAppCredentials';
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
import { ok } from 'assert';

/*
/**
* A Managed Identity implementation of the [ServiceClientCredentialsFactory](xref:botframework-connector.ServiceClientCredentialsFactory) abstract class.
*/
export class ManagedIdentityServiceClientCredentialsFactory extends ServiceClientCredentialsFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,25 @@ function getAppId(claimsIdentity: ClaimsIdentity): string | undefined {
);
}

// Internal
/**
* @internal
* Parameterized [BotFrameworkAuthentication](xref:botframework-connector.BotFrameworkAuthentication) used to authenticate Bot Framework Protocol network calls within this environment.
*/
export class ParameterizedBotFrameworkAuthentication extends BotFrameworkAuthentication {
/**
* @param validateAuthority The validate authority value to use.
* @param toChannelFromBotLoginUrl The to Channel from bot login url.
* @param toChannelFromBotOAuthScope The to Channel from bot oauth scope.
* @param toBotFromChannelTokenIssuer The to bot from Channel Token Issuer.
* @param oAuthUrl The OAuth url.
* @param toBotFromChannelOpenIdMetadataUrl The to bot from Channel Open Id Metadata url.
* @param toBotFromEmulatorOpenIdMetadataUrl The to bot from Emulator Open Id Metadata url.
* @param callerId The callerId set on an authenticated [Activities](xref:botframework-schema.Activity).
* @param credentialsFactory The [ServiceClientCredentialsFactory](xref:botframework-connector.ServiceClientCredentialsFactory) to use to create credentials.
* @param authConfiguration The [AuthenticationConfiguration](xref:botframework-connector.AuthenticationConfiguration) to use.
* @param botFrameworkClientFetch The fetch to use in BotFrameworkClient.
* @param connectorClientOptions The [ConnectorClientOptions](xref:botframework-connector.ConnectorClientOptions) to use when creating ConnectorClients.
*/
constructor(
private readonly validateAuthority: boolean,
private readonly toChannelFromBotLoginUrl: string,
Expand All @@ -53,10 +70,19 @@ export class ParameterizedBotFrameworkAuthentication extends BotFrameworkAuthent
super();
}

/**
* Gets the originating audience from Bot OAuth scope.
*
* @returns The originating audience.
*/
getOriginatingAudience(): string {
return this.toChannelFromBotOAuthScope;
}

/**
* @param authHeader The http auth header received in the skill request.
* @returns The identity validation result.
*/
async authenticateChannelRequest(authHeader: string): Promise<ClaimsIdentity> {
if (!authHeader.trim()) {
const isAuthDisabled = await this.credentialsFactory.isAuthenticationDisabled();
Expand All @@ -76,6 +102,13 @@ export class ParameterizedBotFrameworkAuthentication extends BotFrameworkAuthent
return this.JwtTokenValidation_validateAuthHeader(authHeader, 'unknown', null);
}

/**
* Validate Bot Framework Protocol requests.
*
* @param activity The inbound Activity.
* @param authHeader The http auth header received in the skill request.
* @returns Promise with AuthenticateRequestResult.
*/
async authenticateRequest(activity: Activity, authHeader: string): Promise<AuthenticateRequestResult> {
const claimsIdentity = await this.JwtTokenValidation_authenticateRequest(activity, authHeader);

Expand All @@ -101,6 +134,13 @@ export class ParameterizedBotFrameworkAuthentication extends BotFrameworkAuthent
};
}

/**
* Validate Bot Framework Protocol requests.
*
* @param authHeader The http auth header received in the skill request.
* @param channelIdHeader The channel Id HTTP header.
* @returns Promise with AuthenticateRequestResult.
*/
async authenticateStreamingRequest(
authHeader: string,
channelIdHeader: string
Expand All @@ -118,6 +158,12 @@ export class ParameterizedBotFrameworkAuthentication extends BotFrameworkAuthent
return { audience: outboundAudience, callerId, claimsIdentity };
}

/**
* Creates the appropriate UserTokenClient instance.
*
* @param claimsIdentity The inbound Activity's ClaimsIdentity.
* @returns Promise with UserTokenClient instance.
*/
async createUserTokenClient(claimsIdentity: ClaimsIdentity): Promise<UserTokenClient> {
const appId = getAppId(claimsIdentity);
const credentials = await this.credentialsFactory.createCredentials(
Expand All @@ -130,6 +176,12 @@ export class ParameterizedBotFrameworkAuthentication extends BotFrameworkAuthent
return new UserTokenClientImpl(appId, credentials, this.oAuthUrl, this.connectorClientOptions);
}

/**
* Creates a ConnectorFactory that can be used to create ConnectorClients that can use credentials from this particular Cloud Environment.
*
* @param claimsIdentity The inbound Activity's ClaimsIdentity.
* @returns A ConnectorFactory.
*/
createConnectorFactory(claimsIdentity: ClaimsIdentity): ConnectorFactory {
return new ConnectorFactoryImpl(
getAppId(claimsIdentity),
Expand All @@ -140,6 +192,11 @@ export class ParameterizedBotFrameworkAuthentication extends BotFrameworkAuthent
);
}

/**
* Creates a BotFrameworkClient used for calling Skills.
*
* @returns A BotFrameworkClient instance to call Skills.
*/
createBotFrameworkClient(): BotFrameworkClient {
return new BotFrameworkClientImpl(
this.credentialsFactory,
Expand Down
Loading

0 comments on commit 4b1be03

Please sign in to comment.