@open-mercato/core 0.6.7-develop.6553.1.2ec7246e04 → 0.6.7-develop.6566.1.15385fa179

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.
Files changed (143) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/attachments/api/partitions/route.js.map +1 -1
  3. package/dist/modules/attachments/lib/reconcileOrganization.js +9 -7
  4. package/dist/modules/attachments/lib/reconcileOrganization.js.map +2 -2
  5. package/dist/modules/catalog/api/products/route.js.map +1 -1
  6. package/dist/modules/customers/api/companies/[id]/people/route.js +2 -2
  7. package/dist/modules/customers/api/companies/[id]/people/route.js.map +2 -2
  8. package/dist/modules/customers/api/deals/[id]/companies/route.js +2 -2
  9. package/dist/modules/customers/api/deals/[id]/companies/route.js.map +2 -2
  10. package/dist/modules/customers/api/deals/[id]/people/route.js +2 -2
  11. package/dist/modules/customers/api/deals/[id]/people/route.js.map +2 -2
  12. package/dist/modules/customers/api/dictionaries/[kind]/[id]/route.js +4 -4
  13. package/dist/modules/customers/api/dictionaries/[kind]/[id]/route.js.map +2 -2
  14. package/dist/modules/customers/api/entity-roles-factory.js +3 -3
  15. package/dist/modules/customers/api/entity-roles-factory.js.map +2 -2
  16. package/dist/modules/customers/api/labels/assign/route.js +2 -2
  17. package/dist/modules/customers/api/labels/assign/route.js.map +2 -2
  18. package/dist/modules/customers/api/labels/unassign/route.js +2 -2
  19. package/dist/modules/customers/api/labels/unassign/route.js.map +2 -2
  20. package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js +3 -7
  21. package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js.map +2 -2
  22. package/dist/modules/customers/api/people/[id]/companies/context.js +3 -3
  23. package/dist/modules/customers/api/people/[id]/companies/context.js.map +2 -2
  24. package/dist/modules/customers/api/people/[id]/companies/enriched/route.js +2 -2
  25. package/dist/modules/customers/api/people/[id]/companies/enriched/route.js.map +2 -2
  26. package/dist/modules/customers/api/todos/route.js +2 -2
  27. package/dist/modules/customers/api/todos/route.js.map +2 -2
  28. package/dist/modules/customers/commands/addresses.js +3 -3
  29. package/dist/modules/customers/commands/addresses.js.map +2 -2
  30. package/dist/modules/customers/commands/comments.js +3 -3
  31. package/dist/modules/customers/commands/comments.js.map +2 -2
  32. package/dist/modules/customers/commands/companies.js +2 -2
  33. package/dist/modules/customers/commands/companies.js.map +2 -2
  34. package/dist/modules/customers/commands/deals.js +3 -3
  35. package/dist/modules/customers/commands/deals.js.map +2 -2
  36. package/dist/modules/customers/commands/dictionaries.js +3 -3
  37. package/dist/modules/customers/commands/dictionaries.js.map +2 -2
  38. package/dist/modules/customers/commands/entity-roles.js +3 -3
  39. package/dist/modules/customers/commands/entity-roles.js.map +2 -2
  40. package/dist/modules/customers/commands/interactions.js +6 -6
  41. package/dist/modules/customers/commands/interactions.js.map +2 -2
  42. package/dist/modules/customers/commands/labels.js +7 -7
  43. package/dist/modules/customers/commands/labels.js.map +2 -2
  44. package/dist/modules/customers/commands/people.js +3 -3
  45. package/dist/modules/customers/commands/people.js.map +2 -2
  46. package/dist/modules/customers/commands/personCompanyLinks.js +6 -6
  47. package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
  48. package/dist/modules/customers/commands/pipeline-stages.js +3 -3
  49. package/dist/modules/customers/commands/pipeline-stages.js.map +2 -2
  50. package/dist/modules/customers/commands/pipelines.js +3 -3
  51. package/dist/modules/customers/commands/pipelines.js.map +2 -2
  52. package/dist/modules/customers/commands/shared.js +3 -3
  53. package/dist/modules/customers/commands/shared.js.map +2 -2
  54. package/dist/modules/customers/commands/tags.js +7 -7
  55. package/dist/modules/customers/commands/tags.js.map +2 -2
  56. package/dist/modules/customers/commands/todos.js +3 -3
  57. package/dist/modules/customers/commands/todos.js.map +2 -2
  58. package/dist/modules/customers/lib/personCompanies.js +4 -4
  59. package/dist/modules/customers/lib/personCompanies.js.map +2 -2
  60. package/dist/modules/perspectives/data/validators.js +4 -0
  61. package/dist/modules/perspectives/data/validators.js.map +2 -2
  62. package/dist/modules/sales/api/notes/route.js +2 -4
  63. package/dist/modules/sales/api/notes/route.js.map +2 -2
  64. package/dist/modules/sales/api/quotes/accept/route.js +2 -2
  65. package/dist/modules/sales/api/quotes/accept/route.js.map +2 -2
  66. package/dist/modules/sales/api/quotes/public/[token]/route.js +3 -7
  67. package/dist/modules/sales/api/quotes/public/[token]/route.js.map +2 -2
  68. package/dist/modules/sales/api/quotes/send/route.js +2 -2
  69. package/dist/modules/sales/api/quotes/send/route.js.map +2 -2
  70. package/dist/modules/sales/api/returns/[id]/route.js +2 -2
  71. package/dist/modules/sales/api/returns/[id]/route.js.map +2 -2
  72. package/dist/modules/sales/commands/configuration.js +11 -11
  73. package/dist/modules/sales/commands/configuration.js.map +2 -2
  74. package/dist/modules/sales/commands/documentAddresses.js +3 -3
  75. package/dist/modules/sales/commands/documentAddresses.js.map +2 -2
  76. package/dist/modules/sales/commands/documents.js +31 -39
  77. package/dist/modules/sales/commands/documents.js.map +2 -2
  78. package/dist/modules/sales/commands/notes.js +7 -7
  79. package/dist/modules/sales/commands/notes.js.map +2 -2
  80. package/dist/modules/sales/commands/payments.js +2 -2
  81. package/dist/modules/sales/commands/payments.js.map +2 -2
  82. package/dist/modules/sales/commands/returns.js +8 -8
  83. package/dist/modules/sales/commands/returns.js.map +2 -2
  84. package/dist/modules/sales/commands/shared.js +2 -2
  85. package/dist/modules/sales/commands/shared.js.map +2 -2
  86. package/dist/modules/sales/commands/shipments.js +5 -5
  87. package/dist/modules/sales/commands/shipments.js.map +2 -2
  88. package/dist/modules/sales/commands/statuses.js +2 -2
  89. package/dist/modules/sales/commands/statuses.js.map +2 -2
  90. package/dist/modules/sales/commands/tags.js +3 -3
  91. package/dist/modules/sales/commands/tags.js.map +2 -2
  92. package/package.json +8 -8
  93. package/src/modules/attachments/api/partitions/route.ts +1 -1
  94. package/src/modules/attachments/lib/reconcileOrganization.ts +16 -7
  95. package/src/modules/catalog/api/products/route.ts +1 -1
  96. package/src/modules/customer_accounts/i18n/de.json +12 -0
  97. package/src/modules/customer_accounts/i18n/en.json +12 -0
  98. package/src/modules/customer_accounts/i18n/es.json +34 -22
  99. package/src/modules/customer_accounts/i18n/pl.json +32 -20
  100. package/src/modules/customers/api/companies/[id]/people/route.ts +2 -2
  101. package/src/modules/customers/api/deals/[id]/companies/route.ts +2 -2
  102. package/src/modules/customers/api/deals/[id]/people/route.ts +2 -2
  103. package/src/modules/customers/api/dictionaries/[kind]/[id]/route.ts +4 -4
  104. package/src/modules/customers/api/entity-roles-factory.ts +3 -3
  105. package/src/modules/customers/api/labels/assign/route.ts +2 -2
  106. package/src/modules/customers/api/labels/unassign/route.ts +2 -2
  107. package/src/modules/customers/api/people/[id]/companies/[linkId]/route.ts +3 -7
  108. package/src/modules/customers/api/people/[id]/companies/context.ts +3 -3
  109. package/src/modules/customers/api/people/[id]/companies/enriched/route.ts +2 -2
  110. package/src/modules/customers/api/todos/route.ts +2 -2
  111. package/src/modules/customers/commands/addresses.ts +3 -3
  112. package/src/modules/customers/commands/comments.ts +3 -3
  113. package/src/modules/customers/commands/companies.ts +2 -2
  114. package/src/modules/customers/commands/deals.ts +3 -3
  115. package/src/modules/customers/commands/dictionaries.ts +3 -3
  116. package/src/modules/customers/commands/entity-roles.ts +3 -3
  117. package/src/modules/customers/commands/interactions.ts +6 -6
  118. package/src/modules/customers/commands/labels.ts +7 -7
  119. package/src/modules/customers/commands/people.ts +3 -3
  120. package/src/modules/customers/commands/personCompanyLinks.ts +6 -6
  121. package/src/modules/customers/commands/pipeline-stages.ts +3 -3
  122. package/src/modules/customers/commands/pipelines.ts +3 -3
  123. package/src/modules/customers/commands/shared.ts +3 -3
  124. package/src/modules/customers/commands/tags.ts +7 -7
  125. package/src/modules/customers/commands/todos.ts +3 -3
  126. package/src/modules/customers/lib/personCompanies.ts +4 -4
  127. package/src/modules/perspectives/data/validators.ts +4 -0
  128. package/src/modules/sales/api/notes/route.ts +2 -4
  129. package/src/modules/sales/api/quotes/accept/route.ts +2 -2
  130. package/src/modules/sales/api/quotes/public/[token]/route.ts +3 -7
  131. package/src/modules/sales/api/quotes/send/route.ts +2 -2
  132. package/src/modules/sales/api/returns/[id]/route.ts +2 -2
  133. package/src/modules/sales/commands/configuration.ts +11 -11
  134. package/src/modules/sales/commands/documentAddresses.ts +3 -3
  135. package/src/modules/sales/commands/documents.ts +23 -31
  136. package/src/modules/sales/commands/notes.ts +7 -7
  137. package/src/modules/sales/commands/payments.ts +2 -2
  138. package/src/modules/sales/commands/returns.ts +8 -8
  139. package/src/modules/sales/commands/shared.ts +2 -2
  140. package/src/modules/sales/commands/shipments.ts +5 -5
  141. package/src/modules/sales/commands/statuses.ts +2 -2
  142. package/src/modules/sales/commands/tags.ts +3 -3
  143. package/tsconfig.json +0 -2
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/customers/commands/entity-roles.ts"],
4
- "sourcesContent": ["import { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { emitCrudSideEffects, emitCrudUndoSideEffects } from '@open-mercato/shared/lib/commands/helpers'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CustomerEntity, CustomerEntityRole } from '../data/entities'\nimport {\n entityRoleCreateSchema,\n entityRoleUpdateSchema,\n entityRoleDeleteSchema,\n type EntityRoleCreateInput,\n type EntityRoleUpdateInput,\n type EntityRoleDeleteInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureSameScope,\n ensureTenantScope,\n extractUndoPayload,\n requireCustomerEntity,\n resolveParentResourceKind,\n} from './shared'\nimport { resolveRedoSnapshot } from '@open-mercato/shared/lib/commands/redo'\n\ntype EntityRoleSnapshot = {\n role: {\n id: string\n entityType: 'company' | 'person'\n entityId: string\n userId: string\n roleType: string\n organizationId: string\n tenantId: string\n }\n entityKind: 'company' | 'person' | null\n}\n\ntype EntityRoleUndoPayload = {\n before?: EntityRoleSnapshot | null\n after?: EntityRoleSnapshot | null\n /**\n * True when createEntityRole \"undeleted\" a previously soft-deleted row\n * instead of inserting a fresh one. Undo must restore that soft-delete\n * state rather than soft-delete the freshly-restored row.\n */\n wasUndelete?: boolean\n /** userId held by the soft-deleted row before undelete; restored on undo. */\n previousUserId?: string | null\n /** deletedAt timestamp held by the soft-deleted row before undelete. */\n previousDeletedAt?: string | null\n}\n\nconst entityRoleCrudEvents: CrudEventsConfig = {\n module: 'customers',\n entity: 'entity_role',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n entityId:\n ctx.entity && typeof ctx.entity === 'object' && 'entityId' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).entityId\n : null,\n entityType:\n ctx.entity && typeof ctx.entity === 'object' && 'entityType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).entityType\n : null,\n roleType:\n ctx.entity && typeof ctx.entity === 'object' && 'roleType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).roleType\n : null,\n userId:\n ctx.entity && typeof ctx.entity === 'object' && 'userId' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).userId\n : null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n }),\n}\n\nfunction getRoleIdentifiers(role: CustomerEntityRole) {\n return {\n id: role.id,\n organizationId: role.organizationId,\n tenantId: role.tenantId,\n }\n}\n\nasync function loadEntityRoleSnapshot(\n em: EntityManager,\n id: string,\n scope?: { tenantId?: string | null; organizationId?: string | null },\n): Promise<EntityRoleSnapshot | null> {\n const filter: Record<string, unknown> = { id, deletedAt: null }\n if (scope?.tenantId) filter.tenantId = scope.tenantId\n if (scope?.organizationId) filter.organizationId = scope.organizationId\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n filter,\n undefined,\n { tenantId: scope?.tenantId ?? null, organizationId: scope?.organizationId ?? null },\n )\n if (!role) return null\n\n const entity = await findOneWithDecryption(\n em,\n CustomerEntity,\n { id: role.entityId, tenantId: role.tenantId, deletedAt: null },\n undefined,\n { tenantId: role.tenantId, organizationId: role.organizationId },\n )\n\n return {\n role: {\n id: role.id,\n entityType: role.entityType as 'company' | 'person',\n entityId: role.entityId,\n userId: role.userId,\n roleType: role.roleType,\n organizationId: role.organizationId,\n tenantId: role.tenantId,\n },\n entityKind: entity?.kind === 'company' || entity?.kind === 'person' ? entity.kind : null,\n }\n}\n\nconst createEntityRoleCommand: CommandHandler<EntityRoleCreateInput, { roleId: string; wasUndelete: boolean; previousUserId: string | null; previousDeletedAt: string | null }> = {\n id: 'customers.entityRoles.create',\n async execute(rawInput, ctx) {\n const parsed = entityRoleCreateSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await requireCustomerEntity(em, parsed.entityId, { tenantId: parsed.tenantId, organizationId: parsed.organizationId }, parsed.entityType, 'Customer not found')\n ensureSameScope(entity, parsed.organizationId, parsed.tenantId)\n\n const activeExisting = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n {\n entityType: parsed.entityType,\n entityId: parsed.entityId,\n roleType: parsed.roleType,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n deletedAt: null,\n },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n if (activeExisting) {\n throw new CrudHttpError(409, { error: 'Role type already assigned for this entity' })\n }\n\n const softDeleted = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n {\n entityType: parsed.entityType,\n entityId: parsed.entityId,\n roleType: parsed.roleType,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n let role: CustomerEntityRole\n let wasUndelete = false\n let previousUserId: string | null = null\n let previousDeletedAt: string | null = null\n if (softDeleted) {\n wasUndelete = true\n previousUserId = softDeleted.userId ?? null\n previousDeletedAt = softDeleted.deletedAt instanceof Date ? softDeleted.deletedAt.toISOString() : null\n softDeleted.deletedAt = null\n softDeleted.userId = parsed.userId\n role = softDeleted\n } else {\n role = em.create(CustomerEntityRole, {\n entityType: parsed.entityType,\n entityId: parsed.entityId,\n userId: parsed.userId,\n roleType: parsed.roleType,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n em.persist(role)\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return { roleId: role.id, wasUndelete, previousUserId, previousDeletedAt }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadEntityRoleSnapshot(em, result.roleId, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as EntityRoleSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.entityRoles.create', 'Create entity role'),\n resourceKind: 'customers.entityRole',\n resourceId: result.roleId,\n parentResourceKind: resolveParentResourceKind(snapshot?.entityKind),\n parentResourceId: snapshot?.role.entityId ?? null,\n tenantId: snapshot?.role.tenantId ?? null,\n organizationId: snapshot?.role.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n wasUndelete: result.wasUndelete,\n previousUserId: result.previousUserId,\n previousDeletedAt: result.previousDeletedAt,\n } satisfies EntityRoleUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<EntityRoleUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: after.role.id },\n undefined,\n { tenantId: after.role.tenantId, organizationId: after.role.organizationId },\n )\n if (!role) return\n\n if (payload?.wasUndelete) {\n role.deletedAt = payload.previousDeletedAt ? new Date(payload.previousDeletedAt) : new Date()\n if (payload.previousUserId) role.userId = payload.previousUserId\n } else {\n role.deletedAt = new Date()\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'deleted',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n },\n redo: async ({ logEntry, ctx }) => {\n const after = resolveRedoSnapshot<EntityRoleSnapshot>(logEntry)\n if (!after) {\n throw new CrudHttpError(400, { error: '[internal] redo snapshot unavailable for entity role create' })\n }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: after.role.id },\n undefined,\n { tenantId: after.role.tenantId, organizationId: after.role.organizationId },\n )\n if (!role) {\n role = em.create(CustomerEntityRole, {\n id: after.role.id,\n entityType: after.role.entityType,\n entityId: after.role.entityId,\n userId: after.role.userId,\n roleType: after.role.roleType,\n organizationId: after.role.organizationId,\n tenantId: after.role.tenantId,\n })\n em.persist(role)\n } else {\n role.deletedAt = null\n role.userId = after.role.userId\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return {\n roleId: role.id,\n wasUndelete: false,\n previousUserId: null,\n previousDeletedAt: null,\n }\n },\n}\n\nconst updateEntityRoleCommand: CommandHandler<EntityRoleUpdateInput, { roleId: string }> = {\n id: 'customers.entityRoles.update',\n async prepare(rawInput, ctx) {\n const parsed = entityRoleUpdateSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadEntityRoleSnapshot(em, parsed.id, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = entityRoleUpdateSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: parsed.id, tenantId: parsed.tenantId, organizationId: parsed.organizationId, deletedAt: null },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n if (!role) {\n throw new CrudHttpError(404, { error: 'Role not found' })\n }\n\n role.userId = parsed.userId\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return { roleId: role.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadEntityRoleSnapshot(em, result.roleId, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as EntityRoleSnapshot | undefined\n const after = snapshots.after as EntityRoleSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.entityRoles.update', 'Update entity role'),\n resourceKind: 'customers.entityRole',\n resourceId: result.roleId,\n parentResourceKind: resolveParentResourceKind(after?.entityKind ?? before?.entityKind),\n parentResourceId: after?.role.entityId ?? before?.role.entityId ?? null,\n tenantId: after?.role.tenantId ?? before?.role.tenantId ?? null,\n organizationId: after?.role.organizationId ?? before?.role.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: {\n undo: {\n before: before ?? null,\n after: after ?? null,\n } satisfies EntityRoleUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<EntityRoleUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: before.role.id },\n undefined,\n { tenantId: before.role.tenantId, organizationId: before.role.organizationId },\n )\n if (!role) return\n\n role.userId = before.role.userId\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'updated',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n },\n}\n\nconst deleteEntityRoleCommand: CommandHandler<EntityRoleDeleteInput, { roleId: string }> = {\n id: 'customers.entityRoles.delete',\n async prepare(rawInput, ctx) {\n const parsed = entityRoleDeleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadEntityRoleSnapshot(em, parsed.id, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = entityRoleDeleteSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: parsed.id, tenantId: parsed.tenantId, organizationId: parsed.organizationId, deletedAt: null },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n if (!role) {\n throw new CrudHttpError(404, { error: 'Role not found' })\n }\n\n role.deletedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return { roleId: role.id }\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as EntityRoleSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.entityRoles.delete', 'Delete entity role'),\n resourceKind: 'customers.entityRole',\n resourceId: result.roleId,\n parentResourceKind: resolveParentResourceKind(before?.entityKind),\n parentResourceId: before?.role.entityId ?? null,\n tenantId: before?.role.tenantId ?? null,\n organizationId: before?.role.organizationId ?? null,\n snapshotBefore: before ?? null,\n payload: {\n undo: {\n before: before ?? null,\n } satisfies EntityRoleUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<EntityRoleUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await requireCustomerEntity(\n em,\n before.role.entityId,\n { tenantId: before.role.tenantId, organizationId: before.role.organizationId },\n before.role.entityType,\n 'Customer not found',\n )\n ensureSameScope(entity, before.role.organizationId, before.role.tenantId)\n\n let role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: before.role.id },\n undefined,\n { tenantId: before.role.tenantId, organizationId: before.role.organizationId },\n )\n if (!role) {\n role = em.create(CustomerEntityRole, {\n id: before.role.id,\n entityType: before.role.entityType,\n entityId: before.role.entityId,\n userId: before.role.userId,\n roleType: before.role.roleType,\n organizationId: before.role.organizationId,\n tenantId: before.role.tenantId,\n })\n em.persist(role)\n } else {\n role.userId = before.role.userId\n role.roleType = before.role.roleType\n role.deletedAt = null\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'created',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n },\n}\n\nregisterCommand(createEntityRoleCommand)\nregisterCommand(updateEntityRoleCommand)\nregisterCommand(deleteEntityRoleCommand)\n"],
5
- "mappings": "AAAA,SAAS,uBAAuB;AAGhC,SAAS,qBAAqB,+BAA+B;AAC7D,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AAGtC,SAAS,gBAAgB,0BAA0B;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AA8BpC,MAAM,uBAAyC;AAAA,EAC7C,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,cAAc,CAAC,SAAS;AAAA,IACtB,IAAI,IAAI,YAAY;AAAA,IACpB,gBAAgB,IAAI,YAAY;AAAA,IAChC,UAAU,IAAI,YAAY;AAAA,IAC1B,UACE,IAAI,UAAU,OAAO,IAAI,WAAW,YAAY,cAAe,IAAI,SAC9D,IAAI,OAA8B,WACnC;AAAA,IACN,YACE,IAAI,UAA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,QAAI,OAAO,MAAM;AAAA,MACf;AAAA,MACA;AAAA,MACA,EAAE,IAAI,OAAO,KAAK,GAAG;AAAA,MACrB;AAAA,MACA,EAAE,UAAU,OAAO,KAAK,UAAU,gBAAgB,OAAO,KAAK,eAAe;AAAA,IAC/E;AACA,QAAI,CAAC,MAAM;AACT,aAAO,GAAG,OAAO,oBAAoB;AAAA,QACnC,IAAI,OAAO,KAAK;AAAA,QAChB,YAAY,OAAO,KAAK;AAAA,QACxB,UAAU,OAAO,KAAK;AAAA,QACtB,QAAQ,OAAO,KAAK;AAAA,QACpB,UAAU,OAAO,KAAK;AAAA,QACtB,gBAAgB,OAAO,KAAK;AAAA,QAC5B,UAAU,OAAO,KAAK;AAAA,MACxB,CAAC;AACD,SAAG,QAAQ,IAAI;AAAA,IACjB,OAAO;AACL,WAAK,SAAS,OAAO,KAAK;AAC1B,WAAK,WAAW,OAAO,KAAK;AAC5B,WAAK,YAAY;AAAA,IACnB;AACA,UAAM,GAAG,MAAM;AAEf,UAAM,aAAa,IAAI,UAAU,QAAQ,YAAY;AACrD,UAAM,wBAAwB;AAAA,MAC5B;AAAA,MACA,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,aAAa,mBAAmB,IAAI;AAAA,MACpC,YAAY,IAAI;AAAA,MAChB,QAAQ;AAAA,MACR,SAAS,EAAE,YAAY,wBAAwB;AAAA,IACjD,CAAC;AAAA,EACH;AACF;AAEA,gBAAgB,uBAAuB;AACvC,gBAAgB,uBAAuB;AACvC,gBAAgB,uBAAuB;",
4
+ "sourcesContent": ["import { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport type { CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { emitCrudSideEffects, emitCrudUndoSideEffects } from '@open-mercato/shared/lib/commands/helpers'\nimport { CrudHttpError, notFound } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { CustomerEntity, CustomerEntityRole } from '../data/entities'\nimport {\n entityRoleCreateSchema,\n entityRoleUpdateSchema,\n entityRoleDeleteSchema,\n type EntityRoleCreateInput,\n type EntityRoleUpdateInput,\n type EntityRoleDeleteInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureSameScope,\n ensureTenantScope,\n extractUndoPayload,\n requireCustomerEntity,\n resolveParentResourceKind,\n} from './shared'\nimport { resolveRedoSnapshot } from '@open-mercato/shared/lib/commands/redo'\n\ntype EntityRoleSnapshot = {\n role: {\n id: string\n entityType: 'company' | 'person'\n entityId: string\n userId: string\n roleType: string\n organizationId: string\n tenantId: string\n }\n entityKind: 'company' | 'person' | null\n}\n\ntype EntityRoleUndoPayload = {\n before?: EntityRoleSnapshot | null\n after?: EntityRoleSnapshot | null\n /**\n * True when createEntityRole \"undeleted\" a previously soft-deleted row\n * instead of inserting a fresh one. Undo must restore that soft-delete\n * state rather than soft-delete the freshly-restored row.\n */\n wasUndelete?: boolean\n /** userId held by the soft-deleted row before undelete; restored on undo. */\n previousUserId?: string | null\n /** deletedAt timestamp held by the soft-deleted row before undelete. */\n previousDeletedAt?: string | null\n}\n\nconst entityRoleCrudEvents: CrudEventsConfig = {\n module: 'customers',\n entity: 'entity_role',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n entityId:\n ctx.entity && typeof ctx.entity === 'object' && 'entityId' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).entityId\n : null,\n entityType:\n ctx.entity && typeof ctx.entity === 'object' && 'entityType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).entityType\n : null,\n roleType:\n ctx.entity && typeof ctx.entity === 'object' && 'roleType' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).roleType\n : null,\n userId:\n ctx.entity && typeof ctx.entity === 'object' && 'userId' in (ctx.entity as Record<string, unknown>)\n ? (ctx.entity as CustomerEntityRole).userId\n : null,\n ...(ctx.syncOrigin ? { syncOrigin: ctx.syncOrigin } : {}),\n }),\n}\n\nfunction getRoleIdentifiers(role: CustomerEntityRole) {\n return {\n id: role.id,\n organizationId: role.organizationId,\n tenantId: role.tenantId,\n }\n}\n\nasync function loadEntityRoleSnapshot(\n em: EntityManager,\n id: string,\n scope?: { tenantId?: string | null; organizationId?: string | null },\n): Promise<EntityRoleSnapshot | null> {\n const filter: Record<string, unknown> = { id, deletedAt: null }\n if (scope?.tenantId) filter.tenantId = scope.tenantId\n if (scope?.organizationId) filter.organizationId = scope.organizationId\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n filter,\n undefined,\n { tenantId: scope?.tenantId ?? null, organizationId: scope?.organizationId ?? null },\n )\n if (!role) return null\n\n const entity = await findOneWithDecryption(\n em,\n CustomerEntity,\n { id: role.entityId, tenantId: role.tenantId, deletedAt: null },\n undefined,\n { tenantId: role.tenantId, organizationId: role.organizationId },\n )\n\n return {\n role: {\n id: role.id,\n entityType: role.entityType as 'company' | 'person',\n entityId: role.entityId,\n userId: role.userId,\n roleType: role.roleType,\n organizationId: role.organizationId,\n tenantId: role.tenantId,\n },\n entityKind: entity?.kind === 'company' || entity?.kind === 'person' ? entity.kind : null,\n }\n}\n\nconst createEntityRoleCommand: CommandHandler<EntityRoleCreateInput, { roleId: string; wasUndelete: boolean; previousUserId: string | null; previousDeletedAt: string | null }> = {\n id: 'customers.entityRoles.create',\n async execute(rawInput, ctx) {\n const parsed = entityRoleCreateSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await requireCustomerEntity(em, parsed.entityId, { tenantId: parsed.tenantId, organizationId: parsed.organizationId }, parsed.entityType, 'Customer not found')\n ensureSameScope(entity, parsed.organizationId, parsed.tenantId)\n\n const activeExisting = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n {\n entityType: parsed.entityType,\n entityId: parsed.entityId,\n roleType: parsed.roleType,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n deletedAt: null,\n },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n if (activeExisting) {\n throw new CrudHttpError(409, { error: 'Role type already assigned for this entity' })\n }\n\n const softDeleted = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n {\n entityType: parsed.entityType,\n entityId: parsed.entityId,\n roleType: parsed.roleType,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n let role: CustomerEntityRole\n let wasUndelete = false\n let previousUserId: string | null = null\n let previousDeletedAt: string | null = null\n if (softDeleted) {\n wasUndelete = true\n previousUserId = softDeleted.userId ?? null\n previousDeletedAt = softDeleted.deletedAt instanceof Date ? softDeleted.deletedAt.toISOString() : null\n softDeleted.deletedAt = null\n softDeleted.userId = parsed.userId\n role = softDeleted\n } else {\n role = em.create(CustomerEntityRole, {\n entityType: parsed.entityType,\n entityId: parsed.entityId,\n userId: parsed.userId,\n roleType: parsed.roleType,\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n })\n em.persist(role)\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return { roleId: role.id, wasUndelete, previousUserId, previousDeletedAt }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager)\n return loadEntityRoleSnapshot(em, result.roleId, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as EntityRoleSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.entityRoles.create', 'Create entity role'),\n resourceKind: 'customers.entityRole',\n resourceId: result.roleId,\n parentResourceKind: resolveParentResourceKind(snapshot?.entityKind),\n parentResourceId: snapshot?.role.entityId ?? null,\n tenantId: snapshot?.role.tenantId ?? null,\n organizationId: snapshot?.role.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot ?? null,\n wasUndelete: result.wasUndelete,\n previousUserId: result.previousUserId,\n previousDeletedAt: result.previousDeletedAt,\n } satisfies EntityRoleUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<EntityRoleUndoPayload>(logEntry)\n const after = payload?.after\n if (!after) return\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: after.role.id },\n undefined,\n { tenantId: after.role.tenantId, organizationId: after.role.organizationId },\n )\n if (!role) return\n\n if (payload?.wasUndelete) {\n role.deletedAt = payload.previousDeletedAt ? new Date(payload.previousDeletedAt) : new Date()\n if (payload.previousUserId) role.userId = payload.previousUserId\n } else {\n role.deletedAt = new Date()\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'deleted',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n },\n redo: async ({ logEntry, ctx }) => {\n const after = resolveRedoSnapshot<EntityRoleSnapshot>(logEntry)\n if (!after) {\n throw new CrudHttpError(400, { error: '[internal] redo snapshot unavailable for entity role create' })\n }\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n let role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: after.role.id },\n undefined,\n { tenantId: after.role.tenantId, organizationId: after.role.organizationId },\n )\n if (!role) {\n role = em.create(CustomerEntityRole, {\n id: after.role.id,\n entityType: after.role.entityType,\n entityId: after.role.entityId,\n userId: after.role.userId,\n roleType: after.role.roleType,\n organizationId: after.role.organizationId,\n tenantId: after.role.tenantId,\n })\n em.persist(role)\n } else {\n role.deletedAt = null\n role.userId = after.role.userId\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'created',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return {\n roleId: role.id,\n wasUndelete: false,\n previousUserId: null,\n previousDeletedAt: null,\n }\n },\n}\n\nconst updateEntityRoleCommand: CommandHandler<EntityRoleUpdateInput, { roleId: string }> = {\n id: 'customers.entityRoles.update',\n async prepare(rawInput, ctx) {\n const parsed = entityRoleUpdateSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadEntityRoleSnapshot(em, parsed.id, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = entityRoleUpdateSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: parsed.id, tenantId: parsed.tenantId, organizationId: parsed.organizationId, deletedAt: null },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n if (!role) {\n throw notFound('Role not found')\n }\n\n role.userId = parsed.userId\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'updated',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return { roleId: role.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = ctx.container.resolve('em') as EntityManager\n return loadEntityRoleSnapshot(em, result.roleId, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as EntityRoleSnapshot | undefined\n const after = snapshots.after as EntityRoleSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.entityRoles.update', 'Update entity role'),\n resourceKind: 'customers.entityRole',\n resourceId: result.roleId,\n parentResourceKind: resolveParentResourceKind(after?.entityKind ?? before?.entityKind),\n parentResourceId: after?.role.entityId ?? before?.role.entityId ?? null,\n tenantId: after?.role.tenantId ?? before?.role.tenantId ?? null,\n organizationId: after?.role.organizationId ?? before?.role.organizationId ?? null,\n snapshotBefore: before ?? null,\n snapshotAfter: after ?? null,\n payload: {\n undo: {\n before: before ?? null,\n after: after ?? null,\n } satisfies EntityRoleUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<EntityRoleUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: before.role.id },\n undefined,\n { tenantId: before.role.tenantId, organizationId: before.role.organizationId },\n )\n if (!role) return\n\n role.userId = before.role.userId\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'updated',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n },\n}\n\nconst deleteEntityRoleCommand: CommandHandler<EntityRoleDeleteInput, { roleId: string }> = {\n id: 'customers.entityRoles.delete',\n async prepare(rawInput, ctx) {\n const parsed = entityRoleDeleteSchema.parse(rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadEntityRoleSnapshot(em, parsed.id, {\n tenantId: ctx.auth?.tenantId ?? null,\n organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,\n })\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const parsed = entityRoleDeleteSchema.parse(rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: parsed.id, tenantId: parsed.tenantId, organizationId: parsed.organizationId, deletedAt: null },\n undefined,\n { tenantId: parsed.tenantId, organizationId: parsed.organizationId },\n )\n if (!role) {\n throw notFound('Role not found')\n }\n\n role.deletedAt = new Date()\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudSideEffects({\n dataEngine,\n action: 'deleted',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n\n return { roleId: role.id }\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as EntityRoleSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.entityRoles.delete', 'Delete entity role'),\n resourceKind: 'customers.entityRole',\n resourceId: result.roleId,\n parentResourceKind: resolveParentResourceKind(before?.entityKind),\n parentResourceId: before?.role.entityId ?? null,\n tenantId: before?.role.tenantId ?? null,\n organizationId: before?.role.organizationId ?? null,\n snapshotBefore: before ?? null,\n payload: {\n undo: {\n before: before ?? null,\n } satisfies EntityRoleUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<EntityRoleUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await requireCustomerEntity(\n em,\n before.role.entityId,\n { tenantId: before.role.tenantId, organizationId: before.role.organizationId },\n before.role.entityType,\n 'Customer not found',\n )\n ensureSameScope(entity, before.role.organizationId, before.role.tenantId)\n\n let role = await findOneWithDecryption(\n em,\n CustomerEntityRole,\n { id: before.role.id },\n undefined,\n { tenantId: before.role.tenantId, organizationId: before.role.organizationId },\n )\n if (!role) {\n role = em.create(CustomerEntityRole, {\n id: before.role.id,\n entityType: before.role.entityType,\n entityId: before.role.entityId,\n userId: before.role.userId,\n roleType: before.role.roleType,\n organizationId: before.role.organizationId,\n tenantId: before.role.tenantId,\n })\n em.persist(role)\n } else {\n role.userId = before.role.userId\n role.roleType = before.role.roleType\n role.deletedAt = null\n }\n await em.flush()\n\n const dataEngine = ctx.container.resolve('dataEngine') as DataEngine\n await emitCrudUndoSideEffects({\n dataEngine,\n action: 'created',\n entity: role,\n identifiers: getRoleIdentifiers(role),\n syncOrigin: ctx.syncOrigin,\n events: entityRoleCrudEvents,\n indexer: { entityType: 'customers:entity_role' },\n })\n },\n}\n\nregisterCommand(createEntityRoleCommand)\nregisterCommand(updateEntityRoleCommand)\nregisterCommand(deleteEntityRoleCommand)\n"],
5
+ "mappings": "AAAA,SAAS,uBAAuB;AAGhC,SAAS,qBAAqB,+BAA+B;AAC7D,SAAS,eAAe,gBAAgB;AACxC,SAAS,2BAA2B;AACpC,SAAS,6BAA6B;AAGtC,SAAS,gBAAgB,0BAA0B;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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
6
6
  "names": []
