@open-mercato/enterprise 0.10.1-develop.7753.1.61290f530d → 0.10.1-develop.7756.1.8f5dec1b96

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.
@@ -79,7 +79,7 @@ async function provisionAgentPrincipal(container, scope, input) {
79
79
  const existingAcl = await findOneWithDecryption(
80
80
  tem,
81
81
  auth.RoleAcl,
82
- { role, tenantId },
82
+ { role, tenantId, deletedAt: null },
83
83
  {},
84
84
  { tenantId, organizationId: null }
85
85
  );
@@ -107,7 +107,7 @@ async function provisionAgentPrincipal(container, scope, input) {
107
107
  const existingLink = await findOneWithDecryption(
108
108
  tem,
109
109
  auth.UserRole,
110
- { user, role },
110
+ { user, role, deletedAt: null },
111
111
  {},
112
112
  { tenantId, organizationId: null }
113
113
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/modules/agent_orchestrator/lib/identity/agentPrincipalService.ts"],
4
- "sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AwilixContainer } from 'awilix'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { computeEmailHash } from '@open-mercato/core/modules/auth/lib/emailHash'\nimport { lockAuthorizationState } from '@open-mercato/core/modules/auth/lib/authorizationStateLocks'\nimport {\n provisionAgentPrincipalSchema,\n type ProvisionAgentPrincipalInput,\n} from '../../data/validators'\nimport { AgentPrincipal } from '../../data/entities'\n\nexport type AgentPrincipalScope = { tenantId: string; organizationId: string }\n\n/**\n * The resolved identity of a provisioned agent \u2014 the concrete `auth.User` id used\n * as the actor on every write the agent makes, plus the scoped role and the\n * principal row. Phase 2 (`runAs` / on-behalf-of) reads `userId` as the\n * `actorUserId` it stamps on each `ActionLog`.\n */\nexport type ResolvedAgentPrincipal = {\n principal: AgentPrincipal\n userId: string\n roleId: string\n /** True iff the agent `User` holds NO interactive credential (passwordHash null + not confirmed). */\n interactiveLoginDisabled: boolean\n}\n\n/**\n * Deterministic, internal-only email for an agent `User`. Not a deliverable\n * mailbox \u2014 agents never receive mail and never log in interactively. Keyed by\n * the agent definition id + organization so it is stable across re-provisioning\n * (idempotency) and unique per org. The `.agent.internal` TLD is reserved/non-\n * routable so it can never collide with a real human's address.\n */\nfunction buildAgentUserEmail(agentDefinitionId: string, organizationId: string): string {\n const slug = agentDefinitionId.toLowerCase().replace(/[^a-z0-9._-]+/g, '-')\n return `agent+${slug}+${organizationId}@agent.internal`\n}\n\n/** Deterministic, tenant-scoped role name for an agent's least-privilege role. */\nfunction buildAgentRoleName(agentDefinitionId: string): string {\n return `agent:${agentDefinitionId}`\n}\n\nfunction resolveEm(container: AwilixContainer): EntityManager {\n return (container.resolve('em') as EntityManager).fork()\n}\n\n/**\n * Provisions \u2014 idempotently \u2014 an `AgentPrincipal`: a non-interactive `auth.User`\n * (`kind='agent'`) and a scoped, least-privilege `auth.Role`, so the agent is a\n * first-class principal attributed identically to a human on every write (agent\n * identity & on-behalf-of spec, Wave 4 Phase 1).\n *\n * Internal-agent attribution: the returned `userId` is the concrete actor id the\n * Phase-2 `runAs` wrapper stamps on each `ActionLog`.\n *\n * Non-interactive enforcement: the agent `User` is created with\n * `passwordHash = null` and `isConfirmed = false`, so the interactive\n * password/SSO login flow has no credential to verify against \u2014 it is a property\n * of the principal, not a special-case block. External token flows are Phase 3\n * (`credentialMode='oauth_client'`) and are NOT provisioned here.\n *\n * Idempotency: keyed on `(organizationId, agentDefinitionId)` over live rows\n * (partial unique index). A second call resolves and returns the same principal,\n * creating no duplicate `User`/`Role`/`AgentPrincipal` rows. Tenant-scoped: every\n * lookup and write pins both `tenantId` and `organizationId`.\n */\nexport async function provisionAgentPrincipal(\n container: AwilixContainer,\n scope: AgentPrincipalScope,\n input: ProvisionAgentPrincipalInput,\n): Promise<ResolvedAgentPrincipal> {\n const parsed = provisionAgentPrincipalSchema.parse(input)\n const em = resolveEm(container)\n const { tenantId, organizationId } = scope\n\n const auth = (await import(\n '@open-mercato/core/modules/auth/data/entities'\n )) as typeof import('@open-mercato/core/modules/auth/data/entities')\n\n return em.transactional(async (tem) => {\n const existingPrincipal = await tem.findOne(AgentPrincipal, {\n organizationId,\n agentDefinitionId: parsed.agentDefinitionId,\n deletedAt: null,\n })\n\n // \u2500\u2500 Scoped, least-privilege role (find-or-create, idempotent) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const roleName = buildAgentRoleName(parsed.agentDefinitionId)\n let role = await findOneWithDecryption(\n tem,\n auth.Role,\n { name: roleName, tenantId },\n {},\n { tenantId, organizationId: null },\n )\n if (!role) {\n role = tem.create(auth.Role, { name: roleName, tenantId, minActiveHolders: 0, createdAt: new Date() })\n tem.persist(role)\n await tem.flush()\n }\n\n // \u2500\u2500 Non-interactive agent User (find-or-create, idempotent) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const agentEmail = buildAgentUserEmail(parsed.agentDefinitionId, organizationId)\n let user = existingPrincipal\n ? await findOneWithDecryption(\n tem,\n auth.User,\n { id: existingPrincipal.userId },\n {},\n { tenantId, organizationId },\n )\n : await findOneWithDecryption(\n tem,\n auth.User,\n { emailHash: computeEmailHash(agentEmail), tenantId, deletedAt: null },\n {},\n { tenantId, organizationId },\n )\n\n if (!user) {\n user = tem.create(auth.User, {\n email: agentEmail,\n emailHash: computeEmailHash(agentEmail),\n // No interactive credential: a null passwordHash + unconfirmed account\n // means the password/SSO login flow has nothing to authenticate against.\n passwordHash: null,\n isConfirmed: false,\n kind: 'agent',\n name: parsed.displayName ?? parsed.agentDefinitionId,\n tenantId,\n organizationId,\n createdAt: new Date(),\n })\n tem.persist(user)\n await tem.flush()\n } else if (user.kind !== 'agent') {\n // Defensive: an existing row resolved by the deterministic agent email must\n // be an agent principal. Never silently repurpose a human/service row.\n throw new Error('[internal] resolved a non-agent User for an agent principal')\n }\n\n await lockAuthorizationState(tem, {\n userIds: [String(user.id)],\n roleIds: [String(role.id)],\n })\n\n // The scoped role's ACL grants the agent's least-privilege features (merged\n // idempotently on re-provision), never super-admin.\n const existingAcl = await findOneWithDecryption(\n tem,\n auth.RoleAcl,\n { role, tenantId },\n {},\n { tenantId, organizationId: null },\n )\n if (!existingAcl) {\n tem.persist(\n tem.create(auth.RoleAcl, {\n role,\n tenantId,\n featuresJson: parsed.roleFeatures,\n isSuperAdmin: false,\n organizationsJson: [organizationId],\n createdAt: new Date(),\n }),\n )\n await tem.flush()\n } else {\n const current = Array.isArray(existingAcl.featuresJson) ? existingAcl.featuresJson : []\n const merged = Array.from(new Set([...current, ...parsed.roleFeatures]))\n if (merged.length !== current.length) {\n existingAcl.featuresJson = merged\n tem.persist(existingAcl)\n await tem.flush()\n }\n }\n\n // Link the agent User to its scoped role (idempotent).\n const existingLink = await findOneWithDecryption(\n tem,\n auth.UserRole,\n { user, role },\n {},\n { tenantId, organizationId: null },\n )\n if (!existingLink) {\n tem.persist(tem.create(auth.UserRole, { user, role, createdAt: new Date() }))\n await tem.flush()\n }\n\n // \u2500\u2500 AgentPrincipal row (find-or-create, idempotent) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n let principal = existingPrincipal\n if (!principal) {\n principal = tem.create(AgentPrincipal, {\n tenantId,\n organizationId,\n userId: user.id,\n agentDefinitionId: parsed.agentDefinitionId,\n roleId: role.id,\n credentialMode: parsed.credentialMode,\n enabled: true,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n tem.persist(principal)\n await tem.flush()\n }\n\n return {\n principal,\n userId: principal.userId,\n roleId: principal.roleId,\n interactiveLoginDisabled: !user.passwordHash && user.isConfirmed === false,\n }\n })\n}\n\n/**\n * Resolves the agent principal for `(organizationId, agentDefinitionId)` without\n * provisioning. Returns null when the agent has not been provisioned yet (or was\n * soft-deleted). Org-scoped \u2014 never returns another tenant's row.\n */\nexport async function resolveAgentPrincipal(\n container: AwilixContainer,\n scope: AgentPrincipalScope,\n agentDefinitionId: string,\n): Promise<AgentPrincipal | null> {\n const em = resolveEm(container)\n return em.findOne(AgentPrincipal, {\n organizationId: scope.organizationId,\n agentDefinitionId,\n deletedAt: null,\n })\n}\n"],
5
- "mappings": "AAEA,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,sBAAsB;AAyB/B,SAAS,oBAAoB,mBAA2B,gBAAgC;AACtF,QAAM,OAAO,kBAAkB,YAAY,EAAE,QAAQ,kBAAkB,GAAG;AAC1E,SAAO,SAAS,IAAI,IAAI,cAAc;AACxC;AAGA,SAAS,mBAAmB,mBAAmC;AAC7D,SAAO,SAAS,iBAAiB;AACnC;AAEA,SAAS,UAAU,WAA2C;AAC5D,SAAQ,UAAU,QAAQ,IAAI,EAAoB,KAAK;AACzD;AAsBA,eAAsB,wBACpB,WACA,OACA,OACiC;AACjC,QAAM,SAAS,8BAA8B,MAAM,KAAK;AACxD,QAAM,KAAK,UAAU,SAAS;AAC9B,QAAM,EAAE,UAAU,eAAe,IAAI;AAErC,QAAM,OAAQ,MAAM,OAClB,+CACF;AAEA,SAAO,GAAG,cAAc,OAAO,QAAQ;AACrC,UAAM,oBAAoB,MAAM,IAAI,QAAQ,gBAAgB;AAAA,MAC1D;AAAA,MACA,mBAAmB,OAAO;AAAA,MAC1B,WAAW;AAAA,IACb,CAAC;AAGD,UAAM,WAAW,mBAAmB,OAAO,iBAAiB;AAC5D,QAAI,OAAO,MAAM;AAAA,MACf;AAAA,MACA,KAAK;AAAA,MACL,EAAE,MAAM,UAAU,SAAS;AAAA,MAC3B,CAAC;AAAA,MACD,EAAE,UAAU,gBAAgB,KAAK;AAAA,IACnC;AACA,QAAI,CAAC,MAAM;AACT,aAAO,IAAI,OAAO,KAAK,MAAM,EAAE,MAAM,UAAU,UAAU,kBAAkB,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MAClB,0BAA0B,CAAC,KAAK,gBAAgB,KAAK,gBAAgB;AAAA,IACvE;AAAA,EACF,CAAC;AACH;AAOA,eAAsB,sBACpB,WACA,OACA,mBACgC;AAChC,QAAM,KAAK,UAAU,SAAS;AAC9B,SAAO,GAAG,QAAQ,gBAAgB;AAAA,IAChC,gBAAgB,MAAM;AAAA,IACtB;AAAA,IACA,WAAW;AAAA,EACb,CAAC;AACH;",
4
+ "sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport type { AwilixContainer } from 'awilix'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { computeEmailHash } from '@open-mercato/core/modules/auth/lib/emailHash'\nimport { lockAuthorizationState } from '@open-mercato/core/modules/auth/lib/authorizationStateLocks'\nimport {\n provisionAgentPrincipalSchema,\n type ProvisionAgentPrincipalInput,\n} from '../../data/validators'\nimport { AgentPrincipal } from '../../data/entities'\n\nexport type AgentPrincipalScope = { tenantId: string; organizationId: string }\n\n/**\n * The resolved identity of a provisioned agent \u2014 the concrete `auth.User` id used\n * as the actor on every write the agent makes, plus the scoped role and the\n * principal row. Phase 2 (`runAs` / on-behalf-of) reads `userId` as the\n * `actorUserId` it stamps on each `ActionLog`.\n */\nexport type ResolvedAgentPrincipal = {\n principal: AgentPrincipal\n userId: string\n roleId: string\n /** True iff the agent `User` holds NO interactive credential (passwordHash null + not confirmed). */\n interactiveLoginDisabled: boolean\n}\n\n/**\n * Deterministic, internal-only email for an agent `User`. Not a deliverable\n * mailbox \u2014 agents never receive mail and never log in interactively. Keyed by\n * the agent definition id + organization so it is stable across re-provisioning\n * (idempotency) and unique per org. The `.agent.internal` TLD is reserved/non-\n * routable so it can never collide with a real human's address.\n */\nfunction buildAgentUserEmail(agentDefinitionId: string, organizationId: string): string {\n const slug = agentDefinitionId.toLowerCase().replace(/[^a-z0-9._-]+/g, '-')\n return `agent+${slug}+${organizationId}@agent.internal`\n}\n\n/** Deterministic, tenant-scoped role name for an agent's least-privilege role. */\nfunction buildAgentRoleName(agentDefinitionId: string): string {\n return `agent:${agentDefinitionId}`\n}\n\nfunction resolveEm(container: AwilixContainer): EntityManager {\n return (container.resolve('em') as EntityManager).fork()\n}\n\n/**\n * Provisions \u2014 idempotently \u2014 an `AgentPrincipal`: a non-interactive `auth.User`\n * (`kind='agent'`) and a scoped, least-privilege `auth.Role`, so the agent is a\n * first-class principal attributed identically to a human on every write (agent\n * identity & on-behalf-of spec, Wave 4 Phase 1).\n *\n * Internal-agent attribution: the returned `userId` is the concrete actor id the\n * Phase-2 `runAs` wrapper stamps on each `ActionLog`.\n *\n * Non-interactive enforcement: the agent `User` is created with\n * `passwordHash = null` and `isConfirmed = false`, so the interactive\n * password/SSO login flow has no credential to verify against \u2014 it is a property\n * of the principal, not a special-case block. External token flows are Phase 3\n * (`credentialMode='oauth_client'`) and are NOT provisioned here.\n *\n * Idempotency: keyed on `(organizationId, agentDefinitionId)` over live rows\n * (partial unique index). A second call resolves and returns the same principal,\n * creating no duplicate `User`/`Role`/`AgentPrincipal` rows. Tenant-scoped: every\n * lookup and write pins both `tenantId` and `organizationId`.\n */\nexport async function provisionAgentPrincipal(\n container: AwilixContainer,\n scope: AgentPrincipalScope,\n input: ProvisionAgentPrincipalInput,\n): Promise<ResolvedAgentPrincipal> {\n const parsed = provisionAgentPrincipalSchema.parse(input)\n const em = resolveEm(container)\n const { tenantId, organizationId } = scope\n\n const auth = (await import(\n '@open-mercato/core/modules/auth/data/entities'\n )) as typeof import('@open-mercato/core/modules/auth/data/entities')\n\n return em.transactional(async (tem) => {\n const existingPrincipal = await tem.findOne(AgentPrincipal, {\n organizationId,\n agentDefinitionId: parsed.agentDefinitionId,\n deletedAt: null,\n })\n\n // \u2500\u2500 Scoped, least-privilege role (find-or-create, idempotent) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const roleName = buildAgentRoleName(parsed.agentDefinitionId)\n let role = await findOneWithDecryption(\n tem,\n auth.Role,\n { name: roleName, tenantId },\n {},\n { tenantId, organizationId: null },\n )\n if (!role) {\n role = tem.create(auth.Role, { name: roleName, tenantId, minActiveHolders: 0, createdAt: new Date() })\n tem.persist(role)\n await tem.flush()\n }\n\n // \u2500\u2500 Non-interactive agent User (find-or-create, idempotent) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const agentEmail = buildAgentUserEmail(parsed.agentDefinitionId, organizationId)\n let user = existingPrincipal\n ? await findOneWithDecryption(\n tem,\n auth.User,\n { id: existingPrincipal.userId },\n {},\n { tenantId, organizationId },\n )\n : await findOneWithDecryption(\n tem,\n auth.User,\n { emailHash: computeEmailHash(agentEmail), tenantId, deletedAt: null },\n {},\n { tenantId, organizationId },\n )\n\n if (!user) {\n user = tem.create(auth.User, {\n email: agentEmail,\n emailHash: computeEmailHash(agentEmail),\n // No interactive credential: a null passwordHash + unconfirmed account\n // means the password/SSO login flow has nothing to authenticate against.\n passwordHash: null,\n isConfirmed: false,\n kind: 'agent',\n name: parsed.displayName ?? parsed.agentDefinitionId,\n tenantId,\n organizationId,\n createdAt: new Date(),\n })\n tem.persist(user)\n await tem.flush()\n } else if (user.kind !== 'agent') {\n // Defensive: an existing row resolved by the deterministic agent email must\n // be an agent principal. Never silently repurpose a human/service row.\n throw new Error('[internal] resolved a non-agent User for an agent principal')\n }\n\n await lockAuthorizationState(tem, {\n userIds: [String(user.id)],\n roleIds: [String(role.id)],\n })\n\n // The scoped role's ACL grants the agent's least-privilege features (merged\n // idempotently on re-provision), never super-admin.\n const existingAcl = await findOneWithDecryption(\n tem,\n auth.RoleAcl,\n { role, tenantId, deletedAt: null },\n {},\n { tenantId, organizationId: null },\n )\n if (!existingAcl) {\n tem.persist(\n tem.create(auth.RoleAcl, {\n role,\n tenantId,\n featuresJson: parsed.roleFeatures,\n isSuperAdmin: false,\n organizationsJson: [organizationId],\n createdAt: new Date(),\n }),\n )\n await tem.flush()\n } else {\n const current = Array.isArray(existingAcl.featuresJson) ? existingAcl.featuresJson : []\n const merged = Array.from(new Set([...current, ...parsed.roleFeatures]))\n if (merged.length !== current.length) {\n existingAcl.featuresJson = merged\n tem.persist(existingAcl)\n await tem.flush()\n }\n }\n\n // Link the agent User to its scoped role (idempotent).\n const existingLink = await findOneWithDecryption(\n tem,\n auth.UserRole,\n { user, role, deletedAt: null },\n {},\n { tenantId, organizationId: null },\n )\n if (!existingLink) {\n tem.persist(tem.create(auth.UserRole, { user, role, createdAt: new Date() }))\n await tem.flush()\n }\n\n // \u2500\u2500 AgentPrincipal row (find-or-create, idempotent) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n let principal = existingPrincipal\n if (!principal) {\n principal = tem.create(AgentPrincipal, {\n tenantId,\n organizationId,\n userId: user.id,\n agentDefinitionId: parsed.agentDefinitionId,\n roleId: role.id,\n credentialMode: parsed.credentialMode,\n enabled: true,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n tem.persist(principal)\n await tem.flush()\n }\n\n return {\n principal,\n userId: principal.userId,\n roleId: principal.roleId,\n interactiveLoginDisabled: !user.passwordHash && user.isConfirmed === false,\n }\n })\n}\n\n/**\n * Resolves the agent principal for `(organizationId, agentDefinitionId)` without\n * provisioning. Returns null when the agent has not been provisioned yet (or was\n * soft-deleted). Org-scoped \u2014 never returns another tenant's row.\n */\nexport async function resolveAgentPrincipal(\n container: AwilixContainer,\n scope: AgentPrincipalScope,\n agentDefinitionId: string,\n): Promise<AgentPrincipal | null> {\n const em = resolveEm(container)\n return em.findOne(AgentPrincipal, {\n organizationId: scope.organizationId,\n agentDefinitionId,\n deletedAt: null,\n })\n}\n"],
5
+ "mappings": "AAEA,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,sBAAsB;AAyB/B,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-1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/enterprise",
3
- "version": "0.10.1-develop.7753.1.61290f530d",
3
+ "version": "0.10.1-develop.7756.1.8f5dec1b96",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -70,12 +70,12 @@
70
70
  "@dnd-kit/core": "^6.3.1",
71
71
  "@dnd-kit/sortable": "^10.0.0",
72
72
  "@dnd-kit/utilities": "^3.2.2",
73
- "@open-mercato/ai-assistant": "0.10.1-develop.7753.1.61290f530d",
74
- "@open-mercato/core": "0.10.1-develop.7753.1.61290f530d",
75
- "@open-mercato/queue": "0.10.1-develop.7753.1.61290f530d",
76
- "@open-mercato/scheduler": "0.10.1-develop.7753.1.61290f530d",
77
- "@open-mercato/ui": "0.10.1-develop.7753.1.61290f530d",
78
- "@open-mercato/web-research": "0.10.1-develop.7753.1.61290f530d",
73
+ "@open-mercato/ai-assistant": "0.10.1-develop.7756.1.8f5dec1b96",
74
+ "@open-mercato/core": "0.10.1-develop.7756.1.8f5dec1b96",
75
+ "@open-mercato/queue": "0.10.1-develop.7756.1.8f5dec1b96",
76
+ "@open-mercato/scheduler": "0.10.1-develop.7756.1.8f5dec1b96",
77
+ "@open-mercato/ui": "0.10.1-develop.7756.1.8f5dec1b96",
78
+ "@open-mercato/web-research": "0.10.1-develop.7756.1.8f5dec1b96",
79
79
  "@simplewebauthn/browser": "^13.3.0",
80
80
  "@simplewebauthn/server": "^13.3.2",
81
81
  "@simplewebauthn/types": "^12.0.0",
@@ -87,13 +87,13 @@
87
87
  },
