@open-mercato/core 0.6.6-develop.6515.1.01911d00e2 → 0.6.6-develop.6519.1.bdc91fb755
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/modules/configs/lib/upgrade-actions.js +31 -1
- package/dist/modules/configs/lib/upgrade-actions.js.map +2 -2
- package/dist/modules/customers/ai-tools/activities-tasks-pack.js +11 -2
- package/dist/modules/customers/ai-tools/activities-tasks-pack.js.map +2 -2
- package/dist/modules/customers/api/companies/[id]/route.js +3 -2
- package/dist/modules/customers/api/companies/[id]/route.js.map +2 -2
- package/dist/modules/customers/api/dictionaries/context.js +4 -2
- package/dist/modules/customers/api/dictionaries/context.js.map +2 -2
- package/dist/modules/customers/api/interactions/conflicts/route.js +2 -1
- package/dist/modules/customers/api/interactions/conflicts/route.js.map +2 -2
- package/dist/modules/customers/api/interactions/counts/route.js +7 -2
- package/dist/modules/customers/api/interactions/counts/route.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/route.js +3 -2
- package/dist/modules/customers/api/people/[id]/route.js.map +2 -2
- package/dist/modules/customers/cli.js +19 -0
- package/dist/modules/customers/cli.js.map +2 -2
- package/dist/modules/customers/commands/interactions.js +8 -3
- package/dist/modules/customers/commands/interactions.js.map +2 -2
- package/dist/modules/customers/commands/shared.js +2 -1
- package/dist/modules/customers/commands/shared.js.map +2 -2
- package/dist/modules/customers/components/DictionarySettings.js +5 -0
- package/dist/modules/customers/components/DictionarySettings.js.map +2 -2
- package/dist/modules/customers/components/DictionarySortSettings.js +5 -0
- package/dist/modules/customers/components/DictionarySortSettings.js.map +2 -2
- package/dist/modules/customers/components/detail/ActivitiesCard.js +3 -2
- package/dist/modules/customers/components/detail/ActivitiesCard.js.map +2 -2
- package/dist/modules/customers/components/detail/ActivityCard.js +2 -1
- package/dist/modules/customers/components/detail/ActivityCard.js.map +2 -2
- package/dist/modules/customers/components/detail/ActivityTimeline.js +3 -2
- package/dist/modules/customers/components/detail/ActivityTimeline.js.map +2 -2
- package/dist/modules/customers/components/detail/TaskDialog.js +3 -2
- package/dist/modules/customers/components/detail/TaskDialog.js.map +2 -2
- package/dist/modules/customers/components/detail/TaskForm.js +170 -69
- package/dist/modules/customers/components/detail/TaskForm.js.map +2 -2
- package/dist/modules/customers/components/detail/TasksSection.js +27 -4
- package/dist/modules/customers/components/detail/TasksSection.js.map +2 -2
- package/dist/modules/customers/components/detail/hooks/usePersonTasks.js.map +2 -2
- package/dist/modules/customers/data/enrichers.js +2 -2
- package/dist/modules/customers/data/enrichers.js.map +2 -2
- package/dist/modules/customers/data/validators.js +6 -2
- package/dist/modules/customers/data/validators.js.map +2 -2
- package/dist/modules/customers/lib/dictionaries.js +2 -1
- package/dist/modules/customers/lib/dictionaries.js.map +2 -2
- package/dist/modules/customers/lib/interactionProjection.js +2 -1
- package/dist/modules/customers/lib/interactionProjection.js.map +2 -2
- package/dist/modules/customers/lib/interactionStatus.js +24 -0
- package/dist/modules/customers/lib/interactionStatus.js.map +7 -0
- package/dist/modules/customers/lib/link-channel-message-handler.js +4 -5
- package/dist/modules/customers/lib/link-channel-message-handler.js.map +2 -2
- package/dist/modules/dictionaries/components/AppearanceSelector.js +7 -3
- package/dist/modules/dictionaries/components/AppearanceSelector.js.map +2 -2
- package/dist/modules/dictionaries/components/DictionaryEntriesEditor.js +1 -0
- package/dist/modules/dictionaries/components/DictionaryEntriesEditor.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/configs/lib/upgrade-actions.ts +31 -1
- package/src/modules/customers/ai-tools/activities-tasks-pack.ts +12 -3
- package/src/modules/customers/api/companies/[id]/route.ts +3 -2
- package/src/modules/customers/api/dictionaries/context.ts +2 -0
- package/src/modules/customers/api/interactions/conflicts/route.ts +2 -1
- package/src/modules/customers/api/interactions/counts/route.ts +7 -2
- package/src/modules/customers/api/people/[id]/route.ts +3 -2
- package/src/modules/customers/cli.ts +19 -0
- package/src/modules/customers/commands/interactions.ts +8 -3
- package/src/modules/customers/commands/shared.ts +1 -0
- package/src/modules/customers/components/DictionarySettings.tsx +5 -0
- package/src/modules/customers/components/DictionarySortSettings.tsx +5 -0
- package/src/modules/customers/components/detail/ActivitiesCard.tsx +3 -2
- package/src/modules/customers/components/detail/ActivityCard.tsx +2 -1
- package/src/modules/customers/components/detail/ActivityTimeline.tsx +3 -2
- package/src/modules/customers/components/detail/TaskDialog.tsx +4 -1
- package/src/modules/customers/components/detail/TaskForm.tsx +218 -71
- package/src/modules/customers/components/detail/TasksSection.tsx +28 -2
- package/src/modules/customers/components/detail/hooks/usePersonTasks.ts +1 -0
- package/src/modules/customers/data/enrichers.ts +2 -7
- package/src/modules/customers/data/validators.ts +16 -2
- package/src/modules/customers/i18n/de.json +10 -0
- package/src/modules/customers/i18n/en.json +10 -0
- package/src/modules/customers/i18n/es.json +10 -0
- package/src/modules/customers/i18n/pl.json +10 -0
- package/src/modules/customers/lib/dictionaries.ts +1 -0
- package/src/modules/customers/lib/interactionProjection.ts +6 -2
- package/src/modules/customers/lib/interactionStatus.ts +30 -0
- package/src/modules/customers/lib/link-channel-message-handler.ts +4 -5
- package/src/modules/dictionaries/components/AppearanceSelector.tsx +10 -1
- package/src/modules/dictionaries/components/DictionaryEntriesEditor.tsx +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/customers/api/interactions/conflicts/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { sql } from 'kysely'\nimport { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\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 { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { CustomerInteraction } from '../../../data/entities'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('customers')\n\nconst querySchema = z.object({\n date: z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/),\n startTime: z.string().regex(/^\\d{2}:\\d{2}$/),\n duration: z.coerce.number().int().min(1).max(1440),\n excludeId: z.string().uuid().optional(),\n userId: z.string().uuid().optional(),\n timezoneOffsetMinutes: z.coerce.number().int().min(-900).max(900).optional(),\n})\n\nconst conflictItemSchema = z.object({\n id: z.string(),\n title: z.string().nullable(),\n startTime: z.string(),\n endTime: z.string(),\n type: z.string(),\n})\n\nconst responseSchema = z.object({\n ok: z.literal(true),\n result: z.object({\n hasConflicts: z.boolean(),\n conflicts: z.array(conflictItemSchema),\n }),\n})\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['customers.interactions.view'] },\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Customers',\n methods: {\n GET: {\n summary: 'Detect scheduling conflicts',\n description: 'Checks for overlapping planned interactions within the requested time window.',\n query: querySchema,\n responses: [\n {\n status: 200,\n description: 'Conflict detection result',\n schema: responseSchema,\n },\n ],\n },\n },\n}\n\nexport async function GET(req: Request) {\n const { translate } = await resolveTranslations()\n try {\n const queryUrl = new URL(req.url)\n const query = querySchema.parse(Object.fromEntries(queryUrl.searchParams))\n const container = await createRequestContainer()\n const auth = await getAuthFromRequest(req)\n\n if (!auth || !auth.tenantId) {\n throw new CrudHttpError(401, {\n error: translate('customers.errors.unauthorized', 'Unauthorized'),\n })\n }\n\n const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })\n const organizationIds = Array.isArray(scope?.filterIds) && scope.filterIds.length > 0\n ? scope.filterIds\n : auth.orgId\n ? [auth.orgId]\n : []\n\n const offsetMinutes = query.timezoneOffsetMinutes ?? 0\n const offsetSign = offsetMinutes >= 0 ? '+' : '-'\n const absMinutes = Math.abs(offsetMinutes)\n const offsetHours = String(Math.floor(absMinutes / 60)).padStart(2, '0')\n const offsetMins = String(absMinutes % 60).padStart(2, '0')\n const offsetSuffix = `${offsetSign}${offsetHours}:${offsetMins}`\n const windowStart = new Date(`${query.date}T${query.startTime}:00${offsetSuffix}`)\n const windowEnd = new Date(windowStart.getTime() + query.duration * 60_000)\n\n if (Number.isNaN(windowStart.getTime()) || Number.isNaN(windowEnd.getTime())) {\n throw new CrudHttpError(400, { error: translate('customers.errors.invalid_date_time', 'Invalid date/time') })\n }\n\n const checkUserId = query.userId ?? auth.userId\n const em = (container.resolve('em') as EntityManager).fork()\n const kysely = em.getKysely<any>()\n\n let baseQuery = (kysely as any)\n .selectFrom('customer_interactions')\n .select(['id', 'scheduled_at', 'duration_minutes', 'interaction_type'])\n .where('tenant_id', '=', auth.tenantId)\n .where('status', '
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,SAAS,WAAW;AACpB,SAAS,eAAe,uBAAuB;AAC/C,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,0CAA0C;AACnD,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AAEnC,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,WAAW;AAEvC,MAAM,cAAc,EAAE,OAAO;AAAA,EAC3B,MAAM,EAAE,OAAO,EAAE,MAAM,qBAAqB;AAAA,EAC5C,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe;AAAA,EAC3C,UAAU,EAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI;AAAA,EACjD,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS;AAAA,EACtC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS;AAAA,EACnC,uBAAuB,EAAE,OAA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,UAAM,QAAQ,MAAM,mCAAmC,EAAE,WAAW,MAAM,SAAS,IAAI,CAAC;AACxF,UAAM,kBAAkB,MAAM,QAAQ,OAAO,SAAS,KAAK,MAAM,UAAU,SAAS,IAChF,MAAM,YACN,KAAK,QACH,CAAC,KAAK,KAAK,IACX,CAAC;AAEP,UAAM,gBAAgB,MAAM,yBAAyB;AACrD,UAAM,aAAa,iBAAiB,IAAI,MAAM;AAC9C,UAAM,aAAa,KAAK,IAAI,aAAa;AACzC,UAAM,cAAc,OAAO,KAAK,MAAM,aAAa,EAAE,CAAC,EAAE,SAAS,GAAG,GAAG;AACvE,UAAM,aAAa,OAAO,aAAa,EAAE,EAAE,SAAS,GAAG,GAAG;AAC1D,UAAM,eAAe,GAAG,UAAU,GAAG,WAAW,IAAI,UAAU;AAC9D,UAAM,cAAc,oBAAI,KAAK,GAAG,MAAM,IAAI,IAAI,MAAM,SAAS,MAAM,YAAY,EAAE;AACjF,UAAM,YAAY,IAAI,KAAK,YAAY,QAAQ,IAAI,MAAM,WAAW,GAAM;AAE1E,QAAI,OAAO,MAAM,YAAY,QAAQ,CAAC,KAAK,OAAO,MAAM,UAAU,QAAQ,CAAC,GAAG;AAC5E,YAAM,IAAI,cAAc,KAAK,EAAE,OAAO,UAAU,sCAAsC,mBAAmB,EAAE,CAAC;AAAA,IAC9G;AAEA,UAAM,cAAc,MAAM,UAAU,KAAK;AACzC,UAAM,KAAM,UAAU,QAAQ,IAAI,EAAoB,KAAK;AAC3D,UAAM,SAAS,GAAG,UAAe;AAEjC,QAAI,YAAa,OACd,WAAW,uBAAuB,EAClC,OAAO,CAAC,MAAM,gBAAgB,oBAAoB,kBAAkB,CAAC,EACrE,MAAM,aAAa,KAAK,KAAK,QAAQ,EACrC,MAAM,UAAU,
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { sql } from 'kysely'\nimport { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\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 { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { CustomerInteraction } from '../../../data/entities'\nimport { TERMINAL_INTERACTION_STATUS_LIST } from '../../../lib/interactionStatus'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('customers')\n\nconst querySchema = z.object({\n date: z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/),\n startTime: z.string().regex(/^\\d{2}:\\d{2}$/),\n duration: z.coerce.number().int().min(1).max(1440),\n excludeId: z.string().uuid().optional(),\n userId: z.string().uuid().optional(),\n timezoneOffsetMinutes: z.coerce.number().int().min(-900).max(900).optional(),\n})\n\nconst conflictItemSchema = z.object({\n id: z.string(),\n title: z.string().nullable(),\n startTime: z.string(),\n endTime: z.string(),\n type: z.string(),\n})\n\nconst responseSchema = z.object({\n ok: z.literal(true),\n result: z.object({\n hasConflicts: z.boolean(),\n conflicts: z.array(conflictItemSchema),\n }),\n})\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['customers.interactions.view'] },\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Customers',\n methods: {\n GET: {\n summary: 'Detect scheduling conflicts',\n description: 'Checks for overlapping planned interactions within the requested time window.',\n query: querySchema,\n responses: [\n {\n status: 200,\n description: 'Conflict detection result',\n schema: responseSchema,\n },\n ],\n },\n },\n}\n\nexport async function GET(req: Request) {\n const { translate } = await resolveTranslations()\n try {\n const queryUrl = new URL(req.url)\n const query = querySchema.parse(Object.fromEntries(queryUrl.searchParams))\n const container = await createRequestContainer()\n const auth = await getAuthFromRequest(req)\n\n if (!auth || !auth.tenantId) {\n throw new CrudHttpError(401, {\n error: translate('customers.errors.unauthorized', 'Unauthorized'),\n })\n }\n\n const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })\n const organizationIds = Array.isArray(scope?.filterIds) && scope.filterIds.length > 0\n ? scope.filterIds\n : auth.orgId\n ? [auth.orgId]\n : []\n\n const offsetMinutes = query.timezoneOffsetMinutes ?? 0\n const offsetSign = offsetMinutes >= 0 ? '+' : '-'\n const absMinutes = Math.abs(offsetMinutes)\n const offsetHours = String(Math.floor(absMinutes / 60)).padStart(2, '0')\n const offsetMins = String(absMinutes % 60).padStart(2, '0')\n const offsetSuffix = `${offsetSign}${offsetHours}:${offsetMins}`\n const windowStart = new Date(`${query.date}T${query.startTime}:00${offsetSuffix}`)\n const windowEnd = new Date(windowStart.getTime() + query.duration * 60_000)\n\n if (Number.isNaN(windowStart.getTime()) || Number.isNaN(windowEnd.getTime())) {\n throw new CrudHttpError(400, { error: translate('customers.errors.invalid_date_time', 'Invalid date/time') })\n }\n\n const checkUserId = query.userId ?? auth.userId\n const em = (container.resolve('em') as EntityManager).fork()\n const kysely = em.getKysely<any>()\n\n let baseQuery = (kysely as any)\n .selectFrom('customer_interactions')\n .select(['id', 'scheduled_at', 'duration_minutes', 'interaction_type'])\n .where('tenant_id', '=', auth.tenantId)\n .where('status', 'not in', [...TERMINAL_INTERACTION_STATUS_LIST])\n .where('scheduled_at', 'is not', null)\n .where('deleted_at', 'is', null)\n\n if (organizationIds.length === 1) {\n baseQuery = baseQuery.where('organization_id', '=', organizationIds[0])\n } else if (organizationIds.length > 1) {\n baseQuery = baseQuery.where('organization_id', 'in', organizationIds)\n }\n\n if (checkUserId) {\n baseQuery = baseQuery.where((eb: any) =>\n eb.or([\n eb('author_user_id', '=', checkUserId),\n eb('owner_user_id', '=', checkUserId),\n ])\n )\n }\n\n if (query.excludeId) {\n baseQuery = baseQuery.where('id', '!=', query.excludeId)\n }\n\n // Overlap condition: existing.start < windowEnd AND existing.end > windowStart\n // end = scheduled_at + duration_minutes (default 30 if null)\n baseQuery = baseQuery.where((eb: any) =>\n eb.and([\n eb('scheduled_at', '<', windowEnd.toISOString()),\n eb(sql`(scheduled_at + make_interval(mins => COALESCE(duration_minutes, 30)))`, '>', windowStart.toISOString()),\n ])\n )\n\n // Raw SELECT: reads only unencrypted columns (id, scheduled_at, duration_minutes, interaction_type); title is excluded to avoid ciphertext leakage and is resolved below via findWithDecryption.\n const rows = await baseQuery\n .orderBy('scheduled_at', 'asc')\n .limit(10)\n .execute() as Array<{\n id: string\n scheduled_at: string | Date\n duration_minutes: number | null\n interaction_type: string\n }>\n\n const decryptionScope = {\n tenantId: auth.tenantId ?? null,\n organizationId: auth.orgId ?? null,\n }\n const conflictIds = rows.map((row) => row.id)\n const interactionFilter: Record<string, unknown> = {\n id: { $in: conflictIds },\n tenantId: auth.tenantId,\n deletedAt: null,\n }\n if (organizationIds.length === 1) {\n interactionFilter.organizationId = organizationIds[0]\n } else if (organizationIds.length > 1) {\n interactionFilter.organizationId = { $in: organizationIds }\n }\n const decryptedInteractions = conflictIds.length > 0\n ? await findWithDecryption(\n em,\n CustomerInteraction,\n interactionFilter as any,\n undefined,\n decryptionScope,\n )\n : []\n const titleById = new Map<string, string | null>()\n for (const record of decryptedInteractions) {\n titleById.set((record as any).id, ((record as any).title ?? null) as string | null)\n }\n\n const conflicts = rows.map((row) => {\n const start = new Date(row.scheduled_at)\n const durationMin = row.duration_minutes ?? 30\n const end = new Date(start.getTime() + durationMin * 60_000)\n return {\n id: row.id,\n title: titleById.has(row.id) ? titleById.get(row.id) ?? null : null,\n startTime: start.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false }),\n endTime: end.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false }),\n type: row.interaction_type,\n }\n })\n\n return NextResponse.json({\n ok: true,\n result: { hasConflicts: conflicts.length > 0, conflicts },\n })\n } catch (err) {\n if (isCrudHttpError(err)) {\n return NextResponse.json(err.body, { status: err.status })\n }\n logger.error('GET failed', { component: 'interactions/conflicts', err })\n return NextResponse.json({ error: translate('customers.errors.internal', 'Internal server error') }, { status: 500 })\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,SAAS,WAAW;AACpB,SAAS,eAAe,uBAAuB;AAC/C,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,0CAA0C;AACnD,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AAEnC,SAAS,2BAA2B;AACpC,SAAS,wCAAwC;AACjD,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,WAAW;AAEvC,MAAM,cAAc,EAAE,OAAO;AAAA,EAC3B,MAAM,EAAE,OAAO,EAAE,MAAM,qBAAqB;AAAA,EAC5C,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe;AAAA,EAC3C,UAAU,EAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI;AAAA,EACjD,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS;AAAA,EACtC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS;AAAA,EACnC,uBAAuB,EAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,IAAI,GAAG,EAAE,SAAS;AAC7E,CAAC;AAED,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAClC,IAAI,EAAE,OAAO;AAAA,EACb,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,WAAW,EAAE,OAAO;AAAA,EACpB,SAAS,EAAE,OAAO;AAAA,EAClB,MAAM,EAAE,OAAO;AACjB,CAAC;AAED,MAAM,iBAAiB,EAAE,OAAO;AAAA,EAC9B,IAAI,EAAE,QAAQ,IAAI;AAAA,EAClB,QAAQ,EAAE,OAAO;AAAA,IACf,cAAc,EAAE,QAAQ;AAAA,IACxB,WAAW,EAAE,MAAM,kBAAkB;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BAAmB,SAAS,EAAE,MAAM,WAAW,QAAQ,WAAW,QAAQ,MAAM,CAAC;AAAA,QAClG,SAAS,IAAI,mBAAmB,SAAS,EAAE,MAAM,WAAW,QAAQ,WAAW,QAAQ,MAAM,CAAC;AAAA,QAC9F,MAAM,IAAI;AAAA,MACZ;AAAA,IACF,CAAC;AAED,WAAO,aAAa,KAAK;AAAA,MACvB,IAAI;AAAA,MACJ,QAAQ,EAAE,cAAc,UAAU,SAAS,GAAG,UAAU;AAAA,IAC1D,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,QAAI,gBAAgB,GAAG,GAAG;AACxB,aAAO,aAAa,KAAK,IAAI,MAAM,EAAE,QAAQ,IAAI,OAAO,CAAC;AAAA,IAC3D;AACA,WAAO,MAAM,cAAc,EAAE,WAAW,0BAA0B,IAAI,CAAC;AACvE,WAAO,aAAa,KAAK,EAAE,OAAO,UAAU,6BAA6B,uBAAuB,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,11 +7,14 @@ import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
|
7
7
|
import { resolveOrganizationScopeForRequest } from "@open-mercato/core/modules/directory/utils/organizationScope";
|
|
8
8
|
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
9
9
|
import { applyEmailVisibilityFilter } from "../../../lib/visibilityFilter.js";
|
|
10
|
+
import { TERMINAL_INTERACTION_STATUS_LIST } from "../../../lib/interactionStatus.js";
|
|
10
11
|
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
11
12
|
const logger = createLogger("customers");
|
|
12
13
|
const querySchema = z.object({
|
|
13
14
|
entityId: z.string().uuid(),
|
|
14
|
-
status
|
|
15
|
+
// `open` counts every non-terminal status (planned/in_progress/waiting + any custom status);
|
|
16
|
+
// `planned` is kept as the BC alias for callers that used it to mean "open".
|
|
17
|
+
status: z.enum(["done", "planned", "open"]).optional()
|
|
15
18
|
});
|
|
16
19
|
const responseSchema = z.object({
|
|
17
20
|
ok: z.literal(true),
|
|
@@ -66,7 +69,9 @@ async function GET(req) {
|
|
|
66
69
|
} else if (organizationIds.length > 1) {
|
|
67
70
|
baseQuery = baseQuery.where("organization_id", "in", organizationIds);
|
|
68
71
|
}
|
|
69
|
-
if (query.status) {
|
|
72
|
+
if (query.status === "open" || query.status === "planned") {
|
|
73
|
+
baseQuery = baseQuery.where("status", "not in", [...TERMINAL_INTERACTION_STATUS_LIST]);
|
|
74
|
+
} else if (query.status) {
|
|
70
75
|
baseQuery = baseQuery.where("status", "=", query.status);
|
|
71
76
|
}
|
|
72
77
|
const viewerUserId = auth.isApiKey ? null : auth.sub ?? null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/customers/api/interactions/counts/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { sql } from 'kysely'\nimport { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\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 { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { applyEmailVisibilityFilter } from '../../../lib/visibilityFilter'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('customers')\n\nconst querySchema = z.object({\n entityId: z.string().uuid(),\n status: z.enum(['done', 'planned']).optional(),\n})\n\nconst responseSchema = z.object({\n ok: z.literal(true),\n result: z.object({\n call: z.number(),\n email: z.number(),\n meeting: z.number(),\n note: z.number(),\n task: z.number(),\n total: z.number(),\n }),\n})\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['customers.interactions.view'] },\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Customers',\n methods: {\n GET: {\n summary: 'Get interaction counts by type',\n description: 'Returns per-type interaction counts scoped to an entity.',\n query: querySchema,\n responses: [\n {\n status: 200,\n description: 'Counts by interaction type',\n schema: responseSchema,\n },\n ],\n },\n },\n}\n\nexport async function GET(req: Request) {\n try {\n const queryUrl = new URL(req.url)\n const query = querySchema.parse(Object.fromEntries(queryUrl.searchParams))\n const container = await createRequestContainer()\n const auth = await getAuthFromRequest(req)\n const { translate } = await resolveTranslations()\n\n if (!auth || !auth.tenantId) {\n throw new CrudHttpError(401, {\n error: translate('customers.errors.unauthorized', 'Unauthorized'),\n })\n }\n\n const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })\n const organizationIds = Array.isArray(scope?.filterIds) && scope.filterIds.length > 0\n ? scope.filterIds\n : auth.orgId\n ? [auth.orgId]\n : []\n const em = (container.resolve('em') as EntityManager).fork()\n const kysely = em.getKysely<any>()\n\n let baseQuery = (kysely as any)\n .selectFrom('customer_interactions')\n .where('entity_id', '=', query.entityId)\n .where('tenant_id', '=', auth.tenantId)\n .where('deleted_at', 'is', null)\n\n if (organizationIds.length === 1) {\n baseQuery = baseQuery.where('organization_id', '=', organizationIds[0])\n } else if (organizationIds.length > 1) {\n baseQuery = baseQuery.where('organization_id', 'in', organizationIds)\n }\n\n if (query.status) {\n baseQuery = baseQuery.where('status', '=', query.status)\n }\n\n // Per-user email privacy: exclude other users' private emails from the\n // per-type counts so the `email` total matches the visibility-filtered list.\n // v1 strict owner-only \u2014 no admin bypass (the filter ignores caller features).\n const viewerUserId = auth.isApiKey ? null : auth.sub ?? null\n baseQuery = applyEmailVisibilityFilter(baseQuery, {\n currentUserId: viewerUserId,\n userFeatures: undefined,\n })\n\n // Raw SELECT: reads only unencrypted columns (id, interaction_type); title/notes are excluded to avoid ciphertext leakage.\n const rows = await baseQuery\n .select(['interaction_type', sql<string>`count(*)`.as('count')])\n .groupBy('interaction_type')\n .execute() as Array<{ interaction_type: string; count: string | number }>\n\n const counts: Record<string, number> = { call: 0, email: 0, meeting: 0, note: 0, task: 0 }\n let total = 0\n for (const row of rows) {\n const count = typeof row.count === 'string' ? parseInt(row.count, 10) : row.count\n const type = row.interaction_type\n if (type in counts) {\n counts[type] = count\n }\n total += count\n }\n\n return NextResponse.json({ ok: true, result: { ...counts, total } })\n } catch (err) {\n if (isCrudHttpError(err)) {\n return NextResponse.json(err.body, { status: err.status })\n }\n logger.error('GET failed', { component: 'interactions/counts', err })\n return NextResponse.json({ error: 'Internal server error' }, { status: 500 })\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,SAAS,WAAW;AACpB,SAAS,eAAe,uBAAuB;AAC/C,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,0CAA0C;AACnD,SAAS,2BAA2B;AAEpC,SAAS,kCAAkC;AAC3C,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,WAAW;AAEvC,MAAM,cAAc,EAAE,OAAO;AAAA,EAC3B,UAAU,EAAE,OAAO,EAAE,KAAK;AAAA,
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { sql } from 'kysely'\nimport { CrudHttpError, isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\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 { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { applyEmailVisibilityFilter } from '../../../lib/visibilityFilter'\nimport { TERMINAL_INTERACTION_STATUS_LIST } from '../../../lib/interactionStatus'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('customers')\n\nconst querySchema = z.object({\n entityId: z.string().uuid(),\n // `open` counts every non-terminal status (planned/in_progress/waiting + any custom status);\n // `planned` is kept as the BC alias for callers that used it to mean \"open\".\n status: z.enum(['done', 'planned', 'open']).optional(),\n})\n\nconst responseSchema = z.object({\n ok: z.literal(true),\n result: z.object({\n call: z.number(),\n email: z.number(),\n meeting: z.number(),\n note: z.number(),\n task: z.number(),\n total: z.number(),\n }),\n})\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['customers.interactions.view'] },\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Customers',\n methods: {\n GET: {\n summary: 'Get interaction counts by type',\n description: 'Returns per-type interaction counts scoped to an entity.',\n query: querySchema,\n responses: [\n {\n status: 200,\n description: 'Counts by interaction type',\n schema: responseSchema,\n },\n ],\n },\n },\n}\n\nexport async function GET(req: Request) {\n try {\n const queryUrl = new URL(req.url)\n const query = querySchema.parse(Object.fromEntries(queryUrl.searchParams))\n const container = await createRequestContainer()\n const auth = await getAuthFromRequest(req)\n const { translate } = await resolveTranslations()\n\n if (!auth || !auth.tenantId) {\n throw new CrudHttpError(401, {\n error: translate('customers.errors.unauthorized', 'Unauthorized'),\n })\n }\n\n const scope = await resolveOrganizationScopeForRequest({ container, auth, request: req })\n const organizationIds = Array.isArray(scope?.filterIds) && scope.filterIds.length > 0\n ? scope.filterIds\n : auth.orgId\n ? [auth.orgId]\n : []\n const em = (container.resolve('em') as EntityManager).fork()\n const kysely = em.getKysely<any>()\n\n let baseQuery = (kysely as any)\n .selectFrom('customer_interactions')\n .where('entity_id', '=', query.entityId)\n .where('tenant_id', '=', auth.tenantId)\n .where('deleted_at', 'is', null)\n\n if (organizationIds.length === 1) {\n baseQuery = baseQuery.where('organization_id', '=', organizationIds[0])\n } else if (organizationIds.length > 1) {\n baseQuery = baseQuery.where('organization_id', 'in', organizationIds)\n }\n\n if (query.status === 'open' || query.status === 'planned') {\n baseQuery = baseQuery.where('status', 'not in', [...TERMINAL_INTERACTION_STATUS_LIST])\n } else if (query.status) {\n baseQuery = baseQuery.where('status', '=', query.status)\n }\n\n // Per-user email privacy: exclude other users' private emails from the\n // per-type counts so the `email` total matches the visibility-filtered list.\n // v1 strict owner-only \u2014 no admin bypass (the filter ignores caller features).\n const viewerUserId = auth.isApiKey ? null : auth.sub ?? null\n baseQuery = applyEmailVisibilityFilter(baseQuery, {\n currentUserId: viewerUserId,\n userFeatures: undefined,\n })\n\n // Raw SELECT: reads only unencrypted columns (id, interaction_type); title/notes are excluded to avoid ciphertext leakage.\n const rows = await baseQuery\n .select(['interaction_type', sql<string>`count(*)`.as('count')])\n .groupBy('interaction_type')\n .execute() as Array<{ interaction_type: string; count: string | number }>\n\n const counts: Record<string, number> = { call: 0, email: 0, meeting: 0, note: 0, task: 0 }\n let total = 0\n for (const row of rows) {\n const count = typeof row.count === 'string' ? parseInt(row.count, 10) : row.count\n const type = row.interaction_type\n if (type in counts) {\n counts[type] = count\n }\n total += count\n }\n\n return NextResponse.json({ ok: true, result: { ...counts, total } })\n } catch (err) {\n if (isCrudHttpError(err)) {\n return NextResponse.json(err.body, { status: err.status })\n }\n logger.error('GET failed', { component: 'interactions/counts', err })\n return NextResponse.json({ error: 'Internal server error' }, { status: 500 })\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,SAAS,WAAW;AACpB,SAAS,eAAe,uBAAuB;AAC/C,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,0CAA0C;AACnD,SAAS,2BAA2B;AAEpC,SAAS,kCAAkC;AAC3C,SAAS,wCAAwC;AACjD,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,WAAW;AAEvC,MAAM,cAAc,EAAE,OAAO;AAAA,EAC3B,UAAU,EAAE,OAAO,EAAE,KAAK;AAAA;AAAA;AAAA,EA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I,IAAI;AAAA,MACjB;AACA,eAAS;AAAA,IACX;AAEA,WAAO,aAAa,KAAK,EAAE,IAAI,MAAM,QAAQ,EAAE,GAAG,QAAQ,MAAM,EAAE,CAAC;AAAA,EACrE,SAAS,KAAK;AACZ,QAAI,gBAAgB,GAAG,GAAG;AACxB,aAAO,aAAa,KAAK,IAAI,MAAM,EAAE,QAAQ,IAAI,OAAO,CAAC;AAAA,IAC3D;AACA,WAAO,MAAM,cAAc,EAAE,WAAW,uBAAuB,IAAI,CAAC;AACpE,WAAO,aAAa,KAAK,EAAE,OAAO,wBAAwB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC9E;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,6 +19,7 @@ import { User } from "@open-mercato/core/modules/auth/data/entities";
|
|
|
19
19
|
import { loadCustomFieldValues } from "@open-mercato/shared/lib/crud/custom-fields";
|
|
20
20
|
import { E } from "../../../../../generated/entities.ids.generated.js";
|
|
21
21
|
import { mergePersonCustomFieldValues, resolvePersonCustomFieldRouting } from "../../../lib/customFieldRouting.js";
|
|
22
|
+
import { isOpenInteractionStatus, TERMINAL_INTERACTION_STATUS_LIST } from "../../../lib/interactionStatus.js";
|
|
22
23
|
import {
|
|
23
24
|
CUSTOMER_INTERACTION_ACTIVITY_ADAPTER_SOURCE,
|
|
24
25
|
EXAMPLE_TODO_SOURCE,
|
|
@@ -521,7 +522,7 @@ async function GET(_req, ctx) {
|
|
|
521
522
|
}) : [];
|
|
522
523
|
profiler.mark("canonical_interactions_hydrated", { count: canonicalInteractions.length });
|
|
523
524
|
const plannedPreviewInteractions = shouldLoadCanonicalInteractions ? (() => {
|
|
524
|
-
const sorted = [...canonicalInteractions].filter((interaction) => interaction.status
|
|
525
|
+
const sorted = [...canonicalInteractions].filter((interaction) => isOpenInteractionStatus(interaction.status) && interaction.interactionType !== "task").sort((left, right) => {
|
|
525
526
|
const leftTime = new Date(left.scheduledAt ?? left.createdAt).getTime();
|
|
526
527
|
const rightTime = new Date(right.scheduledAt ?? right.createdAt).getTime();
|
|
527
528
|
if (leftTime === rightTime) return left.id.localeCompare(right.id);
|
|
@@ -541,7 +542,7 @@ async function GET(_req, ctx) {
|
|
|
541
542
|
organizationId: person.organizationId,
|
|
542
543
|
tenantId: person.tenantId,
|
|
543
544
|
deletedAt: null,
|
|
544
|
-
status:
|
|
545
|
+
status: { $nin: [...TERMINAL_INTERACTION_STATUS_LIST] },
|
|
545
546
|
interactionType: { $ne: "task" },
|
|
546
547
|
...emailVisibilityFilter
|
|
547
548
|
},
|