@open-mercato/core 0.5.1-develop.2744.9c8be0dd93 → 0.5.1-develop.2762.90c271efe2

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 (41) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/audit_logs/services/accessLogService.js +3 -4
  3. package/dist/modules/audit_logs/services/accessLogService.js.map +2 -2
  4. package/dist/modules/audit_logs/services/actionLogService.js +3 -2
  5. package/dist/modules/audit_logs/services/actionLogService.js.map +2 -2
  6. package/dist/modules/auth/api/users/route.js +38 -2
  7. package/dist/modules/auth/api/users/route.js.map +2 -2
  8. package/dist/modules/catalog/lib/bulkDelete.js +17 -14
  9. package/dist/modules/catalog/lib/bulkDelete.js.map +2 -2
  10. package/dist/modules/configs/lib/system-status.js +2 -1
  11. package/dist/modules/configs/lib/system-status.js.map +2 -2
  12. package/dist/modules/customer_accounts/api/portal/password-change.js +3 -1
  13. package/dist/modules/customer_accounts/api/portal/password-change.js.map +2 -2
  14. package/dist/modules/customers/api/deals/[id]/route.js +2 -1
  15. package/dist/modules/customers/api/deals/[id]/route.js.map +2 -2
  16. package/dist/modules/customers/api/interactions/route.js +2 -1
  17. package/dist/modules/customers/api/interactions/route.js.map +2 -2
  18. package/dist/modules/customers/lib/interactionReadModel.js +6 -1
  19. package/dist/modules/customers/lib/interactionReadModel.js.map +2 -2
  20. package/dist/modules/feature_toggles/lib/feature-flag-check.js +7 -3
  21. package/dist/modules/feature_toggles/lib/feature-flag-check.js.map +2 -2
  22. package/dist/modules/inbox_ops/encryption.js +47 -0
  23. package/dist/modules/inbox_ops/encryption.js.map +7 -0
  24. package/dist/modules/workflows/api/definitions/[id]/route.js +3 -0
  25. package/dist/modules/workflows/api/definitions/[id]/route.js.map +2 -2
  26. package/dist/modules/workflows/api/definitions/route.js +2 -0
  27. package/dist/modules/workflows/api/definitions/route.js.map +2 -2
  28. package/package.json +3 -3
  29. package/src/modules/audit_logs/services/accessLogService.ts +5 -4
  30. package/src/modules/audit_logs/services/actionLogService.ts +9 -2
  31. package/src/modules/auth/api/users/route.ts +55 -2
  32. package/src/modules/catalog/lib/bulkDelete.ts +17 -14
  33. package/src/modules/configs/lib/system-status.ts +2 -1
  34. package/src/modules/customer_accounts/api/portal/password-change.ts +6 -1
  35. package/src/modules/customers/api/deals/[id]/route.ts +2 -1
  36. package/src/modules/customers/api/interactions/route.ts +2 -1
  37. package/src/modules/customers/lib/interactionReadModel.ts +12 -1
  38. package/src/modules/feature_toggles/lib/feature-flag-check.ts +7 -4
  39. package/src/modules/inbox_ops/encryption.ts +51 -0
  40. package/src/modules/workflows/api/definitions/[id]/route.ts +7 -0
  41. package/src/modules/workflows/api/definitions/route.ts +6 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/catalog/lib/bulkDelete.ts"],
4
- "sourcesContent": ["import type { AwilixContainer } from 'awilix'\nimport type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { createModuleQueue, type Queue } from '@open-mercato/queue'\nimport type { ProgressService, ProgressServiceContext } from '../../progress/lib/progressService'\n\nexport const CATALOG_PRODUCT_BULK_DELETE_QUEUE = 'catalog-product-bulk-delete'\n\nconst queues = new Map<string, Queue<Record<string, unknown>>>()\n\nexport type CatalogProductBulkDeleteScope = {\n organizationId: string\n tenantId: string\n userId?: string | null\n}\n\nexport type CatalogProductBulkDeleteJobPayload = {\n progressJobId: string\n ids: string[]\n scope: CatalogProductBulkDeleteScope\n}\n\nexport type CatalogProductBulkDeleteSummary = {\n affectedCount: number\n}\n\nconst BULK_DELETE_CACHE_ALIASES = ['catalog.products']\n\nexport function getCatalogQueue(queueName: string): Queue<Record<string, unknown>> {\n const existing = queues.get(queueName)\n if (existing) return existing\n\n const concurrency = Math.max(1, Number.parseInt(process.env.CATALOG_QUEUE_CONCURRENCY ?? '3', 10) || 3)\n const created = createModuleQueue<Record<string, unknown>>(queueName, { concurrency })\n\n queues.set(queueName, created)\n return created\n}\n\nfunction buildCommandContext(\n scope: CatalogProductBulkDeleteScope,\n container: AwilixContainer,\n): CommandRuntimeContext {\n return {\n container,\n auth: null,\n organizationScope: {\n selectedId: scope.organizationId,\n filterIds: [scope.organizationId],\n allowedIds: [scope.organizationId],\n tenantId: scope.tenantId,\n },\n selectedOrganizationId: scope.organizationId,\n organizationIds: [scope.organizationId],\n }\n}\n\nexport async function deleteCatalogProductsWithProgress(params: {\n container: AwilixContainer\n progressJobId: string\n ids: string[]\n scope: CatalogProductBulkDeleteScope\n}): Promise<CatalogProductBulkDeleteSummary> {\n const { container, progressJobId, ids, scope } = params\n const commandBus = container.resolve('commandBus') as CommandBus\n const progressService = container.resolve('progressService') as ProgressService\n const progressContext: ProgressServiceContext = {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n userId: scope.userId,\n }\n\n await progressService.startJob(progressJobId, progressContext)\n await progressService.updateProgress(\n progressJobId,\n { totalCount: ids.length, processedCount: 0 },\n progressContext,\n )\n\n const commandContext = buildCommandContext(scope, container)\n let affectedCount = 0\n const deletedIds = new Set<string>()\n\n for (const [index, id] of ids.entries()) {\n await commandBus.execute<{ body?: Record<string, unknown> }, { productId: string }>('catalog.products.delete', {\n input: { body: { id } },\n ctx: commandContext,\n skipCacheInvalidation: true,\n })\n affectedCount += 1\n deletedIds.add(id)\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: ids.length,\n processedCount: index + 1,\n },\n progressContext,\n )\n }\n\n const summary: CatalogProductBulkDeleteSummary = { affectedCount }\n for (const id of deletedIds) {\n await invalidateCrudCache(\n container,\n 'catalog.product',\n {\n id,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n },\n scope.tenantId,\n 'bulk-delete:catalog.products',\n BULK_DELETE_CACHE_ALIASES,\n )\n }\n await progressService.completeJob(progressJobId, { resultSummary: summary }, progressContext)\n\n return summary\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BAAI,IAAY;AAEnC,aAAW,CAAC,OAAO,EAAE,KAAK,IAAI,QAAQ,GAAG;AACvC,UAAM,WAAW,QAAmE,2BAA2B;AAAA,MAC7G,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE;AAAA,MACtB,KAAK;AAAA,MACL,uBAAuB;AAAA,IACzB,CAAC;AACD,qBAAiB;AACjB,eAAW,IAAI,EAAE;AAEjB,UAAM,gBAAgB;AAAA,MACpB;AAAA,MACA;AAAA,QACE,YAAY,IAAI;AAAA,QAChB,gBAAgB,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAA2C,EAAE,cAAc;AACjE,aAAW,MAAM,YAAY;AAC3B,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,QACE;AAAA,QACA,gBAAgB,MAAM;AAAA,QACtB,UAAU,MAAM;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,QAAM,gBAAgB,YAAY,eAAe,EAAE,eAAe,QAAQ,GAAG,eAAe;AAE5F,SAAO;AACT;",
4
+ "sourcesContent": ["import type { AwilixContainer } from 'awilix'\nimport type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { invalidateCrudCache } from '@open-mercato/shared/lib/crud/cache'\nimport { runWithCacheTenant } from '@open-mercato/cache'\nimport { createModuleQueue, type Queue } from '@open-mercato/queue'\nimport type { ProgressService, ProgressServiceContext } from '../../progress/lib/progressService'\n\nexport const CATALOG_PRODUCT_BULK_DELETE_QUEUE = 'catalog-product-bulk-delete'\n\nconst queues = new Map<string, Queue<Record<string, unknown>>>()\n\nexport type CatalogProductBulkDeleteScope = {\n organizationId: string\n tenantId: string\n userId?: string | null\n}\n\nexport type CatalogProductBulkDeleteJobPayload = {\n progressJobId: string\n ids: string[]\n scope: CatalogProductBulkDeleteScope\n}\n\nexport type CatalogProductBulkDeleteSummary = {\n affectedCount: number\n}\n\nconst BULK_DELETE_CACHE_ALIASES = ['catalog.products']\n\nexport function getCatalogQueue(queueName: string): Queue<Record<string, unknown>> {\n const existing = queues.get(queueName)\n if (existing) return existing\n\n const concurrency = Math.max(1, Number.parseInt(process.env.CATALOG_QUEUE_CONCURRENCY ?? '3', 10) || 3)\n const created = createModuleQueue<Record<string, unknown>>(queueName, { concurrency })\n\n queues.set(queueName, created)\n return created\n}\n\nfunction buildCommandContext(\n scope: CatalogProductBulkDeleteScope,\n container: AwilixContainer,\n): CommandRuntimeContext {\n return {\n container,\n auth: null,\n organizationScope: {\n selectedId: scope.organizationId,\n filterIds: [scope.organizationId],\n allowedIds: [scope.organizationId],\n tenantId: scope.tenantId,\n },\n selectedOrganizationId: scope.organizationId,\n organizationIds: [scope.organizationId],\n }\n}\n\nexport async function deleteCatalogProductsWithProgress(params: {\n container: AwilixContainer\n progressJobId: string\n ids: string[]\n scope: CatalogProductBulkDeleteScope\n}): Promise<CatalogProductBulkDeleteSummary> {\n const { container, progressJobId, ids, scope } = params\n const commandBus = container.resolve('commandBus') as CommandBus\n const progressService = container.resolve('progressService') as ProgressService\n const progressContext: ProgressServiceContext = {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n userId: scope.userId,\n }\n\n await progressService.startJob(progressJobId, progressContext)\n await progressService.updateProgress(\n progressJobId,\n { totalCount: ids.length, processedCount: 0 },\n progressContext,\n )\n\n const commandContext = buildCommandContext(scope, container)\n let affectedCount = 0\n const deletedIds = new Set<string>()\n\n for (const [index, id] of ids.entries()) {\n await commandBus.execute<{ body?: Record<string, unknown> }, { productId: string }>('catalog.products.delete', {\n input: { body: { id } },\n ctx: commandContext,\n skipCacheInvalidation: true,\n })\n affectedCount += 1\n deletedIds.add(id)\n\n await progressService.updateProgress(\n progressJobId,\n {\n totalCount: ids.length,\n processedCount: index + 1,\n },\n progressContext,\n )\n }\n\n const summary: CatalogProductBulkDeleteSummary = { affectedCount }\n await runWithCacheTenant(scope.tenantId, async () => {\n for (const id of deletedIds) {\n await invalidateCrudCache(\n container,\n 'catalog.product',\n {\n id,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n },\n scope.tenantId,\n 'bulk-delete:catalog.products',\n BULK_DELETE_CACHE_ALIASES,\n )\n }\n })\n await progressService.completeJob(progressJobId, { resultSummary: summary }, progressContext)\n\n return summary\n}\n"],
5
+ "mappings": "AAEA,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,yBAAqC;AAGvC,MAAM,oCAAoC;AAEjD,MAAM,SAAS,oBAAI,IAA4C;AAkB/D,MAAM,4BAA4B,CAAC,kBAAkB;AAE9C,SAAS,gBAAgB,WAAmD;AACjF,QAAM,WAAW,OAAO,IAAI,SAAS;AACrC,MAAI,SAAU,QAAO;AAErB,QAAM,cAAc,KAAK,IAAI,GAAG,OAAO,SAAS,QAAQ,IAAI,6BAA6B,KAAK,EAAE,KAAK,CAAC;AACtG,QAAM,UAAU,kBAA2C,WAAW,EAAE,YAAY,CAAC;AAErF,SAAO,IAAI,WAAW,OAAO;AAC7B,SAAO;AACT;AAEA,SAAS,oBACP,OACA,WACuB;AACvB,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,mBAAmB;AAAA,MACjB,YAAY,MAAM;AAAA,MAClB,WAAW,CAAC,MAAM,cAAc;AAAA,MAChC,YAAY,CAAC,MAAM,cAAc;AAAA,MACjC,UAAU,MAAM;AAAA,IAClB;AAAA,IACA,wBAAwB,MAAM;AAAA,IAC9B,iBAAiB,CAAC,MAAM,cAAc;AAAA,EACxC;AACF;AAEA,eAAsB,kCAAkC,QAKX;AAC3C,QAAM,EAAE,WAAW,eAAe,KAAK,MAAM,IAAI;AACjD,QAAM,aAAa,UAAU,QAAQ,YAAY;AACjD,QAAM,kBAAkB,UAAU,QAAQ,iBAAiB;AAC3D,QAAM,kBAA0C;AAAA,IAC9C,UAAU,MAAM;AAAA,IAChB,gBAAgB,MAAM;AAAA,IACtB,QAAQ,MAAM;AAAA,EAChB;AAEA,QAAM,gBAAgB,SAAS,eAAe,eAAe;AAC7D,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA,EAAE,YAAY,IAAI,QAAQ,gBAAgB,EAAE;AAAA,IAC5C;AAAA,EACF;AAEA,QAAM,iBAAiB,oBAAoB,OAAO,SAAS;AAC3D,MAAI,gBAAgB;AACpB,QAAM,aAAa,oBAAI,IAAY;AAEnC,aAAW,CAAC,OAAO,EAAE,KAAK,IAAI,QAAQ,GAAG;AACvC,UAAM,WAAW,QAAmE,2BAA2B;AAAA,MAC7G,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE;AAAA,MACtB,KAAK;AAAA,MACL,uBAAuB;AAAA,IACzB,CAAC;AACD,qBAAiB;AACjB,eAAW,IAAI,EAAE;AAEjB,UAAM,gBAAgB;AAAA,MACpB;AAAA,MACA;AAAA,QACE,YAAY,IAAI;AAAA,QAChB,gBAAgB,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAA2C,EAAE,cAAc;AACjE,QAAM,mBAAmB,MAAM,UAAU,YAAY;AACnD,eAAW,MAAM,YAAY;AAC3B,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,UACE;AAAA,UACA,gBAAgB,MAAM;AAAA,UACtB,UAAU,MAAM;AAAA,QAClB;AAAA,QACA,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACD,QAAM,gBAAgB,YAAY,eAAe,EAAE,eAAe,QAAQ,GAAG,eAAe;AAE5F,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -34,6 +34,7 @@ const CATEGORY_METADATA = {
34
34
  }
