@elevasis/sdk 1.27.1 → 1.28.1

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/cli.cjs CHANGED
@@ -36948,6 +36948,8 @@ function childSystemsOf2(system) {
36948
36948
  return system.systems ?? system.subsystems ?? {};
36949
36949
  }
36950
36950
  function getSystem(model, path3) {
36951
+ const flatMatch = model.systems[path3];
36952
+ if (flatMatch !== void 0) return flatMatch;
36951
36953
  const segments = path3.split(".");
36952
36954
  let current = model.systems;
36953
36955
  let node;
@@ -37592,6 +37594,26 @@ var SystemUiSchema = external_exports.object({
37592
37594
  icon: IconNameSchema.optional(),
37593
37595
  order: external_exports.number().int().optional()
37594
37596
  });
37597
+ var SystemInterfaceKeySchema = ModelIdSchema;
37598
+ var SystemInterfaceLifecycleSchema = external_exports.enum(["draft", "active", "disabled", "deprecated", "archived"]).meta({ label: "System interface lifecycle", color: "teal" });
37599
+ var SystemInterfaceReadinessProfileSchema = external_exports.string().trim().min(1).max(200).regex(
37600
+ /^[a-z0-9][a-z0-9-]*(?:\.[a-z0-9][a-z0-9-]*)*(?:\.[a-z0-9][a-z0-9-]*)?$/,
37601
+ 'Readiness profiles must use dotted lowercase identifiers (e.g. "sales.lead-gen.api")'
37602
+ );
37603
+ var SystemInterfaceResourceScopeSchema = external_exports.array(ModelIdSchema).default([]);
37604
+ var SystemApiInterfaceSchema = external_exports.object({
37605
+ lifecycle: SystemInterfaceLifecycleSchema.default("active"),
37606
+ readinessProfile: SystemInterfaceReadinessProfileSchema.optional(),
37607
+ /**
37608
+ * Resource ids that participate in this API interface. This scopes readiness
37609
+ * derivation without duplicating authored required/provided contract refs.
37610
+ */
37611
+ resourceIds: SystemInterfaceResourceScopeSchema.optional()
37612
+ }).strict();
37613
+ var SystemInterfaceRefSchema = external_exports.object({
37614
+ systemPath: SystemPathSchema,
37615
+ interfaceKey: SystemInterfaceKeySchema
37616
+ }).strict();
37595
37617
  var JsonValueSchema = external_exports.lazy(
37596
37618
  () => external_exports.union([
37597
37619
  external_exports.string(),
@@ -37630,6 +37652,8 @@ var SystemEntrySchema = external_exports.object({
37630
37652
  policies: external_exports.array(ModelIdSchema.meta({ ref: "policy" })).default([]).optional(),
37631
37653
  /** Optional goals this system contributes to. */
37632
37654
  drivesGoals: external_exports.array(ModelIdSchema.meta({ ref: "goal" })).default([]).optional(),
37655
+ /** Thin API runtime-boundary marker. Readiness is derived from scoped resources and topology. */
37656
+ apiInterface: SystemApiInterfaceSchema.optional(),
37633
37657
  /** @deprecated Use lifecycle. Accepted for one publish cycle. */
37634
37658
  status: SystemStatusSchema.optional(),
37635
37659
  /** @deprecated Use ui.path. Kept for one-cycle Feature compatibility. */
@@ -38066,6 +38090,15 @@ var OmTopologyMetadataSchema = external_exports.record(external_exports.string()
38066
38090
  }
38067
38091
  visit(metadata, []);
38068
38092
  });
38093
+ var OmTopologySystemInterfaceGrantSchema = external_exports.object({
38094
+ consumer: SystemInterfaceRefSchema,
38095
+ provider: SystemInterfaceRefSchema,
38096
+ resourceIds: external_exports.array(ResourceIdSchema).default([]),
38097
+ ontologyIds: external_exports.array(OntologyIdSchema).default([])
38098
+ }).strict();
38099
+ var OmTopologySystemInterfaceGrantMetadataSchema = external_exports.object({
38100
+ systemInterfaceGrant: OmTopologySystemInterfaceGrantSchema
38101
+ }).strict();
38069
38102
  var OmTopologyRelationshipSchema = external_exports.object({
38070
38103
  from: OmTopologyNodeRefSchema,
38071
38104
  kind: OmTopologyRelationshipKindSchema,
@@ -38617,6 +38650,26 @@ function refineOrganizationModel(model, ctx) {
38617
38650
  );
38618
38651
  }
38619
38652
  });
38653
+ allSystems.forEach(({ path: systemPath, schemaPath, system }) => {
38654
+ system.apiInterface?.resourceIds?.forEach((resourceId, resourceIndex) => {
38655
+ const resource = resourcesById.get(resourceId);
38656
+ if (resource === void 0) {
38657
+ addIssue(
38658
+ ctx,
38659
+ [...schemaPath, "apiInterface", "resourceIds", resourceIndex],
38660
+ `System Interface "${systemPath}/api" scopes unknown resource "${resourceId}"`
38661
+ );
38662
+ return;
38663
+ }
38664
+ if (resource.systemPath !== systemPath) {
38665
+ addIssue(
38666
+ ctx,
38667
+ [...schemaPath, "apiInterface", "resourceIds", resourceIndex],
38668
+ `System Interface "${systemPath}/api" scopes resource "${resourceId}" from system "${resource.systemPath}"`
38669
+ );
38670
+ }
38671
+ });
38672
+ });
38620
38673
  function validateResourceOntologyBinding(resourceId, bindingKey, expectedKind, ids) {
38621
38674
  const ontologyIds2 = ids === void 0 ? [] : Array.isArray(ids) ? ids : [ids];
38622
38675
  ontologyIds2.forEach((ontologyId, ontologyIndex) => {
@@ -40215,6 +40268,458 @@ function validateModelConfig(config3) {
40215
40268
  }
40216
40269
  }
40217
40270
 
40271
+ // ../core/src/business/acquisition/ontology-validation.ts
40272
+ var LEAD_GEN_API_INTERFACE = {
40273
+ systemPath: "sales.lead-gen",
40274
+ interfaceKey: "api",
40275
+ readinessProfile: "sales.lead-gen.api"
40276
+ };
40277
+ var CRM_API_INTERFACE = {
40278
+ systemPath: "sales.crm",
40279
+ interfaceKey: "api",
40280
+ readinessProfile: "sales.crm.api"
40281
+ };
40282
+ var LEAD_GEN_CRM_HANDOFF_INTERFACE = {
40283
+ systemPath: "sales.lead-gen",
40284
+ interfaceKey: "crm-handoff",
40285
+ readinessProfile: "sales.lead-gen.crm-handoff"
40286
+ };
40287
+ var LEAD_GEN_API_READINESS_LABEL = LEAD_GEN_API_INTERFACE.readinessProfile;
40288
+ var CRM_API_READINESS_LABEL = CRM_API_INTERFACE.readinessProfile;
40289
+ var LEAD_GEN_CRM_HANDOFF_READINESS_LABEL = LEAD_GEN_CRM_HANDOFF_INTERFACE.readinessProfile;
40290
+ var LEAD_GEN_LIST_OBJECT_ONTOLOGY_ID = formatOntologyId({
40291
+ scope: "sales.lead-gen",
40292
+ kind: "object",
40293
+ localId: "list"
40294
+ });
40295
+ var LEAD_GEN_COMPANY_OBJECT_ONTOLOGY_ID = formatOntologyId({
40296
+ scope: "sales.lead-gen",
40297
+ kind: "object",
40298
+ localId: "company"
40299
+ });
40300
+ var LEAD_GEN_CONTACT_OBJECT_ONTOLOGY_ID = formatOntologyId({
40301
+ scope: "sales.lead-gen",
40302
+ kind: "object",
40303
+ localId: "contact"
40304
+ });
40305
+ var LEAD_GEN_BUILD_TEMPLATE_CATALOG_ONTOLOGY_ID = formatOntologyId({
40306
+ scope: "sales.lead-gen",
40307
+ kind: "catalog",
40308
+ localId: "build-template"
40309
+ });
40310
+ var LEAD_GEN_COMPANY_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
40311
+ scope: "sales.lead-gen",
40312
+ kind: "catalog",
40313
+ localId: "company-stage"
40314
+ });
40315
+ var LEAD_GEN_CONTACT_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
40316
+ scope: "sales.lead-gen",
40317
+ kind: "catalog",
40318
+ localId: "contact-stage"
40319
+ });
40320
+ var CRM_PIPELINE_CATALOG_ONTOLOGY_ID = formatOntologyId({
40321
+ scope: "sales.crm",
40322
+ kind: "catalog",
40323
+ localId: "crm.pipeline"
40324
+ });
40325
+ var LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
40326
+ scope: "sales.lead-gen",
40327
+ kind: "catalog",
40328
+ localId: "lead-gen.stage-catalog"
40329
+ });
40330
+ function createLeadGenStageCatalog(model) {
40331
+ return {
40332
+ id: LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID,
40333
+ label: "Lead Gen Processing Stages",
40334
+ ownerSystemId: "sales.lead-gen",
40335
+ kind: "processing-stage-catalog",
40336
+ entries: Object.fromEntries(
40337
+ Object.entries(getLeadGenStageCatalog(model)).map(([key, entry]) => [
40338
+ key,
40339
+ {
40340
+ ...entry
40341
+ }
40342
+ ])
40343
+ ),
40344
+ legacyCatalogKey: "LEAD_GEN_STAGE_CATALOG"
40345
+ };
40346
+ }
40347
+ function isPlainRecord(value) {
40348
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
40349
+ }
40350
+ function addReadinessIssue(issues, family, code, message, details = {}) {
40351
+ issues.push({
40352
+ family,
40353
+ code,
40354
+ message,
40355
+ ...details
40356
+ });
40357
+ }
40358
+ function formatInterfaceIdentity(systemPath, interfaceKey) {
40359
+ return `${systemPath}/${interfaceKey}`;
40360
+ }
40361
+ function profileForInterface(systemPath, interfaceKey, readinessProfile) {
40362
+ return readinessProfile ?? `${systemPath}.${interfaceKey}`;
40363
+ }
40364
+ function readinessMarkerPath(context) {
40365
+ return context.interfaceKey === "api" ? `systems.${context.systemPath}.apiInterface` : `systems.${context.systemPath}.derivedCrmHandoffReadiness`;
40366
+ }
40367
+ function getActiveScopedResources(model, resourceIds, issues, context) {
40368
+ const resources = [];
40369
+ for (const [index, resourceId] of resourceIds.entries()) {
40370
+ const resource = model.resources?.[resourceId];
40371
+ const path3 = `${readinessMarkerPath(context)}.resourceIds.${index}`;
40372
+ if (resource === void 0) {
40373
+ addReadinessIssue(
40374
+ issues,
40375
+ "SYSTEM_INTERFACE_NOT_READY",
40376
+ "missing-resource",
40377
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" scopes missing resource "${resourceId}".`,
40378
+ { path: path3, ref: resourceId }
40379
+ );
40380
+ continue;
40381
+ }
40382
+ if (resource.systemPath !== context.systemPath) {
40383
+ addReadinessIssue(
40384
+ issues,
40385
+ "SYSTEM_INTERFACE_INVALID",
40386
+ "resource-system-mismatch",
40387
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" scopes resource "${resourceId}" from system "${resource.systemPath}".`,
40388
+ { path: path3, ref: resourceId }
40389
+ );
40390
+ continue;
40391
+ }
40392
+ if (resource.status !== "active") {
40393
+ addReadinessIssue(
40394
+ issues,
40395
+ "SYSTEM_INTERFACE_NOT_READY",
40396
+ "inactive-resource",
40397
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" scopes inactive resource "${resourceId}".`,
40398
+ { path: path3, ref: resourceId }
40399
+ );
40400
+ continue;
40401
+ }
40402
+ resources.push(resource);
40403
+ }
40404
+ return resources;
40405
+ }
40406
+ function resourceBindingIds(resources, key) {
40407
+ return new Set(resources.flatMap((resource) => resource.ontology?.[key] ?? []));
40408
+ }
40409
+ function requireScopedBinding(issues, boundIds, bindingKey, ontologyId, context) {
40410
+ if (boundIds.has(ontologyId)) return;
40411
+ addReadinessIssue(
40412
+ issues,
40413
+ "SYSTEM_INTERFACE_NOT_READY",
40414
+ "missing-resource-binding",
40415
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" has no active scoped resource with ontology.${bindingKey} binding "${ontologyId}".`,
40416
+ { path: `${readinessMarkerPath(context)}.resourceIds`, ref: ontologyId }
40417
+ );
40418
+ }
40419
+ function ontologyOwnerMatches(ontologyId, expectedSystemPath, catalog) {
40420
+ if (catalog?.ownerSystemId !== void 0) return catalog.ownerSystemId === expectedSystemPath;
40421
+ return parseOntologyId(ontologyId).scope === expectedSystemPath;
40422
+ }
40423
+ function requireObjectReadiness(issues, index, objectId, context) {
40424
+ const object2 = index.ontology.objectTypes[objectId];
40425
+ if (object2 === void 0) {
40426
+ addReadinessIssue(
40427
+ issues,
40428
+ "SYSTEM_INTERFACE_NOT_READY",
40429
+ "missing-object",
40430
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" is missing required object type "${objectId}".`,
40431
+ { ref: objectId }
40432
+ );
40433
+ return;
40434
+ }
40435
+ const ownerSystemId = object2.ownerSystemId ?? parseOntologyId(objectId).scope;
40436
+ if (ownerSystemId !== context.systemPath) {
40437
+ addReadinessIssue(
40438
+ issues,
40439
+ "SYSTEM_INTERFACE_INVALID",
40440
+ "foreign-object",
40441
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" requires object "${objectId}" owned by "${ownerSystemId}".`,
40442
+ { ref: objectId }
40443
+ );
40444
+ }
40445
+ }
40446
+ function requireCatalogReadiness(issues, index, catalogId, context) {
40447
+ const catalog = index.ontology.catalogTypes[catalogId];
40448
+ if (catalog === void 0) {
40449
+ addReadinessIssue(
40450
+ issues,
40451
+ "SYSTEM_INTERFACE_NOT_READY",
40452
+ "missing-catalog",
40453
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" is missing required catalog "${catalogId}".`,
40454
+ { ref: catalogId }
40455
+ );
40456
+ return void 0;
40457
+ }
40458
+ if (context.allowForeignOwner !== true && !ontologyOwnerMatches(catalogId, context.systemPath, catalog)) {
40459
+ addReadinessIssue(
40460
+ issues,
40461
+ "SYSTEM_INTERFACE_INVALID",
40462
+ "foreign-catalog",
40463
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" requires catalog "${catalogId}" owned by "${catalog.ownerSystemId ?? parseOntologyId(catalogId).scope}".`,
40464
+ { ref: catalogId }
40465
+ );
40466
+ }
40467
+ if (Object.keys(getCatalogEntries(catalog)).length === 0) {
40468
+ addReadinessIssue(
40469
+ issues,
40470
+ "SYSTEM_INTERFACE_NOT_READY",
40471
+ "empty-catalog",
40472
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" requires catalog entries for "${catalogId}".`,
40473
+ { ref: catalogId }
40474
+ );
40475
+ }
40476
+ return catalog;
40477
+ }
40478
+ function requireLeadGenInterfaceReadiness(issues, index, resources, context) {
40479
+ const reads = resourceBindingIds(resources, "reads");
40480
+ const catalogs = resourceBindingIds(resources, "usesCatalogs");
40481
+ for (const objectId of [
40482
+ LEAD_GEN_LIST_OBJECT_ONTOLOGY_ID,
40483
+ LEAD_GEN_COMPANY_OBJECT_ONTOLOGY_ID,
40484
+ LEAD_GEN_CONTACT_OBJECT_ONTOLOGY_ID
40485
+ ]) {
40486
+ requireObjectReadiness(issues, index, objectId, context);
40487
+ requireScopedBinding(issues, reads, "reads", objectId, context);
40488
+ }
40489
+ for (const catalogId of [
40490
+ LEAD_GEN_BUILD_TEMPLATE_CATALOG_ONTOLOGY_ID,
40491
+ LEAD_GEN_COMPANY_STAGE_CATALOG_ONTOLOGY_ID,
40492
+ LEAD_GEN_CONTACT_STAGE_CATALOG_ONTOLOGY_ID
40493
+ ]) {
40494
+ requireCatalogReadiness(issues, index, catalogId, context);
40495
+ requireScopedBinding(issues, catalogs, "usesCatalogs", catalogId, context);
40496
+ }
40497
+ const templateStepCatalog = findLeadGenTemplateStepCatalog(index);
40498
+ if (templateStepCatalog === void 0) {
40499
+ addReadinessIssue(
40500
+ issues,
40501
+ "SYSTEM_INTERFACE_NOT_READY",
40502
+ "missing-template-step-catalog",
40503
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" is missing a lead-gen template-step catalog.`
40504
+ );
40505
+ } else {
40506
+ requireCatalogReadiness(issues, index, templateStepCatalog.id, context);
40507
+ requireScopedBinding(issues, catalogs, "usesCatalogs", templateStepCatalog.id, context);
40508
+ }
40509
+ const leadGenStageCatalog = requireCatalogReadiness(issues, index, LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID, context);
40510
+ return leadGenStageCatalog;
40511
+ }
40512
+ function requireCrmInterfaceReadiness(issues, index, resources, context) {
40513
+ const catalogs = resourceBindingIds(resources, "usesCatalogs");
40514
+ const crmPipelineCatalog = requireCatalogReadiness(issues, index, CRM_PIPELINE_CATALOG_ONTOLOGY_ID, context);
40515
+ requireScopedBinding(issues, catalogs, "usesCatalogs", CRM_PIPELINE_CATALOG_ONTOLOGY_ID, context);
40516
+ return crmPipelineCatalog;
40517
+ }
40518
+ function findSystemInterfaceGrant(model, consumer, provider) {
40519
+ return Object.values(model.topology?.relationships ?? {}).find((relationship) => {
40520
+ const grant = relationship.metadata?.["systemInterfaceGrant"];
40521
+ if (!isPlainRecord(grant) || !isPlainRecord(grant.consumer) || !isPlainRecord(grant.provider)) return false;
40522
+ return grant.consumer.systemPath === consumer.systemPath && grant.consumer.interfaceKey === consumer.interfaceKey && grant.provider.systemPath === provider.systemPath && grant.provider.interfaceKey === provider.interfaceKey;
40523
+ });
40524
+ }
40525
+ function requireHandoffBridgeReadiness(issues, model, context) {
40526
+ const crmResult = computeInterfaceReadiness(model, CRM_API_INTERFACE);
40527
+ if (!crmResult.ready) {
40528
+ for (const issue2 of crmResult.issues) {
40529
+ addReadinessIssue(
40530
+ issues,
40531
+ "SYSTEM_BRIDGE_NOT_READY",
40532
+ issue2.code,
40533
+ `Provider interface ${formatInterfaceIdentity(CRM_API_INTERFACE.systemPath, CRM_API_INTERFACE.interfaceKey)} is not ready: ${issue2.message}`,
40534
+ { path: issue2.path, ref: issue2.ref }
40535
+ );
40536
+ }
40537
+ }
40538
+ const bridgeGrant = findSystemInterfaceGrant(model, context, CRM_API_INTERFACE);
40539
+ if (bridgeGrant === void 0) {
40540
+ addReadinessIssue(
40541
+ issues,
40542
+ "SYSTEM_BRIDGE_NOT_READY",
40543
+ "missing-topology-grant",
40544
+ `System Interface "${formatInterfaceIdentity(context.systemPath, context.interfaceKey)}" requires a scoped topology grant to "${formatInterfaceIdentity(CRM_API_INTERFACE.systemPath, CRM_API_INTERFACE.interfaceKey)}".`
40545
+ );
40546
+ }
40547
+ return bridgeGrant;
40548
+ }
40549
+ function getLeadGenCrmHandoffResourceIds(model) {
40550
+ return Object.values(model.resources ?? {}).filter(
40551
+ (resource) => resource.systemPath === LEAD_GEN_CRM_HANDOFF_INTERFACE.systemPath && resource.ontology?.usesCatalogs?.includes(CRM_PIPELINE_CATALOG_ONTOLOGY_ID) === true
40552
+ ).map((resource) => resource.id);
40553
+ }
40554
+ function getSystemInterfaceReadinessMarker(model, request) {
40555
+ const system = getSystem(model, request.systemPath);
40556
+ if (system === void 0) return void 0;
40557
+ if (request.interfaceKey === LEAD_GEN_API_INTERFACE.interfaceKey) {
40558
+ return system.apiInterface;
40559
+ }
40560
+ if (request.systemPath === LEAD_GEN_CRM_HANDOFF_INTERFACE.systemPath && request.interfaceKey === LEAD_GEN_CRM_HANDOFF_INTERFACE.interfaceKey) {
40561
+ return {
40562
+ lifecycle: "active",
40563
+ readinessProfile: LEAD_GEN_CRM_HANDOFF_INTERFACE.readinessProfile,
40564
+ resourceIds: getLeadGenCrmHandoffResourceIds(model)
40565
+ };
40566
+ }
40567
+ return void 0;
40568
+ }
40569
+ function mergeLeadGenDerivedCatalogs(model) {
40570
+ const baseCatalogTypes = model.ontology?.catalogTypes ?? {};
40571
+ const derivedCatalogTypes = {};
40572
+ if (baseCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] === void 0) {
40573
+ derivedCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] = createLeadGenStageCatalog(model);
40574
+ }
40575
+ if (Object.keys(derivedCatalogTypes).length === 0) return model;
40576
+ return {
40577
+ ...model,
40578
+ ontology: {
40579
+ ...model.ontology ?? {},
40580
+ catalogTypes: {
40581
+ ...baseCatalogTypes,
40582
+ ...derivedCatalogTypes
40583
+ }
40584
+ }
40585
+ };
40586
+ }
40587
+ function compileBusinessOntology(model, contractId) {
40588
+ const compilation = compileOrganizationOntology(mergeLeadGenDerivedCatalogs(model));
40589
+ if (compilation.diagnostics.length > 0) {
40590
+ const summary = compilation.diagnostics.map((diagnostic) => diagnostic.message).join("; ");
40591
+ throw new Error(`${contractId} ontology validation index failed to compile: ${summary}`);
40592
+ }
40593
+ return {
40594
+ ontology: compilation.ontology,
40595
+ actionTypesByLegacyId: indexActionTypesByLegacyId(compilation.ontology.actionTypes)
40596
+ };
40597
+ }
40598
+ function tryCompileBusinessOntology(model, readinessProfile, issues) {
40599
+ try {
40600
+ return compileBusinessOntology(model, readinessProfile);
40601
+ } catch (error46) {
40602
+ addReadinessIssue(
40603
+ issues,
40604
+ "SYSTEM_INTERFACE_INVALID",
40605
+ "ontology-compile-failed",
40606
+ error46 instanceof Error ? error46.message : String(error46)
40607
+ );
40608
+ return void 0;
40609
+ }
40610
+ }
40611
+ function computeInterfaceReadiness(model, request) {
40612
+ const issues = [];
40613
+ const system = getSystem(model, request.systemPath);
40614
+ const systemInterface = getSystemInterfaceReadinessMarker(model, request);
40615
+ const readinessProfile = systemInterface === void 0 ? void 0 : profileForInterface(request.systemPath, request.interfaceKey, systemInterface.readinessProfile);
40616
+ const scopedResourceIds = systemInterface?.resourceIds ?? [];
40617
+ if (system === void 0) {
40618
+ addReadinessIssue(
40619
+ issues,
40620
+ "SYSTEM_INTERFACE_MISSING",
40621
+ "missing-system",
40622
+ `System "${request.systemPath}" is missing.`,
40623
+ { ref: request.systemPath }
40624
+ );
40625
+ return { ready: false, systemPath: request.systemPath, interfaceKey: request.interfaceKey, scopedResourceIds, issues };
40626
+ }
40627
+ if (systemInterface === void 0) {
40628
+ addReadinessIssue(
40629
+ issues,
40630
+ "SYSTEM_INTERFACE_MISSING",
40631
+ "missing-interface",
40632
+ `System "${request.systemPath}" does not declare interface "${request.interfaceKey}".`,
40633
+ { path: readinessMarkerPath(request) }
40634
+ );
40635
+ return { ready: false, systemPath: request.systemPath, interfaceKey: request.interfaceKey, scopedResourceIds, issues };
40636
+ }
40637
+ if (systemInterface.lifecycle !== "active") {
40638
+ addReadinessIssue(
40639
+ issues,
40640
+ "SYSTEM_INTERFACE_DISABLED",
40641
+ "inactive-interface",
40642
+ `System Interface "${formatInterfaceIdentity(request.systemPath, request.interfaceKey)}" lifecycle is "${systemInterface.lifecycle}".`,
40643
+ { path: `${readinessMarkerPath(request)}.lifecycle` }
40644
+ );
40645
+ }
40646
+ const supportedProfiles = [
40647
+ LEAD_GEN_API_INTERFACE.readinessProfile,
40648
+ CRM_API_INTERFACE.readinessProfile,
40649
+ LEAD_GEN_CRM_HANDOFF_INTERFACE.readinessProfile
40650
+ ];
40651
+ const supportedProfile = readinessProfile !== void 0 && supportedProfiles.some((profile) => profile === readinessProfile);
40652
+ if (!supportedProfile) {
40653
+ addReadinessIssue(
40654
+ issues,
40655
+ "SYSTEM_INTERFACE_INVALID",
40656
+ "unknown-readiness-profile",
40657
+ `System Interface "${formatInterfaceIdentity(request.systemPath, request.interfaceKey)}" references unknown readiness profile "${readinessProfile}".`,
40658
+ { path: `${readinessMarkerPath(request)}.readinessProfile`, ref: readinessProfile }
40659
+ );
40660
+ return {
40661
+ ready: false,
40662
+ systemPath: request.systemPath,
40663
+ interfaceKey: request.interfaceKey,
40664
+ readinessProfile,
40665
+ scopedResourceIds,
40666
+ issues
40667
+ };
40668
+ }
40669
+ if (scopedResourceIds.length === 0) {
40670
+ addReadinessIssue(
40671
+ issues,
40672
+ "SYSTEM_INTERFACE_NOT_READY",
40673
+ "missing-scoped-resources",
40674
+ `System Interface "${formatInterfaceIdentity(request.systemPath, request.interfaceKey)}" must scope at least one active resource.`,
40675
+ { path: `${readinessMarkerPath(request)}.resourceIds` }
40676
+ );
40677
+ }
40678
+ const checkedReadinessProfile = readinessProfile;
40679
+ if (checkedReadinessProfile === void 0) {
40680
+ throw new Error("Supported readiness profile unexpectedly resolved to undefined");
40681
+ }
40682
+ const resources = getActiveScopedResources(model, scopedResourceIds, issues, request);
40683
+ const index = tryCompileBusinessOntology(model, checkedReadinessProfile, issues);
40684
+ if (index !== void 0) {
40685
+ if (checkedReadinessProfile === LEAD_GEN_API_INTERFACE.readinessProfile) {
40686
+ requireLeadGenInterfaceReadiness(issues, index, resources, request);
40687
+ } else if (checkedReadinessProfile === CRM_API_INTERFACE.readinessProfile) {
40688
+ requireCrmInterfaceReadiness(issues, index, resources, request);
40689
+ } else if (checkedReadinessProfile === LEAD_GEN_CRM_HANDOFF_INTERFACE.readinessProfile) {
40690
+ requireLeadGenInterfaceReadiness(issues, index, resources, request);
40691
+ requireCrmInterfaceReadiness(issues, index, resources, { ...request, allowForeignOwner: true });
40692
+ requireHandoffBridgeReadiness(issues, model, request);
40693
+ }
40694
+ }
40695
+ return {
40696
+ ready: issues.length === 0,
40697
+ systemPath: request.systemPath,
40698
+ interfaceKey: request.interfaceKey,
40699
+ readinessProfile,
40700
+ scopedResourceIds,
40701
+ issues
40702
+ };
40703
+ }
40704
+ function findLeadGenTemplateStepCatalog(index) {
40705
+ return Object.values(index.ontology.catalogTypes).find(
40706
+ (catalog) => catalog.ownerSystemId === "sales.lead-gen" && catalog.kind === "template-step" && catalog.appliesTo === LEAD_GEN_LIST_OBJECT_ONTOLOGY_ID
40707
+ );
40708
+ }
40709
+ function indexActionTypesByLegacyId(actionTypes) {
40710
+ const byLegacyId = {};
40711
+ for (const actionType of Object.values(actionTypes)) {
40712
+ const legacyActionId = actionType["legacyActionId"];
40713
+ if (typeof legacyActionId === "string") {
40714
+ byLegacyId[legacyActionId] = actionType;
40715
+ }
40716
+ }
40717
+ return byLegacyId;
40718
+ }
40719
+ function getCatalogEntries(catalog) {
40720
+ return isPlainRecord(catalog.entries) ? catalog.entries : {};
40721
+ }
40722
+
40218
40723
  // ../core/src/platform/registry/validation.ts
