@fabricorg/platform-host 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { ActorType, ActionId, ActionStatus, AgentActionRoute, AgentActionRiskTier, MutationFootprint, ExecutionPrincipal, GovernanceRuntimeEvidence, PolicyOutcome, AssetEventEnvelope, ExecutionAttestation, ExternalReconciliation, PolicyObligation, PolicyObligationStatus, ActionDefinition, AdapterImplementation, FabricRuntimeServices, AgentActionPolicyEvaluator, MutationGovernanceResolver, RuntimePolicyDefinition } from '@fabricorg/platform';
1
+ import { ActorType, ActionId, ActionStatus, AgentActionRoute, AgentActionRiskTier, MutationFootprint, ExecutionPrincipal, GovernanceRuntimeEvidence, PolicyOutcome, AssetEventEnvelope, ExecutionAttestation, ExternalReconciliation, PolicyObligation, PolicyObligationStatus, ModuleRegistry, ActionDefinition, AdapterImplementation, FabricRuntimeServices, AgentActionPolicyEvaluator, MutationGovernanceResolver, RuntimePolicyDefinition } from '@fabricorg/platform';
2
2
 
3
3
  /** Durable Host lifecycle generation, independent from the npm package version. */
4
4
  declare const PLATFORM_HOST_CONTRACT_VERSION: 2;
5
- type InvocationSource = "sdui" | "api" | "agent" | "worker" | "system";
5
+ type InvocationSource = "ui" | "api" | "agent" | "worker" | "system" | (string & {});
6
6
  type NamespacedAttributes = Record<string, string>;
