Skip to main content

Resources Module

The Resources module provides type-safe CRUD operations for managing resources in the EnterpriseAI platform. Resources are the primary data entities in vertical applications (e.g., projects, deals, cases, assets).

Basic Usage

import { PlatformClient } from '@enterpriseaigroup/platform-sdk';

const client = new PlatformClient({ /* config */ });

// List resources
const projects = await client.resources.list({ type: 'project' });

// Get a single resource
const project = await client.resources.get('project', 'proj_123');

// Create a resource
const newProject = await client.resources.create('project', {
name: 'Q1 Initiative',
status: 'active',
budget: 500000
});

// Update a resource
const updated = await client.resources.update('project', 'proj_123', {
status: 'completed'
});

// Delete a resource
await client.resources.delete('project', 'proj_123');

Methods

list()

Retrieve a paginated list of resources with optional filtering and sorting.

list<T = Resource>(options: ListOptions): Promise<ResourceList<T>>

Parameters

ParameterTypeRequiredDescription
typestringYesResource type identifier
filterRecord<string, any>NoFilter criteria (field-value pairs)
sortSortOptionsNoSorting configuration
limitnumberNoMaximum number of results (default: 50, max: 100)
offsetnumberNoPagination offset
cursorstringNoCursor for cursor-based pagination

Returns

interface ResourceList<T> {
data: T[];
total: number;
hasMore: boolean;
nextCursor?: string;
}

Example

interface Project {
id: string;
name: string;
status: 'active' | 'completed' | 'archived';
budget: number;
createdAt: string;
}

const result = await client.resources.list<Project>({
type: 'project',
filter: {
status: 'active',
'budget.gte': 100000
},
sort: {
field: 'createdAt',
order: 'desc'
},
limit: 20
});

console.log(`Found ${result.total} projects`);
result.data.forEach(project => {
console.log(`${project.name}: $${project.budget}`);
});

get()

Retrieve a single resource by ID.

get<T = Resource>(type: string, id: string): Promise<T>

Parameters

ParameterTypeRequiredDescription
typestringYesResource type identifier
idstringYesResource ID

Returns

The resource object of type T.

Example

const project = await client.resources.get<Project>('project', 'proj_123');
console.log(project.name);

create()

Create a new resource.

create<T = Resource>(type: string, data: Partial<T>): Promise<T>

Parameters

ParameterTypeRequiredDescription
typestringYesResource type identifier
dataPartial<T>YesResource data (fields depend on resource type)

Returns

The created resource object of type T.

Example

const newProject = await client.resources.create<Project>('project', {
name: 'Digital Transformation',
status: 'active',
budget: 750000,
startDate: '2026-04-01',
owner: 'user_456'
});

console.log(`Created project: ${newProject.id}`);

update()

Update an existing resource.

update<T = Resource>(type: string, id: string, data: Partial<T>): Promise<T>

Parameters

ParameterTypeRequiredDescription
typestringYesResource type identifier
idstringYesResource ID
dataPartial<T>YesFields to update

Returns

The updated resource object of type T.

Example

const updated = await client.resources.update<Project>('project', 'proj_123', {
status: 'completed',
completedAt: new Date().toISOString()
});

delete()

Delete a resource.

delete(type: string, id: string): Promise<void>

Parameters

ParameterTypeRequiredDescription
typestringYesResource type identifier
idstringYesResource ID

Example

await client.resources.delete('project', 'proj_123');
console.log('Project deleted');

query()

Execute a complex query with advanced filtering, aggregations, and joins.

query<T = Resource>(options: QueryOptions): Promise<QueryResult<T>>

Parameters

ParameterTypeRequiredDescription
typestringYesResource type identifier
filterFilterExpressionNoComplex filter expression (supports operators like $and, $or, $not)
aggregationsAggregation[]NoAggregation operations (count, sum, avg, min, max)
joinsJoinConfig[]NoRelated resources to include
groupBystring[]NoFields to group by
limitnumberNoMaximum results

Example

const result = await client.resources.query({
type: 'project',
filter: {
$and: [
{ status: 'active' },
{ $or: [
{ 'budget.gte': 500000 },
{ priority: 'high' }
]}
]
},
aggregations: [
{ field: 'budget', operation: 'sum', alias: 'totalBudget' },
{ field: 'id', operation: 'count', alias: 'projectCount' }
],
joins: [
{ type: 'user', field: 'owner', as: 'ownerDetails' }
],
groupBy: ['status']
});

console.log(`Total budget: $${result.aggregations.totalBudget}`);

TypeScript Generics

The Resources module supports TypeScript generics for type-safe responses:

interface Deal {
id: string;
title: string;
value: number;
stage: 'prospect' | 'negotiation' | 'closed';
probability: number;
closeDate: string;
}

// Typed list
const deals = await client.resources.list<Deal>({ type: 'deal' });
deals.data.forEach(deal => {
console.log(deal.title); // TypeScript knows all Deal properties
});

// Typed get
const deal = await client.resources.get<Deal>('deal', 'deal_789');
console.log(deal.probability); // Type-safe access

// Typed create
const newDeal = await client.resources.create<Deal>('deal', {
title: 'Enterprise Contract',
value: 250000,
stage: 'prospect',
probability: 0.3,
closeDate: '2026-06-30'
});

Filtering

Simple Filters

const resources = await client.resources.list({
type: 'project',
filter: {
status: 'active',
owner: 'user_123'
}
});

Comparison Operators

Use dotted notation for comparison operators:

const resources = await client.resources.list({
type: 'project',
filter: {
'budget.gte': 100000, // Greater than or equal
'budget.lt': 1000000, // Less than
'createdAt.gte': '2026-01-01', // Date comparison
'status.in': ['active', 'pending'] // In array
}
});

Supported operators:

  • eq: Equal (default)
  • ne: Not equal
  • gt: Greater than
  • gte: Greater than or equal
  • lt: Less than
  • lte: Less than or equal
  • in: In array
  • nin: Not in array
  • contains: String contains
  • startsWith: String starts with
  • endsWith: String ends with

Complex Filters (query method)

const result = await client.resources.query({
type: 'project',
filter: {
$and: [
{ status: 'active' },
{
$or: [
{ 'budget.gte': 500000 },
{ priority: 'critical' }
]
},
{ $not: { archived: true } }
]
}
});

Sorting

const resources = await client.resources.list({
type: 'project',
sort: {
field: 'createdAt',
order: 'desc' // or 'asc'
}
});

// Multiple sort fields
const result = await client.resources.query({
type: 'project',
sort: [
{ field: 'priority', order: 'desc' },
{ field: 'createdAt', order: 'asc' }
]
});

Pagination

Offset-based Pagination

// Page 1
const page1 = await client.resources.list({
type: 'project',
limit: 50,
offset: 0
});

// Page 2
const page2 = await client.resources.list({
type: 'project',
limit: 50,
offset: 50
});

Cursor-based Pagination

let cursor: string | undefined;
const allProjects = [];

do {
const result = await client.resources.list({
type: 'project',
limit: 100,
cursor
});

allProjects.push(...result.data);
cursor = result.nextCursor;
} while (cursor);

console.log(`Fetched ${allProjects.length} total projects`);

Error Handling

try {
const project = await client.resources.get('project', 'proj_999');
} catch (error) {
if (error.code === 'NOT_FOUND') {
console.error('Project not found');
} else if (error.code === 'VALIDATION_ERROR') {
console.error('Invalid resource type or ID');
} else {
console.error('Unexpected error:', error);
}
}

Next Steps