diff --git a/libraries/botbuilder-ai/package.json b/libraries/botbuilder-ai/package.json index 19da60fb88..b55451f3fc 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.0.0" }, "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..51934d95e2 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.0.0", "@azure/core-http": "^3.0.2" }, "scripts": { diff --git a/libraries/botbuilder-core/package.json b/libraries/botbuilder-core/package.json index d7d3fd3ceb..6994525e2c 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.0.0" }, "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; diff --git a/yarn.lock b/yarn.lock index 72190516e9..103e19a30e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14177,6 +14177,11 @@ z-schema@~3.18.3: optionalDependencies: commander "^2.7.1" +zod@^3.0.0: + version "3.22.4" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" + integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg== + zod@~1.11.17: version "1.11.17" resolved "https://registry.yarnpkg.com/zod/-/zod-1.11.17.tgz#2aae9e91fc66128116ae9844e8f416a95f453f8e"