From ecb77e1c6758b5edd184c1375de3ef2021d03c5b Mon Sep 17 00:00:00 2001 From: Joel Mut <62260472+sw-joelmut@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:27:50 +0100 Subject: [PATCH] fix: [#4545] Please upgrade zod package - botbuilder (#4561) * update zod in botbuilder * change ts support in test consumer * fix ts config * simplify use of safeParse * fix lint --------- Co-authored-by: JhontSouth --- libraries/botbuilder/package.json | 2 +- .../botbuilder/src/botFrameworkAdapter.ts | 13 +- libraries/botbuilder/src/cloudAdapter.ts | 4 +- .../botbuilder/src/setSpeakMiddleware.ts | 19 +- .../teams/teamsSSOTokenExchangeMiddleware.ts | 6 +- .../botbuilder/tests/cloudAdapter.test.js | 2 +- libraries/botframework-connector/package.json | 2 +- .../etc/botframework-schema.api.md | 939 ++++++++++++++++++ libraries/botframework-schema/package.json | 2 +- libraries/botframework-schema/src/index.ts | 34 +- testing/botbuilder-test-utils/package.json | 2 +- 11 files changed, 989 insertions(+), 36 deletions(-) diff --git a/libraries/botbuilder/package.json b/libraries/botbuilder/package.json index 257891e736..ea8918c26e 100644 --- a/libraries/botbuilder/package.json +++ b/libraries/botbuilder/package.json @@ -40,7 +40,7 @@ "fs-extra": "^7.0.1", "htmlparser2": "^6.0.1", "uuid": "^8.3.2", - "zod": "~1.11.17" + "zod": "^3.22.4" }, "devDependencies": { "chai": "^4.2.0", diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index fb68810a4a..a5bbfd4afd 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -37,6 +37,7 @@ import { StatusCodes, TokenResponse, TurnContext, + conversationParametersObject, } from 'botbuilder-core'; import { @@ -391,7 +392,7 @@ export class BotFrameworkAdapter maybeLogic?: (context: TurnContext) => Promise ): Promise { let audience: string; - if (LogicT.check(oAuthScopeOrlogic)) { + if (LogicT.safeParse(oAuthScopeOrlogic).success) { // Because the OAuthScope parameter was not provided, get the correct value via the channelService. // In this scenario, the ConnectorClient for the continued conversation can only communicate with // official channels, not with other bots. @@ -401,8 +402,8 @@ export class BotFrameworkAdapter } else { audience = z.string().parse(oAuthScopeOrlogic); } - - const logic = LogicT.check(oAuthScopeOrlogic) ? oAuthScopeOrlogic : LogicT.parse(maybeLogic); + const logicParse = LogicT.safeParse(oAuthScopeOrlogic); + const logic = logicParse.success ? logicParse.data : LogicT.parse(maybeLogic); let credentials = this.credentials; @@ -510,10 +511,12 @@ export class BotFrameworkAdapter if (!reference.serviceUrl) { throw new Error('BotFrameworkAdapter.createConversation(): missing serviceUrl.'); } + const logicParse = LogicT.safeParse(parametersOrLogic); + const parameterParse = conversationParametersObject.partial().safeParse(parametersOrLogic); - const parameters = LogicT.check(parametersOrLogic) ? {} : parametersOrLogic; + const parameters = parameterParse.success ? parameterParse.data : {}; - const logic = LogicT.check(parametersOrLogic) ? parametersOrLogic : LogicT.parse(maybeLogic); + const logic = logicParse.success ? logicParse.data : LogicT.parse(maybeLogic); // Create conversation parameters, taking care to provide defaults that can be // overridden by passed in parameters diff --git a/libraries/botbuilder/src/cloudAdapter.ts b/libraries/botbuilder/src/cloudAdapter.ts index b31f3f41bb..bc64874df3 100644 --- a/libraries/botbuilder/src/cloudAdapter.ts +++ b/libraries/botbuilder/src/cloudAdapter.ts @@ -38,7 +38,7 @@ import { } from 'botframework-streaming'; // Note: this is _okay_ because we pass the result through `validateAndFixActivity`. Should not be used otherwise. -const ActivityT = z.custom((val) => z.record(z.unknown()).check(val), { message: 'Activity' }); +const ActivityT = z.custom((val) => z.record(z.unknown()).safeParse(val).success, { message: 'Activity' }); /** * An adapter that implements the Bot Framework Protocol and can be hosted in different cloud environmens both public and private. @@ -118,7 +118,7 @@ export class CloudAdapter extends CloudAdapterBase implements BotFrameworkHttpAd // Ensure we have a parsed request body already. We rely on express/restify middleware to parse // request body and azure functions, which does it for us before invoking our code. Warn the user // to update their code and return an error. - if (!z.record(z.unknown()).check(req.body)) { + if (!z.record(z.unknown()).safeParse(req.body).success) { return end( StatusCodes.BAD_REQUEST, '`req.body` not an object, make sure you are using middleware to parse incoming requests.' diff --git a/libraries/botbuilder/src/setSpeakMiddleware.ts b/libraries/botbuilder/src/setSpeakMiddleware.ts index 95988db0c7..78480d4c99 100644 --- a/libraries/botbuilder/src/setSpeakMiddleware.ts +++ b/libraries/botbuilder/src/setSpeakMiddleware.ts @@ -11,20 +11,19 @@ const supportedChannels = new Set([Channels.DirectlineSpeech, Channels.E function hasTag(tag: string, nodes: unknown[]): boolean { while (nodes.length) { const item = nodes.shift(); + const itemParsed = z + .object({ tagName: z.string(), children: z.array(z.unknown()) }) + .partial() + .nonstrict() + .safeParse(item); - if ( - z - .object({ tagName: z.string(), children: z.array(z.unknown()) }) - .partial() - .nonstrict() - .check(item) - ) { - if (item.tagName === tag) { + if (itemParsed.success) { + if (itemParsed.data.tagName === tag) { return true; } - if (item.children) { - nodes.push(...item.children); + if (itemParsed.data.children) { + nodes.push(...itemParsed.data.children); } } } diff --git a/libraries/botbuilder/src/teams/teamsSSOTokenExchangeMiddleware.ts b/libraries/botbuilder/src/teams/teamsSSOTokenExchangeMiddleware.ts index c93c79264f..76a8f8378e 100644 --- a/libraries/botbuilder/src/teams/teamsSSOTokenExchangeMiddleware.ts +++ b/libraries/botbuilder/src/teams/teamsSSOTokenExchangeMiddleware.ts @@ -144,6 +144,8 @@ export class TeamsSSOTokenExchangeMiddleware implements Middleware { const userTokenClient = context.turnState.get( (context.adapter as CloudAdapterBase).UserTokenClientKey ); + const exchangeToken = ExchangeToken.safeParse(context.adapter); + if (userTokenClient) { tokenExchangeResponse = await userTokenClient.exchangeToken( context.activity.from.id, @@ -151,8 +153,8 @@ export class TeamsSSOTokenExchangeMiddleware implements Middleware { context.activity.channelId, { token: tokenExchangeRequest.token } ); - } else if (ExchangeToken.check(context.adapter)) { - tokenExchangeResponse = await context.adapter.exchangeToken( + } else if (exchangeToken.success) { + tokenExchangeResponse = await exchangeToken.data.exchangeToken( context, this.oAuthConnectionName, context.activity.from.id, diff --git a/libraries/botbuilder/tests/cloudAdapter.test.js b/libraries/botbuilder/tests/cloudAdapter.test.js index ce5d42f430..013aa0fac4 100644 --- a/libraries/botbuilder/tests/cloudAdapter.test.js +++ b/libraries/botbuilder/tests/cloudAdapter.test.js @@ -257,7 +257,7 @@ describe('CloudAdapter', function () { describe('connectNamedPipe', function () { it('throws for bad args', async function () { const includesParam = (param) => (err) => { - assert(err.message.includes(`at ${param}`), err.message); + assert(err.message.includes(`${param}`), err.message); return true; }; diff --git a/libraries/botframework-connector/package.json b/libraries/botframework-connector/package.json index fb77db9772..5ca4e70ea1 100644 --- a/libraries/botframework-connector/package.json +++ b/libraries/botframework-connector/package.json @@ -37,7 +37,7 @@ "cross-fetch": "^3.0.5", "jsonwebtoken": "^9.0.0", "rsa-pem-from-mod-exp": "^0.8.4", - "zod": "~1.11.17" + "zod": "^3.22.4" }, "devDependencies": { "@types/jsonwebtoken": "8.3.5", diff --git a/libraries/botframework-schema/etc/botframework-schema.api.md b/libraries/botframework-schema/etc/botframework-schema.api.md index bc6d54d6a7..625d472f1b 100644 --- a/libraries/botframework-schema/etc/botframework-schema.api.md +++ b/libraries/botframework-schema/etc/botframework-schema.api.md @@ -5,6 +5,7 @@ ```ts import { AdaptiveCard } from 'adaptivecards'; +import * as z from 'zod'; // @public export type AceCardSize = 'Medium' | 'Large'; @@ -720,6 +721,944 @@ export interface ConversationParameters { topicName?: string; } +// @public (undocumented) +export const conversationParametersObject: z.ZodObject<{ + isGroup: z.ZodBoolean; + bot: z.ZodObject<{ + id: z.ZodString; + name: z.ZodString; + aadObjectId: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>; + members: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>, "many">>; + topicName: z.ZodOptional; + tenantId: z.ZodOptional; + activity: z.ZodObject<{ + type: z.ZodString; + id: z.ZodOptional; + timestamp: z.ZodOptional>; + localTimestamp: z.ZodOptional>; + localTimezone: z.ZodString; + callerId: z.ZodString; + serviceUrl: z.ZodString; + channelId: z.ZodString; + from: z.ZodObject<{ + id: z.ZodString; + name: z.ZodString; + aadObjectId: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>; + conversation: z.ZodObject<{ + isGroup: z.ZodBoolean; + conversationType: z.ZodString; + tenantId: z.ZodOptional; + id: z.ZodString; + name: z.ZodString; + aadObjectId: z.ZodOptional; + role: z.ZodOptional; + properties: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }, { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }>; + recipient: z.ZodObject<{ + id: z.ZodString; + name: z.ZodString; + aadObjectId: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>; + textFormat: z.ZodOptional; + attachmentLayout: z.ZodOptional; + membersAdded: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>, "many">>; + membersRemoved: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>, "many">>; + reactionsAdded: z.ZodOptional, "many">>; + reactionsRemoved: z.ZodOptional, "many">>; + topicName: z.ZodOptional; + historyDisclosed: z.ZodOptional; + locale: z.ZodOptional; + text: z.ZodString; + speak: z.ZodOptional; + inputHint: z.ZodOptional; + summary: z.ZodOptional; + suggestedActions: z.ZodOptional; + actions: z.ZodArray; + text: z.ZodOptional; + displayText: z.ZodOptional; + value: z.ZodUnknown; + channelData: z.ZodUnknown; + imageAltText: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }, { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }>, "many">; + }, "strip", z.ZodTypeAny, { + to?: string[]; + actions?: { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }[]; + }, { + to?: string[]; + actions?: { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }[]; + }>>; + attachments: z.ZodOptional; + content: z.ZodOptional; + name: z.ZodOptional; + thumbnailUrl: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + contentType?: string; + contentUrl?: string; + content?: unknown; + name?: string; + thumbnailUrl?: string; + }, { + contentType?: string; + contentUrl?: string; + content?: unknown; + name?: string; + thumbnailUrl?: string; + }>, "many">>; + entities: z.ZodOptional, Record, Record>, "many">>; + channelData: z.ZodOptional; + action: z.ZodOptional; + replyToId: z.ZodOptional; + label: z.ZodString; + valueType: z.ZodString; + value: z.ZodOptional; + name: z.ZodOptional; + relatesTo: z.ZodOptional; + user: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>>; + locale: z.ZodOptional; + bot: z.ZodObject<{ + id: z.ZodString; + name: z.ZodString; + aadObjectId: z.ZodOptional; + role: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }, { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }>; + conversation: z.ZodObject<{ + isGroup: z.ZodBoolean; + conversationType: z.ZodString; + tenantId: z.ZodOptional; + id: z.ZodString; + name: z.ZodString; + aadObjectId: z.ZodOptional; + role: z.ZodOptional; + properties: z.ZodOptional; + }, "strip", z.ZodTypeAny, { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }, { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }>; + channelId: z.ZodString; + serviceUrl: z.ZodString; + }, "strip", z.ZodTypeAny, { + ActivityId?: string; + user?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + locale?: string; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + channelId?: string; + serviceUrl?: string; + }, { + ActivityId?: string; + user?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + locale?: string; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + channelId?: string; + serviceUrl?: string; + }>>; + code: z.ZodOptional; + importance: z.ZodOptional; + deliveryMode: z.ZodOptional; + listenFor: z.ZodOptional>; + textHighlights: z.ZodOptional, "many">>; + semanticAction: z.ZodOptional, Record, Record>>; + }, "strip", z.ZodTypeAny, { + id?: string; + state?: string; + entities?: Record>; + }, { + id?: string; + state?: string; + entities?: Record>; + }>>; + }, "strip", z.ZodTypeAny, { + type?: string; + id?: string; + timestamp?: Date; + localTimestamp?: Date; + localTimezone?: string; + callerId?: string; + serviceUrl?: string; + channelId?: string; + from?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + recipient?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + textFormat?: string; + attachmentLayout?: string; + membersAdded?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + membersRemoved?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + reactionsAdded?: { + type?: string; + }[]; + reactionsRemoved?: { + type?: string; + }[]; + topicName?: string; + historyDisclosed?: boolean; + locale?: string; + text?: string; + speak?: string; + inputHint?: string; + summary?: string; + suggestedActions?: { + to?: string[]; + actions?: { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }[]; + }; + attachments?: { + contentType?: string; + contentUrl?: string; + content?: unknown; + name?: string; + thumbnailUrl?: string; + }[]; + entities?: Record[]; + channelData?: unknown; + action?: string; + replyToId?: string; + label?: string; + valueType?: string; + value?: unknown; + name?: string; + relatesTo?: { + ActivityId?: string; + user?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + locale?: string; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + channelId?: string; + serviceUrl?: string; + }; + code?: string; + importance?: string; + deliveryMode?: string; + listenFor?: string[]; + textHighlights?: { + text?: string; + occurrence?: number; + }[]; + semanticAction?: { + id?: string; + state?: string; + entities?: Record>; + }; + }, { + type?: string; + id?: string; + timestamp?: Date; + localTimestamp?: Date; + localTimezone?: string; + callerId?: string; + serviceUrl?: string; + channelId?: string; + from?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + recipient?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + textFormat?: string; + attachmentLayout?: string; + membersAdded?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + membersRemoved?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + reactionsAdded?: { + type?: string; + }[]; + reactionsRemoved?: { + type?: string; + }[]; + topicName?: string; + historyDisclosed?: boolean; + locale?: string; + text?: string; + speak?: string; + inputHint?: string; + summary?: string; + suggestedActions?: { + to?: string[]; + actions?: { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }[]; + }; + attachments?: { + contentType?: string; + contentUrl?: string; + content?: unknown; + name?: string; + thumbnailUrl?: string; + }[]; + entities?: Record[]; + channelData?: unknown; + action?: string; + replyToId?: string; + label?: string; + valueType?: string; + value?: unknown; + name?: string; + relatesTo?: { + ActivityId?: string; + user?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + locale?: string; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + channelId?: string; + serviceUrl?: string; + }; + code?: string; + importance?: string; + deliveryMode?: string; + listenFor?: string[]; + textHighlights?: { + text?: string; + occurrence?: number; + }[]; + semanticAction?: { + id?: string; + state?: string; + entities?: Record>; + }; + }>; + channelData: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + isGroup?: boolean; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + members?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + topicName?: string; + tenantId?: string; + activity?: { + type?: string; + id?: string; + timestamp?: Date; + localTimestamp?: Date; + localTimezone?: string; + callerId?: string; + serviceUrl?: string; + channelId?: string; + from?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + recipient?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + textFormat?: string; + attachmentLayout?: string; + membersAdded?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + membersRemoved?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + reactionsAdded?: { + type?: string; + }[]; + reactionsRemoved?: { + type?: string; + }[]; + topicName?: string; + historyDisclosed?: boolean; + locale?: string; + text?: string; + speak?: string; + inputHint?: string; + summary?: string; + suggestedActions?: { + to?: string[]; + actions?: { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }[]; + }; + attachments?: { + contentType?: string; + contentUrl?: string; + content?: unknown; + name?: string; + thumbnailUrl?: string; + }[]; + entities?: Record[]; + channelData?: unknown; + action?: string; + replyToId?: string; + label?: string; + valueType?: string; + value?: unknown; + name?: string; + relatesTo?: { + ActivityId?: string; + user?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + locale?: string; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + channelId?: string; + serviceUrl?: string; + }; + code?: string; + importance?: string; + deliveryMode?: string; + listenFor?: string[]; + textHighlights?: { + text?: string; + occurrence?: number; + }[]; + semanticAction?: { + id?: string; + state?: string; + entities?: Record>; + }; + }; + channelData?: unknown; +}, { + isGroup?: boolean; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + members?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + topicName?: string; + tenantId?: string; + activity?: { + type?: string; + id?: string; + timestamp?: Date; + localTimestamp?: Date; + localTimezone?: string; + callerId?: string; + serviceUrl?: string; + channelId?: string; + from?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + recipient?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + textFormat?: string; + attachmentLayout?: string; + membersAdded?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + membersRemoved?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }[]; + reactionsAdded?: { + type?: string; + }[]; + reactionsRemoved?: { + type?: string; + }[]; + topicName?: string; + historyDisclosed?: boolean; + locale?: string; + text?: string; + speak?: string; + inputHint?: string; + summary?: string; + suggestedActions?: { + to?: string[]; + actions?: { + type?: string; + title?: string; + image?: string; + text?: string; + displayText?: string; + value?: unknown; + channelData?: unknown; + imageAltText?: string; + }[]; + }; + attachments?: { + contentType?: string; + contentUrl?: string; + content?: unknown; + name?: string; + thumbnailUrl?: string; + }[]; + entities?: Record[]; + channelData?: unknown; + action?: string; + replyToId?: string; + label?: string; + valueType?: string; + value?: unknown; + name?: string; + relatesTo?: { + ActivityId?: string; + user?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + locale?: string; + bot?: { + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + }; + conversation?: { + isGroup?: boolean; + conversationType?: string; + tenantId?: string; + id?: string; + name?: string; + aadObjectId?: string; + role?: string; + properties?: unknown; + }; + channelId?: string; + serviceUrl?: string; + }; + code?: string; + importance?: string; + deliveryMode?: string; + listenFor?: string[]; + textHighlights?: { + text?: string; + occurrence?: number; + }[]; + semanticAction?: { + id?: string; + state?: string; + entities?: Record>; + }; + }; + channelData?: unknown; +}>; + // @public export interface ConversationReference { activityId?: string; diff --git a/libraries/botframework-schema/package.json b/libraries/botframework-schema/package.json index fab3d0030c..6b15e31049 100644 --- a/libraries/botframework-schema/package.json +++ b/libraries/botframework-schema/package.json @@ -28,7 +28,7 @@ }, "dependencies": { "uuid": "^8.3.2", - "zod": "~1.11.17", + "zod": "^3.22.4", "adaptivecards": "1.2.3" }, "scripts": { diff --git a/libraries/botframework-schema/src/index.ts b/libraries/botframework-schema/src/index.ts index ea98f9aa5e..019813f808 100644 --- a/libraries/botframework-schema/src/index.ts +++ b/libraries/botframework-schema/src/index.ts @@ -50,7 +50,7 @@ export function assertAttachmentView(val: unknown, ..._args: unknown[]): asserts * @internal */ export function isAttachmentView(val: unknown): val is AttachmentView { - return attachmentView.check(val); + return attachmentView.safeParse(val).success; } /** @@ -88,7 +88,7 @@ export function assertAttachmentInfo(val: unknown, ..._args: unknown[]): asserts * @internal */ export function isAttachmentInfo(val: unknown): val is AttachmentInfo { - return attachmentInfo.check(val); + return attachmentInfo.safeParse(val).success; } /** @@ -175,7 +175,7 @@ export function assertChannelAccount(val: unknown, ..._args: unknown[]): asserts * @internal */ export function isChannelAccount(val: unknown): val is ChannelAccount { - return channelAccount.check(val); + return channelAccount.safeParse(val).success; } /** @@ -241,7 +241,7 @@ export function assertConversationAccount(val: unknown, ..._args: unknown[]): as * @internal */ export function isConversationAccount(val: unknown): val is ConversationAccount { - return conversationAccount.check(val); + return conversationAccount.safeParse(val).success; } /** @@ -269,7 +269,7 @@ export function assertMessageReaction(val: unknown, ..._args: unknown[]): assert * @internal */ export function isMessageReaction(val: unknown): val is MessageReaction { - return messageReaction.check(val); + return messageReaction.safeParse(val).success; } /** @@ -334,7 +334,7 @@ export function assertCardAction(val: unknown, ..._args: unknown[]): asserts val * @internal */ export function isCardAction(val: unknown): val is CardAction { - return cardAction.check(val); + return cardAction.safeParse(val).success; } /** @@ -368,7 +368,7 @@ export function assertSuggestedActions(val: unknown, ..._args: unknown[]): asser * @internal */ export function isSuggestedActions(val: unknown): val is SuggestedActions { - return suggestedActions.check(val); + return suggestedActions.safeParse(val).success; } /** @@ -416,7 +416,7 @@ export function assertAttachment(val: unknown, ..._args: unknown[]): asserts val * @internal */ export function isAttachment(val: unknown): val is Attachment { - return attachment.check(val); + return attachment.safeParse(val).success; } /** @@ -446,7 +446,7 @@ export function assertEntity(val: unknown, ..._args: unknown[]): asserts val is * @internal */ export function isEntity(val: unknown): val is Entity { - return entity.check(val); + return entity.safeParse(val).success; } /** @@ -508,7 +508,7 @@ export function assertConversationReference(val: unknown, ..._args: unknown[]): * @internal */ export function isConversationReference(val: unknown): val is ConversationReference { - return conversationReference.check(val); + return conversationReference.safeParse(val).success; } /** @@ -565,7 +565,7 @@ export function assertSemanticAction(val: unknown, ..._args: unknown[]): asserts * @internal */ export function isSemanticAction(val: unknown): val is SemanticAction { - return semanticAction.check(val); + return semanticAction.safeParse(val).success; } /** @@ -816,7 +816,7 @@ export function assertActivity(val: unknown, ..._args: unknown[]): asserts val i * @internal */ export function isActivity(val: unknown): val is Activity { - return activity.check(val); + return activity.safeParse(val).success; } /** @@ -830,6 +830,16 @@ export interface ActivityTimestamps extends Activity { rawLocalTimestamp?: string; } +export const conversationParametersObject = z.object({ + isGroup: z.boolean(), + bot: channelAccount, + members: z.array(channelAccount).optional(), + topicName: z.string().optional(), + tenantId: z.string().optional(), + activity: activity, + channelData: z.unknown().optional(), +}); + /** * Parameters for creating a new conversation */ diff --git a/testing/botbuilder-test-utils/package.json b/testing/botbuilder-test-utils/package.json index 6ca188a747..aceecf314f 100644 --- a/testing/botbuilder-test-utils/package.json +++ b/testing/botbuilder-test-utils/package.json @@ -21,6 +21,6 @@ "dependencies": { "nanoid": "^3.1.31", "node-forge": "^1.3.0", - "zod": "~1.11.17" + "zod": "^3.22.4" } }