7
7
  interface InvocationProvenance {
8
8
  source: InvocationSource;
@@ -431,6 +431,8 @@ interface PlatformActionWorkerCycleResult {
431
431
  interface PlatformHostOptions<TDb> {
432
432
  store: PlatformHostStore<TDb>;
433
433
  authorization: PlatformHostAuthorization;
434
+ /** Preferred explicit catalog assembled from this runtime's Fabric modules. */
435
+ registry?: Pick<ModuleRegistry<TDb>, "resolveAction" | "resolvePolicy" | "resolveStateMachine">;
434
436
  /** Resolve vertical- or runtime-local actions without mutating the process-wide registry. */
435
437
  resolveAction?: (actionId: ActionId) => ActionDefinition<TDb> | undefined;
436
438
  adapters?: readonly AdapterImplementation[];
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ActorType, ActionId, ActionStatus, AgentActionRoute, AgentActionRiskTier, MutationFootprint, ExecutionPrincipal, GovernanceRuntimeEvidence, PolicyOutcome, AssetEventEnvelope, ExecutionAttestation, ExternalReconciliation, PolicyObligation, PolicyObligationStatus, ActionDefinition, AdapterImplementation, FabricRuntimeServices, AgentActionPolicyEvaluator, MutationGovernanceResolver, RuntimePolicyDefinition } from '@fabricorg/platform';
1
+ import { ActorType, ActionId, ActionStatus, AgentActionRoute, AgentActionRiskTier, MutationFootprint, ExecutionPrincipal, GovernanceRuntimeEvidence, PolicyOutcome, AssetEventEnvelope, ExecutionAttestation, ExternalReconciliation, PolicyObligation, PolicyObligationStatus, ModuleRegistry, ActionDefinition, AdapterImplementation, FabricRuntimeServices, AgentActionPolicyEvaluator, MutationGovernanceResolver, RuntimePolicyDefinition } from '@fabricorg/platform';
2
2
 
3
3
  /** Durable Host lifecycle generation, independent from the npm package version. */
4
4
  declare const PLATFORM_HOST_CONTRACT_VERSION: 2;
5
- type InvocationSource = "sdui" | "api" | "agent" | "worker" | "system";
5
+ type InvocationSource = "ui" | "api" | "agent" | "worker" | "system" | (string & {});
6
6
  type NamespacedAttributes = Record<string, string>;
7
7
  interface InvocationProvenance {
8
8
  source: InvocationSource;
@@ -431,6 +431,8 @@ interface PlatformActionWorkerCycleResult {
431
431
  interface PlatformHostOptions<TDb> {
432
432
  store: PlatformHostStore<TDb>;
433
433
  authorization: PlatformHostAuthorization;
434
+ /** Preferred explicit catalog assembled from this runtime's Fabric modules. */
435
+ registry?: Pick<ModuleRegistry<TDb>, "resolveAction" | "resolvePolicy" | "resolveStateMachine">;
434
436
  /** Resolve vertical- or runtime-local actions without mutating the process-wide registry. */
435
437
  resolveAction?: (actionId: ActionId) => ActionDefinition<TDb> | undefined;
436
438
  adapters?: readonly AdapterImplementation[];
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AdapterRegistry, resolveAction, createFabricId, assertGovernanceRuntimeEvidence, FABRIC_GOVERNANCE_CONTRACT_VERSION, assertMutationGovernanceContext, evaluatePolicyDefinitions, aggregatePolicyOutcomes, validateTransition, executeWithAdapterRetry, resolveStateMachine } from '@fabricorg/platform';
1
+ import { AdapterRegistry, createFabricId, assertGovernanceRuntimeEvidence, FABRIC_GOVERNANCE_CONTRACT_VERSION, assertMutationGovernanceContext, evaluatePolicyDefinitions, aggregatePolicyOutcomes, validateStateMachineTransition, executeWithAdapterRetry } from '@fabricorg/platform';
2
2
  import { createHash } from 'crypto';
3
3
 
4
4
  // src/host.ts
@@ -29,10 +29,10 @@ function digestParameters(parameters) {
29
29
  return createHash("sha256").update(canonicalJson(parameters)).digest("hex");
30
30
  }
31
31
  var ATTRIBUTE_NAME = /^[a-z][a-z0-9-]*(?:\.[A-Za-z][A-Za-z0-9_-]*)+$/;
32
- var INVOCATION_SOURCES = /* @__PURE__ */ new Set(["sdui", "api", "agent", "worker", "system"]);
32
+ var INVOCATION_SOURCE = /^(?:ui|sdui|api|agent|worker|system|[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+)$/;
33
33
  function normalizeProvenance(input, options) {
34
34
  if (!input) return void 0;
35
- if (!INVOCATION_SOURCES.has(input.source)) throw new Error(`Invalid invocation provenance source: ${input.source}`);
35
+ if (!INVOCATION_SOURCE.test(input.source)) throw new Error(`Invalid invocation provenance source: ${input.source}`);
36
36
  const maxAttributes = options?.maxAttributes ?? 16;
37
37
  const maxValueLength = options?.maxValueLength ?? 256;
38
38
  const allowlist = new Set(options?.auditAttributeAllowlist ?? []);
@@ -81,7 +81,10 @@ function createGovernedActionHost(options) {
81
81
  for (const adapter of options.adapters ?? []) adapters.register(adapter);
82
82
  const now = options.now ?? (() => /* @__PURE__ */ new Date());
83
83
  const extractEvents = options.extractEvents ?? DEFAULT_EXTRACT_EVENTS;
84
- const actionResolver = options.resolveAction ?? resolveAction;
84
+ const configuredActionResolver = options.resolveAction ?? options.registry?.resolveAction;
85
+ if (!configuredActionResolver) throw new Error("Platform Host requires an explicit module registry or resolveAction function.");
86
+ const actionResolver = configuredActionResolver;
87
+ const stateMachineResolver = options.registry?.resolveStateMachine ?? (() => void 0);
85
88
  const eventResultFields = options.eventResultFields ?? ["_events"];
86
89
  async function submitAction(input) {
87
90
  if (input.executionReason && !["initial", "offline_replay"].includes(input.executionReason)) {
@@ -386,6 +389,7 @@ function createGovernedActionHost(options) {
386
389
  parameters: parsed.data,
387
390
  db: options.store.db,
388
391
  services: options.services,
392
+ resolveCodePolicy: options.registry?.resolvePolicy,
389
393
  mode: "execute",
390
394
  now: now()
391
395
  });
@@ -438,10 +442,11 @@ function createGovernedActionHost(options) {
438
442
  spaceId,
439
443
  binding.entityType,
440
444
  entityId
441
- ) ?? initialState(binding.entityType) : initialState(binding.entityType);
445
+ ) ?? initialState(stateMachineResolver(binding.entityType)) : initialState(stateMachineResolver(binding.entityType));
442
446
  const targetState = typeof binding.targetState === "function" ? binding.targetState(parsed.data) : binding.targetState;
443
447
  if (targetState !== "") {
444
- const transition = validateTransition(
448
+ const transition = validateStateMachineTransition(
449
+ stateMachineResolver(binding.entityType),
445
450
  binding.entityType,
446
451
  currentState,
447
452
  targetState,
@@ -927,8 +932,7 @@ function declaredPolicies(policyIds) {
927
932
  codeEvaluatorPolicyId: policyId
928
933
  }));
929
934
  }
930
- function initialState(entityType) {
931
- const machine = resolveStateMachine(entityType);
935
+ function initialState(machine) {
932
936
  return Object.values(machine?.states ?? {}).find((state) => state.stateClass === "initial")?.id ?? "none";
933
937
  }
934
938
  function isTerminal(status) {