11import { RuntimeError } from '@botpress/client'
2- import { IntegrationLogger , z , ZodIssueCode } from '@botpress/sdk'
2+ import { IntegrationLogger , z } from '@botpress/sdk'
33import Firecrawl , { SdkError } from '@mendable/firecrawl-js'
44import { trackEvent } from '../tracking'
55import { isValidGlob , matchGlob } from '../utils/globs'
@@ -11,37 +11,36 @@ const COST_PER_FIRECRAWL_MAP = 0.001
1111
1212type StopReason = Awaited < ReturnType < bp . IntegrationProps [ 'actions' ] [ 'discoverUrls' ] > > [ 'stopReason' ]
1313
14- export const urlSchema = z . string ( ) . transform ( ( url , ctx ) => {
14+ type ZodIssueCode = z . ZodIssue [ 'code' ]
15+
16+ export const urlSchema = z . string ( ) . downstream ( ( url ) => {
1517 url = url . trim ( )
1618 if ( ! url . includes ( '://' ) ) {
1719 url = `https://${ url } `
1820 }
1921 try {
2022 const x = new URL ( url )
2123 if ( x . protocol !== 'http:' && x . protocol !== 'https:' ) {
22- ctx . addIssue ( {
23- code : ZodIssueCode . custom ,
24+ return z . ERR ( {
25+ code : ' custom' satisfies ZodIssueCode ,
2426 message : 'Invalid protocol, only URLs starting with HTTP and HTTPS are supported' ,
2527 } )
26- return z . NEVER
2728 }
2829
2930 if ( ! / .\. [ a - z A - Z ] { 2 , } $ / . test ( x . hostname ) ) {
30- ctx . addIssue ( {
31- code : ZodIssueCode . custom ,
31+ return z . ERR ( {
32+ code : ' custom' satisfies ZodIssueCode ,
3233 message : 'Invalid TLD' ,
3334 } )
34- return z . NEVER
3535 }
3636 const pathName = x . pathname . endsWith ( '/' ) ? x . pathname . slice ( 0 , - 1 ) : x . pathname
37- return `${ x . origin } ${ pathName } ${ x . search ? x . search : '' } `
37+ return z . OK ( `${ x . origin } ${ pathName } ${ x . search ? x . search : '' } ` )
3838 } catch ( caught ) {
3939 const err = caught instanceof Error ? caught : new Error ( 'Unknown error while parsing URL' )
40- ctx . addIssue ( {
41- code : ZodIssueCode . custom ,
40+ return z . ERR ( {
41+ code : ' custom' satisfies ZodIssueCode ,
4242 message : 'Invalid URL: ' + err . message ,
4343 } )
44- return z . NEVER
4544 }
4645} )
4746
0 commit comments