7
7
  }
@@ -31,7 +31,7 @@ import {
31
31
  loadCustomFieldSnapshot,
32
32
  buildCustomFieldResetMap
33
33
  } from "@open-mercato/shared/lib/commands/customFieldSnapshots";
34
- import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
34
+ import { CrudHttpError, notFound } from "@open-mercato/shared/lib/crud/errors";
35
35
  import { enforceRecordGoneIsConflict, enforceCommandOptimisticLockWithGuards } from "@open-mercato/shared/lib/crud/optimistic-lock-command";
36
36
  import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
37
37
  import { recomputeNextInteraction } from "../lib/interactionProjection.js";
@@ -474,7 +474,7 @@ const updateInteractionCommand = {
474
474
  const interaction2 = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null });
475
475
  if (!interaction2) {
476
476
  enforceRecordGoneIsConflict({ resourceKind: "customers.interaction", resourceId: parsed.id, request: ctx.request ?? null });
477
- throw new CrudHttpError(404, { error: "Interaction not found" });
477
+ throw notFound("Interaction not found");
478
478
  }
479
479
  ensureTenantScope(ctx, interaction2.tenantId);
480
480
  ensureOrganizationScope(ctx, interaction2.organizationId);
@@ -496,7 +496,7 @@ const updateInteractionCommand = {
496
496
  // bypass (canChangeEmailVisibility ignores caller features in v1).
497
497
  userFeatures: void 0
498
498
  })) {
499
- throw new CrudHttpError(404, { error: "Email not found" });
499
+ throw notFound("Email not found");
500
500
  }
