Skip to content

Commit 1997d0a

Browse files
authored
fix(integrations): validate spotify, buffer (#10175)
* fix(integrations): validate spotify, buffer * fix(integrations): cap spotify playlist items limit at 50 and drop buffer tests for rejected output enums * fix(integrations): keep spotify get playlist tracks on the read endpoint that serves any public playlist * fix(integrations): batch spotify library requests up to each tool's old id limit, restore playlist tracks limit, list new buffer channel actions * fix(integrations): honor cancellation in later spotify library batches, report the exact rejected id range, reject unknown follow types * fix(integrations): reject spotify uris of another type, fail on invalid library check chunks, describe partial batch failures * chore(integrations): regenerate artifacts after rebase
1 parent ea0421f commit 1997d0a

39 files changed

Lines changed: 652 additions & 241 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: 4 additions & 5 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

@@ -895,7 +894,7 @@ export const SpotifyBlock: BlockConfig = {
895894
id: 'limit',
896895
title: 'Limit',
897896
type: 'short-input',
898-
placeholder: 'Number of results (1-50, default: 20)',
897+
placeholder: 'Number of results (leave empty for the default)',
899898
condition: {
900899
field: 'operation',
901900
value: [

‎apps/sim/lib/internal/buffer/operations.test.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ describe('Buffer operations', () => {
190190
error: 'Post.isCustomScheduled must be a boolean',
191191
},
192192
{ corruption: { allowedActions: [42] }, error: 'Post.allowedActions[] must be a string' },
193-
{ corruption: { status: 'invalid-status' }, error: 'Post.status must be one of' },
194-
{
195-
corruption: { allowedActions: ['invalid-action'] },
196-
error: 'Post.allowedActions[] must be one of',
197-
},
198193
{
199194
corruption: {
200195
channel: {
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: 33 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))
@@ -385,8 +405,13 @@ const BUFFER_SCHEMA: Record<string, BufferSchemaType> = {
385405
},
386406
ChannelAction: {
387407
values: [
408+
'approvePosts',
388409
'backfillChannel',
410+
'cleanQueue',
411+
'deleteDrafts',
412+
'emptyQueue',
389413
'exportInsights',
414+
'interactWithTakeaways',
390415
'manageCapabilities',
391416
'manageChannelSettings',
392417
'manageComments',
@@ -399,6 +424,7 @@ const BUFFER_SCHEMA: Record<string, BufferSchemaType> = {
399424
'reconnectChannel',
400425
'removeChannel',
401426
'scheduleUpdates',
427+
'shuffleQueue',
402428
'viewCapabilities',
403429
'viewChannel',
404430
'viewComments',
@@ -1415,6 +1441,7 @@ const BUFFER_SCHEMA: Record<string, BufferSchemaType> = {
14151441
metadata: 'ThreadItemMetadata',
14161442
text: 'String!',
14171443
},
1444+
retired: ['linkAttachment'],
14181445
},
14191446
ThreadedPostInput: {
14201447
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: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { sendRemainingSpotifyLibraryChunks, spotifyLibraryUrl } from '@/tools/spotify/utils'
12
import type { ToolConfig, ToolResponse } from '@/tools/types'
23

34
interface SpotifyCheckFollowingParams {
@@ -10,6 +11,15 @@ interface SpotifyCheckFollowingResponse extends ToolResponse {
1011
output: { results: boolean[] }
1112
}
1213

14+
/** The library URI type for `type`, rejecting anything other than `artist` or `user`. */
15+
function followType(type: string): 'artist' | 'user' {
16+
const normalized = String(type ?? '')
17+
.trim()
18+
.toLowerCase()
19+
if (normalized === 'artist' || normalized === 'user') return normalized
20+
throw new Error('Type must be "artist" or "user"')
21+
}
22+
1323
export const spotifyCheckFollowingTool: ToolConfig<
1424
SpotifyCheckFollowingParams,
1525
SpotifyCheckFollowingResponse
@@ -41,22 +51,31 @@ export const spotifyCheckFollowingTool: ToolConfig<
4151
},
4252

4353
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-
},
54+
url: (params) =>
55+
spotifyLibraryUrl(params.ids, followType(params.type), {
56+
contains: true,
57+
maxIds: 50,
58+
}),
5259
method: 'GET',
5360
headers: (params) => ({
5461
Authorization: `Bearer ${params.accessToken}`,
5562
}),
5663
},
5764

58-
transformResponse: async (response): Promise<SpotifyCheckFollowingResponse> => {
59-
const results = await response.json()
65+
transformResponse: async (response, params, context): Promise<SpotifyCheckFollowingResponse> => {
66+
const results: boolean[] = [
67+
...(await response.json()),
68+
...(params
69+
? await sendRemainingSpotifyLibraryChunks(
70+
params,
71+
params.ids,
72+
followType(params.type),
73+
'GET',
74+
{ contains: true, maxIds: 50 },
75+
context?.signal
76+
)
77+
: []),
78+
]
6079
return { success: true, output: { results } }
6180
},
6281

‎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: 'Array with one boolean: whether the current user follows the playlist',
62+
},
6563
},
6664
}

0 commit comments

Comments
 (0)