Skip to content

Commit 7680326

Browse files
committed
fix(integrations): address v4 review findings
- wordpress: reject unparseable term IDs instead of dropping them, map date explicitly, type search ids as number | string - typeform: keep filename whitespace when building the file download URL - brex: reject a limit buffer percentage outside Brex's 0-100 integer range - calcom: type bookingUrl, hidden and ownerId on event type responses - tests: call tool builders through ToolConfig instead of a type assertion
1 parent 3a86662 commit 7680326

8 files changed

Lines changed: 45 additions & 14 deletions

File tree

‎apps/sim/blocks/blocks/calendly.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
22
import { CalendlyBlock } from '@/blocks/blocks/calendly'
33
import type { BlockToolParamsContext } from '@/blocks/types'
44
import { listEventTypesTool } from '@/tools/calendly/list_event_types'
5+
import type { ToolConfig } from '@/tools/types'
56

67
/**
78
* Assertions run against `{ ...inputs, ...mapper(inputs, context) }`, the shape both the canvas
@@ -17,9 +18,10 @@ describe('CalendlyBlock params mapper', () => {
1718
})
1819

1920
const eventTypesUrl = (params: Record<string, unknown>) => {
20-
const url = listEventTypesTool.request.url
21+
const tool: ToolConfig = listEventTypesTool
22+
const url = tool.request.url
2123
if (typeof url !== 'function') throw new Error('Expected a url builder')
22-
return url(params as Parameters<typeof url>[0])
24+
return url(params)
2325
}
2426

2527
it('lists all event types on the canvas when the Active Only switch was turned off', () => {

‎apps/sim/blocks/blocks/typeform.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TypeformV2Block } from '@/blocks/blocks/typeform'
33
import type { BlockToolParamsContext } from '@/blocks/types'
44
import { createFormTool } from '@/tools/typeform/create_form'
55
import { updateFormTool } from '@/tools/typeform/update_form'
6+
import type { ToolConfig } from '@/tools/types'
67

78
/**
89
* Assertions run against `{ ...inputs, ...mapper(inputs, context) }`, the shape both the canvas
@@ -18,15 +19,17 @@ describe('TypeformV2Block params mapper', () => {
1819
})
1920

2021
const patchBody = (params: Record<string, unknown>) => {
21-
const body = updateFormTool.request.body
22+
const tool: ToolConfig = updateFormTool
23+
const body = tool.request.body
2224
if (!body) throw new Error('Expected a body builder')
23-
return body(params as Parameters<typeof body>[0])
25+
return body(params)
2426
}
2527

2628
const createBody = (params: Record<string, unknown>) => {
27-
const body = createFormTool.request.body
29+
const tool: ToolConfig = createFormTool
30+
const body = tool.request.body
2831
if (!body) throw new Error('Expected a body builder')
29-
return body(params as Parameters<typeof body>[0])
32+
return body(params)
3033
}
3134

3235
it('sends patch operations a model passed as an array on a tool call', () => {

‎apps/sim/blocks/blocks/wordpress.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ export const WordPressBlock: BlockConfig = {
980980
status: params.status,
981981
excerpt: params.excerpt,
982982
slug: params.slug,
983+
date: params.date,
983984
categories: params.categories,
984985
tags: params.tags,
985986
featuredMedia: optionalNumber(params.featuredMedia),
@@ -993,6 +994,7 @@ export const WordPressBlock: BlockConfig = {
993994
status: params.status,
994995
excerpt: params.excerpt,
995996
slug: params.slug,
997+
date: params.date,
996998
categories: params.categories,
997999
tags: params.tags,
9981000
featuredMedia: optionalNumber(params.featuredMedia),
@@ -1031,6 +1033,7 @@ export const WordPressBlock: BlockConfig = {
10311033
status: params.status,
10321034
excerpt: params.excerpt,
10331035
slug: params.slug,
1036+
date: params.date,
10341037
parent: optionalNumber(params.parent),
10351038
menuOrder: optionalNumber(params.menuOrder),
10361039
featuredMedia: optionalNumber(params.featuredMedia),
@@ -1044,6 +1047,7 @@ export const WordPressBlock: BlockConfig = {
10441047
status: params.status,
10451048
excerpt: params.excerpt,
10461049
slug: params.slug,
1050+
date: params.date,
10471051
parent: optionalNumber(params.parent),
10481052
menuOrder: optionalNumber(params.menuOrder),
10491053
featuredMedia: optionalNumber(params.featuredMedia),

‎apps/sim/lib/internal/typeform/operations.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export interface TypeformOperationContext {
2424
signal?: AbortSignal
2525
}
2626

27-
/** Rejects dot segments (which `new URL` would resolve away) before they reach the authenticated request. */
27+
/**
28+
* Rejects dot segments (which `new URL` would resolve away) before they reach the authenticated request.
29+
* Returns the trimmed, encoded segment; a filename keeps its own whitespace, so it is encoded raw after this check.
30+
*/
2831
function typeformPathSegment(
2932
value: string,
3033
paramName: string,
@@ -41,7 +44,8 @@ function buildTypeformFileUrl(input: TypeformFilesParams): string {
4144
const formId = typeformPathSegment(input.formId, 'formId')
4245
const responseId = typeformPathSegment(input.responseId, 'responseId')
4346
const fieldId = typeformPathSegment(input.fieldId, 'fieldId')
44-
const filename = typeformPathSegment(input.filename, 'filename', { allowSeparators: true })
47+
typeformPathSegment(input.filename, 'filename', { allowSeparators: true })
48+
const filename = encodeURIComponent(input.filename)
4549
const url = new URL(
4650
`https://api.typeform.com/forms/${formId}/responses/${responseId}/fields/${fieldId}/files/${filename}`
4751
)

‎apps/sim/tools/brex/create_spend_limit.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ const DELIVERY = defineBrexKeyedSite(
1414
'a second card program of the same size would be created, doubling the spend the company has authorized'
1515
)
1616

17+
/** Brex accepts `limit_buffer_percentage` only as a 0-100 integer; reject anything else before the request. */
18+
function toLimitBufferPercentage(value: number): number {
19+
const percentage = Number(value)
20+
if (!Number.isInteger(percentage) || percentage < 0 || percentage > 100) {
21+
throw new Error('Limit buffer percentage must be a whole number from 0 to 100')
22+
}
23+
return percentage
24+
}
25+
1726
export const brexCreateSpendLimitTool: ToolConfig<
1827
BrexCreateSpendLimitParams & BrexDeliveryContextParams,
1928
BrexCreateSpendLimitResponse
@@ -194,7 +203,7 @@ export const brexCreateSpendLimitTool: ToolConfig<
194203
authorization_type: params.authorizationType,
195204
rollover_refresh_rate: params.rolloverRefreshRate,
196205
...(params.limitBufferPercentage !== undefined
197-
? { limit_buffer_percentage: params.limitBufferPercentage }
206+
? { limit_buffer_percentage: toLimitBufferPercentage(params.limitBufferPercentage) }
198207
: {}),
199208
},
200209
}