35
35
  };
36
36
  const SYSTEM_STATUS_DOC_BASE = "https://docs.openmercato.com/docs/framework/operations/system-status";
37
+ const DEFAULT_SQLITE_CACHE_PATH = "./.mercato/cache/cache.db";
37
38
  function maskConnectionCredentials(raw) {
38
39
  if (typeof raw !== "string") return raw;
39
40
  const trimmed = raw.trim();
@@ -206,7 +207,7 @@ const SYSTEM_STATUS_VARIABLES = [
206
207
  labelKey: "configs.systemStatus.variables.cacheSqlitePath.label",
207
208
  descriptionKey: "configs.systemStatus.variables.cacheSqlitePath.description",
208
209
  docUrl: `${SYSTEM_STATUS_DOC_BASE}#cache_sqlite_path`,
209
- defaultValue: "./data/cache.db"
210
+ defaultValue: DEFAULT_SQLITE_CACHE_PATH
210
211
  },
211
212
  {
212
213
  key: "SCHEDULE_AUTO_REINDEX",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/configs/lib/system-status.ts"],
4
- "sourcesContent": ["import type {\n SystemStatusCategory,\n SystemStatusCategoryKey,\n SystemStatusItem,\n SystemStatusSnapshot,\n SystemStatusVariableKind,\n SystemStatusState,\n SystemStatusRuntimeMode,\n} from './system-status.types'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\n\ntype SystemStatusVariableDefinition = {\n key: string\n category: SystemStatusCategoryKey\n kind: SystemStatusVariableKind\n labelKey: string\n descriptionKey: string\n docUrl: string | null\n defaultValue: string | null\n valueTransform?: (raw: string | undefined) => string | undefined\n}\n\nconst CATEGORY_ORDER: SystemStatusCategoryKey[] = [\n 'profiling',\n 'logging',\n 'security',\n 'caching',\n 'query_index',\n 'entities',\n]\n\nconst CATEGORY_METADATA: Record<\n SystemStatusCategoryKey,\n { labelKey: string; descriptionKey: string | null }\n> = {\n profiling: {\n labelKey: 'configs.systemStatus.categories.profiling',\n descriptionKey: 'configs.systemStatus.categories.profilingDescription',\n },\n logging: {\n labelKey: 'configs.systemStatus.categories.logging',\n descriptionKey: 'configs.systemStatus.categories.loggingDescription',\n },\n security: {\n labelKey: 'configs.systemStatus.categories.security',\n descriptionKey: 'configs.systemStatus.categories.securityDescription',\n },\n caching: {\n labelKey: 'configs.systemStatus.categories.caching',\n descriptionKey: 'configs.systemStatus.categories.cachingDescription',\n },\n query_index: {\n labelKey: 'configs.systemStatus.categories.queryIndex',\n descriptionKey: 'configs.systemStatus.categories.queryIndexDescription',\n },\n entities: {\n labelKey: 'configs.systemStatus.categories.entities',\n descriptionKey: 'configs.systemStatus.categories.entitiesDescription',\n },\n}\n\nconst SYSTEM_STATUS_DOC_BASE = 'https://docs.openmercato.com/docs/framework/operations/system-status'\n\nfunction maskConnectionCredentials(raw: string | undefined): string | undefined {\n if (typeof raw !== 'string') return raw\n const trimmed = raw.trim()\n if (!trimmed) return trimmed\n\n const maskAuthorityLikeCredentials = (value: string): string => {\n const schemeIndex = value.indexOf('://')\n if (schemeIndex < 0) return value\n\n const userInfoStart = schemeIndex + 3\n const queryIndex = value.indexOf('?', userInfoStart)\n const fragmentIndex = value.indexOf('#', userInfoStart)\n const searchEnd =\n queryIndex >= 0 && fragmentIndex >= 0\n ? Math.min(queryIndex, fragmentIndex)\n : queryIndex >= 0\n ? queryIndex\n : fragmentIndex >= 0\n ? fragmentIndex\n : value.length\n\n const authorityLikeSegment = value.slice(userInfoStart, searchEnd)\n const lastAtIndex = authorityLikeSegment.lastIndexOf('@')\n if (lastAtIndex < 0) return value\n\n return `${value.slice(0, userInfoStart)}${authorityLikeSegment.slice(lastAtIndex + 1)}${value.slice(searchEnd)}`\n }\n\n try {\n const parsed = new URL(trimmed)\n if (!parsed.username && !parsed.password) {\n return trimmed\n }\n parsed.username = ''\n parsed.password = ''\n return parsed.toString()\n } catch {\n return maskAuthorityLikeCredentials(trimmed)\n }\n}\n\nexport const SYSTEM_STATUS_VARIABLES: SystemStatusVariableDefinition[] = [\n {\n key: 'OM_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.omProfile.label',\n descriptionKey: 'configs.systemStatus.variables.omProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_profile`,\n defaultValue: '',\n },\n {\n key: 'NEXT_PUBLIC_OM_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.nextPublicOmProfile.label',\n descriptionKey: 'configs.systemStatus.variables.nextPublicOmProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#next_public_om_profile`,\n defaultValue: '',\n },\n {\n key: 'OM_CRUD_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.omCrudProfile.label',\n descriptionKey: 'configs.systemStatus.variables.omCrudProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_crud_profile`,\n defaultValue: '',\n },\n {\n key: 'OM_QE_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.omQeProfile.label',\n descriptionKey: 'configs.systemStatus.variables.omQeProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_qe_profile`,\n defaultValue: '',\n },\n {\n key: 'QUERY_ENGINE_DEBUG_SQL',\n category: 'logging',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.queryEngineDebugSql.label',\n descriptionKey: 'configs.systemStatus.variables.queryEngineDebugSql.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#query_engine_debug_sql`,\n defaultValue: 'false',\n },\n {\n key: 'LOG_VERBOSITY',\n category: 'logging',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.logVerbosity.label',\n descriptionKey: 'configs.systemStatus.variables.logVerbosity.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#log_verbosity`,\n defaultValue: '',\n },\n {\n key: 'LOG_LEVEL',\n category: 'logging',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.logLevel.label',\n descriptionKey: 'configs.systemStatus.variables.logLevel.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#log_level`,\n defaultValue: '',\n },\n {\n key: 'OM_PASSWORD_MIN_LENGTH',\n category: 'security',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.passwordMinLength.label',\n descriptionKey: 'configs.systemStatus.variables.passwordMinLength.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_min_length`,\n defaultValue: '6',\n },\n {\n key: 'DATABASE_URL',\n category: 'security',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.databaseUrl.label',\n descriptionKey: 'configs.systemStatus.variables.databaseUrl.description',\n docUrl: null,\n defaultValue: null,\n valueTransform: maskConnectionCredentials,\n },\n {\n key: 'OM_PASSWORD_REQUIRE_DIGIT',\n category: 'security',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.passwordRequireDigit.label',\n descriptionKey: 'configs.systemStatus.variables.passwordRequireDigit.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_require_digit`,\n defaultValue: 'true',\n },\n {\n key: 'OM_PASSWORD_REQUIRE_UPPERCASE',\n category: 'security',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.passwordRequireUppercase.label',\n descriptionKey: 'configs.systemStatus.variables.passwordRequireUppercase.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_require_uppercase`,\n defaultValue: 'true',\n },\n {\n key: 'OM_PASSWORD_REQUIRE_SPECIAL',\n category: 'security',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.passwordRequireSpecial.label',\n descriptionKey: 'configs.systemStatus.variables.passwordRequireSpecial.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_require_special`,\n defaultValue: 'true',\n },\n {\n key: 'ENABLE_CRUD_API_CACHE',\n category: 'caching',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.enableCrudApiCache.label',\n descriptionKey: 'configs.systemStatus.variables.enableCrudApiCache.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#enable_crud_api_cache`,\n defaultValue: 'false',\n },\n {\n key: 'CACHE_STRATEGY',\n category: 'caching',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.cacheStrategy.label',\n descriptionKey: 'configs.systemStatus.variables.cacheStrategy.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#cache_strategy`,\n defaultValue: 'memory',\n },\n {\n key: 'CACHE_TTL',\n category: 'caching',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.cacheTtl.label',\n descriptionKey: 'configs.systemStatus.variables.cacheTtl.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#cache_ttl`,\n defaultValue: '',\n },\n {\n key: 'CACHE_SQLITE_PATH',\n category: 'caching',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.cacheSqlitePath.label',\n descriptionKey: 'configs.systemStatus.variables.cacheSqlitePath.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#cache_sqlite_path`,\n defaultValue: './data/cache.db',\n },\n {\n key: 'SCHEDULE_AUTO_REINDEX',\n category: 'query_index',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.scheduleAutoReindex.label',\n descriptionKey: 'configs.systemStatus.variables.scheduleAutoReindex.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#schedule_auto_reindex`,\n defaultValue: 'true',\n },\n {\n key: 'OPTIMIZE_INDEX_COVERAGE_STATS',\n category: 'query_index',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.optimizeIndexCoverageStats.label',\n descriptionKey: 'configs.systemStatus.variables.optimizeIndexCoverageStats.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#optimize_index_coverage_stats`,\n defaultValue: 'false',\n },\n {\n key: 'FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES',\n category: 'query_index',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.forceQueryIndexOnPartialIndexes.label',\n descriptionKey: 'configs.systemStatus.variables.forceQueryIndexOnPartialIndexes.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#force_query_index_on_partial_indexes`,\n defaultValue: 'false',\n },\n {\n key: 'ENTITIES_BACKCOMPAT_EAV_FOR_CUSTOM',\n category: 'entities',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.entitiesBackcompatEav.label',\n descriptionKey: 'configs.systemStatus.variables.entitiesBackcompatEav.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#entities_backcompat_eav_for_custom`,\n defaultValue: 'false',\n },\n]\n\ntype AnalyzedValue = { state: SystemStatusState; value: string | null; normalizedValue: string | null }\n\nfunction analyzeBooleanValue(raw: string | undefined): AnalyzedValue {\n if (typeof raw !== 'string') {\n return { state: 'unset', value: null, normalizedValue: null }\n }\n const trimmed = raw.trim()\n if (!trimmed) return { state: 'unset', value: null, normalizedValue: null }\n const parsed = parseBooleanToken(trimmed)\n if (parsed === true) {\n return { state: 'enabled', value: trimmed, normalizedValue: 'true' }\n }\n if (parsed === false) {\n return { state: 'disabled', value: trimmed, normalizedValue: 'false' }\n }\n return { state: 'unknown', value: trimmed, normalizedValue: trimmed }\n}\n\nfunction analyzeStringValue(raw: string | undefined): AnalyzedValue {\n if (typeof raw !== 'string') {\n return { state: 'unset', value: null, normalizedValue: null }\n }\n const trimmed = raw.trim()\n if (!trimmed) return { state: 'unset', value: null, normalizedValue: null }\n return { state: 'set', value: trimmed, normalizedValue: trimmed }\n}\n\nfunction toItem(definition: SystemStatusVariableDefinition, env: Record<string, string | undefined>): SystemStatusItem {\n const raw = definition.valueTransform ? definition.valueTransform(env[definition.key]) : env[definition.key]\n const analyzed = definition.kind === 'boolean' ? analyzeBooleanValue(raw) : analyzeStringValue(raw)\n return {\n key: definition.key,\n category: definition.category,\n kind: definition.kind,\n labelKey: definition.labelKey,\n descriptionKey: definition.descriptionKey,\n docUrl: definition.docUrl,\n defaultValue: definition.defaultValue,\n state: analyzed.state,\n value: analyzed.value,\n normalizedValue: analyzed.normalizedValue,\n }\n}\n\nfunction buildCategorySnapshot(\n key: SystemStatusCategoryKey,\n items: SystemStatusItem[],\n): SystemStatusCategory {\n const metadata = CATEGORY_METADATA[key]\n return {\n key,\n labelKey: metadata.labelKey,\n descriptionKey: metadata.descriptionKey,\n items,\n }\n}\n\nfunction resolveRuntimeMode(env: Record<string, string | undefined>): SystemStatusRuntimeMode {\n const raw = env.NODE_ENV\n if (typeof raw !== 'string') return 'unknown'\n const value = raw.trim().toLowerCase()\n if (value === 'development') return 'development'\n if (value === 'production') return 'production'\n if (value === 'test') return 'test'\n return 'unknown'\n}\n\nexport function buildSystemStatusSnapshot(\n env: Record<string, string | undefined> = process.env as Record<string, string | undefined>,\n): SystemStatusSnapshot {\n const byCategory = new Map<SystemStatusCategoryKey, SystemStatusItem[]>()\n for (const definition of SYSTEM_STATUS_VARIABLES) {\n const bucket = byCategory.get(definition.category)\n const item = toItem(definition, env)\n if (bucket) {\n bucket.push(item)\n } else {\n byCategory.set(definition.category, [item])\n }\n }\n\n const categories: SystemStatusCategory[] = []\n for (const categoryKey of CATEGORY_ORDER) {\n const items = byCategory.get(categoryKey) ?? []\n categories.push(buildCategorySnapshot(categoryKey, items))\n }\n\n return {\n generatedAt: new Date().toISOString(),\n runtimeMode: resolveRuntimeMode(env),\n categories,\n }\n}\n"],
5
- "mappings": "AASA,SAAS,yBAAyB;AAalC,MAAM,iBAA4C;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,oBAGF;AAAA,EACF,WAAW;AAAA,IACT,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,SAAS;AAAA,IACP,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,UAAU;AAAA,IACR,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,SAAS;AAAA,IACP,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,aAAa;AAAA,IACX,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,UAAU;AAAA,IACR,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AACF;AAEA,MAAM,yBAAyB;AAE/B,SAAS,0BAA0B,KAA6C;AAC9E,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAM,UAAU,IAAI,KAAK;AACzB,MAAI,CAAC,QAAS,QAAO;A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WAAW,KAAK,CAAC;AAC9C,eAAW,KAAK,sBAAsB,aAAa,KAAK,CAAC;AAAA,EAC3D;AAEA,SAAO;AAAA,IACL,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,IACpC,aAAa,mBAAmB,GAAG;AAAA,IACnC;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import type {\n SystemStatusCategory,\n SystemStatusCategoryKey,\n SystemStatusItem,\n SystemStatusSnapshot,\n SystemStatusVariableKind,\n SystemStatusState,\n SystemStatusRuntimeMode,\n} from './system-status.types'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\n\ntype SystemStatusVariableDefinition = {\n key: string\n category: SystemStatusCategoryKey\n kind: SystemStatusVariableKind\n labelKey: string\n descriptionKey: string\n docUrl: string | null\n defaultValue: string | null\n valueTransform?: (raw: string | undefined) => string | undefined\n}\n\nconst CATEGORY_ORDER: SystemStatusCategoryKey[] = [\n 'profiling',\n 'logging',\n 'security',\n 'caching',\n 'query_index',\n 'entities',\n]\n\nconst CATEGORY_METADATA: Record<\n SystemStatusCategoryKey,\n { labelKey: string; descriptionKey: string | null }\n> = {\n profiling: {\n labelKey: 'configs.systemStatus.categories.profiling',\n descriptionKey: 'configs.systemStatus.categories.profilingDescription',\n },\n logging: {\n labelKey: 'configs.systemStatus.categories.logging',\n descriptionKey: 'configs.systemStatus.categories.loggingDescription',\n },\n security: {\n labelKey: 'configs.systemStatus.categories.security',\n descriptionKey: 'configs.systemStatus.categories.securityDescription',\n },\n caching: {\n labelKey: 'configs.systemStatus.categories.caching',\n descriptionKey: 'configs.systemStatus.categories.cachingDescription',\n },\n query_index: {\n labelKey: 'configs.systemStatus.categories.queryIndex',\n descriptionKey: 'configs.systemStatus.categories.queryIndexDescription',\n },\n entities: {\n labelKey: 'configs.systemStatus.categories.entities',\n descriptionKey: 'configs.systemStatus.categories.entitiesDescription',\n },\n}\n\nconst SYSTEM_STATUS_DOC_BASE = 'https://docs.openmercato.com/docs/framework/operations/system-status'\nconst DEFAULT_SQLITE_CACHE_PATH = './.mercato/cache/cache.db'\n\nfunction maskConnectionCredentials(raw: string | undefined): string | undefined {\n if (typeof raw !== 'string') return raw\n const trimmed = raw.trim()\n if (!trimmed) return trimmed\n\n const maskAuthorityLikeCredentials = (value: string): string => {\n const schemeIndex = value.indexOf('://')\n if (schemeIndex < 0) return value\n\n const userInfoStart = schemeIndex + 3\n const queryIndex = value.indexOf('?', userInfoStart)\n const fragmentIndex = value.indexOf('#', userInfoStart)\n const searchEnd =\n queryIndex >= 0 && fragmentIndex >= 0\n ? Math.min(queryIndex, fragmentIndex)\n : queryIndex >= 0\n ? queryIndex\n : fragmentIndex >= 0\n ? fragmentIndex\n : value.length\n\n const authorityLikeSegment = value.slice(userInfoStart, searchEnd)\n const lastAtIndex = authorityLikeSegment.lastIndexOf('@')\n if (lastAtIndex < 0) return value\n\n return `${value.slice(0, userInfoStart)}${authorityLikeSegment.slice(lastAtIndex + 1)}${value.slice(searchEnd)}`\n }\n\n try {\n const parsed = new URL(trimmed)\n if (!parsed.username && !parsed.password) {\n return trimmed\n }\n parsed.username = ''\n parsed.password = ''\n return parsed.toString()\n } catch {\n return maskAuthorityLikeCredentials(trimmed)\n }\n}\n\nexport const SYSTEM_STATUS_VARIABLES: SystemStatusVariableDefinition[] = [\n {\n key: 'OM_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.omProfile.label',\n descriptionKey: 'configs.systemStatus.variables.omProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_profile`,\n defaultValue: '',\n },\n {\n key: 'NEXT_PUBLIC_OM_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.nextPublicOmProfile.label',\n descriptionKey: 'configs.systemStatus.variables.nextPublicOmProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#next_public_om_profile`,\n defaultValue: '',\n },\n {\n key: 'OM_CRUD_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.omCrudProfile.label',\n descriptionKey: 'configs.systemStatus.variables.omCrudProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_crud_profile`,\n defaultValue: '',\n },\n {\n key: 'OM_QE_PROFILE',\n category: 'profiling',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.omQeProfile.label',\n descriptionKey: 'configs.systemStatus.variables.omQeProfile.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_qe_profile`,\n defaultValue: '',\n },\n {\n key: 'QUERY_ENGINE_DEBUG_SQL',\n category: 'logging',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.queryEngineDebugSql.label',\n descriptionKey: 'configs.systemStatus.variables.queryEngineDebugSql.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#query_engine_debug_sql`,\n defaultValue: 'false',\n },\n {\n key: 'LOG_VERBOSITY',\n category: 'logging',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.logVerbosity.label',\n descriptionKey: 'configs.systemStatus.variables.logVerbosity.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#log_verbosity`,\n defaultValue: '',\n },\n {\n key: 'LOG_LEVEL',\n category: 'logging',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.logLevel.label',\n descriptionKey: 'configs.systemStatus.variables.logLevel.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#log_level`,\n defaultValue: '',\n },\n {\n key: 'OM_PASSWORD_MIN_LENGTH',\n category: 'security',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.passwordMinLength.label',\n descriptionKey: 'configs.systemStatus.variables.passwordMinLength.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_min_length`,\n defaultValue: '6',\n },\n {\n key: 'DATABASE_URL',\n category: 'security',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.databaseUrl.label',\n descriptionKey: 'configs.systemStatus.variables.databaseUrl.description',\n docUrl: null,\n defaultValue: null,\n valueTransform: maskConnectionCredentials,\n },\n {\n key: 'OM_PASSWORD_REQUIRE_DIGIT',\n category: 'security',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.passwordRequireDigit.label',\n descriptionKey: 'configs.systemStatus.variables.passwordRequireDigit.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_require_digit`,\n defaultValue: 'true',\n },\n {\n key: 'OM_PASSWORD_REQUIRE_UPPERCASE',\n category: 'security',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.passwordRequireUppercase.label',\n descriptionKey: 'configs.systemStatus.variables.passwordRequireUppercase.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_require_uppercase`,\n defaultValue: 'true',\n },\n {\n key: 'OM_PASSWORD_REQUIRE_SPECIAL',\n category: 'security',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.passwordRequireSpecial.label',\n descriptionKey: 'configs.systemStatus.variables.passwordRequireSpecial.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#om_password_require_special`,\n defaultValue: 'true',\n },\n {\n key: 'ENABLE_CRUD_API_CACHE',\n category: 'caching',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.enableCrudApiCache.label',\n descriptionKey: 'configs.systemStatus.variables.enableCrudApiCache.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#enable_crud_api_cache`,\n defaultValue: 'false',\n },\n {\n key: 'CACHE_STRATEGY',\n category: 'caching',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.cacheStrategy.label',\n descriptionKey: 'configs.systemStatus.variables.cacheStrategy.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#cache_strategy`,\n defaultValue: 'memory',\n },\n {\n key: 'CACHE_TTL',\n category: 'caching',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.cacheTtl.label',\n descriptionKey: 'configs.systemStatus.variables.cacheTtl.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#cache_ttl`,\n defaultValue: '',\n },\n {\n key: 'CACHE_SQLITE_PATH',\n category: 'caching',\n kind: 'string',\n labelKey: 'configs.systemStatus.variables.cacheSqlitePath.label',\n descriptionKey: 'configs.systemStatus.variables.cacheSqlitePath.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#cache_sqlite_path`,\n defaultValue: DEFAULT_SQLITE_CACHE_PATH,\n },\n {\n key: 'SCHEDULE_AUTO_REINDEX',\n category: 'query_index',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.scheduleAutoReindex.label',\n descriptionKey: 'configs.systemStatus.variables.scheduleAutoReindex.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#schedule_auto_reindex`,\n defaultValue: 'true',\n },\n {\n key: 'OPTIMIZE_INDEX_COVERAGE_STATS',\n category: 'query_index',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.optimizeIndexCoverageStats.label',\n descriptionKey: 'configs.systemStatus.variables.optimizeIndexCoverageStats.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#optimize_index_coverage_stats`,\n defaultValue: 'false',\n },\n {\n key: 'FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES',\n category: 'query_index',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.forceQueryIndexOnPartialIndexes.label',\n descriptionKey: 'configs.systemStatus.variables.forceQueryIndexOnPartialIndexes.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#force_query_index_on_partial_indexes`,\n defaultValue: 'false',\n },\n {\n key: 'ENTITIES_BACKCOMPAT_EAV_FOR_CUSTOM',\n category: 'entities',\n kind: 'boolean',\n labelKey: 'configs.systemStatus.variables.entitiesBackcompatEav.label',\n descriptionKey: 'configs.systemStatus.variables.entitiesBackcompatEav.description',\n docUrl: `${SYSTEM_STATUS_DOC_BASE}#entities_backcompat_eav_for_custom`,\n defaultValue: 'false',\n },\n]\n\ntype AnalyzedValue = { state: SystemStatusState; value: string | null; normalizedValue: string | null }\n\nfunction analyzeBooleanValue(raw: string | undefined): AnalyzedValue {\n if (typeof raw !== 'string') {\n return { state: 'unset', value: null, normalizedValue: null }\n }\n const trimmed = raw.trim()\n if (!trimmed) return { state: 'unset', value: null, normalizedValue: null }\n const parsed = parseBooleanToken(trimmed)\n if (parsed === true) {\n return { state: 'enabled', value: trimmed, normalizedValue: 'true' }\n }\n if (parsed === false) {\n return { state: 'disabled', value: trimmed, normalizedValue: 'false' }\n }\n return { state: 'unknown', value: trimmed, normalizedValue: trimmed }\n}\n\nfunction analyzeStringValue(raw: string | undefined): AnalyzedValue {\n if (typeof raw !== 'string') {\n return { state: 'unset', value: null, normalizedValue: null }\n }\n const trimmed = raw.trim()\n if (!trimmed) return { state: 'unset', value: null, normalizedValue: null }\n return { state: 'set', value: trimmed, normalizedValue: trimmed }\n}\n\nfunction toItem(definition: SystemStatusVariableDefinition, env: Record<string, string | undefined>): SystemStatusItem {\n const raw = definition.valueTransform ? definition.valueTransform(env[definition.key]) : env[definition.key]\n const analyzed = definition.kind === 'boolean' ? analyzeBooleanValue(raw) : analyzeStringValue(raw)\n return {\n key: definition.key,\n category: definition.category,\n kind: definition.kind,\n labelKey: definition.labelKey,\n descriptionKey: definition.descriptionKey,\n docUrl: definition.docUrl,\n defaultValue: definition.defaultValue,\n state: analyzed.state,\n value: analyzed.value,\n normalizedValue: analyzed.normalizedValue,\n }\n}\n\nfunction buildCategorySnapshot(\n key: SystemStatusCategoryKey,\n items: SystemStatusItem[],\n): SystemStatusCategory {\n const metadata = CATEGORY_METADATA[key]\n return {\n key,\n labelKey: metadata.labelKey,\n descriptionKey: metadata.descriptionKey,\n items,\n }\n}\n\nfunction resolveRuntimeMode(env: Record<string, string | undefined>): SystemStatusRuntimeMode {\n const raw = env.NODE_ENV\n if (typeof raw !== 'string') return 'unknown'\n const value = raw.trim().toLowerCase()\n if (value === 'development') return 'development'\n if (value === 'production') return 'production'\n if (value === 'test') return 'test'\n return 'unknown'\n}\n\nexport function buildSystemStatusSnapshot(\n env: Record<string, string | undefined> = process.env as Record<string, string | undefined>,\n): SystemStatusSnapshot {\n const byCategory = new Map<SystemStatusCategoryKey, SystemStatusItem[]>()\n for (const definition of SYSTEM_STATUS_VARIABLES) {\n const bucket = byCategory.get(definition.category)\n const item = toItem(definition, env)\n if (bucket) {\n bucket.push(item)\n } else {\n byCategory.set(definition.category, [item])\n }\n }\n\n const categories: SystemStatusCategory[] = []\n for (const categoryKey of CATEGORY_ORDER) {\n const items = byCategory.get(categoryKey) ?? []\n categories.push(buildCategorySnapshot(categoryKey, items))\n }\n\n return {\n generatedAt: new Date().toISOString(),\n runtimeMode: resolveRuntimeMode(env),\n categories,\n }\n}\n"],
5
+ "mappings": "AASA,SAAS,yBAAyB;AAalC,MAAM,iBAA4C;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,oBAGF;AAAA,EACF,WAAW;AAAA,IACT,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,SAAS;AAAA,IACP,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,UAAU;AAAA,IACR,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,SAAS;AAAA,IACP,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,aAAa;AAAA,IACX,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AAAA,EACA,UAAU;AAAA,IACR,UAAU;AAAA,IACV,gBAAgB;AAAA,EAClB;AACF;AAEA,MAAM,yBAAyB;AAC/B,MAAM,4BAA4B;AAElC,SAAS,0BAA0B,KAA6C;AAC9E,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAM,UAAU,IAAI,KAAK;AACzB,MAAI,CAAC,QAAS,QAAO;AAErB,QAAM,+BAA+B,CAAC,UAA0B;AAC9D,UAAM,cAAc,MAAM,QAAQ,KAAK;AACvC,QAAI,cAAc,EAAG,QAAO;AAE5B,UAAM,gBAAgB,cAA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AAY;AAAA,IACpC,aAAa,mBAAmB,GAAG;AAAA,IACnC;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -21,6 +21,7 @@ async function POST(req) {
21
21
  }
