@farmart-tech/brave-react-adapter
    Preparing search index...

    Class WorkspaceAPI

    Client for managing workspaces in the Brave Ship system.

    Provides methods for creating, reading, updating, and deleting workspaces. All operations require proper Firebase authentication.

    Protected workspaces ('global', 'test') have special restrictions:

    • Cannot be deleted
    • Cannot have their IDs changed
    • Always exist in the system
    import { WorkspaceAPI } from '@farmart-tech/brave-admin-sdk';
    import { getAuth } from 'firebase/auth';

    const api = new WorkspaceAPI({
    api: 'https://api.farmart.com/api/v1',
    getIdToken: async () => {
    const user = getAuth().currentUser;
    return await user.getIdToken();
    }
    });

    // List all workspaces
    const workspaces = await api.list();

    // Create new workspace
    const newWorkspace = await api.create({
    id: 'staging',
    name: 'Staging Environment',
    description: 'For testing before production'
    });

    // Update workspace
    await api.update({
    id: 'staging',
    name: 'Staging (Updated)',
    description: 'New description'
    });

    // Delete workspace
    await api.delete('staging');
    Index

    Constructors

    Methods

    Constructors

    • Creates a new WorkspaceAPI client instance.

      Parameters

      Returns WorkspaceAPI

      const api = new WorkspaceAPI({
      api: 'https://api.farmart.com/api/v1',
      getIdToken: async () => await getAuth().currentUser.getIdToken()
      });

    Methods

    • Creates a new workspace.

      Parameters

      Returns Promise<Workspace>

      Promise resolving to the created workspace

      If workspace ID already exists, uses a reserved name, or authentication fails

      • Workspace ID must be unique and cannot be changed after creation
      • Protected names ('global', 'test') cannot be used
      • ID should be lowercase with hyphens or underscores
      const newWorkspace = await api.create({
      id: 'production',
      name: 'Production Environment',
      description: 'Live production workspace'
      });
    • Deletes a workspace.

      Parameters

      • workspaceId: string

        ID of the workspace to delete

      Returns Promise<void>

      Promise that resolves when deletion is complete

      If workspace not found, is protected, or authentication fails

      Protected workspaces ('global', 'test') cannot be deleted and will throw an error.

      await api.delete('old-workspace');
      
      try {
      await api.delete('global'); // This will throw an error
      } catch (error) {
      console.error('Cannot delete protected workspace');
      }
    • Lists all available workspaces.

      Returns Promise<Workspace[]>

      Promise resolving to array of workspaces

      If authentication fails or network error occurs

      Protected workspaces ('global', 'test') will always be included in the response.

      const workspaces = await api.list();
      console.log(workspaces.map(w => w.name));
      // Output: ['Global', 'Test', 'Production', 'Staging']
    • Updates an existing workspace.

      Parameters

      Returns Promise<Workspace>

      Promise resolving to the updated workspace

      If workspace not found or authentication fails

      • The workspace ID cannot be changed
      • Only name and description fields can be updated
      • Provide only the fields you want to update
      await api.update({
      id: 'staging',
      name: 'Staging (Updated)'
      });
      await api.update({
      id: 'staging',
      name: 'Staging Environment',
      description: 'Updated for Q1 2025'
      });