The Workspace class represents a Yasumu workspace and provides access to REST, email, and environment modules.
Access workspaces
Access workspaces through the workspaces manager on the Yasumu instance:
// Get active workspace
const workspace = yasumu . workspaces . getActiveWorkspace ();
// Create new workspace
const workspace = await yasumu . workspaces . create ({
name: 'My Project' ,
path: '/path/to/workspace' ,
});
// Open existing workspace
const workspace = await yasumu . workspaces . open ({
id: 'workspace-id' ,
});
// List all workspaces
const workspaces = await yasumu . workspaces . list ();
WorkspaceManager
The workspace manager handles workspace lifecycle operations.
create()
Creates a new workspace.
const workspace = await yasumu . workspaces . create ({
name: 'My Project' ,
path: '/path/to/workspace' ,
metadata: {
description: 'API testing workspace' ,
},
});
options
WorkspaceCreateOptions
required
Show WorkspaceCreateOptions properties
File system path for the workspace
Optional metadata for the workspace
The created workspace instance
open()
Opens an existing workspace by ID.
const workspace = await yasumu . workspaces . open ({
id: 'workspace-id' ,
});
options
WorkspaceOpenOptions
required
Show WorkspaceOpenOptions properties
ID of the workspace to open
The opened workspace instance
list()
Lists all available workspaces.
const workspaces = await yasumu . workspaces . list ();
// With limit
const recent = await yasumu . workspaces . list ({ take: 10 });
Maximum number of workspaces to return
Array of workspace instances
getActiveWorkspace()
Returns the currently active workspace.
// Returns null if no workspace is active
const workspace = yasumu . workspaces . getActiveWorkspace ();
// Throws error if no workspace is active
const workspace = yasumu . workspaces . getActiveWorkspace ( true );
If true, throws an error when no workspace is active
The active workspace, or null if none is active (unless throwIfNotFound is true)
close()
Closes a workspace.
await yasumu . workspaces . close ( workspace );
delete()
Deletes a workspace by ID.
await yasumu . workspaces . delete ( 'workspace-id' );
ID of the workspace to delete
Workspace properties
workspace.id
Unique identifier for the workspace
workspace.name
Display name of the workspace
workspace.path
File system path where the workspace is stored
Custom metadata associated with the workspace
workspace.createdAt
Timestamp when the workspace was created
workspace.updatedAt
Timestamp when the workspace was last updated
workspace.lastOpenedAt
Timestamp when the workspace was last opened, or null if never opened
Workspace modules
workspace.rest
Module for managing REST API requests and entities. See RestModule for details.
const entity = await workspace . rest . create ({
name: 'Get Users' ,
url: 'https://api.example.com/users' ,
method: 'GET' ,
});
workspace.emails
Module for SMTP email testing. See EmailModule for details.
const config = await workspace . emails . getSmtpConfig ();
const emails = await workspace . emails . listEmails ({ page: 1 , limit: 10 });
workspace.environments
const env = await workspace . environments . create ({
name: 'Production' ,
});
await env . setActive ();
Workspace methods
synchronize()
Synchronizes the workspace data with the backend.
await workspace . synchronize ();
Resolves when synchronization is complete
toJSON()
Converts the workspace to a plain object.
const data = workspace . toJSON ();
console . log ( data . name , data . path );
Plain object representation of the workspace
Example usage
// Create and configure a workspace
const workspace = await yasumu . workspaces . create ({
name: 'E-commerce API' ,
path: '/projects/ecommerce' ,
metadata: {
version: '1.0' ,
team: 'backend' ,
},
});
// Create environments
const dev = await workspace . environments . create ({
name: 'Development' ,
});
const prod = await workspace . environments . create ({
name: 'Production' ,
});
await dev . setActive ();
// Add environment variables
await dev . variables . set ( 'API_URL' , 'http://localhost:3000' );
await prod . variables . set ( 'API_URL' , 'https://api.example.com' );
// Create REST entities
const getProducts = await workspace . rest . create ({
name: 'Get Products' ,
url: '{{API_URL}}/products' ,
method: 'GET' ,
});
const createOrder = await workspace . rest . create ({
name: 'Create Order' ,
url: '{{API_URL}}/orders' ,
method: 'POST' ,
});
// List all REST entities
const entities = await workspace . rest . list ();
console . log ( `Created ${ entities . length } endpoints` );
RestModule REST API testing
EnvironmentManager Environment variables