22
22
  const container = await createRequestContainer();
23
23
  const customerUserService = container.resolve("customerUserService");
24
+ const customerSessionService = container.resolve("customerSessionService");
24
25
  const user = await customerUserService.findById(auth.sub, auth.tenantId);
25
26
  if (!user) {
26
27
  return NextResponse.json({ ok: false, error: "User not found" }, { status: 404 });
@@ -30,13 +31,14 @@ async function POST(req) {
30
31
  return NextResponse.json({ ok: false, error: "Current password is incorrect" }, { status: 400 });
31
32
  }
32
33
  await customerUserService.updatePassword(user, parsed.data.newPassword);
34
+ await customerSessionService.revokeAllUserSessions(user.id);
33
35
  return NextResponse.json({ ok: true });
34
36
  }
35
37
  const successSchema = z.object({ ok: z.literal(true) });
36
38
  const errorSchema = z.object({ ok: z.literal(false), error: z.string() });
37
39
  const methodDoc = {
38
40
  summary: "Change customer password",
39
- description: "Changes the authenticated customer user password after verifying the current password.",
41
+ description: "Changes the authenticated customer user password after verifying the current password. Revokes all existing sessions.",
40
42
  tags: ["Customer Portal"],
41
43
  requestBody: { schema: passwordChangeSchema },
42
44
  responses: [{ status: 200, description: "Password changed", schema: successSchema }],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/modules/customer_accounts/api/portal/password-change.ts"],
4
- "sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib/openapi'\nimport { getCustomerAuthFromRequest } from '@open-mercato/core/modules/customer_accounts/lib/customerAuth'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { CustomerUserService } from '@open-mercato/core/modules/customer_accounts/services/customerUserService'\nimport { passwordChangeSchema } from '@open-mercato/core/modules/customer_accounts/data/validators'\n\nexport const metadata: { path?: string; requireAuth?: boolean } = { requireAuth: false }\n\nexport async function POST(req: Request) {\n const auth = await getCustomerAuthFromRequest(req)\n if (!auth) {\n return NextResponse.json({ ok: false, error: 'Authentication required' }, { status: 401 })\n }\n\n let body: unknown\n try {\n body = await req.json()\n } catch {\n return NextResponse.json({ ok: false, error: 'Invalid request body' }, { status: 400 })\n }\n\n const parsed = passwordChangeSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ ok: false, error: 'Validation failed' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const customerUserService = container.resolve('customerUserService') as CustomerUserService\n\n const user = await customerUserService.findById(auth.sub, auth.tenantId)\n if (!user) {\n return NextResponse.json({ ok: false, error: 'User not found' }, { status: 404 })\n }\n\n const currentValid = await customerUserService.verifyPassword(user, parsed.data.currentPassword)\n if (!currentValid) {\n return NextResponse.json({ ok: false, error: 'Current password is incorrect' }, { status: 400 })\n }\n\n await customerUserService.updatePassword(user, parsed.data.newPassword)\n\n return NextResponse.json({ ok: true })\n}\n\nconst successSchema = z.object({ ok: z.literal(true) })\nconst errorSchema = z.object({ ok: z.literal(false), error: z.string() })\n\nconst methodDoc: OpenApiMethodDoc = {\n summary: 'Change customer password',\n description: 'Changes the authenticated customer user password after verifying the current password.',\n tags: ['Customer Portal'],\n requestBody: { schema: passwordChangeSchema },\n responses: [{ status: 200, description: 'Password changed', schema: successSchema }],\n errors: [\n { status: 400, description: 'Current password incorrect or validation failed', schema: errorSchema },\n { status: 401, description: 'Not authenticated', schema: errorSchema },\n ],\n}\n\nexport const openApi: OpenApiRouteDoc = {\n summary: 'Change customer password',\n methods: { POST: methodDoc },\n}\n"],
5
- "mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,SAAS,kCAAkC;AAC3C,SAAS,8BAA8B;AAEvC,SAAS,4BAA4B;AAE9B,MAAM,WAAqD,EAAE,aAAa,MAAM;AAEvF,eAAsB,KAAK,KAAc;AACvC,QAAM,OAAO,MAAM,2BAA2B,GAAG;AACjD,MAAI,CAAC,MA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,EACb,MAAM,CAAC,iBAAiB;AAAA,EACxB,aAAa,EAAE,QAAQ,qBAAqB;AAAA,EAC5C,WAAW,CAAC,EAAE,QAAQ,KAAK,aAAa,oBAAoB,QAAQ,cAAc,CAAC;AAAA,EACnF,QAAQ;AAAA,IACN,EAAE,QAAQ,KAAK,aAAa,mDAAmD,QAAQ,YAAY;AAAA,IACnG,EAAE,QAAQ,KAAK,aAAa,qBAAqB,QAAQ,YAAY;AAAA,EACvE;AACF;AAEO,MAAM,UAA2B;AAAA,EACtC,SAAS;AAAA,EACT,SAAS,EAAE,MAAM,UAAU;AAC7B;",
4
+ "sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport type { OpenApiRouteDoc, OpenApiMethodDoc } from '@open-mercato/shared/lib/openapi'\nimport { getCustomerAuthFromRequest } from '@open-mercato/core/modules/customer_accounts/lib/customerAuth'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { CustomerUserService } from '@open-mercato/core/modules/customer_accounts/services/customerUserService'\nimport { CustomerSessionService } from '@open-mercato/core/modules/customer_accounts/services/customerSessionService'\nimport { passwordChangeSchema } from '@open-mercato/core/modules/customer_accounts/data/validators'\n\nexport const metadata: { path?: string; requireAuth?: boolean } = { requireAuth: false }\n\nexport async function POST(req: Request) {\n const auth = await getCustomerAuthFromRequest(req)\n if (!auth) {\n return NextResponse.json({ ok: false, error: 'Authentication required' }, { status: 401 })\n }\n\n let body: unknown\n try {\n body = await req.json()\n } catch {\n return NextResponse.json({ ok: false, error: 'Invalid request body' }, { status: 400 })\n }\n\n const parsed = passwordChangeSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ ok: false, error: 'Validation failed' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const customerUserService = container.resolve('customerUserService') as CustomerUserService\n const customerSessionService = container.resolve('customerSessionService') as CustomerSessionService\n\n const user = await customerUserService.findById(auth.sub, auth.tenantId)\n if (!user) {\n return NextResponse.json({ ok: false, error: 'User not found' }, { status: 404 })\n }\n\n const currentValid = await customerUserService.verifyPassword(user, parsed.data.currentPassword)\n if (!currentValid) {\n return NextResponse.json({ ok: false, error: 'Current password is incorrect' }, { status: 400 })\n }\n\n await customerUserService.updatePassword(user, parsed.data.newPassword)\n\n // Revoke all existing sessions for security\n await customerSessionService.revokeAllUserSessions(user.id)\n\n return NextResponse.json({ ok: true })\n}\n\nconst successSchema = z.object({ ok: z.literal(true) })\nconst errorSchema = z.object({ ok: z.literal(false), error: z.string() })\n\nconst methodDoc: OpenApiMethodDoc = {\n summary: 'Change customer password',\n description: 'Changes the authenticated customer user password after verifying the current password. Revokes all existing sessions.',\n tags: ['Customer Portal'],\n requestBody: { schema: passwordChangeSchema },\n responses: [{ status: 200, description: 'Password changed', schema: successSchema }],\n errors: [\n { status: 400, description: 'Current password incorrect or validation failed', schema: errorSchema },\n { status: 401, description: 'Not authenticated', schema: errorSchema },\n ],\n}\n\nexport const openApi: OpenApiRouteDoc = {\n summary: 'Change customer password',\n methods: { POST: methodDoc },\n}\n"],
5
+ "mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,SAAS,kCAAkC;AAC3C,SAAS,8BAA8B;AAGvC,SAAS,4BAA4B;AAE9B,MAAM,WAAqD,EAAE,aAAa,MAAM;AAEvF,eAAsB,KAAK,KAAc;AACvC,QAAM,OAAO,MAAM,2BAA2B,GAAG;AACjD,MAAI,CAAC,MAAM;AACT,WAAO,aAAa,KAAK,EAAE,IAAI,OAAO,OAAO,0BAA0B,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC3F;AAEA,MAAI;AACJ,MAAI;AACF,WAAO,MAAM,IAAI,KAAK;AAAA,EACxB,QAAQ;AACN,WAAO,aAAa,KAAK,EAAE,IAAI,OAAO,OAAO,uBAAuB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACxF;AAEA,QAAM,SAAS,qBAAqB,UAAU,IAAI;AAClD,MAAI,CAAC,OAAO,SAAS;AACn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AqB,QAAQ,YAAY;AAAA,EACvE;AACF;AAEO,MAAM,UAA2B;AAAA,EACtC,SAAS;AAAA,EACT,SAAS,EAAE,MAAM,UAAU;AAC7B;",
6
6
  "names": []
