Teams
@idiomark/teams provides enterprise team collaboration for managing Idiomark files across organizations — roles, permissions, invitations, resource sharing, and full audit trails.
Installation
pnpm add @idiomark/teams
Quick Start
import {
TeamManager,
MemberManager,
ResourceManager,
PermissionChecker,
InMemoryTeamStore,
InMemoryAuditLogger,
} from "@idiomark/teams";
const store = new InMemoryTeamStore();
const audit = new InMemoryAuditLogger();
// Create a team
const teamMgr = new TeamManager(store, audit);
const team = await teamMgr.create("My Team", userId, {
tier: "pro",
description: "AI personality team",
});
// Add a member
const memberMgr = new MemberManager(store, audit);
await memberMgr.addMember(team.id, "user-id", {
roles: ["admin"],
email: "user@example.com",
});
// Share a Idiomark file
const resourceMgr = new ResourceManager(store, audit);
await resourceMgr.shareResource(
team.id,
"idiomark:files",
"file-id",
"My Personality",
{
scope: "roles",
allowedRoles: ["admin", "member"],
},
);
// Check permissions
const checker = new PermissionChecker();
const result = await checker.check(
{
userId: "user-id",
teamId: team.id,
resource: "idiomark:files",
action: "read",
},
context,
);
Team Tiers
| Tier | Members | Roles | Resources | Price |
|---|---|---|---|---|
| Free | 5 | 3 | 10 | Free |
| Pro | 50 | 20 | 1,000 | $29/mo |
| Enterprise | Unlimited | Unlimited | Unlimited | Custom |
System Roles
| Role | Priority | Permissions |
|---|---|---|
| Owner | 100 | Full access including billing |
| Admin | 80 | All except billing |
| Member | 50 | Read access to files |
| Viewer | 20 | Read-only |
Custom Roles
const role: Role = {
id: "role-id",
teamId: "team-id",
name: "Editor",
description: "Can edit but not delete",
isSystemRole: false,
permissions: [
{ resource: "idiomark:files", action: "read", condition: null },
{ resource: "idiomark:files", action: "write", condition: null },
],
priority: 60,
};
Permission Types
| Resource | Actions |
|---|---|
idiomark:files | read, write, delete, share, admin |
idiomark:profiles | read, write, delete, share, admin |
team:members | read, write, delete, admin |
team:settings | read, write, admin |
billing:info | read, admin |
audit:logs | read |
Permission Conditions
// Only the owner can delete
{ resource: 'idiomark:files', action: 'delete', condition: { type: 'owner', value: true } }
// Only the creator can edit
{ resource: 'idiomark:files', action: 'write', condition: { type: 'creator', value: true } }
Resource Sharing
Share with entire team
await resourceMgr.shareResource(teamId, "idiomark:files", fileId, name, {
scope: "team",
});
Share with specific roles
await resourceMgr.shareResource(teamId, "idiomark:files", fileId, name, {
scope: "roles",
allowedRoles: ["admin", "editor"],
});
Share with specific users
await resourceMgr.shareResource(teamId, "idiomark:files", fileId, name, {
scope: "specific",
allowedUsers: ["user-id-1", "user-id-2"],
});
Invitations
import { InvitationManager } from "@idiomark/teams";
const inviteMgr = new InvitationManager(store, audit);
// Create invitation
const invite = await inviteMgr.create(
teamId,
{
email: "user@example.com",
roles: ["member"],
message: "Join our team!",
expiresInSeconds: 604800, // 7 days
},
actorId,
);
// Accept invitation
const { team, member } = await inviteMgr.accept(invite.token, userId, {
displayName: "User Name",
email: "user@example.com",
});
// Revoke invitation
await inviteMgr.revoke(invitationId, actorId);
Audit Logging
All operations are logged for compliance:
const logs = await audit.query(teamId, {
eventType: "member:invited",
startDate: new Date("2024-01-01"),
limit: 100,
});
API Reference
TeamManager
| Method | Description |
|---|---|
create(name, owner, options) | Create a team |
get(teamId) | Get team by ID |
getBySlug(slug) | Get team by slug |
update(teamId, updates, actor) | Update a team |
delete(teamId, actor) | Delete a team |
listByUser(userId, options) | List user's teams |
getStats(teamId) | Get team statistics |
MemberManager
| Method | Description |
|---|---|
addMember(teamId, userId, options) | Add member |
removeMember(teamId, memberId, actor) | Remove member |
updateMemberRoles(teamId, memberId, roles, actor) | Update roles |
listMembers(teamId, options) | List members |
countMembers(teamId) | Count members |
ResourceManager
| Method | Description |
|---|---|
shareResource(teamId, type, resourceId, name, options) | Share resource |
unshareResource(teamId, sharedResourceId, actor) | Unshare resource |
listResources(teamId, options) | List shared resources |
canAccessResource(teamId, userId, resourceId, roles) | Check access |
PermissionChecker
| Method | Description |
|---|---|
check(request, context) | Check single permission |
checkActions(userId, teamId, resource, actions) | Check multiple actions |
Related
- Access Control — Enterprise API access control
- Identity — Cryptographic identity verification