Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/content/docs/integrations/cloudflare.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7744,7 +7744,7 @@ Replaces the object lifecycle rules for an R2 bucket. Rules match object-key pre
| `accountId` | string | Yes | Account id |
| `bucketName` | string | Yes | Bucket name |
| `apiKey` | string | Yes | Cloudflare API token |
| `rules` | json | No | JSON array. rules Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions. |
| `rules` | string | Yes | Complete JSON array of lifecycle rules. Read the current rules first and include every rule to retain. Use \[\] only to remove all lifecycle rules. Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions. |
| `jurisdiction` | string | No | Jurisdiction where objects in this bucket are guaranteed to be stored. |

#### Output
Expand Down
11 changes: 5 additions & 6 deletions apps/sim/blocks/blocks/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4300,14 +4300,13 @@ export const CloudflareBlock: BlockConfig = {
id: 'r2BucketLifecycleRules',
title: 'Rules',
type: 'long-input',
placeholder: 'Enter rules as JSON',
placeholder: 'Enter all lifecycle rules as JSON; [] removes all rules',
condition: { field: 'operation', value: ['update_r2_bucket_lifecycle'] },
required: false,
mode: 'advanced',
required: true,
wandConfig: {
enabled: true,
prompt:
'Generate the Cloudflare rules value. JSON array. rules Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions. Return ONLY the value.',
'Generate the complete Cloudflare lifecycle rules JSON array. Include every existing rule the user wants to retain. Use [] only when the user wants to remove all lifecycle rules. Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions. Return ONLY the value.',
placeholder: 'Describe the rules',
},
},
Expand Down Expand Up @@ -5300,9 +5299,9 @@ export const CloudflareBlock: BlockConfig = {
description: 'JSON array. rules Fields: allowed, exposeHeaders, id, maxAgeSeconds.',
},
r2BucketLifecycleRules: {
type: 'json',
type: 'string',
description:
'JSON array. rules Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions.',
'Complete JSON array of lifecycle rules. Read the current rules first and include every rule to retain. Use [] only to remove all lifecycle rules. Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions.',
},
rulesetRulePosition: {
type: 'json',
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/tools/cloudflare/operation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export interface CloudflareUpdateR2BucketLifecycleParams {
accountId: string
bucketName: string
apiKey: string
rules?: string | Record<string, unknown> | unknown[]
rules: string | unknown[]
jurisdiction?: string
}

Expand Down
51 changes: 51 additions & 0 deletions apps/sim/tools/cloudflare/request-boundary.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
import { describe, expect, it } from 'vitest'
import { createDnsRecordTool } from '@/tools/cloudflare/create_dns_record'
import { deleteDnsRecordTool } from '@/tools/cloudflare/delete_dns_record'
import { updateR2BucketLifecycleTool } from '@/tools/cloudflare/update_r2_bucket_lifecycle'
import { updateRulesetRuleTool } from '@/tools/cloudflare/update_ruleset_rule'

describe('Cloudflare provider request boundaries', () => {
it.each([undefined, null, '', ' '])(
'rejects an R2 lifecycle replacement without explicit rules (%j)',
(rules) => {
const body = updateR2BucketLifecycleTool.request.body
if (!body) throw new Error('Expected a request body')
const wireInput = { apiKey: 'token', accountId: 'account', bucketName: 'bucket', rules }
expect(() => Reflect.apply(body, undefined, [wireInput])).toThrow(/rules/)
}
)

it.each([{ rules: [] }, { rules: '[]' }])(
'preserves an explicit R2 lifecycle clear (%j)',
({ rules }) => {
const body = updateR2BucketLifecycleTool.request.body
if (!body) throw new Error('Expected a request body')
expect(body({ apiKey: 'token', accountId: 'account', bucketName: 'bucket', rules })).toEqual({
rules: [],
})
}
)

it('preserves every explicitly supplied R2 lifecycle rule', () => {
const body = updateR2BucketLifecycleTool.request.body
if (!body) throw new Error('Expected a request body')
const rules = [
{
id: 'expire-logs',
enabled: true,
conditions: { prefix: 'logs/' },
deleteObjectsTransition: { condition: { type: 'Age', maxAge: 86400 } },
},
{
id: 'retain-archive-transition',
enabled: false,
conditions: { prefix: 'archive/' },
storageClassTransitions: [
{ condition: { type: 'Age', maxAge: 2592000 }, storageClass: 'InfrequentAccess' },
],
},
]
expect(
body({
apiKey: 'token',
accountId: 'account',
bucketName: 'bucket',
rules: JSON.stringify(rules),
})
).toEqual({ rules })
})

it('rejects a DNS deletion identifier that would address the collection instead', () => {
const url = deleteDnsRecordTool.request.url
if (typeof url !== 'function') throw new Error('Expected a parameterized URL')
Expand Down
16 changes: 12 additions & 4 deletions apps/sim/tools/cloudflare/update_r2_bucket_lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export const updateR2BucketLifecycleTool: ToolConfig<
description: 'Cloudflare API token',
},
rules: {
type: 'json',
required: false,
type: 'string',
required: true,
visibility: 'user-or-llm',
description:
'JSON array. rules Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions.',
'Complete JSON array of lifecycle rules. Read the current rules first and include every rule to retain. Use [] only to remove all lifecycle rules. Fields: abortMultipartUploadsTransition, conditions, deleteObjectsTransition, enabled, id, storageClassTransitions.',
},
jurisdiction: {
type: 'string',
Expand All @@ -61,7 +61,15 @@ export const updateR2BucketLifecycleTool: ToolConfig<
...cloudflareHeaders(params.apiKey),
...(params.jurisdiction ? { 'cf-r2-jurisdiction': params.jurisdiction } : {}),
}),
body: (params) => ({ rules: parseJsonArrayParam(params.rules, 'rules') }),
body: (params) => {
const rules = parseJsonArrayParam(params.rules, 'rules')
if (rules === undefined) {
throw new Error(
'rules is required; supply a JSON array or [] to remove all lifecycle rules'
)
}
return { rules }
},
},
transformResponse: async (response) => {
const data = await readCloudflareResponse(response)
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/tools/generated/tool-metadata.ts

Large diffs are not rendered by default.

Loading