@@ -11,7 +11,7 @@ import {
1111 type ProviderProps ,
1212 type ProxyProps
1313} from 'react-chain-of-responsibility/preview' ;
14- import { array , function_ , safeParse , type InferOutput } from 'valibot' ;
14+ import { array , check , function_ , pipe , safeParse , type InferOutput } from 'valibot' ;
1515
1616const arrayOfFunctionSchema = array ( function_ ( ) ) ;
1717
@@ -35,6 +35,11 @@ function templatePolyMiddleware<Request, Props extends {}>(name: string) {
3535
3636 const middlewareFactoryMarker = Symbol ( ) ;
3737
38+ const middlewareSchema = pipe (
39+ function_ ( ) ,
40+ check ( value => middlewareFactoryMarker in value )
41+ ) ;
42+
3843 const createMiddleware = ( enhancer : TemplatedEnhancer ) : TemplatedMiddleware => {
3944 const factory : TemplatedMiddleware = init => ( init === name ? enhancer : BYPASS_ENHANCER ) ;
4045
@@ -57,15 +62,15 @@ function templatePolyMiddleware<Request, Props extends {}>(name: string) {
5762 return Object . freeze (
5863 middleware
5964 . map ( middleware => {
60- if ( ! ( middlewareFactoryMarker in middleware ) ) {
61- console . warn ( `botframework-webchat: ${ name } .middleware must be created via factory function` ) ;
65+ if ( ! safeParse ( middlewareSchema , middleware ) . success ) {
66+ console . warn ( `botframework-webchat: ${ name } .middleware must be created using its factory function` ) ;
6267
6368 return false ;
6469 }
6570
6671 const result = middleware ( name ) ;
6772
68- if ( typeof result !== 'function' && result ) {
73+ if ( typeof result !== 'function' && result !== false ) {
6974 console . warn ( `botframework-webchat: ${ name } .middleware must return enhancer function or false` ) ;
7075
7176 return false ;
0 commit comments