feat(contracts): @insignia/iios-contracts — scope, enums, platform ports, CloudEvents, errors

Verbatim IiosPlatformPorts from the bottom-up atlas; orgId/appId required scope
(KG-02); PolicyDeniedError for fail-closed. Vitest as workspace test runner.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-30 20:59:34 +05:30
parent c00d038df2
commit fbea291609
12 changed files with 1248 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
import { describe, it, expect } from 'vitest';
import {
IIOS_EVENTS,
PolicyDeniedError,
ACTOR_KINDS,
type ScopeVector,
type IiosPlatformPorts,
} from './index';
describe('iios-contracts public entrypoint', () => {
it('exports the event catalog', () => {
expect(IIOS_EVENTS.interactionNormalized).toBe('com.insignia.iios.interaction.normalized.v1');
});
it('PolicyDeniedError carries the stable POLICY_DENIED code', () => {
const err = new PolicyDeniedError('opa denied');
expect(err.code).toBe('POLICY_DENIED');
expect(err).toBeInstanceOf(Error);
});
it('actor kinds include the four real principals + UNKNOWN', () => {
expect(ACTOR_KINDS).toContain('HUMAN');
expect(ACTOR_KINDS).toContain('AI');
expect(ACTOR_KINDS).toContain('SERVICE');
});
it('types are usable (compile-time check)', () => {
const scope: ScopeVector = { orgId: 'org_1', appId: 'portal-demo' };
const ports: Pick<IiosPlatformPorts, 'opa'> = {
opa: { decide: async () => ({ decisionRef: 'd', allow: true, obligations: [], ttlSeconds: 60 }) },
};
expect(scope.appId).toBe('portal-demo');
expect(typeof ports.opa.decide).toBe('function');
});
});