Skip to content

Commit a9fd4ca

Browse files
committed
fix(integrations): validate spotify, buffer
1 parent db05a26 commit a9fd4ca

37 files changed

Lines changed: 234 additions & 230 deletions

‎apps/docs/content/docs/integrations/buffer.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Create a post in Buffer for a channel — add it to the queue, share it immediat
270270
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
271271
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
272272
| ↳ `width` | number | VideoMetadata width |
273-
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
273+
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
274274
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
275275
| ↳ `text` | string | LinkAttachment text |
276276
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
@@ -601,7 +601,7 @@ Edit an existing Buffer post — update its text, schedule, or media. Attaching
601601
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
602602
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
603603
| ↳ `width` | number | VideoMetadata width |
604-
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
604+
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
605605
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
606606
| ↳ `text` | string | LinkAttachment text |
607607
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
@@ -924,7 +924,7 @@ List posts in a Buffer organization, optionally filtered by channel and status (
924924
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
925925
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
926926
| ↳ `width` | number | VideoMetadata width |
927-
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
927+
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
928928
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
929929
| ↳ `text` | string | LinkAttachment text |
930930
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
@@ -1222,7 +1222,7 @@ List posts in a Buffer organization, optionally filtered by channel and status (
12221222
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
12231223
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
12241224
| ↳ `width` | number | VideoMetadata width |
1225-
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
1225+
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
12261226
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
12271227
| ↳ `text` | string | LinkAttachment text |
12281228
| ↳ `thumbnail` | string | LinkAttachment thumbnail |
@@ -1542,7 +1542,7 @@ Get a single Buffer post by ID, including its status, schedule, and media
15421542
| ↳ `videoBitRate` | number | VideoMetadata videoBitRate |
15431543
| ↳ `videoCodec` | string | VideoMetadata videoCodec |
15441544
| ↳ `width` | number | VideoMetadata width |
1545-
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment |
1545+
| ↳ `linkAttachment` | object | ThreadedPost linkAttachment \(removed by Buffer, always null\) |
15461546
| ↳ `expandedUrl` | string | LinkAttachment expandedUrl |
15471547
| ↳ `text` | string | LinkAttachment text |
15481548
| ↳ `thumbnail` | string | LinkAttachment thumbnail |

‎apps/sim/blocks/blocks/spotify.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ export const SpotifyBlock: BlockConfig = {
190190
spotify_follow_playlist: [{ text: 'Follow playlist', field: 'playlistId', core: true }],
191191
spotify_unfollow_playlist: [{ text: 'Unfollow playlist', field: 'playlistId', core: true }],
192192
spotify_check_playlist_followers: [
193-
{ text: 'Check whether', field: 'userIds', core: true },
194-
{ text: 'follow playlist', field: 'playlistId', core: true },
193+
{ text: 'Check whether you follow playlist', field: 'playlistId', core: true },
195194
],
196195
spotify_get_current_user: ['Read the current user profile'],
197196
spotify_get_user_profile: [
@@ -703,8 +702,8 @@ export const SpotifyBlock: BlockConfig = {
703702
id: 'userIds',
704703
title: 'User IDs',
705704
type: 'short-input',
706-
placeholder: 'Comma-separated user IDs to check (max 5)',
707-
required: true,
705+
placeholder: 'Not used: Spotify checks the current user',
706+
mode: 'advanced',
708707
condition: { field: 'operation', value: 'spotify_check_playlist_followers' },
709708
},
710709

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, expect, it } from 'vitest'
2+
import post from '@/tools/buffer/__fixtures__/post.json'
3+
import { bufferSelection, projectBufferObject } from '@/tools/buffer/schema'
4+
5+
/** The field names a GraphQL selection set picks at its own level, without nested selections. */
6+
function topLevelFields(selection: string): string[] {
7+
let depth = 0
8+
let flat = ''
9+
for (const char of selection) {
10+
if (char === '{') depth++
11+
else if (char === '}') depth--
12+
else if (depth === 0) flat += char
13+
}
14+
return flat.split(/\s+/).filter(Boolean)
15+
}
16+
17+
describe('Buffer response schema', () => {
18+
it('keeps a channel whose allowedActions include a value added by Buffer after this schema', () => {
19+
const channel = projectBufferObject('Channel', {
20+
...post.channel,
21+
allowedActions: ['shuffleQueue', 'emptyQueue', 'someFutureAction'],
22+
})
23+
24+
expect(channel.allowedActions).toEqual(['shuffleQueue', 'emptyQueue', 'someFutureAction'])
25+
})
26+
27+
it('never selects ThreadedPost.linkAttachment, which Buffer removes on 2026-12-15', () => {
28+
const fields = topLevelFields(bufferSelection('ThreadedPost'))
29+
30+
expect(fields).toEqual(expect.arrayContaining(['assets', 'metadata', 'text']))
31+
expect(fields).not.toContain('linkAttachment')
32+
})
33+
})

‎apps/sim/tools/buffer/schema.ts‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import type { OutputProperty } from '@/tools/types'
1313

1414
interface BufferSchemaType {
1515
fields?: Record<string, string>
16+
/**
17+
* Fields Buffer has removed or is removing from the API. They stay in the outputs (always null)
18+
* so saved references keep resolving, but are never selected, since querying a removed field
19+
* fails the whole GraphQL request.
20+
*/
21+
retired?: string[]
1622
members?: string[]
1723
values?: string[]
1824
defaults?: string[]
@@ -48,6 +54,7 @@ export function bufferSelection(type: string): string {
4854
return `__typename ${schema.members.map((member) => `... on ${member} { ${bufferSelection(member)} }`).join(' ')}`
4955
}
5056
return Object.entries(schema.fields ?? {})
57+
.filter(([field]) => !schema.retired?.includes(field))
5158
.map(([field, wireType]) => {
5259
const selection = bufferSelection(baseType(wireType))
5360
return selection ? `${field} { ${selection} }` : field
@@ -77,7 +84,9 @@ export function bufferOutputProperties(type: string): Record<string, OutputPrope
7784
const object = Boolean(nested?.fields || nested?.members)
7885
const property: OutputProperty = {
7986
type: object ? 'object' : scalarType(nestedType),
80-
description: `${type} ${field}`,
87+
description: schema.retired?.includes(field)
88+
? `${type} ${field} (removed by Buffer, always null)`
89+
: `${type} ${field}`,
8190
...(object ? { properties: bufferOutputProperties(nestedType) } : {}),
8291
}
8392
properties[field] = wireType.startsWith('[')
@@ -133,12 +142,12 @@ export function projectBufferObject(type: string, value: unknown): unknown {
133142
}
134143
return object
135144
? projectBufferObject(nestedType, entry)
136-
: parseValue(nestedType, entry, `Buffer response ${type}.${field}[]`)
145+
: parseValue(nestedType, entry, `Buffer response ${type}.${field}[]`, 'output')
137146
})
138147
} else {
139148
result[field] = object
140149
? projectBufferObject(nestedType, candidate)
141-
: parseValue(nestedType, candidate, `Buffer response ${type}.${field}`)
150+
: parseValue(nestedType, candidate, `Buffer response ${type}.${field}`, 'output')
142151
}
143152
}
144153
return result
@@ -202,7 +211,16 @@ export function bufferInputDescription(type: string, description: string): strin
202211
: description
203212
}
204213

205-
function parseValue(wireType: string, value: unknown, path: string): unknown {
214+
/**
215+
* Validates one wire value. Enum membership is enforced only on inputs: Buffer adds enum values
216+
* to responses without notice (GraphQL clients must tolerate them), so an output keeps any string.
217+
*/
218+
function parseValue(
219+
wireType: string,
220+
value: unknown,
221+
path: string,
222+
direction: 'input' | 'output' = 'input'
223+
): unknown {
206224
if (value == null) {
207225
if (wireType.endsWith('!')) throw new Error(`${path} is required`)
208226
return null
@@ -211,12 +229,14 @@ function parseValue(wireType: string, value: unknown, path: string): unknown {
211229
if (type.startsWith('[')) {
212230
if (!Array.isArray(value)) throw new Error(`${path} must be an array`)
213231
if (value.length > 1000) throw new Error(`${path} exceeds the integration limit of 1000 items`)
214-
return value.map((entry, index) => parseValue(type.slice(1, -1), entry, `${path}[${index}]`))
232+
return value.map((entry, index) =>
233+
parseValue(type.slice(1, -1), entry, `${path}[${index}]`, direction)
234+
)
215235
}
216236
const schema = BUFFER_SCHEMA[type]
217237
if (schema?.fields) return parseBufferInput(type, value, path)
218238
if (typeof value !== scalarType(type)) throw new Error(`${path} must be a ${scalarType(type)}`)
219-
if (schema?.values && !schema.values.includes(String(value)))
239+
if (direction === 'input' && schema?.values && !schema.values.includes(String(value)))
220240
throw new Error(`${path} must be one of ${schema.values.join(', ')}`)
221241
if (type === 'Int' && !Number.isInteger(value)) throw new Error(`${path} must be an integer`)
222242
if ((type === 'Int' || type === 'Float') && !Number.isFinite(value))
@@ -1415,6 +1435,7 @@ const BUFFER_SCHEMA: Record<string, BufferSchemaType> = {
14151435
metadata: 'ThreadItemMetadata',
14161436
text: 'String!',
14171437
},
1438+
retired: ['linkAttachment'],
14181439
},
14191440
ThreadedPostInput: {
14201441
fields: {

‎apps/sim/tools/generated/tool-metadata.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/generated/tool-outputs.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/spotify/add_tracks_to_playlist.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const spotifyAddTracksToPlaylistTool: ToolConfig<
4141
},
4242

4343
request: {
44-
url: (params) => `https://api.spotify.com/v1/playlists/${params.playlistId}/tracks`,
44+
url: (params) => `https://api.spotify.com/v1/playlists/${params.playlistId}/items`,
4545
method: 'POST',
4646
headers: (params) => ({
4747
Authorization: `Bearer ${params.accessToken}`,

‎apps/sim/tools/spotify/check_following.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { spotifyLibraryUrl } from '@/tools/spotify/utils'
12
import type { ToolConfig, ToolResponse } from '@/tools/types'
23

34
interface SpotifyCheckFollowingParams {
@@ -36,19 +37,13 @@ export const spotifyCheckFollowingTool: ToolConfig<
3637
type: 'string',
3738
required: true,
3839
visibility: 'user-or-llm',
39-
description: 'Comma-separated artist or user IDs (max 50)',
40+
description: 'Comma-separated artist or user IDs (max 40)',
4041
},
4142
},
4243

4344
request: {
44-
url: (params) => {
45-
const ids = params.ids
46-
.split(',')
47-
.map((id) => id.trim())
48-
.slice(0, 50)
49-
.join(',')
50-
return `https://api.spotify.com/v1/me/following/contains?type=${params.type}&ids=${ids}`
51-
},
45+
url: (params) =>
46+
spotifyLibraryUrl(params.ids, params.type === 'user' ? 'user' : 'artist', { contains: true }),
5247
method: 'GET',
5348
headers: (params) => ({
5449
Authorization: `Bearer ${params.accessToken}`,

‎apps/sim/tools/spotify/check_playlist_followers.ts‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { spotifyLibraryUrl } from '@/tools/spotify/utils'
12
import type { ToolConfig, ToolResponse } from '@/tools/types'
23

34
interface SpotifyCheckPlaylistFollowersParams {
@@ -16,7 +17,7 @@ export const spotifyCheckPlaylistFollowersTool: ToolConfig<
1617
> = {
1718
id: 'spotify_check_playlist_followers',
1819
name: 'Spotify Check Playlist Followers',
19-
description: 'Check if users follow a playlist.',
20+
description: 'Check if the current user follows a playlist.',
2021
version: '1.0.0',
2122

2223
oauth: {
@@ -34,21 +35,15 @@ export const spotifyCheckPlaylistFollowersTool: ToolConfig<
3435
},
3536
userIds: {
3637
type: 'string',
37-
required: true,
38+
required: false,
3839
visibility: 'user-or-llm',
39-
description: 'Comma-separated user IDs to check (max 5)',
40+
description:
41+
'Not used: Spotify only checks whether the current user follows the playlist, whatever IDs are given',
4042
},
4143
},
4244

4345
request: {
44-
url: (params) => {
45-
const ids = params.userIds
46-
.split(',')
47-
.map((id) => id.trim())
48-
.slice(0, 5)
49-
.join(',')
50-
return `https://api.spotify.com/v1/playlists/${params.playlistId}/followers/contains?ids=${ids}`
51-
},
46+
url: (params) => spotifyLibraryUrl(params.playlistId, 'playlist', { contains: true }),
5247
method: 'GET',
5348
headers: (params) => ({
5449
Authorization: `Bearer ${params.accessToken}`,
@@ -61,6 +56,9 @@ export const spotifyCheckPlaylistFollowersTool: ToolConfig<
6156
},
6257

6358
outputs: {
64-
results: { type: 'json', description: 'Array of booleans for each user' },
59+
results: {
60+
type: 'json',
61+
description: 'One boolean: whether the current user follows the playlist',
62+
},
6563
},
6664
}

‎apps/sim/tools/spotify/check_saved_albums.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { spotifyLibraryUrl } from '@/tools/spotify/utils'
12
import type { ToolConfig, ToolResponse } from '@/tools/types'
23

34
interface SpotifyCheckSavedAlbumsParams {
@@ -29,19 +30,12 @@ export const spotifyCheckSavedAlbumsTool: ToolConfig<
2930
type: 'string',
3031
required: true,
3132
visibility: 'user-or-llm',
32-
description: 'Comma-separated album IDs (max 20)',
33+
description: 'Comma-separated album IDs (max 40)',
3334
},
3435
},
3536

3637
request: {
37-
url: (params) => {
38-
const ids = params.albumIds
39-
.split(',')
40-
.map((id) => id.trim())
41-
.slice(0, 20)
42-
.join(',')
43-
return `https://api.spotify.com/v1/me/albums/contains?ids=${ids}`
44-
},
38+
url: (params) => spotifyLibraryUrl(params.albumIds, 'album', { contains: true }),
4539
method: 'GET',
4640
headers: (params) => ({
4741
Authorization: `Bearer ${params.accessToken}`,

0 commit comments

Comments
 (0)