88
88
  "peerDependencies": {
89
89
  "@mikro-orm/core": "^7.0.14",
90
- "@open-mercato/shared": "0.10.1-develop.7753.1.61290f530d",
90
+ "@open-mercato/shared": "0.10.1-develop.7756.1.8f5dec1b96",
91
91
  "react": "^19.0.0",
92
92
  "react-dom": "^19.0.0",
93
93
  "zod": ">=3.23.0"
94
94
  },
95
95
  "devDependencies": {
96
- "@open-mercato/shared": "0.10.1-develop.7753.1.61290f530d",
96
+ "@open-mercato/shared": "0.10.1-develop.7756.1.8f5dec1b96",
97
97
  "@types/jest": "^30.0.0",
98
98
  "@types/react": "^19.2.18",
99
99
  "@types/react-dom": "^19.2.5",
@@ -151,7 +151,7 @@ export async function provisionAgentPrincipal(
151
151
  const existingAcl = await findOneWithDecryption(
152
152
  tem,
153
153
  auth.RoleAcl,
154
- { role, tenantId },
154
+ { role, tenantId, deletedAt: null },
155
155
  {},
156
156
  { tenantId, organizationId: null },
157
157
  )
@@ -181,7 +181,7 @@ export async function provisionAgentPrincipal(
181
181
  const existingLink = await findOneWithDecryption(
182
182
  tem,
183
183
  auth.UserRole,
184
- { user, role },
184
+ { user, role, deletedAt: null },
185
185
  {},
186
186
  { tenantId, organizationId: null },
187
187
  )