7
7
  }
@@ -15,6 +15,7 @@ import {
15
15
  } from "../../../data/entities.js";
16
16
  import { User } from "@open-mercato/core/modules/auth/data/entities";
17
17
  import { loadCustomFieldValues } from "@open-mercato/shared/lib/crud/custom-fields";
18
+ import { normalizeCustomFieldResponse } from "@open-mercato/shared/lib/custom-fields/normalize";
18
19
  import { E } from "../../../../../generated/entities.ids.generated.js";
19
20
  import { findWithDecryption, findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
20
21
  import { decryptEntitiesWithFallbackScope } from "@open-mercato/shared/lib/encryption/subscriber";
@@ -408,7 +409,7 @@ async function GET(request, context) {
408
409
  organizationIdByRecord: { [deal.id]: deal.organizationId ?? null },
409
410
  tenantFallbacks: [deal.tenantId ?? auth.tenantId ?? null].filter((value) => !!value)
410
411
  });
411
- const customFields = customFieldValues[deal.id] ?? {};
412
+ const customFields = normalizeCustomFieldResponse(customFieldValues[deal.id]) ?? {};
412
413
  const viewerUserId = auth.isApiKey ? null : auth.sub ?? null;
413
414
  let viewerName = null;
414
415
  let viewerEmail = auth.email ?? null;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/customers/api/deals/%5Bid%5D/route.ts"],