40219
40724
  var RegistryValidationError = class extends Error {
40220
40725
  constructor(orgName, resourceId, field2, message) {
@@ -40305,7 +40810,7 @@ function ontologyIndexForKind(index, kind) {
40305
40810
  function sameJson(left, right) {
40306
40811
  return JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
40307
40812
  }
40308
- function addOntologyBindingIssues(issues, orgName, resource, ontologyIndex) {
40813
+ function addOntologyBindingIssues(issues, orgName, resource, ontologyIndex, organizationModel) {
40309
40814
  const binding = resource.ontology;
40310
40815
  if (binding === void 0) return;
40311
40816
  const hasOperationalOntologyBinding = binding.primaryAction !== void 0 || (binding.reads?.length ?? 0) > 0 || (binding.writes?.length ?? 0) > 0 || (binding.usesCatalogs?.length ?? 0) > 0 || (binding.emits?.length ?? 0) > 0;
@@ -40348,6 +40853,45 @@ function addOntologyBindingIssues(issues, orgName, resource, ontologyIndex) {
40348
40853
  validateRefs("writes", "object", binding.writes);
40349
40854
  validateRefs("usesCatalogs", "catalog", binding.usesCatalogs);
40350
40855
  validateRefs("emits", "event", binding.emits);
40856
+ addOntologyTopologyGrantIssues(issues, orgName, resource, organizationModel);
40857
+ }
40858
+ function addOntologyTopologyGrantIssues(issues, orgName, resource, organizationModel) {
40859
+ const binding = resource.ontology;
40860
+ if (binding === void 0) return;
40861
+ const refs = [
40862
+ ...binding.actions ?? [],
40863
+ ...binding.primaryAction !== void 0 ? [binding.primaryAction] : [],
40864
+ ...binding.reads ?? [],
40865
+ ...binding.writes ?? [],
40866
+ ...binding.usesCatalogs ?? [],
40867
+ ...binding.emits ?? []
40868
+ ];
40869
+ for (const ontologyId of new Set(refs)) {
40870
+ const parsed = parseOntologyId(ontologyId);
40871
+ if (parsed.isGlobal || parsed.scope === resource.systemPath) continue;
40872
+ if (hasScopedTopologyGrant(organizationModel, resource, parsed.scope, ontologyId)) continue;
40873
+ const missingGrant = `systemInterfaceGrant(${resource.systemPath} -> ${parsed.scope}, resourceIds: ["${resource.id}"], ontologyIds: ["${ontologyId}"])`;
40874
+ addGovernanceIssue(
40875
+ issues,
40876
+ "ontology-topology-grant-missing",
40877
+ orgName,
40878
+ resource.id,
40879
+ `[${orgName}] Resource '${resource.id}' in system '${resource.systemPath}' references ontology '${ontologyId}' from system '${parsed.scope}' without scoped topology grant '${missingGrant}'.`
40880
+ );
40881
+ }
40882
+ }
40883
+ function hasScopedTopologyGrant(organizationModel, resource, targetSystemPath, ontologyId) {
40884
+ return Object.values(organizationModel.topology?.relationships ?? {}).some((relationship) => {
40885
+ if (relationship.kind !== "uses") return false;
40886
+ const grant = relationship.metadata?.["systemInterfaceGrant"];
40887
+ if (!isSystemInterfaceGrantRecord(grant)) return false;
40888
+ return grant.consumer.systemPath === resource.systemPath && grant.provider.systemPath === targetSystemPath && grant.resourceIds.includes(resource.id) && grant.ontologyIds.includes(ontologyId);
40889
+ });
40890
+ }
40891
+ function isSystemInterfaceGrantRecord(value) {
40892
+ if (typeof value !== "object" || value === null) return false;
40893
+ const grant = value;
40894
+ return typeof grant.consumer?.systemPath === "string" && typeof grant.consumer.interfaceKey === "string" && typeof grant.provider?.systemPath === "string" && typeof grant.provider.interfaceKey === "string" && Array.isArray(grant.resourceIds) && grant.resourceIds.every((id) => typeof id === "string") && Array.isArray(grant.ontologyIds) && grant.ontologyIds.every((id) => typeof id === "string");
40351
40895
  }
40352
40896
  function addTopologyIssues(issues, orgName, deployment, organizationModel, systemsById, omResourcesById, ontologyIndex) {
40353
40897
  const relationships = organizationModel.topology?.relationships;
@@ -40463,7 +41007,7 @@ function validateResourceGovernance(orgName, deployment, organizationModel = dep
40463
41007
  `[${orgName}] Resource '${resource.id}' ontology descriptor mismatch between code and OM.`
40464
41008
  );
40465
41009
  }
40466
- addOntologyBindingIssues(issues, orgName, resource, ontologyIndex);
41010
+ addOntologyBindingIssues(issues, orgName, resource, ontologyIndex, organizationModel);
40467
41011
  }
40468
41012
  for (const runtimeResource of runtimeResources) {
40469
41013
  const omResource = omResourcesById.get(runtimeResource.resourceId);
@@ -40513,6 +41057,41 @@ function validateResourceGovernance(orgName, deployment, organizationModel = dep
40513
41057
  issues
40514
41058
  };
40515
41059
  }
41060
+ function addSystemInterfaceIssue(issues, orgName, systemPath, interfaceKey, issue2) {
41061
+ issues.push({
41062
+ type: issue2.family,
41063
+ orgName,
41064
+ systemPath,
41065
+ interfaceKey,
41066
+ code: issue2.code,
41067
+ path: issue2.path,
41068
+ ref: issue2.ref,
41069
+ message: `[${orgName}] ${issue2.family}:${issue2.code}: ${issue2.message}`
41070
+ });
41071
+ }
41072
+ function validateDeclaredSystemInterfaceReadiness(orgName, organizationModel) {
41073
+ const issues = [];
41074
+ if (organizationModel === void 0) return { valid: true, issues };
41075
+ const model = organizationModel;
41076
+ for (const { path: path3, system } of listAllSystems(model)) {
41077
+ if (system.apiInterface === void 0) continue;
41078
+ const interfaceKey = "api";
41079
+ const result = computeInterfaceReadiness(model, { systemPath: path3, interfaceKey });
41080
+ for (const issue2 of result.issues) {
41081
+ addSystemInterfaceIssue(issues, orgName, path3, interfaceKey, issue2);
41082
+ }
41083
+ }
41084
+ if (issues.length > 0) {
41085
+ const first = issues[0];
41086
+ throw new RegistryValidationError(
41087
+ first.orgName,
41088
+ `${first.systemPath}/${first.interfaceKey}`,
41089
+ first.path ?? "organizationModel.systems.apiInterface",
41090
+ first.message
41091
+ );
41092
+ }
41093
+ return { valid: true, issues };
41094
+ }
40516
41095
  function validateDeploymentSpec(orgName, resources) {
40517
41096
  const seenIds = /* @__PURE__ */ new Set();
40518
41097
  resources.workflows?.forEach((workflow) => {
@@ -40550,6 +41129,7 @@ function validateDeploymentSpec(orgName, resources) {
40550
41129
  }
40551
41130
  });
40552
41131
  validateResourceGovernance(orgName, resources);
41132
+ validateDeclaredSystemInterfaceReadiness(orgName, resources.organizationModel);
40553
41133
  }
40554
41134
  function validateResourceModelConfig(orgName, resourceId, modelConfig) {
40555
41135
  try {
@@ -43420,6 +44000,7 @@ var ResourceRegistry = class {
43420
44000
  const candidate = base ? {
43421
44001
  ...base,
43422
44002
  version: incoming.version ?? base.version ?? "0.0.0",
44003
+ organizationModel: incoming.organizationModel ?? base.organizationModel,
43423
44004
  workflows: [...base.workflows ?? [], ...incoming.workflows ?? []],
43424
44005
  agents: [...base.agents ?? [], ...incoming.agents ?? []],
43425
44006
  triggers: incoming.triggers,
@@ -43581,6 +44162,7 @@ var ResourceRegistry = class {
43581
44162
  }
43582
44163
  const existingOrg = this.registry[orgName];
43583
44164
  if (existingOrg) {
44165
+ existingOrg.organizationModel = org.organizationModel ?? existingOrg.organizationModel;
43584
44166
  existingOrg.workflows = [...existingOrg.workflows ?? [], ...org.workflows ?? []];
43585
44167
  existingOrg.agents = [...existingOrg.agents ?? [], ...org.agents ?? []];
43586
44168
  existingOrg.triggers = org.triggers;
@@ -44130,7 +44712,7 @@ function wrapAction(commandName, fn) {
44130
44712
  // package.json
44131
44713
  var package_default = {
44132
44714
  name: "@elevasis/sdk",
44133
- version: "1.27.1",
44715
+ version: "1.28.1",
44134
44716
  description: "SDK for building Elevasis organization resources",
44135
44717
  type: "module",
44136
44718
  bin: {
@@ -44382,6 +44964,7 @@ function validateResourceGovernancePreflight(orgName, org, contractRegistry) {
44382
44964
  if (org.organizationModel !== void 0) {
44383
44965
  OrganizationModelSchema.parse(org.organizationModel);
44384
44966
  }
44967
+ validateDeclaredSystemInterfaceReadiness(orgName, org.organizationModel);
44385
44968
  if (process.env.ELEVASIS_RESOURCE_VALIDATOR === "warn-only") return;
44386
44969
  validateResourceGovernance(orgName, org, org.organizationModel, { mode: "strict" });
44387
44970
  const contractRefs = listOrganizationModelContractRefs(org);