Skip to content

Building a source adapter ​

A source adapter (driver) reads data from an external platform and delivers it to the IDVIZE ingestion pipeline. The pipeline writes objects to the tenant-scoped store, marks what the source stopped reporting, correlates identities across sources, and feeds the assessment engine.


The SourceAdapter interface ​

Every source adapter implements SourceAdapter from src/modules/ingestion/ingestion.contract.ts:

typescript
export interface SourceAdapter {
  /** Short lowercase identifier: 'servicenow.cmdb', 'entra', 'workday.hcm' */
  readonly source: string;

  /** Shown in the UI: 'ServiceNow CMDB', 'Microsoft Entra ID' */
  readonly displayName: string;

  /** Which of the five ingestion kinds this source provides */
  readonly kinds: readonly IngestKind[];

  /** Whether the adapter is configured and what basis it will produce */
  readiness(): SourceReadiness;

  /** Per-tenant readiness (optional). Called when per-tenant credentials exist. */
  readinessForTenant?(tenantId: string): Promise<SourceReadiness>;

  /** Read the FULL view of the requested kinds */
  read(kinds: readonly IngestKind[], ctx: ReadContext): Promise<SourceView>;
}

Ingestion kinds ​

A source can provide one or more of these five kinds:

KindWhat it carriesExample
applicationsApplication inventory (name, tier, segment, owner)ServiceNow CMDB business applications
identitiesPeople from HR or directory (employee ID, status, department)Workday workers, Entra users
accountsDirectory accounts (enabled, MFA, credentials, type)Entra user accounts and service principals
accessEntitlements, groups, roles and their membershipsEntra groups, directory roles, app role assignments
policiesAuthentication and access policiesEntra conditional access policies

Source ID rules ​

The source property must match /^[a-z0-9][a-z0-9._-]{1,63}$/. Convention: platform for single-purpose adapters (e.g. entra), platform.subsystem for CMDB-style sources (e.g. servicenow.cmdb).


The full-view contract ​

This is the most important rule. read() must return the complete view of the requested kinds. No paging, no filtering, no delta:

  • If the source has 10,000 accounts, read(['accounts'], ctx) returns all 10,000.
  • If the adapter cannot read everything (rate limit, permission denied), it must throw rather than return a partial set.
  • A partial view causes the write path to mark every omitted object as absent_from_source — which looks like every missing object was deleted.

The contract comment in ingestion.contract.ts says it plainly:

A source's read is a FULL view, so the account write path's absent_from_source marking is what a source's omission means.

Why full view? ​

The ingestion pipeline compares each run against the previous run to detect what changed. If a source previously reported an object and no longer does, the pipeline marks it absent_from_source. This is how IDVIZE detects that an identity platform stopped managing an account, or that a CMDB entry was removed. A partial view would trigger false absent-from-source markings across the entire dataset.


Readiness ​

readiness() reports whether the adapter is configured and what evidence basis it will produce:

typescript
interface SourceReadiness {
  configured: boolean;
  basis: 'live' | 'mock';
  reason: string;
}
  • configured: true, basis: 'live' — real credentials are present and the adapter will query the real API
  • configured: true, basis: 'mock' — the adapter will return representative sample data
  • configured: false — the adapter cannot run

Mock mode is mandatory. When credentials are absent, an adapter must return basis: 'mock' with representative sample data so the platform can demonstrate the ingestion flow. Mock data must be refused when SEED_MODE=production.

Per-tenant readiness ​

If your adapter supports per-tenant credentials (from the credential vault), implement readinessForTenant(tenantId). The ingestion service calls this first; if it returns configured: true, the adapter runs in live mode for that tenant even when the global environment has no credentials.

typescript
async readinessForTenant(tenantId: string): Promise<SourceReadiness> {
  const creds = await resolveCredentials(tenantId, 'my_platform');
  if (creds) {
    return { configured: true, basis: 'live', reason: 'Per-tenant credentials found' };
  }
  return this.readiness(); // fall back to global readiness
}

The SourceView return shape ​

read() returns a SourceView with optional fields per kind:

typescript
interface SourceView {
  applications?: ApplicationIngestInput[];
  identities?: IdentityIngestInput[];
  accounts?: AccountIngestInput[];
  access?: AccessIngestInput;       // objects + edges together
  policies?: PolicyIngestInput;
  workloadDependencies?: WorkloadDependencyInput[];
}

Only the requested kinds need to be populated. If read(['accounts'], ctx) is called, only accounts needs a value.

Input shapes ​

Each ingest input carries the source's own identifiers so the pipeline can track provenance:

typescript
// Application from a CMDB
interface ApplicationIngestInput {
  sourceObjectId: string;    // The source's own ID (e.g. CMDB sys_id)
  name: string;
  tier?: string;             // Risk tier: critical, high, medium, low
  segment?: string;          // Business segment
  owner?: string;
  attributes?: Record<string, unknown>;
}

// Identity from HR
interface IdentityIngestInput {
  sourceObjectId: string;    // Employee ID
  email?: string;
  displayName?: string;
  status?: 'active' | 'inactive';
  terminatedAt?: string;     // ISO date
  department?: string;
  jobTitle?: string;
  manager?: string;
  attributes?: Record<string, unknown>;
}