4
- "sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport {\n CustomerDeal,\n CustomerDealPersonLink,\n CustomerDealCompanyLink,\n CustomerDealStageTransition,\n CustomerDictionaryEntry,\n CustomerEntity,\n CustomerPipeline,\n CustomerPipelineStage,\n} from '../../../data/entities'\nimport { User } from '@open-mercato/core/modules/auth/data/entities'\nimport type { ActionLogService } from '@open-mercato/core/modules/audit_logs/services/actionLogService'\nimport { loadCustomFieldValues } from '@open-mercato/shared/lib/crud/custom-fields'\nimport { E } from '#generated/entities.ids.generated'\nimport type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { findWithDecryption, findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { decryptEntitiesWithFallbackScope } from '@open-mercato/shared/lib/encryption/subscriber'\nimport { isMissingDealStageTransitionTable, warnMissingDealStageTransitionTable } from '../../../lib/dealStageTransitionTable'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['customers.deals.view'] },\n}\n\nconst paramsSchema = z.object({\n id: z.string().uuid(),\n})\n\nfunction notFound(message: string) {\n return NextResponse.json({ error: message }, { status: 404 })\n}\n\nfunction forbidden(message: string) {\n return NextResponse.json({ error: message }, { status: 403 })\n}\n\ntype DealAssociation = {\n id: string\n label: string\n subtitle: string | null\n kind: 'person' | 'company'\n}\n\nfunction normalizePersonAssociation(entity: CustomerEntity): { label: string; subtitle: string | null } {\n const displayName = typeof entity.displayName === 'string' ? entity.displayName.trim() : ''\n const email =\n typeof entity.primaryEmail === 'string' && entity.primaryEmail.trim().length\n ? entity.primaryEmail.trim()\n : null\n const phone =\n typeof entity.primaryPhone === 'string' && entity.primaryPhone.trim().length\n ? entity.primaryPhone.trim()\n : null\n const jobTitle =\n entity.personProfile &&\n typeof (entity.personProfile as { jobTitle?: string | null })?.jobTitle === 'string' &&\n (entity.personProfile as { jobTitle?: string | null }).jobTitle?.trim().length\n ? ((entity.personProfile as { jobTitle?: string | null }).jobTitle as string).trim()\n : null\n const subtitle = jobTitle ?? email ?? phone ?? null\n const label = displayName.length ? displayName : email ?? phone ?? entity.id\n return { label, subtitle }\n}\n\nfunction normalizeCompanyAssociation(entity: CustomerEntity): { label: string; subtitle: string | null } {\n const displayName = typeof entity.displayName === 'string' ? entity.displayName.trim() : ''\n const domain =\n entity.companyProfile &&\n typeof (entity.companyProfile as { domain?: string | null })?.domain === 'string' &&\n (entity.companyProfile as { domain?: string | null }).domain?.trim().length\n ? ((entity.companyProfile as { domain?: string | null }).domain as string).trim()\n : null\n const website =\n entity.companyProfile &&\n typeof (entity.companyProfile as { websiteUrl?: string | null })?.websiteUrl === 'string' &&\n (entity.companyProfile as { websiteUrl?: string | null }).websiteUrl?.trim().length\n ? ((entity.companyProfile as { websiteUrl?: string | null }).websiteUrl as string).trim()\n : null\n const subtitle = domain ?? website ?? null\n const label = displayName.length ? displayName : domain ?? website ?? entity.id\n return { label, subtitle }\n}\n\nfunction readIncludeFlags(request: Request): Set<string> {\n const flags = new Set<string>()\n const url = new URL(request.url)\n for (const rawValue of url.searchParams.getAll('include')) {\n rawValue\n .split(',')\n .map((value) => value.trim().toLowerCase())\n .filter(Boolean)\n .forEach((value) => flags.add(value))\n }\n return flags\n}\n\nfunction readViewMode(request: Request): 'full' | 'lite' {\n const raw = new URL(request.url).searchParams.get('view')\n return raw === 'lite' || raw === 'detail-lite' ? 'lite' : 'full'\n}\n\nfunction normalizeStageLabel(value: string | null | undefined): string {\n return typeof value === 'string' ? value.trim().toLowerCase() : ''\n}\n\ntype StageTransitionPayload = {\n stageId: string\n stageLabel: string\n stageOrder: number\n transitionedAt: string\n}\n\ntype DealSnapshotStageInfo = {\n pipelineId: string | null\n stageId: string | null\n stageLabel: string | null\n}\n\nfunction asObject(value: unknown): Record<string, unknown> | null {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n ? value as Record<string, unknown>\n : null\n}\n\nfunction readRecordString(record: Record<string, unknown> | null, ...keys: string[]): string | null {\n if (!record) return null\n for (const key of keys) {\n const value = record[key]\n if (typeof value === 'string' && value.trim().length > 0) {\n return value.trim()\n }\n }\n return null\n}\n\nfunction readSnapshotDealRecord(snapshot: unknown): Record<string, unknown> | null {\n const root = asObject(snapshot)\n if (!root) return null\n return asObject(root.deal) ?? root\n}\n\nfunction readSnapshotStageInfo(snapshot: unknown): DealSnapshotStageInfo {\n const dealRecord = readSnapshotDealRecord(snapshot)\n return {\n pipelineId: readRecordString(dealRecord, 'pipelineId', 'pipeline_id'),\n stageId: readRecordString(dealRecord, 'pipelineStageId', 'pipeline_stage_id'),\n stageLabel: readRecordString(dealRecord, 'pipelineStage', 'pipeline_stage'),\n }\n}\n\nasync function loadAuditStageTransitionsFallback({\n container,\n deal,\n pipelineStages,\n}: {\n container: Awaited<ReturnType<typeof createRequestContainer>>\n deal: CustomerDeal\n pipelineStages: CustomerPipelineStage[]\n}): Promise<StageTransitionPayload[]> {\n if (!deal.tenantId || !deal.organizationId || !pipelineStages.length) return []\n\n let actionLogs: ActionLogService | null = null\n try {\n actionLogs = container.resolve('actionLogService') as ActionLogService\n } catch {\n return []\n }\n if (!actionLogs || typeof actionLogs.list !== 'function') return []\n const stageOrderById = new Map(pipelineStages.map((stage) => [stage.id, stage.order]))\n const stageLabelById = new Map(pipelineStages.map((stage) => [stage.id, stage.label]))\n const transitionsByStageId = new Map<string, StageTransitionPayload>()\n const logsResult = await actionLogs.list({\n tenantId: deal.tenantId,\n organizationId: deal.organizationId,\n resourceKind: 'customers.deal',\n resourceId: deal.id,\n limit: 200,\n offset: 0,\n sortField: 'createdAt',\n sortDir: 'asc',\n }).catch(() => null)\n const logs = logsResult?.items ?? []\n\n let previousStageId: string | null = null\n for (const log of logs) {\n if (log.executionState === 'failed' || log.executionState === 'undone') continue\n\n const before = readSnapshotStageInfo(log.snapshotBefore)\n const after = readSnapshotStageInfo(log.snapshotAfter)\n const nextStageId = after.stageId\n if (!nextStageId) continue\n\n const stageOrder = stageOrderById.get(nextStageId)\n if (typeof stageOrder !== 'number') {\n previousStageId = nextStageId\n continue\n }\n\n const effectivePreviousStageId: string | null = before.stageId ?? previousStageId\n if (effectivePreviousStageId === nextStageId && transitionsByStageId.has(nextStageId)) {\n previousStageId = nextStageId\n continue\n }\n\n transitionsByStageId.set(nextStageId, {\n stageId: nextStageId,\n stageLabel: after.stageLabel ?? stageLabelById.get(nextStageId) ?? nextStageId,\n stageOrder,\n transitionedAt: log.createdAt.toISOString(),\n })\n previousStageId = nextStageId\n }\n\n return Array.from(transitionsByStageId.values()).sort((left, right) => left.stageOrder - right.stageOrder)\n}\n\nfunction mergeStageTransitions({\n persisted,\n recovered,\n currentStage,\n fallbackTimestamp,\n}: {\n persisted: StageTransitionPayload[]\n recovered: StageTransitionPayload[]\n currentStage: { id: string; label: string; order: number } | null\n fallbackTimestamp: string\n}): StageTransitionPayload[] {\n const merged = new Map<string, StageTransitionPayload>()\n for (const transition of persisted) {\n merged.set(transition.stageId, transition)\n }\n for (const transition of recovered) {\n if (!merged.has(transition.stageId)) {\n merged.set(transition.stageId, transition)\n }\n }\n if (currentStage && !merged.has(currentStage.id)) {\n merged.set(currentStage.id, {\n stageId: currentStage.id,\n stageLabel: currentStage.label,\n stageOrder: currentStage.order,\n transitionedAt: fallbackTimestamp,\n })\n }\n return Array.from(merged.values()).sort((left, right) => left.stageOrder - right.stageOrder)\n}\n\nasync function loadPipelineStageAppearanceMap(\n em: EntityManager,\n stages: CustomerPipelineStage[],\n organizationId: string,\n tenantId: string,\n): Promise<Map<string, CustomerDictionaryEntry>> {\n const normalizedValues = stages\n .map((stage) => stage.label.trim().toLowerCase())\n .filter((value) => value.length > 0)\n if (!normalizedValues.length) return new Map<string, CustomerDictionaryEntry>()\n const entries = await findWithDecryption(\n em,\n CustomerDictionaryEntry,\n {\n organizationId,\n tenantId,\n kind: 'pipeline_stage',\n normalizedValue: { $in: normalizedValues },\n },\n undefined,\n { tenantId, organizationId },\n )\n const map = new Map<string, CustomerDictionaryEntry>()\n entries.forEach((entry) => map.set(entry.normalizedValue, entry))\n return map\n}\n\nasync function resolveEffectivePipelineStage(\n em: EntityManager,\n deal: CustomerDeal,\n decryptionScope: { tenantId: string | null; organizationId: string | null },\n): Promise<CustomerPipelineStage | null> {\n if (deal.pipelineStageId) {\n const exactStage = await findOneWithDecryption(\n em,\n CustomerPipelineStage,\n {\n id: deal.pipelineStageId,\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n },\n {},\n decryptionScope,\n )\n if (exactStage) return exactStage\n }\n\n const normalizedStageLabel = normalizeStageLabel(deal.pipelineStage)\n if (!normalizedStageLabel) return null\n\n const scopedStages = await findWithDecryption(\n em,\n CustomerPipelineStage,\n {\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n ...(deal.pipelineId ? { pipelineId: deal.pipelineId } : {}),\n },\n { orderBy: { order: 'ASC' } },\n decryptionScope,\n )\n\n const matchingStages = scopedStages.filter((stage) => normalizeStageLabel(stage.label) === normalizedStageLabel)\n if (matchingStages.length === 1) return matchingStages[0] ?? null\n if (matchingStages.length > 1) {\n const distinctPipelineIds = new Set(matchingStages.map((stage) => stage.pipelineId))\n if (distinctPipelineIds.size === 1) return matchingStages[0] ?? null\n }\n return null\n}\n\nexport async function GET(request: Request, context: { params?: Record<string, unknown> }) {\n const parsedParams = paramsSchema.safeParse(context.params)\n if (!parsedParams.success) {\n return notFound('Deal not found')\n }\n\n const includeFlags = readIncludeFlags(request)\n const viewMode = readViewMode(request)\n const liteView = viewMode === 'lite'\n const includeStages = includeFlags.has('stages')\n const container = await createRequestContainer()\n const auth = await getAuthFromRequest(request)\n if (!auth?.sub && !auth?.isApiKey) {\n return NextResponse.json({ error: 'Authentication required' }, { status: 401 })\n }\n\n let rbac: RbacService | null = null\n try {\n rbac = (container.resolve('rbacService') as RbacService)\n } catch {\n rbac = null\n }\n\n if (!rbac || !auth?.sub) {\n return forbidden('Access denied')\n }\n const hasFeature = await rbac.userHasAllFeatures(auth.sub, ['customers.deals.view'], {\n tenantId: auth.tenantId ?? null,\n organizationId: auth.orgId ?? null,\n })\n if (!hasFeature) {\n return forbidden('Access denied')\n }\n\n const scope = await resolveOrganizationScopeForRequest({ container, auth, request })\n const em = (container.resolve('em') as EntityManager)\n\n const deal = await findOneWithDecryption(\n em,\n CustomerDeal,\n { id: parsedParams.data.id, deletedAt: null },\n {\n populate: ['people.person', 'people.person.personProfile', 'companies.company', 'companies.company.companyProfile'],\n },\n { tenantId: auth.tenantId ?? null, organizationId: auth.orgId ?? null },\n )\n if (!deal) {\n return notFound('Deal not found')\n }\n\n if (auth.tenantId && deal.tenantId && auth.tenantId !== deal.tenantId) {\n return notFound('Deal not found')\n }\n\n const allowedOrgIds = new Set<string>()\n if (Array.isArray(scope?.filterIds)) {\n scope.filterIds.forEach((id) => {\n if (typeof id === 'string' && id.trim().length) allowedOrgIds.add(id)\n })\n } else if (auth.orgId) {\n allowedOrgIds.add(auth.orgId)\n }\n if (allowedOrgIds.size && deal.organizationId && !allowedOrgIds.has(deal.organizationId)) {\n return forbidden('Access denied')\n }\n\n const decryptionScope = {\n tenantId: deal.tenantId ?? auth.tenantId ?? null,\n organizationId: deal.organizationId ?? auth.orgId ?? null,\n }\n let linkedPersonIds: string[] = []\n let linkedCompanyIds: string[] = []\n let people: DealAssociation[] = []\n let companies: DealAssociation[] = []\n\n if (liteView) {\n const personLinkRows = await findWithDecryption(\n em,\n CustomerDealPersonLink,\n { deal: deal.id },\n { orderBy: { createdAt: 'ASC' } },\n decryptionScope,\n )\n const companyLinkRows = await findWithDecryption(\n em,\n CustomerDealCompanyLink,\n { deal: deal.id },\n { orderBy: { createdAt: 'ASC' } },\n decryptionScope,\n )\n\n linkedPersonIds = Array.from(\n new Set(\n personLinkRows\n .map((link) => {\n const personRef = link.person\n if (!personRef) return null\n if (typeof personRef === 'string') return personRef\n const personIdValue = personRef.id\n return typeof personIdValue === 'string' ? personIdValue : null\n })\n .filter((value): value is string => typeof value === 'string' && value.trim().length > 0),\n ),\n )\n linkedCompanyIds = Array.from(\n new Set(\n companyLinkRows\n .map((link) => {\n const companyRef = link.company\n if (!companyRef) return null\n if (typeof companyRef === 'string') return companyRef\n const companyIdValue = companyRef.id\n return typeof companyIdValue === 'string' ? companyIdValue : null\n })\n .filter((value): value is string => typeof value === 'string' && value.trim().length > 0),\n ),\n )\n\n const previewPeople = linkedPersonIds.length\n ? await findWithDecryption(\n em,\n CustomerEntity,\n { id: { $in: linkedPersonIds.slice(0, 3) } },\n { populate: ['personProfile'] },\n decryptionScope,\n )\n : []\n const previewCompanies = linkedCompanyIds.length\n ? await findWithDecryption(\n em,\n CustomerEntity,\n { id: { $in: linkedCompanyIds.slice(0, 3) } },\n { populate: ['companyProfile'] },\n decryptionScope,\n )\n : []\n const previewPeopleMap = new Map(previewPeople.map((entity) => [entity.id, entity]))\n const previewCompaniesMap = new Map(previewCompanies.map((entity) => [entity.id, entity]))\n people = linkedPersonIds.slice(0, 3).reduce<DealAssociation[]>((acc, personId) => {\n const entity = previewPeopleMap.get(personId) ?? null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizePersonAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'person' })\n return acc\n }, [])\n companies = linkedCompanyIds.slice(0, 3).reduce<DealAssociation[]>((acc, companyId) => {\n const entity = previewCompaniesMap.get(companyId) ?? null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizeCompanyAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'company' })\n return acc\n }, [])\n } else {\n const personLinks = await findWithDecryption(\n em,\n CustomerDealPersonLink,\n { deal: deal.id },\n { populate: ['person', 'person.personProfile'] },\n decryptionScope,\n )\n const companyLinks = await findWithDecryption(\n em,\n CustomerDealCompanyLink,\n { deal: deal.id },\n { populate: ['company', 'company.companyProfile'] },\n decryptionScope,\n )\n const fallbackTenantId = deal.tenantId ?? auth.tenantId ?? null\n const fallbackOrgId = deal.organizationId ?? auth.orgId ?? null\n await decryptEntitiesWithFallbackScope(personLinks, {\n em,\n tenantId: fallbackTenantId,\n organizationId: fallbackOrgId,\n })\n await decryptEntitiesWithFallbackScope(companyLinks, {\n em,\n tenantId: fallbackTenantId,\n organizationId: fallbackOrgId,\n })\n\n people = personLinks.reduce<DealAssociation[]>((acc, link) => {\n const entity = link.person as CustomerEntity | null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizePersonAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'person' })\n return acc\n }, [])\n\n companies = companyLinks.reduce<DealAssociation[]>((acc, link) => {\n const entity = link.company as CustomerEntity | null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizeCompanyAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'company' })\n return acc\n }, [])\n linkedPersonIds = people.map((entry) => entry.id)\n linkedCompanyIds = companies.map((entry) => entry.id)\n }\n\n const customFieldValues = await loadCustomFieldValues({\n em,\n entityId: E.customers.customer_deal,\n recordIds: [deal.id],\n tenantIdByRecord: { [deal.id]: deal.tenantId ?? null },\n organizationIdByRecord: { [deal.id]: deal.organizationId ?? null },\n tenantFallbacks: [deal.tenantId ?? auth.tenantId ?? null].filter((value): value is string => !!value),\n })\n const customFields = customFieldValues[deal.id] ?? {}\n\n const viewerUserId = auth.isApiKey ? null : auth.sub ?? null\n let viewerName: string | null = null\n let viewerEmail: string | null = auth.email ?? null\n if (viewerUserId) {\n const viewerScope = {\n tenantId: auth.tenantId ?? null,\n organizationId: auth.orgId ?? null,\n }\n const viewer = await findOneWithDecryption(\n em,\n User,\n { id: viewerUserId, tenantId: auth.tenantId ?? null },\n {},\n viewerScope,\n )\n viewerName = viewer?.name ?? null\n viewerEmail = viewer?.email ?? viewerEmail ?? null\n }\n\n const owner = deal.ownerUserId\n ? await findOneWithDecryption(\n em,\n User,\n { id: deal.ownerUserId, tenantId: deal.tenantId ?? auth.tenantId ?? null },\n {},\n decryptionScope,\n )\n : null\n const ownerPayload = owner\n ? {\n id: owner.id,\n name: owner.name ?? owner.email ?? owner.id,\n email: owner.email ?? '',\n }\n : null\n\n const effectiveStage = includeStages\n ? await resolveEffectivePipelineStage(em, deal, decryptionScope)\n : null\n const effectivePipelineId = deal.pipelineId ?? effectiveStage?.pipelineId ?? null\n const effectivePipelineStageId = deal.pipelineStageId ?? effectiveStage?.id ?? null\n const effectivePipelineStageLabel = deal.pipelineStage ?? effectiveStage?.label ?? null\n\n const pipelineStages = includeStages && effectivePipelineId\n ? await findWithDecryption(\n em,\n CustomerPipelineStage,\n {\n pipelineId: effectivePipelineId,\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n },\n { orderBy: { order: 'ASC' } },\n decryptionScope,\n )\n : []\n const pipeline = effectivePipelineId\n ? await findOneWithDecryption(\n em,\n CustomerPipeline,\n {\n id: effectivePipelineId,\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n },\n {},\n decryptionScope,\n )\n : null\n const pipelineStageAppearanceMap = pipelineStages.length\n ? await loadPipelineStageAppearanceMap(em, pipelineStages, deal.organizationId, deal.tenantId)\n : new Map<string, CustomerDictionaryEntry>()\n let stageTransitions: CustomerDealStageTransition[] = []\n if (includeStages) {\n try {\n stageTransitions = await findWithDecryption(\n em,\n CustomerDealStageTransition,\n { deal: deal.id, deletedAt: null },\n { orderBy: { stageOrder: 'ASC', transitionedAt: 'ASC' } },\n decryptionScope,\n )\n } catch (error) {\n if (!isMissingDealStageTransitionTable(error)) {\n throw error\n }\n warnMissingDealStageTransitionTable('customers.api.deals.detail.GET')\n stageTransitions = []\n }\n }\n const persistedStageTransitions = stageTransitions.map((transition) => ({\n stageId: transition.stageId,\n stageLabel: transition.stageLabel,\n stageOrder: transition.stageOrder,\n transitionedAt: transition.transitionedAt.toISOString(),\n }))\n const recoveredStageTransitions = includeStages && persistedStageTransitions.length === 0\n ? await loadAuditStageTransitionsFallback({ container, deal, pipelineStages })\n : []\n const effectiveCurrentStage = (() => {\n if (!effectivePipelineStageId) return null\n const matchingStage = pipelineStages.find((stage) => stage.id === effectivePipelineStageId)\n if (matchingStage) {\n return {\n id: matchingStage.id,\n label: matchingStage.label,\n order: matchingStage.order,\n }\n }\n if (!effectivePipelineStageLabel) return null\n return {\n id: effectivePipelineStageId,\n label: effectivePipelineStageLabel,\n order: 0,\n }\n })()\n const stageTransitionPayload = mergeStageTransitions({\n persisted: persistedStageTransitions,\n recovered: recoveredStageTransitions,\n currentStage: effectiveCurrentStage,\n fallbackTimestamp: deal.createdAt.toISOString(),\n })\n\n return NextResponse.json({\n deal: {\n id: deal.id,\n title: deal.title,\n description: deal.description ?? null,\n status: deal.status ?? null,\n pipelineStage: effectivePipelineStageLabel,\n pipelineId: effectivePipelineId,\n pipelineStageId: effectivePipelineStageId,\n valueAmount: deal.valueAmount ?? null,\n valueCurrency: deal.valueCurrency ?? null,\n probability: deal.probability ?? null,\n expectedCloseAt: deal.expectedCloseAt ? deal.expectedCloseAt.toISOString() : null,\n ownerUserId: deal.ownerUserId ?? null,\n source: deal.source ?? null,\n closureOutcome: deal.closureOutcome ?? null,\n lossReasonId: deal.lossReasonId ?? null,\n lossNotes: deal.lossNotes ?? null,\n organizationId: deal.organizationId ?? null,\n tenantId: deal.tenantId ?? null,\n createdAt: deal.createdAt.toISOString(),\n updatedAt: deal.updatedAt.toISOString(),\n },\n people,\n companies,\n linkedPersonIds,\n linkedCompanyIds,\n counts: {\n people: linkedPersonIds.length,\n companies: linkedCompanyIds.length,\n },\n customFields,\n viewer: {\n userId: viewerUserId,\n name: viewerName,\n email: viewerEmail,\n },\n pipelineStages: pipelineStages.map((stage) => {\n const appearance = pipelineStageAppearanceMap.get(stage.label.trim().toLowerCase())\n return {\n id: stage.id,\n label: stage.label,\n order: stage.order,\n color: appearance?.color ?? null,\n icon: appearance?.icon ?? null,\n }\n }),\n pipelineName: pipeline?.name ?? null,\n stageTransitions: stageTransitionPayload,\n owner: ownerPayload,\n })\n}\n\nconst dealDetailQuerySchema = z.object({\n include: z.string().optional(),\n})\n\nconst pipelineStageInfoSchema = z.object({\n id: z.string().uuid(),\n label: z.string(),\n order: z.number().int(),\n color: z.string().nullable(),\n icon: z.string().nullable(),\n})\n\nconst stageTransitionInfoSchema = z.object({\n stageId: z.string().uuid(),\n stageLabel: z.string(),\n stageOrder: z.number().int(),\n transitionedAt: z.string(),\n})\n\nconst dealDetailResponseSchema = z.object({\n deal: z.object({\n id: z.string().uuid(),\n title: z.string().nullable().optional(),\n description: z.string().nullable().optional(),\n status: z.string().nullable().optional(),\n pipelineStage: z.string().nullable().optional(),\n pipelineId: z.string().uuid().nullable().optional(),\n pipelineStageId: z.string().uuid().nullable().optional(),\n valueAmount: z.string().nullable().optional(),\n valueCurrency: z.string().nullable().optional(),\n probability: z.number().nullable().optional(),\n expectedCloseAt: z.string().nullable().optional(),\n ownerUserId: z.string().uuid().nullable().optional(),\n source: z.string().nullable().optional(),\n closureOutcome: z.enum(['won', 'lost']).nullable().optional(),\n lossReasonId: z.string().uuid().nullable().optional(),\n lossNotes: z.string().nullable().optional(),\n organizationId: z.string().uuid().nullable().optional(),\n tenantId: z.string().uuid().nullable().optional(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n people: z.array(\n z.object({\n id: z.string().uuid(),\n label: z.string(),\n subtitle: z.string().nullable().optional(),\n kind: z.literal('person'),\n }),\n ),\n companies: z.array(\n z.object({\n id: z.string().uuid(),\n label: z.string(),\n subtitle: z.string().nullable().optional(),\n kind: z.literal('company'),\n }),\n ),\n customFields: z.record(z.string(), z.unknown()),\n viewer: z.object({\n userId: z.string().uuid().nullable(),\n name: z.string().nullable(),\n email: z.string().nullable(),\n }),\n pipelineStages: z.array(pipelineStageInfoSchema),\n stageTransitions: z.array(stageTransitionInfoSchema),\n owner: z.object({\n id: z.string().uuid(),\n name: z.string(),\n email: z.string(),\n }).nullable(),\n})\n\nconst dealDetailErrorSchema = z.object({\n error: z.string(),\n})\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Customers',\n summary: 'Fetch deal detail',\n methods: {\n GET: {\n summary: 'Fetch deal with associations and pipeline context',\n description: 'Returns a deal with linked people, companies, closure fields, optional pipeline history, custom fields, and viewer context.',\n query: dealDetailQuerySchema,\n responses: [\n { status: 200, description: 'Deal detail payload', schema: dealDetailResponseSchema },\n ],\n errors: [\n { status: 401, description: 'Unauthorized', schema: dealDetailErrorSchema },\n { status: 403, description: 'Forbidden for tenant/organization scope', schema: dealDetailErrorSchema },\n { status: 404, description: 'Deal not found', schema: dealDetailErrorSchema },\n ],\n },\n },\n}\n"],
5
- "mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,0CAA0C;AAEnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY;AAErB,SAAS,6BAA6B;AACtC,SAAS,SAAS;AAGlB,SAAS,oBAAoB,6BAA6B;AAC1D,SAAS,wCAAwC;AACjD,SAAS,mCAAmC,2CAA2C;AAEhF,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,sBAAsB,EAAE;AACtE;AAEA,MAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,IAAI,EAAE,OAAO,EAAE,KAAK;AACtB,CAAC;AAED,SAAS,SAAS,SAAiB;AACjC,SAAO,aAAa,KAAK,EAAE,OAAO,QAAQ,GAAG,EAAE,QAAQ,IAAI,CAAC;AAC9D;AAEA,SAAS,UAAU,SAAiB;AAClC,SAAO,aAAa,KAAK,EAAE,OAAO,QAAQ,GAAG,EAAE,QAAQ,IAAI,CAAC;AAC9D;AASA,SAAS,2BAA2B,QAAoE;AACtG,QAAM,cAAc,OAAO,OAAO,gBAAgB,WAAW,OAAO,YAAY,KAAK,IAAI;AACzF,QAAM,QACJ,OAAO,OAAO,iBAAiB,YAAY,OAAO,aAAa,KAAK,EAAE,SAClE,OAAO,aAAa,KAAK,IACzB;AACN,QAAM,QACJ,OAAO,OAAO,iBAAiB,YAAY,OAAO,aAAa,KAAK,EAAE,SAClE,OAAO,aAAa,KAAK,IACzB;AACN,QAAM,WACJ,OAAO,iBACP,OAAQ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AAAA,MACH,SAAS;AAAA,MACT,aAAa;AAAA,MACb,OAAO;AAAA,MACP,WAAW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,uBAAuB,QAAQ,yBAAyB;AAAA,MACtF;AAAA,MACA,QAAQ;AAAA,QACN,EAAE,QAAQ,KAAK,aAAa,gBAAgB,QAAQ,sBAAsB;AAAA,QAC1E,EAAE,QAAQ,KAAK,aAAa,2CAA2C,QAAQ,sBAAsB;AAAA,QACrG,EAAE,QAAQ,KAAK,aAAa,kBAAkB,QAAQ,sBAAsB;AAAA,MAC9E;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport {\n CustomerDeal,\n CustomerDealPersonLink,\n CustomerDealCompanyLink,\n CustomerDealStageTransition,\n CustomerDictionaryEntry,\n CustomerEntity,\n CustomerPipeline,\n CustomerPipelineStage,\n} from '../../../data/entities'\nimport { User } from '@open-mercato/core/modules/auth/data/entities'\nimport type { ActionLogService } from '@open-mercato/core/modules/audit_logs/services/actionLogService'\nimport { loadCustomFieldValues } from '@open-mercato/shared/lib/crud/custom-fields'\nimport { normalizeCustomFieldResponse } from '@open-mercato/shared/lib/custom-fields/normalize'\nimport { E } from '#generated/entities.ids.generated'\nimport type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { findWithDecryption, findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { decryptEntitiesWithFallbackScope } from '@open-mercato/shared/lib/encryption/subscriber'\nimport { isMissingDealStageTransitionTable, warnMissingDealStageTransitionTable } from '../../../lib/dealStageTransitionTable'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['customers.deals.view'] },\n}\n\nconst paramsSchema = z.object({\n id: z.string().uuid(),\n})\n\nfunction notFound(message: string) {\n return NextResponse.json({ error: message }, { status: 404 })\n}\n\nfunction forbidden(message: string) {\n return NextResponse.json({ error: message }, { status: 403 })\n}\n\ntype DealAssociation = {\n id: string\n label: string\n subtitle: string | null\n kind: 'person' | 'company'\n}\n\nfunction normalizePersonAssociation(entity: CustomerEntity): { label: string; subtitle: string | null } {\n const displayName = typeof entity.displayName === 'string' ? entity.displayName.trim() : ''\n const email =\n typeof entity.primaryEmail === 'string' && entity.primaryEmail.trim().length\n ? entity.primaryEmail.trim()\n : null\n const phone =\n typeof entity.primaryPhone === 'string' && entity.primaryPhone.trim().length\n ? entity.primaryPhone.trim()\n : null\n const jobTitle =\n entity.personProfile &&\n typeof (entity.personProfile as { jobTitle?: string | null })?.jobTitle === 'string' &&\n (entity.personProfile as { jobTitle?: string | null }).jobTitle?.trim().length\n ? ((entity.personProfile as { jobTitle?: string | null }).jobTitle as string).trim()\n : null\n const subtitle = jobTitle ?? email ?? phone ?? null\n const label = displayName.length ? displayName : email ?? phone ?? entity.id\n return { label, subtitle }\n}\n\nfunction normalizeCompanyAssociation(entity: CustomerEntity): { label: string; subtitle: string | null } {\n const displayName = typeof entity.displayName === 'string' ? entity.displayName.trim() : ''\n const domain =\n entity.companyProfile &&\n typeof (entity.companyProfile as { domain?: string | null })?.domain === 'string' &&\n (entity.companyProfile as { domain?: string | null }).domain?.trim().length\n ? ((entity.companyProfile as { domain?: string | null }).domain as string).trim()\n : null\n const website =\n entity.companyProfile &&\n typeof (entity.companyProfile as { websiteUrl?: string | null })?.websiteUrl === 'string' &&\n (entity.companyProfile as { websiteUrl?: string | null }).websiteUrl?.trim().length\n ? ((entity.companyProfile as { websiteUrl?: string | null }).websiteUrl as string).trim()\n : null\n const subtitle = domain ?? website ?? null\n const label = displayName.length ? displayName : domain ?? website ?? entity.id\n return { label, subtitle }\n}\n\nfunction readIncludeFlags(request: Request): Set<string> {\n const flags = new Set<string>()\n const url = new URL(request.url)\n for (const rawValue of url.searchParams.getAll('include')) {\n rawValue\n .split(',')\n .map((value) => value.trim().toLowerCase())\n .filter(Boolean)\n .forEach((value) => flags.add(value))\n }\n return flags\n}\n\nfunction readViewMode(request: Request): 'full' | 'lite' {\n const raw = new URL(request.url).searchParams.get('view')\n return raw === 'lite' || raw === 'detail-lite' ? 'lite' : 'full'\n}\n\nfunction normalizeStageLabel(value: string | null | undefined): string {\n return typeof value === 'string' ? value.trim().toLowerCase() : ''\n}\n\ntype StageTransitionPayload = {\n stageId: string\n stageLabel: string\n stageOrder: number\n transitionedAt: string\n}\n\ntype DealSnapshotStageInfo = {\n pipelineId: string | null\n stageId: string | null\n stageLabel: string | null\n}\n\nfunction asObject(value: unknown): Record<string, unknown> | null {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n ? value as Record<string, unknown>\n : null\n}\n\nfunction readRecordString(record: Record<string, unknown> | null, ...keys: string[]): string | null {\n if (!record) return null\n for (const key of keys) {\n const value = record[key]\n if (typeof value === 'string' && value.trim().length > 0) {\n return value.trim()\n }\n }\n return null\n}\n\nfunction readSnapshotDealRecord(snapshot: unknown): Record<string, unknown> | null {\n const root = asObject(snapshot)\n if (!root) return null\n return asObject(root.deal) ?? root\n}\n\nfunction readSnapshotStageInfo(snapshot: unknown): DealSnapshotStageInfo {\n const dealRecord = readSnapshotDealRecord(snapshot)\n return {\n pipelineId: readRecordString(dealRecord, 'pipelineId', 'pipeline_id'),\n stageId: readRecordString(dealRecord, 'pipelineStageId', 'pipeline_stage_id'),\n stageLabel: readRecordString(dealRecord, 'pipelineStage', 'pipeline_stage'),\n }\n}\n\nasync function loadAuditStageTransitionsFallback({\n container,\n deal,\n pipelineStages,\n}: {\n container: Awaited<ReturnType<typeof createRequestContainer>>\n deal: CustomerDeal\n pipelineStages: CustomerPipelineStage[]\n}): Promise<StageTransitionPayload[]> {\n if (!deal.tenantId || !deal.organizationId || !pipelineStages.length) return []\n\n let actionLogs: ActionLogService | null = null\n try {\n actionLogs = container.resolve('actionLogService') as ActionLogService\n } catch {\n return []\n }\n if (!actionLogs || typeof actionLogs.list !== 'function') return []\n const stageOrderById = new Map(pipelineStages.map((stage) => [stage.id, stage.order]))\n const stageLabelById = new Map(pipelineStages.map((stage) => [stage.id, stage.label]))\n const transitionsByStageId = new Map<string, StageTransitionPayload>()\n const logsResult = await actionLogs.list({\n tenantId: deal.tenantId,\n organizationId: deal.organizationId,\n resourceKind: 'customers.deal',\n resourceId: deal.id,\n limit: 200,\n offset: 0,\n sortField: 'createdAt',\n sortDir: 'asc',\n }).catch(() => null)\n const logs = logsResult?.items ?? []\n\n let previousStageId: string | null = null\n for (const log of logs) {\n if (log.executionState === 'failed' || log.executionState === 'undone') continue\n\n const before = readSnapshotStageInfo(log.snapshotBefore)\n const after = readSnapshotStageInfo(log.snapshotAfter)\n const nextStageId = after.stageId\n if (!nextStageId) continue\n\n const stageOrder = stageOrderById.get(nextStageId)\n if (typeof stageOrder !== 'number') {\n previousStageId = nextStageId\n continue\n }\n\n const effectivePreviousStageId: string | null = before.stageId ?? previousStageId\n if (effectivePreviousStageId === nextStageId && transitionsByStageId.has(nextStageId)) {\n previousStageId = nextStageId\n continue\n }\n\n transitionsByStageId.set(nextStageId, {\n stageId: nextStageId,\n stageLabel: after.stageLabel ?? stageLabelById.get(nextStageId) ?? nextStageId,\n stageOrder,\n transitionedAt: log.createdAt.toISOString(),\n })\n previousStageId = nextStageId\n }\n\n return Array.from(transitionsByStageId.values()).sort((left, right) => left.stageOrder - right.stageOrder)\n}\n\nfunction mergeStageTransitions({\n persisted,\n recovered,\n currentStage,\n fallbackTimestamp,\n}: {\n persisted: StageTransitionPayload[]\n recovered: StageTransitionPayload[]\n currentStage: { id: string; label: string; order: number } | null\n fallbackTimestamp: string\n}): StageTransitionPayload[] {\n const merged = new Map<string, StageTransitionPayload>()\n for (const transition of persisted) {\n merged.set(transition.stageId, transition)\n }\n for (const transition of recovered) {\n if (!merged.has(transition.stageId)) {\n merged.set(transition.stageId, transition)\n }\n }\n if (currentStage && !merged.has(currentStage.id)) {\n merged.set(currentStage.id, {\n stageId: currentStage.id,\n stageLabel: currentStage.label,\n stageOrder: currentStage.order,\n transitionedAt: fallbackTimestamp,\n })\n }\n return Array.from(merged.values()).sort((left, right) => left.stageOrder - right.stageOrder)\n}\n\nasync function loadPipelineStageAppearanceMap(\n em: EntityManager,\n stages: CustomerPipelineStage[],\n organizationId: string,\n tenantId: string,\n): Promise<Map<string, CustomerDictionaryEntry>> {\n const normalizedValues = stages\n .map((stage) => stage.label.trim().toLowerCase())\n .filter((value) => value.length > 0)\n if (!normalizedValues.length) return new Map<string, CustomerDictionaryEntry>()\n const entries = await findWithDecryption(\n em,\n CustomerDictionaryEntry,\n {\n organizationId,\n tenantId,\n kind: 'pipeline_stage',\n normalizedValue: { $in: normalizedValues },\n },\n undefined,\n { tenantId, organizationId },\n )\n const map = new Map<string, CustomerDictionaryEntry>()\n entries.forEach((entry) => map.set(entry.normalizedValue, entry))\n return map\n}\n\nasync function resolveEffectivePipelineStage(\n em: EntityManager,\n deal: CustomerDeal,\n decryptionScope: { tenantId: string | null; organizationId: string | null },\n): Promise<CustomerPipelineStage | null> {\n if (deal.pipelineStageId) {\n const exactStage = await findOneWithDecryption(\n em,\n CustomerPipelineStage,\n {\n id: deal.pipelineStageId,\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n },\n {},\n decryptionScope,\n )\n if (exactStage) return exactStage\n }\n\n const normalizedStageLabel = normalizeStageLabel(deal.pipelineStage)\n if (!normalizedStageLabel) return null\n\n const scopedStages = await findWithDecryption(\n em,\n CustomerPipelineStage,\n {\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n ...(deal.pipelineId ? { pipelineId: deal.pipelineId } : {}),\n },\n { orderBy: { order: 'ASC' } },\n decryptionScope,\n )\n\n const matchingStages = scopedStages.filter((stage) => normalizeStageLabel(stage.label) === normalizedStageLabel)\n if (matchingStages.length === 1) return matchingStages[0] ?? null\n if (matchingStages.length > 1) {\n const distinctPipelineIds = new Set(matchingStages.map((stage) => stage.pipelineId))\n if (distinctPipelineIds.size === 1) return matchingStages[0] ?? null\n }\n return null\n}\n\nexport async function GET(request: Request, context: { params?: Record<string, unknown> }) {\n const parsedParams = paramsSchema.safeParse(context.params)\n if (!parsedParams.success) {\n return notFound('Deal not found')\n }\n\n const includeFlags = readIncludeFlags(request)\n const viewMode = readViewMode(request)\n const liteView = viewMode === 'lite'\n const includeStages = includeFlags.has('stages')\n const container = await createRequestContainer()\n const auth = await getAuthFromRequest(request)\n if (!auth?.sub && !auth?.isApiKey) {\n return NextResponse.json({ error: 'Authentication required' }, { status: 401 })\n }\n\n let rbac: RbacService | null = null\n try {\n rbac = (container.resolve('rbacService') as RbacService)\n } catch {\n rbac = null\n }\n\n if (!rbac || !auth?.sub) {\n return forbidden('Access denied')\n }\n const hasFeature = await rbac.userHasAllFeatures(auth.sub, ['customers.deals.view'], {\n tenantId: auth.tenantId ?? null,\n organizationId: auth.orgId ?? null,\n })\n if (!hasFeature) {\n return forbidden('Access denied')\n }\n\n const scope = await resolveOrganizationScopeForRequest({ container, auth, request })\n const em = (container.resolve('em') as EntityManager)\n\n const deal = await findOneWithDecryption(\n em,\n CustomerDeal,\n { id: parsedParams.data.id, deletedAt: null },\n {\n populate: ['people.person', 'people.person.personProfile', 'companies.company', 'companies.company.companyProfile'],\n },\n { tenantId: auth.tenantId ?? null, organizationId: auth.orgId ?? null },\n )\n if (!deal) {\n return notFound('Deal not found')\n }\n\n if (auth.tenantId && deal.tenantId && auth.tenantId !== deal.tenantId) {\n return notFound('Deal not found')\n }\n\n const allowedOrgIds = new Set<string>()\n if (Array.isArray(scope?.filterIds)) {\n scope.filterIds.forEach((id) => {\n if (typeof id === 'string' && id.trim().length) allowedOrgIds.add(id)\n })\n } else if (auth.orgId) {\n allowedOrgIds.add(auth.orgId)\n }\n if (allowedOrgIds.size && deal.organizationId && !allowedOrgIds.has(deal.organizationId)) {\n return forbidden('Access denied')\n }\n\n const decryptionScope = {\n tenantId: deal.tenantId ?? auth.tenantId ?? null,\n organizationId: deal.organizationId ?? auth.orgId ?? null,\n }\n let linkedPersonIds: string[] = []\n let linkedCompanyIds: string[] = []\n let people: DealAssociation[] = []\n let companies: DealAssociation[] = []\n\n if (liteView) {\n const personLinkRows = await findWithDecryption(\n em,\n CustomerDealPersonLink,\n { deal: deal.id },\n { orderBy: { createdAt: 'ASC' } },\n decryptionScope,\n )\n const companyLinkRows = await findWithDecryption(\n em,\n CustomerDealCompanyLink,\n { deal: deal.id },\n { orderBy: { createdAt: 'ASC' } },\n decryptionScope,\n )\n\n linkedPersonIds = Array.from(\n new Set(\n personLinkRows\n .map((link) => {\n const personRef = link.person\n if (!personRef) return null\n if (typeof personRef === 'string') return personRef\n const personIdValue = personRef.id\n return typeof personIdValue === 'string' ? personIdValue : null\n })\n .filter((value): value is string => typeof value === 'string' && value.trim().length > 0),\n ),\n )\n linkedCompanyIds = Array.from(\n new Set(\n companyLinkRows\n .map((link) => {\n const companyRef = link.company\n if (!companyRef) return null\n if (typeof companyRef === 'string') return companyRef\n const companyIdValue = companyRef.id\n return typeof companyIdValue === 'string' ? companyIdValue : null\n })\n .filter((value): value is string => typeof value === 'string' && value.trim().length > 0),\n ),\n )\n\n const previewPeople = linkedPersonIds.length\n ? await findWithDecryption(\n em,\n CustomerEntity,\n { id: { $in: linkedPersonIds.slice(0, 3) } },\n { populate: ['personProfile'] },\n decryptionScope,\n )\n : []\n const previewCompanies = linkedCompanyIds.length\n ? await findWithDecryption(\n em,\n CustomerEntity,\n { id: { $in: linkedCompanyIds.slice(0, 3) } },\n { populate: ['companyProfile'] },\n decryptionScope,\n )\n : []\n const previewPeopleMap = new Map(previewPeople.map((entity) => [entity.id, entity]))\n const previewCompaniesMap = new Map(previewCompanies.map((entity) => [entity.id, entity]))\n people = linkedPersonIds.slice(0, 3).reduce<DealAssociation[]>((acc, personId) => {\n const entity = previewPeopleMap.get(personId) ?? null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizePersonAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'person' })\n return acc\n }, [])\n companies = linkedCompanyIds.slice(0, 3).reduce<DealAssociation[]>((acc, companyId) => {\n const entity = previewCompaniesMap.get(companyId) ?? null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizeCompanyAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'company' })\n return acc\n }, [])\n } else {\n const personLinks = await findWithDecryption(\n em,\n CustomerDealPersonLink,\n { deal: deal.id },\n { populate: ['person', 'person.personProfile'] },\n decryptionScope,\n )\n const companyLinks = await findWithDecryption(\n em,\n CustomerDealCompanyLink,\n { deal: deal.id },\n { populate: ['company', 'company.companyProfile'] },\n decryptionScope,\n )\n const fallbackTenantId = deal.tenantId ?? auth.tenantId ?? null\n const fallbackOrgId = deal.organizationId ?? auth.orgId ?? null\n await decryptEntitiesWithFallbackScope(personLinks, {\n em,\n tenantId: fallbackTenantId,\n organizationId: fallbackOrgId,\n })\n await decryptEntitiesWithFallbackScope(companyLinks, {\n em,\n tenantId: fallbackTenantId,\n organizationId: fallbackOrgId,\n })\n\n people = personLinks.reduce<DealAssociation[]>((acc, link) => {\n const entity = link.person as CustomerEntity | null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizePersonAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'person' })\n return acc\n }, [])\n\n companies = companyLinks.reduce<DealAssociation[]>((acc, link) => {\n const entity = link.company as CustomerEntity | null\n if (!entity || entity.deletedAt) return acc\n const { label, subtitle } = normalizeCompanyAssociation(entity)\n acc.push({ id: entity.id, label, subtitle, kind: 'company' })\n return acc\n }, [])\n linkedPersonIds = people.map((entry) => entry.id)\n linkedCompanyIds = companies.map((entry) => entry.id)\n }\n\n const customFieldValues = await loadCustomFieldValues({\n em,\n entityId: E.customers.customer_deal,\n recordIds: [deal.id],\n tenantIdByRecord: { [deal.id]: deal.tenantId ?? null },\n organizationIdByRecord: { [deal.id]: deal.organizationId ?? null },\n tenantFallbacks: [deal.tenantId ?? auth.tenantId ?? null].filter((value): value is string => !!value),\n })\n const customFields = normalizeCustomFieldResponse(customFieldValues[deal.id]) ?? {}\n\n const viewerUserId = auth.isApiKey ? null : auth.sub ?? null\n let viewerName: string | null = null\n let viewerEmail: string | null = auth.email ?? null\n if (viewerUserId) {\n const viewerScope = {\n tenantId: auth.tenantId ?? null,\n organizationId: auth.orgId ?? null,\n }\n const viewer = await findOneWithDecryption(\n em,\n User,\n { id: viewerUserId, tenantId: auth.tenantId ?? null },\n {},\n viewerScope,\n )\n viewerName = viewer?.name ?? null\n viewerEmail = viewer?.email ?? viewerEmail ?? null\n }\n\n const owner = deal.ownerUserId\n ? await findOneWithDecryption(\n em,\n User,\n { id: deal.ownerUserId, tenantId: deal.tenantId ?? auth.tenantId ?? null },\n {},\n decryptionScope,\n )\n : null\n const ownerPayload = owner\n ? {\n id: owner.id,\n name: owner.name ?? owner.email ?? owner.id,\n email: owner.email ?? '',\n }\n : null\n\n const effectiveStage = includeStages\n ? await resolveEffectivePipelineStage(em, deal, decryptionScope)\n : null\n const effectivePipelineId = deal.pipelineId ?? effectiveStage?.pipelineId ?? null\n const effectivePipelineStageId = deal.pipelineStageId ?? effectiveStage?.id ?? null\n const effectivePipelineStageLabel = deal.pipelineStage ?? effectiveStage?.label ?? null\n\n const pipelineStages = includeStages && effectivePipelineId\n ? await findWithDecryption(\n em,\n CustomerPipelineStage,\n {\n pipelineId: effectivePipelineId,\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n },\n { orderBy: { order: 'ASC' } },\n decryptionScope,\n )\n : []\n const pipeline = effectivePipelineId\n ? await findOneWithDecryption(\n em,\n CustomerPipeline,\n {\n id: effectivePipelineId,\n organizationId: deal.organizationId,\n tenantId: deal.tenantId,\n },\n {},\n decryptionScope,\n )\n : null\n const pipelineStageAppearanceMap = pipelineStages.length\n ? await loadPipelineStageAppearanceMap(em, pipelineStages, deal.organizationId, deal.tenantId)\n : new Map<string, CustomerDictionaryEntry>()\n let stageTransitions: CustomerDealStageTransition[] = []\n if (includeStages) {\n try {\n stageTransitions = await findWithDecryption(\n em,\n CustomerDealStageTransition,\n { deal: deal.id, deletedAt: null },\n { orderBy: { stageOrder: 'ASC', transitionedAt: 'ASC' } },\n decryptionScope,\n )\n } catch (error) {\n if (!isMissingDealStageTransitionTable(error)) {\n throw error\n }\n warnMissingDealStageTransitionTable('customers.api.deals.detail.GET')\n stageTransitions = []\n }\n }\n const persistedStageTransitions = stageTransitions.map((transition) => ({\n stageId: transition.stageId,\n stageLabel: transition.stageLabel,\n stageOrder: transition.stageOrder,\n transitionedAt: transition.transitionedAt.toISOString(),\n }))\n const recoveredStageTransitions = includeStages && persistedStageTransitions.length === 0\n ? await loadAuditStageTransitionsFallback({ container, deal, pipelineStages })\n : []\n const effectiveCurrentStage = (() => {\n if (!effectivePipelineStageId) return null\n const matchingStage = pipelineStages.find((stage) => stage.id === effectivePipelineStageId)\n if (matchingStage) {\n return {\n id: matchingStage.id,\n label: matchingStage.label,\n order: matchingStage.order,\n }\n }\n if (!effectivePipelineStageLabel) return null\n return {\n id: effectivePipelineStageId,\n label: effectivePipelineStageLabel,\n order: 0,\n }\n })()\n const stageTransitionPayload = mergeStageTransitions({\n persisted: persistedStageTransitions,\n recovered: recoveredStageTransitions,\n currentStage: effectiveCurrentStage,\n fallbackTimestamp: deal.createdAt.toISOString(),\n })\n\n return NextResponse.json({\n deal: {\n id: deal.id,\n title: deal.title,\n description: deal.description ?? null,\n status: deal.status ?? null,\n pipelineStage: effectivePipelineStageLabel,\n pipelineId: effectivePipelineId,\n pipelineStageId: effectivePipelineStageId,\n valueAmount: deal.valueAmount ?? null,\n valueCurrency: deal.valueCurrency ?? null,\n probability: deal.probability ?? null,\n expectedCloseAt: deal.expectedCloseAt ? deal.expectedCloseAt.toISOString() : null,\n ownerUserId: deal.ownerUserId ?? null,\n source: deal.source ?? null,\n closureOutcome: deal.closureOutcome ?? null,\n lossReasonId: deal.lossReasonId ?? null,\n lossNotes: deal.lossNotes ?? null,\n organizationId: deal.organizationId ?? null,\n tenantId: deal.tenantId ?? null,\n createdAt: deal.createdAt.toISOString(),\n updatedAt: deal.updatedAt.toISOString(),\n },\n people,\n companies,\n linkedPersonIds,\n linkedCompanyIds,\n counts: {\n people: linkedPersonIds.length,\n companies: linkedCompanyIds.length,\n },\n customFields,\n viewer: {\n userId: viewerUserId,\n name: viewerName,\n email: viewerEmail,\n },\n pipelineStages: pipelineStages.map((stage) => {\n const appearance = pipelineStageAppearanceMap.get(stage.label.trim().toLowerCase())\n return {\n id: stage.id,\n label: stage.label,\n order: stage.order,\n color: appearance?.color ?? null,\n icon: appearance?.icon ?? null,\n }\n }),\n pipelineName: pipeline?.name ?? null,\n stageTransitions: stageTransitionPayload,\n owner: ownerPayload,\n })\n}\n\nconst dealDetailQuerySchema = z.object({\n include: z.string().optional(),\n})\n\nconst pipelineStageInfoSchema = z.object({\n id: z.string().uuid(),\n label: z.string(),\n order: z.number().int(),\n color: z.string().nullable(),\n icon: z.string().nullable(),\n})\n\nconst stageTransitionInfoSchema = z.object({\n stageId: z.string().uuid(),\n stageLabel: z.string(),\n stageOrder: z.number().int(),\n transitionedAt: z.string(),\n})\n\nconst dealDetailResponseSchema = z.object({\n deal: z.object({\n id: z.string().uuid(),\n title: z.string().nullable().optional(),\n description: z.string().nullable().optional(),\n status: z.string().nullable().optional(),\n pipelineStage: z.string().nullable().optional(),\n pipelineId: z.string().uuid().nullable().optional(),\n pipelineStageId: z.string().uuid().nullable().optional(),\n valueAmount: z.string().nullable().optional(),\n valueCurrency: z.string().nullable().optional(),\n probability: z.number().nullable().optional(),\n expectedCloseAt: z.string().nullable().optional(),\n ownerUserId: z.string().uuid().nullable().optional(),\n source: z.string().nullable().optional(),\n closureOutcome: z.enum(['won', 'lost']).nullable().optional(),\n lossReasonId: z.string().uuid().nullable().optional(),\n lossNotes: z.string().nullable().optional(),\n organizationId: z.string().uuid().nullable().optional(),\n tenantId: z.string().uuid().nullable().optional(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n people: z.array(\n z.object({\n id: z.string().uuid(),\n label: z.string(),\n subtitle: z.string().nullable().optional(),\n kind: z.literal('person'),\n }),\n ),\n companies: z.array(\n z.object({\n id: z.string().uuid(),\n label: z.string(),\n subtitle: z.string().nullable().optional(),\n kind: z.literal('company'),\n }),\n ),\n customFields: z.record(z.string(), z.unknown()),\n viewer: z.object({\n userId: z.string().uuid().nullable(),\n name: z.string().nullable(),\n email: z.string().nullable(),\n }),\n pipelineStages: z.array(pipelineStageInfoSchema),\n stageTransitions: z.array(stageTransitionInfoSchema),\n owner: z.object({\n id: z.string().uuid(),\n name: z.string(),\n email: z.string(),\n }).nullable(),\n})\n\nconst dealDetailErrorSchema = z.object({\n error: z.string(),\n})\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Customers',\n summary: 'Fetch deal detail',\n methods: {\n GET: {\n summary: 'Fetch deal with associations and pipeline context',\n description: 'Returns a deal with linked people, companies, closure fields, optional pipeline history, custom fields, and viewer context.',\n query: dealDetailQuerySchema,\n responses: [\n { status: 200, description: 'Deal detail payload', schema: dealDetailResponseSchema },\n ],\n errors: [\n { status: 401, description: 'Unauthorized', schema: dealDetailErrorSchema },\n { status: 403, description: 'Forbidden for tenant/organization scope', schema: dealDetailErrorSchema },\n { status: 404, description: 'Deal not found', schema: dealDetailErrorSchema },\n ],\n },\n },\n}\n"],
5
+ "mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,0CAA0C;AAEnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY;AAErB,SAAS,6BAA6B;AACtC,SAAS,o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7
  }
