Skip to content

Filtering

Filter and search resources using the SDK's powerful query options.

Basic Filtering

Pass filter options to any list method:

typescript
const highRisks = await client.risks.list({
  filter: {
    severity: 'high',
  }
});

Filter Operators

Equality

typescript
// Exact match
const activeControls = await client.controls.list({
  filter: { status: 'active' }
});

// Multiple values (OR)
const criticalOrHigh = await client.risks.list({
  filter: { severity: { in: ['critical', 'high'] } }
});

Comparison

typescript
// Greater than
const recentRisks = await client.risks.list({
  filter: { createdAt: { gt: '2024-01-01' } }
});

// Less than or equal
const oldTasks = await client.tasks.list({
  filter: { dueDate: { lte: '2024-06-30' } }
});

// Range
const dateRange = await client.risks.list({
  filter: {
    createdAt: { gte: '2024-01-01', lt: '2024-07-01' }
  }
});
typescript
// Contains (case-insensitive)
const searchResults = await client.policies.search('security');

// Like pattern
const matched = await client.risks.list({
  filter: { name: { like: '%access%' } }
});

Negation

typescript
// Not equal
const notClosed = await client.tasks.list({
  filter: { status: { ne: 'closed' } }
});

// Not in list
const notLowRisks = await client.risks.list({
  filter: { severity: { nin: ['low', 'informational'] } }
});

Filter Operators Reference

OperatorDescriptionExample
eqEquals (default){ status: 'active' }
neNot equals{ status: { ne: 'closed' } }
gtGreater than{ score: { gt: 50 } }
gteGreater than or equal{ score: { gte: 50 } }
ltLess than{ score: { lt: 100 } }
lteLess than or equal{ score: { lte: 100 } }
inIn array{ status: { in: ['a', 'b'] } }
ninNot in array{ status: { nin: ['x', 'y'] } }
likePattern match{ name: { like: '%test%' } }

Sorting

Sort results by any field:

typescript
// Ascending (default)
const oldestFirst = await client.risks.list({
  sort: 'createdAt'
});

// Descending (prefix with -)
const newestFirst = await client.risks.list({
  sort: '-createdAt'
});

// Multiple fields
const sorted = await client.risks.list({
  sort: '-severity,createdAt'
});

Combining Filters

Multiple Conditions (AND)

typescript
// All conditions must match
const filtered = await client.risks.list({
  filter: {
    severity: 'high',
    status: 'open',
    owner: 'user@example.com',
  }
});

Complex Queries

typescript
// High severity risks created in 2024, sorted by date
const complexQuery = await client.risks.list({
  filter: {
    severity: { in: ['critical', 'high'] },
    createdAt: { gte: '2024-01-01' },
    status: { ne: 'closed' },
  },
  sort: '-createdAt',
  page: { size: 50 },
});

Fetch related resources in a single request:

typescript
// Include linked controls with each risk
const risksWithControls = await client.risks.list({
  include: ['controls'],
});

// Multiple includes
const fullData = await client.risks.list({
  include: ['controls', 'tasks', 'owner'],
});

Field Selection

Select only the fields you need:

typescript
// Only fetch specific fields
const minimal = await client.risks.list({
  fields: {
    risks: ['id', 'name', 'severity'],
  }
});

Examples

Dashboard Query

typescript
// Fetch data for a risk dashboard
const dashboardData = await client.risks.list({
  filter: {
    status: { ne: 'closed' },
  },
  sort: '-severity,-createdAt',
  page: { size: 100 },
  include: ['controls'],
});

Overdue Tasks

typescript
const today = new Date().toISOString().split('T')[0];

const overdueTasks = await client.tasks.list({
  filter: {
    dueDate: { lt: today },
    status: { ne: 'completed' },
  },
  sort: 'dueDate',
});

console.log(`Found ${overdueTasks.data.length} overdue tasks`);

Search with Filters

typescript
// Search policies containing "security" that are published
const policies = await client.policies.search('security', {
  filter: { status: 'published' },
  sort: '-updatedAt',
});

Type-Safe Filters

The SDK provides type checking for filter fields:

typescript
// ✅ Valid filter
const valid = await client.risks.list({
  filter: { severity: 'high' }
});

// ❌ TypeScript error - invalid field
const invalid = await client.risks.list({
  filter: { invalidField: 'value' }
});

Next Steps

Released under the MIT License.