// Account from a directory
interface AccountIngestInput {
  sourceObjectId: string;    // Directory user ID
  username?: string;
  email?: string;
  displayName?: string;
  accountType?: 'user' | 'service' | 'shared';
  enabled?: boolean;
  mfaEnrolled?: boolean | null;
  lastSignIn?: string;       // ISO datetime
  credentialSetAt?: string;  // ISO datetime
  attributes?: Record<string, unknown>;
  methods?: AuthMethodInput[];     // Authentication methods
  owners?: string[];               // Owner user IDs (for service accounts)
}

Access input ​

Access ingestion carries objects (entitlements, groups, roles) and edges (who holds what) together:

typescript
interface AccessIngestInput {
  objects: AccessObjectInput[];    // Groups, roles, entitlements
  edges: AccessEdgeInput[];        // Memberships and assignments
}

interface AccessObjectInput {
  sourceObjectId: string;
  kind: 'entitlement' | 'group' | 'role';
  name: string;
  resource?: string;
  privileged?: boolean | null;     // null = the source did not say
}

interface AccessEdgeInput {
  holderSourceId: string;          // Account or group that holds
  holderKind: 'account' | 'group' | 'role';
  targetSourceId: string;          // What is held
  assignment?: 'standing' | 'eligible' | 'activated' | null;
}

Critical: an edge naming an account the source never reported in the same run is refused (HTTP 409). Report accounts before access.


Registration ​

Add your adapter to the ADAPTERS array in src/modules/ingestion/ingestion.registry.ts:

typescript
import { myPlatformAdapter } from './adapters/my-platform.adapter';

const ADAPTERS: readonly SourceAdapter[] = [
  serviceNowCmdbAdapter,
  entraUsersAdapter,
  workdayWorkersAdapter,
  myPlatformAdapter,          // <-- your adapter
];

The registry validates your source ID against the regex and rejects duplicates at startup.


File structure ​

src/modules/ingestion/adapters/
  my-platform.adapter.ts       — SourceAdapter implementation
  my-platform.adapter.test.ts  — Tests (required)

Example: minimal adapter ​

typescript
import type { SourceAdapter, SourceReadiness, SourceView, ReadContext }
  from '../ingestion.contract';

class MyPlatformAdapter implements SourceAdapter {
  readonly source = 'my_platform';
  readonly displayName = 'My Security Platform';
  readonly kinds = ['accounts'] as const;

  readiness(): SourceReadiness {
    const apiKey = process.env.MY_PLATFORM_API_KEY;
    if (apiKey) {
      return { configured: true, basis: 'live', reason: 'API key present' };
    }
    return { configured: true, basis: 'mock', reason: 'No API key — mock mode' };
  }

  async read(
    kinds: readonly string[],
    ctx: ReadContext,
  ): Promise<SourceView> {
    if (!kinds.includes('accounts')) return {};

    if (this.readiness().basis === 'mock') {
      return { accounts: this.mockAccounts(ctx.tenantId) };
    }

    // Real API call — must return the FULL view or throw
    const response = await fetch('https://api.myplatform.com/v1/users', {
      headers: { Authorization: `Bearer ${process.env.MY_PLATFORM_API_KEY}` },
    });
    if (!response.ok) {
      throw new Error(`My Platform API returned ${response.status}`);
    }
    const users = await response.json();

    return {
      accounts: users.map((u: any) => ({
        sourceObjectId: u.id,
        username: u.username,
        email: u.email,
        displayName: u.name,
        accountType: u.serviceAccount ? 'service' : 'user',
        enabled: u.active,
        lastSignIn: u.lastLogin,
      })),
    };
  }

  private mockAccounts(tenantId: string) {
    return [
      {
        sourceObjectId: 'mock-001',
        username: 'alice@example.com',
        email: 'alice@example.com',
        displayName: 'Alice Example',
        accountType: 'user' as const,
        enabled: true,
        lastSignIn: new Date().toISOString(),
      },
    ];
  }
}

export const myPlatformAdapter = new MyPlatformAdapter();

Testing requirements ​

Your adapter tests should cover:

  1. Mock readiness — returns basis: 'mock' when credentials are absent
  2. Live readiness — returns basis: 'live' when credentials are present
  3. Full view — read() returns all objects for the requested kinds
  4. Empty kinds — read() with unrequested kinds returns {}
  5. Error handling — API failures throw, never return partial data
  6. Input shape — every returned object has a valid sourceObjectId

Checklist ​

  • [ ] Implements SourceAdapter with a valid source ID matching /^[a-z0-9][a-z0-9._-]{1,63}$/
  • [ ] kinds lists exactly which ingestion kinds the adapter provides
  • [ ] readiness() returns mock mode when credentials are absent
  • [ ] read() returns the complete view or throws — never a partial set
  • [ ] Added to the ADAPTERS array in ingestion.registry.ts
  • [ ] Mock data is representative and loads only when SEED_MODE is not production
  • [ ] Per-tenant readiness implemented if vault credentials are supported
  • [ ] Tests cover readiness, full view, empty kinds and error handling