@@ -4,6 +4,7 @@ import { sql } from "kysely";
4
4
  import { makeCrudRoute } from "@open-mercato/shared/lib/crud/factory";
5
5
  import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
6
6
  import { loadCustomFieldValues } from "@open-mercato/shared/lib/crud/custom-fields";
7
+ import { normalizeCustomFieldResponse } from "@open-mercato/shared/lib/custom-fields/normalize";
7
8
  import { applyResponseEnrichers } from "@open-mercato/shared/lib/crud/enricher-runner";
8
9
  import { findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
9
10
  import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
@@ -372,7 +373,7 @@ async function GET(req) {
372
373
  authorName: row.author_user_id ? userMap.get(row.author_user_id)?.name ?? null : null,
373
374
  authorEmail: row.author_user_id ? userMap.get(row.author_user_id)?.email ?? null : null,
374
375
  dealTitle: row.deal_id ? dealMap.get(row.deal_id) ?? null : null,
375
- customValues: customFieldValues[row.id] ?? null
376
+ customValues: normalizeCustomFieldResponse(customFieldValues[row.id]) ?? null
376
377
  }));
377
378
  const enricherContext = await buildEnricherContext(container, auth, selectedOrganizationId);
378
379
  const enriched = await applyResponseEnrichers(baseItems, "customers.interaction", enricherContext);