‎apps/sim/tools/calcom/types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ interface CalcomEventType {
300300
disableGuests: boolean
301301
createdAt: string
302302
updatedAt: string
303+
bookingUrl?: string
304+
hidden?: boolean
305+
ownerId?: number
303306
}
304307

305308
export interface CalcomCreateEventTypeResponse extends ToolResponse {

‎apps/sim/tools/wordpress/types.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ export interface WordPressSearchContentParams extends WordPressBaseParams {
586586
}
587587

588588
interface WordPressSearchResult {
589-
id: number
589+
/** Numeric for post and term results; post-format results are identified by their slug. */
590+
id: number | string
590591
title: string
591592
url: string
592593
type: string

‎apps/sim/tools/wordpress/utils.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ export function splitIdList(value: unknown): string[] {
77
return entries.map((entry) => String(entry).trim()).filter((entry) => entry.length > 0)
88
}
99

10-
/** {@link splitIdList}, parsed to integers with unparseable entries dropped. */
10+
/**
11+
* {@link splitIdList}, parsed to integers. Throws on an unparseable entry rather than dropping
12+
* it, since an emptied list would clear the post's existing terms on update.
13+
*/
1114
export function parseIdList(value: unknown): number[] {
12-
return splitIdList(value)
13-
.map((entry) => Number.parseInt(entry, 10))
14-
.filter((id) => !Number.isNaN(id))
15+
return splitIdList(value).map((entry) => {
16+
const id = Number.parseInt(entry, 10)
17+
if (Number.isNaN(id)) throw new Error(`Invalid WordPress term ID: "${entry}"`)
18+
return id
19+
})
1520
}

0 commit comments

Comments
 (0)