diff --git a/libraries/botbuilder-ai/package.json b/libraries/botbuilder-ai/package.json index 19da60fb88..4691e52198 100644 --- a/libraries/botbuilder-ai/package.json +++ b/libraries/botbuilder-ai/package.json @@ -37,7 +37,7 @@ "lodash": "^4.17.21", "node-fetch": "^2.6.7", "url-parse": "^1.5.9", - "zod": "~1.11.17" + "zod": "^3.22.4" }, "resolutions": { "follow-redirects": "1.14.7" diff --git a/libraries/botbuilder-ai/src/luisRecognizer.ts b/libraries/botbuilder-ai/src/luisRecognizer.ts index f5d218fb40..14a0647247 100644 --- a/libraries/botbuilder-ai/src/luisRecognizer.ts +++ b/libraries/botbuilder-ai/src/luisRecognizer.ts @@ -243,7 +243,7 @@ export interface LuisRecognizerOptionsV2 extends LuisRecognizerOptions { // This is just meant to operate as a simple type assertion. const UnsafeLuisRecognizerUnion = z.custom( (val: unknown): val is LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2 | LuisPredictionOptions => - z.record(z.unknown()).check(val), + z.record(z.unknown()).safeParse(val).success, { message: 'LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2 | LuisPredictionOptions', } diff --git a/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts b/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts index 549207731e..dd8c5c1ee7 100644 --- a/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts +++ b/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts @@ -110,14 +110,13 @@ export class LuisRecognizerV3 extends LuisRecognizerInternal { const values: unknown[] = Array.isArray(value) ? value : []; if (instances?.length === values?.length) { instances.forEach((childInstance) => { - if ( - z - .object({ startIndex: z.number(), endIndex: z.number() }) - .nonstrict() - .check(childInstance) - ) { - const start = childInstance.startIndex; - const end = childInstance.endIndex; + const childInstanceParsed = z + .object({ startIndex: z.number(), endIndex: z.number() }) + .nonstrict() + .safeParse(childInstance); + if (childInstanceParsed.success) { + const start = childInstanceParsed.data.startIndex; + const end = childInstanceParsed.data.endIndex; externalEntities.push({ entityName: key, startIndex: start, diff --git a/libraries/botbuilder-ai/src/qnaMakerDialog.ts b/libraries/botbuilder-ai/src/qnaMakerDialog.ts index a7d624197e..bb55911565 100644 --- a/libraries/botbuilder-ai/src/qnaMakerDialog.ts +++ b/libraries/botbuilder-ai/src/qnaMakerDialog.ts @@ -448,17 +448,21 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon if (top) { this.top = new IntExpression(top); } - - if (qnaSuggestionsActivityFactory.check(activeLearningTitleOrFactory)) { + const qnaSuggestionsActivityFactoryParsed = qnaSuggestionsActivityFactory.safeParse( + activeLearningTitleOrFactory + ); + if (qnaSuggestionsActivityFactoryParsed.success) { if (!cardNoMatchText) { // Without a developer-provided cardNoMatchText, the end user will not be able to tell the convey to the bot and QnA Maker that the suggested alternative questions were not correct. // When the user's reply to a suggested alternatives Activity matches the cardNoMatchText, the QnAMakerDialog sends this information to the QnA Maker service for active learning. throw new Error('cardNoMatchText is required when using the suggestionsActivityFactory.'); } - this.suggestionsActivityFactory = activeLearningTitleOrFactory; + this.suggestionsActivityFactory = qnaSuggestionsActivityFactoryParsed.data; } else { - this.activeLearningCardTitle = new StringExpression(activeLearningTitleOrFactory ?? this.defaultCardTitle); + this.activeLearningCardTitle = new StringExpression( + activeLearningTitleOrFactory?.toString() ?? this.defaultCardTitle + ); } if (cardNoMatchText) { diff --git a/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js b/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js index 972b64f3b8..77d9db5f5f 100644 --- a/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js +++ b/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js @@ -504,8 +504,9 @@ describe('QnAMakerDialog', function () { await rejects( adapter.send('QnaMaker_TopNAnswer.json').startTest(), (thrown) => - thrown.message.includes('invalid_type at message') && - thrown.message.includes('Expected object, received number') + thrown.message.includes('invalid_type') && + thrown.message.includes('"expected": "object"') && + thrown.message.includes('"received": "number"') ); }); @@ -544,7 +545,7 @@ describe('QnAMakerDialog', function () { await rejects( adapter.send('QnaMaker_TopNAnswer.json').startTest(), - (thrown) => thrown.message.includes('invalid_type at message') && thrown.message.includes('Required') + (thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required') ); sandbox.verify(); @@ -586,7 +587,7 @@ describe('QnAMakerDialog', function () { await rejects( adapter.send('QnaMaker_TopNAnswer.json').startTest(), - (thrown) => thrown.message.includes('invalid_type at message') && thrown.message.includes('Required') + (thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required') ); sandbox.verify(); diff --git a/libraries/botbuilder-azure-blobs/package.json b/libraries/botbuilder-azure-blobs/package.json index 64092a0a8d..1b6b9447ff 100644 --- a/libraries/botbuilder-azure-blobs/package.json +++ b/libraries/botbuilder-azure-blobs/package.json @@ -32,7 +32,7 @@ "botbuilder-stdlib": "4.1.6", "get-stream": "^6.0.0", "p-map": "^4.0.0", - "zod": "~1.11.17", + "zod": "^3.22.4", "@azure/core-http": "^3.0.2" }, "scripts": { diff --git a/libraries/botbuilder-core/etc/botbuilder-core.api.md b/libraries/botbuilder-core/etc/botbuilder-core.api.md index 4c1b37e4a3..27644b195b 100644 --- a/libraries/botbuilder-core/etc/botbuilder-core.api.md +++ b/libraries/botbuilder-core/etc/botbuilder-core.api.md @@ -52,7 +52,7 @@ import * as z from 'zod'; // @public export class ActivityFactory { static fromObject(lgResult: any): Partial; - } +} // @public export class ActivityHandler extends ActivityHandlerBase { @@ -191,7 +191,7 @@ export abstract class BotComponent { // (undocumented) abstract configureServices(services: ServiceCollection, configuration: Configuration): void; // (undocumented) - static z: z.ZodType; + static z: z.ZodType; } export { BotFrameworkClient } @@ -342,7 +342,7 @@ export abstract class CloudAdapterBase extends BotAdapter { export class ComponentRegistration { static add(componentRegistration: ComponentRegistration): void; static get components(): ComponentRegistration[]; - } +} // @public export class ConfigurationBotFrameworkAuthentication extends BotFrameworkAuthentication { @@ -353,7 +353,7 @@ export class ConfigurationBotFrameworkAuthentication extends BotFrameworkAuthent createBotFrameworkClient(): BotFrameworkClient; createConnectorFactory(claimsIdentity: ClaimsIdentity): ConnectorFactory; createUserTokenClient(claimsIdentity: ClaimsIdentity): Promise; - } +} // Warning: (ae-forgotten-export) The symbol "TypedOptions" needs to be exported by the entry point index.d.ts // @@ -385,7 +385,7 @@ export class ConsoleTranscriptLogger implements TranscriptLogger { export class ConversationState extends BotState { constructor(storage: Storage_2, namespace?: string); getStorageKey(context: TurnContext): string | undefined; - } +} // @public export interface CoreAppCredentials { @@ -436,7 +436,7 @@ export const INVOKE_RESPONSE_KEY: unique symbol; export class InvokeException extends Error { constructor(status: StatusCodes, response?: T); createInvokeResponse(): InvokeResponse; - } +} export { InvokeResponse } @@ -473,7 +473,7 @@ export class MemoryTranscriptStore implements TranscriptStore { getTranscriptActivities(channelId: string, conversationId: string, continuationToken?: string, startDate?: Date): Promise>; listTranscripts(channelId: string, continuationToken?: string): Promise>; logActivity(activity: Activity): void | Promise; - } +} // @public export class MessageFactory { @@ -528,7 +528,7 @@ export interface PagedResult { export class PrivateConversationState extends BotState { constructor(storage: Storage_2, namespace?: string); getStorageKey(context: TurnContext): string | undefined; - } +} // @public export interface PropertyManager { @@ -577,7 +577,7 @@ export enum Severity { export class ShowTypingMiddleware implements Middleware { constructor(delay?: number, period?: number); onTurn(context: TurnContext, next: () => Promise): Promise; - } +} // @public export class SkillConversationIdFactory extends SkillConversationIdFactoryBase { @@ -585,7 +585,7 @@ export class SkillConversationIdFactory extends SkillConversationIdFactoryBase { createSkillConversationIdWithOptions(options: SkillConversationIdFactoryOptions): Promise; deleteConversationReference(skillConversationId: string): Promise; getSkillConversationReference(skillConversationId: string): Promise; - } +} // @public export abstract class SkillConversationIdFactoryBase { @@ -638,7 +638,6 @@ interface Storage_2 { read(keys: string[]): Promise; write(changes: StoreItems): Promise; } - export { Storage_2 as Storage } // @public @@ -730,7 +729,7 @@ export class TelemetryLoggerMiddleware implements Middleware { onTurn(context: TurnContext, next: () => Promise): Promise; protected onUpdateActivity(activity: Activity): Promise; get telemetryClient(): BotTelemetryClient; - } +} // @public (undocumented) export interface TelemetryPageView { @@ -805,7 +804,7 @@ export class TestAdapter extends BotAdapter implements ExtendedUserTokenProvider testActivities(activities: Partial[], description?: string, timeout?: number): TestFlow; throwOnExchangeRequest(connectionName: string, channelId: string, userId: string, exchangeableItem: string): void; updateActivity(context: TurnContext, activity: Partial): Promise; - } +} // @public export class TestFlow { @@ -856,7 +855,7 @@ export interface TranscriptLogger { export class TranscriptLoggerMiddleware implements Middleware { constructor(logger: TranscriptLogger); onTurn(context: TurnContext, next: () => Promise): Promise; - } +} // @public export interface TranscriptStore extends TranscriptLogger { @@ -918,7 +917,7 @@ export function useBotState(botAdapter: BotAdapter, ...botStates: BotState[]): B export class UserState extends BotState { constructor(storage: Storage_2, namespace?: string); getStorageKey(context: TurnContext): string | undefined; - } +} // @public export const verifyStateOperationName = "signin/verifyState"; diff --git a/libraries/botbuilder-core/package.json b/libraries/botbuilder-core/package.json index d7d3fd3ceb..5f3de44df3 100644 --- a/libraries/botbuilder-core/package.json +++ b/libraries/botbuilder-core/package.json @@ -32,7 +32,7 @@ "botframework-connector": "4.1.6", "botframework-schema": "4.1.6", "uuid": "^8.3.2", - "zod": "~1.11.17" + "zod": "^3.22.4" }, "devDependencies": { "@microsoft/bf-chatdown": "^4.15.0", diff --git a/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts b/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts index d195f02ce4..b13b4174f5 100644 --- a/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts +++ b/libraries/botbuilder-core/src/configurationBotFrameworkAuthentication.ts @@ -173,7 +173,7 @@ export class ConfigurationBotFrameworkAuthentication extends BotFrameworkAuthent ); } catch (err) { // Throw a new error with the validation details prominently featured. - if (z.instanceof(z.ZodError).check(err)) { + if (z.instanceof(z.ZodError).safeParse(err).success) { throw new Error(JSON.stringify(err.errors, null, 2)); } throw err;