Skip to content

Commit 07ba55e

Browse files
feat(zui): revamp the API for simpler type manipulation (botpress#14947)
2 parents f7ef99a + c339853 commit 07ba55e

299 files changed

Lines changed: 6574 additions & 7330 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ tilt_config.json
1919
hubspot.config.yml
2020
AGENTS.md
2121
CLAUDE.md
22+
.claude

integrations/browser/integration.definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IntegrationDefinition } from '@botpress/sdk'
33
import { actionDefinitions } from 'src/definitions/actions'
44

55
export const INTEGRATION_NAME = 'browser'
6-
export const INTEGRATION_VERSION = '0.8.4'
6+
export const INTEGRATION_VERSION = '0.8.5'
77

88
export default new IntegrationDefinition({
99
name: INTEGRATION_NAME,

integrations/browser/src/actions/discover-urls.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RuntimeError } from '@botpress/client'
2-
import { IntegrationLogger, z, ZodIssueCode } from '@botpress/sdk'
2+
import { IntegrationLogger, z } from '@botpress/sdk'
33
import Firecrawl, { SdkError } from '@mendable/firecrawl-js'
44
import { trackEvent } from '../tracking'
55
import { isValidGlob, matchGlob } from '../utils/globs'
@@ -11,37 +11,36 @@ const COST_PER_FIRECRAWL_MAP = 0.001
1111

1212
type 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-zA-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

integrations/calendly/integration.definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { inviteeEventOutputSchema } from 'definitions/events'
55
export default new IntegrationDefinition({
66
name: 'calendly',
77
title: 'Calendly',
8-
version: '0.0.2',
8+
version: '0.0.3',
99
readme: 'hub.md',
1010
icon: 'icon.svg',
1111
description: 'Schedule meetings and manage events using the Calendly scheduling platform.',

integrations/calendly/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { RuntimeError, ZodError } from '@botpress/sdk'
1+
import { RuntimeError, z } from '@botpress/sdk'
22
import axios from 'axios'
33
import type { Result } from './types'
44

5-
const _isZodError = (error: any): error is ZodError => {
6-
return error && typeof error === 'object' && error instanceof ZodError && 'errors' in error
5+
const _isZodError = (error: any): error is z.ZodError => {
6+
return error && typeof error === 'object' && z.is.zuiError(error) && 'errors' in error
77
}
88

99
export function parseError(thrown: unknown): RuntimeError {

integrations/github/integration.definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { actions, events, configuration, configurations, channels, user, secrets
77
export default new sdk.IntegrationDefinition({
88
name: INTEGRATION_NAME,
99
title: 'GitHub',
10-
version: '1.1.8',
10+
version: '1.1.9',
1111
icon: 'icon.svg',
1212
readme: 'hub.md',
1313
description: 'Manage GitHub issues, pull requests, and repositories.',

integrations/github/src/definitions/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { z, ZodTypeAny } from '@botpress/sdk'
1+
import { z } from '@botpress/sdk'
22
import * as sdk from '@botpress/sdk'
33
import { Issue, PullRequest, User, PullRequestReview } from './entities'
44

55
const COMMON_EVENT_FIELDS = {
66
sender: {
77
eventSender: User.title('Sender').describe('The user who triggered the event'),
88
},
9-
} as const satisfies Record<string, Record<string, ZodTypeAny>>
9+
} as const satisfies Record<string, Record<string, z.ZodTypeAny>>
1010

1111
const pullRequestOpened = {
1212
title: 'Pull Request opened',

integrations/github/src/definitions/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z, ZodRawShape } from '@botpress/sdk'
1+
import { z } from '@botpress/sdk'
22
import * as sdk from '@botpress/sdk'
33

44
export { actions } from './actions'
@@ -23,7 +23,7 @@ const webhookSecret = {
2323
.describe(
2424
'A high-entropy string that only you and Botpress know. Must be set to the same value as in the GitHub organization settings.'
2525
),
26-
} as const satisfies ZodRawShape
26+
} as const satisfies z.ZodRawShape
2727

2828
export const configurations = {
2929
manualApp: {

integrations/mailchimp/integration.definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const INTEGRATION_NAME = 'mailchimp'
1616
export default new IntegrationDefinition({
1717
name: INTEGRATION_NAME,
1818
title: 'Mailchimp',
19-
version: '0.3.10',
19+
version: '0.3.11',
2020
readme: 'hub.md',
2121
icon: 'icon.svg',
2222
description: 'Send mass email campaigns from within your workflows. Manage customers, campaigns, lists and more.',

integrations/mailchimp/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ZodError, RuntimeError } from '@botpress/sdk'
1+
import { RuntimeError, z } from '@botpress/sdk'
22
import { MailchimpApi } from './client'
33
import { Customer, MailchimpAPIError } from './misc/custom-types'
44
import { Logger } from './misc/types'
@@ -27,8 +27,8 @@ export const isMailchimpError = (error: any): error is MailchimpAPIError => {
2727
return 'status' in error && 'response' in error && 'body' in error.response
2828
}
2929

30-
export const isZodError = (error: any): error is ZodError => {
31-
return error && typeof error === 'object' && error instanceof ZodError && 'errors' in error
30+
export const isZodError = (error: any): error is z.ZodError => {
31+
return error && typeof error === 'object' && z.is.zuiError(error) && 'errors' in error
3232
}
3333

3434
export const parseError = (error: any): RuntimeError => {

0 commit comments

Comments
 (0)