501
501
  }
502
502
  if (parsed.dealId !== void 0) {
@@ -712,7 +712,7 @@ const completeInteractionCommand = {
712
712
  const interaction2 = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null });
713
713
  if (!interaction2) {
714
714
  enforceRecordGoneIsConflict({ resourceKind: "customers.interaction", resourceId: parsed.id, request: ctx.request ?? null });
715
- throw new CrudHttpError(404, { error: "Interaction not found" });
715
+ throw notFound("Interaction not found");
716
716
  }
717
717
  ensureTenantScope(ctx, interaction2.tenantId);
718
718
  ensureOrganizationScope(ctx, interaction2.organizationId);
@@ -841,7 +841,7 @@ const cancelInteractionCommand = {
841
841
  const interaction2 = await findOneWithDecryption(trx, CustomerInteraction, { id: parsed.id, deletedAt: null });
842
842
  if (!interaction2) {
843
843
  enforceRecordGoneIsConflict({ resourceKind: "customers.interaction", resourceId: parsed.id, request: ctx.request ?? null });
844
- throw new CrudHttpError(404, { error: "Interaction not found" });
844
+ throw notFound("Interaction not found");
845
845
  }
846
846
  ensureTenantScope(ctx, interaction2.tenantId);
847
847
  ensureOrganizationScope(ctx, interaction2.organizationId);
@@ -967,7 +967,7 @@ const deleteInteractionCommand = {
967
967
  const interaction2 = await findOneWithDecryption(trx, CustomerInteraction, { id, deletedAt: null });
968
968
  if (!interaction2) {
969
969
  enforceRecordGoneIsConflict({ resourceKind: "customers.interaction", resourceId: id, request: ctx.request ?? null });
970
- throw new CrudHttpError(404, { error: "Interaction not found" });
970
+ throw notFound("Interaction not found");
971
971
  }
972
972
  ensureTenantScope(ctx, interaction2.tenantId);
973
973
  ensureOrganizationScope(ctx, interaction2.organizationId);