Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.1 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { createClient } from '@supabase/supabase-js';
import { supabaseAuth } from '../auth';
import { createBucketActionOutputSchema } from '../output-schemas';

export const createBucket = createAction({
    name: 'create_bucket',
    classification: 'WRITE',
    displayName: 'Create Storage Bucket',
    description: 'Creates a new Storage bucket, public or private.',
    audience: 'both',
    aiMetadata: {
        description: 'Creates a new Storage bucket with a given name, either public (files reachable by direct URL) or private (files require a signed URL or download). Use before uploading files to a bucket that does not exist yet. Not idempotent: creating a bucket with a name that already exists errors.',
        idempotent: false,
    },
    auth: supabaseAuth,
    props: {
        name: Property.ShortText({
            displayName: 'Bucket Name',
            description: 'Must be unique in the project.',
            placeholder: 'avatars',
            required: true,
        }),
        public: Property.Checkbox({
            displayName: 'Public',
            description: 'Whether files in this bucket are publicly readable by URL.',
            required: false,
            defaultValue: false,
        }),
        fileSizeLimit: Property.Number({
            displayName: 'Max File Size',
            description: "In bytes. Empty uses the project's upload limit.",
            required: false,
            advanced: true,
        }),
    },
    outputSchema: createBucketActionOutputSchema,
    async run(context) {
        const { name, public: isPublic, fileSizeLimit } = context.propsValue;
        const { url, apiKey } = context.auth.props;
        const supabase = createClient(url, apiKey);

        const { data, error } = await supabase.storage.createBucket(name, {
            public: isPublic ?? false,
            fileSizeLimit: fileSizeLimit || undefined,
        });

        if (error) {
            throw new Error(`Failed to create bucket: ${error.message}`);
        }

        return {
            name: data.name,
        };
    },
});