@open-mercato/core 0.5.1-develop.2802.9223828f7f → 0.5.1-develop.2855.9b058b7483
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/generated/entities/action_log/index.js +4 -0
- package/dist/generated/entities/action_log/index.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +2 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/audit_logs/data/entities.js +10 -1
- package/dist/modules/audit_logs/data/entities.js.map +2 -2
- package/dist/modules/audit_logs/data/validators.js +2 -0
- package/dist/modules/audit_logs/data/validators.js.map +2 -2
- package/dist/modules/audit_logs/migrations/Migration20260423202109.js +15 -0
- package/dist/modules/audit_logs/migrations/Migration20260423202109.js.map +7 -0
- package/dist/modules/audit_logs/services/accessLogService.js +3 -2
- package/dist/modules/audit_logs/services/accessLogService.js.map +3 -3
- package/dist/modules/audit_logs/services/actionLogService.js +13 -2
- package/dist/modules/audit_logs/services/actionLogService.js.map +3 -3
- package/dist/modules/customers/api/entity-roles-factory.js +3 -18
- package/dist/modules/customers/api/entity-roles-factory.js.map +2 -2
- package/dist/modules/customers/api/interactions/cancel/route.js +7 -2
- package/dist/modules/customers/api/interactions/cancel/route.js.map +2 -2
- package/dist/modules/customers/api/interactions/complete/route.js +7 -2
- package/dist/modules/customers/api/interactions/complete/route.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/page.js +45 -44
- package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
- package/dist/modules/customers/commands/comments.js +6 -0
- package/dist/modules/customers/commands/comments.js.map +2 -2
- package/dist/modules/customers/components/detail/AssignRoleDialog.js +41 -13
- package/dist/modules/customers/components/detail/AssignRoleDialog.js.map +2 -2
- package/dist/modules/customers/components/detail/CompanyDetailHeader.js +30 -0
- package/dist/modules/customers/components/detail/CompanyDetailHeader.js.map +2 -2
- package/dist/modules/customers/components/detail/DealDetailHeader.js +32 -0
- package/dist/modules/customers/components/detail/DealDetailHeader.js.map +2 -2
- package/dist/modules/customers/components/detail/DealWonPopup.js +2 -2
- package/dist/modules/customers/components/detail/DealWonPopup.js.map +2 -2
- package/dist/modules/customers/components/detail/InlineActivityComposer.js +62 -6
- package/dist/modules/customers/components/detail/InlineActivityComposer.js.map +2 -2
- package/dist/modules/customers/components/detail/ObjectHistoryButton.js +39 -0
- package/dist/modules/customers/components/detail/ObjectHistoryButton.js.map +7 -0
- package/dist/modules/customers/components/detail/PersonDetailHeader.js +30 -0
- package/dist/modules/customers/components/detail/PersonDetailHeader.js.map +2 -2
- package/dist/modules/customers/components/detail/RolesSection.js +14 -4
- package/dist/modules/customers/components/detail/RolesSection.js.map +3 -3
- package/dist/modules/customers/components/formConfig.js +16 -2
- package/dist/modules/customers/components/formConfig.js.map +2 -2
- package/dist/modules/customers/lib/displayName.js +15 -0
- package/dist/modules/customers/lib/displayName.js.map +7 -0
- package/dist/modules/customers/lib/interactionReadModel.js +1 -2
- package/dist/modules/customers/lib/interactionReadModel.js.map +2 -2
- package/dist/modules/customers/lib/operationMetadata.js +21 -0
- package/dist/modules/customers/lib/operationMetadata.js.map +7 -0
- package/generated/entities/action_log/index.ts +2 -0
- package/generated/entity-fields-registry.ts +2 -0
- package/package.json +3 -3
- package/src/modules/audit_logs/data/entities.ts +7 -0
- package/src/modules/audit_logs/data/validators.ts +2 -0
- package/src/modules/audit_logs/migrations/.snapshot-open-mercato.json +51 -5
- package/src/modules/audit_logs/migrations/Migration20260423202109.ts +15 -0
- package/src/modules/audit_logs/services/accessLogService.ts +1 -3
- package/src/modules/audit_logs/services/actionLogService.ts +11 -6
- package/src/modules/customers/api/entity-roles-factory.ts +3 -23
- package/src/modules/customers/api/interactions/cancel/route.ts +7 -2
- package/src/modules/customers/api/interactions/complete/route.ts +7 -2
- package/src/modules/customers/backend/customers/deals/page.tsx +48 -44
- package/src/modules/customers/commands/comments.ts +6 -0
- package/src/modules/customers/components/detail/AssignRoleDialog.tsx +37 -9
- package/src/modules/customers/components/detail/CompanyDetailHeader.tsx +25 -0
- package/src/modules/customers/components/detail/DealDetailHeader.tsx +29 -0
- package/src/modules/customers/components/detail/DealWonPopup.tsx +2 -2
- package/src/modules/customers/components/detail/InlineActivityComposer.tsx +65 -6
- package/src/modules/customers/components/detail/ObjectHistoryButton.tsx +47 -0
- package/src/modules/customers/components/detail/PersonDetailHeader.tsx +25 -0
- package/src/modules/customers/components/detail/RolesSection.tsx +20 -1
- package/src/modules/customers/components/formConfig.tsx +14 -2
- package/src/modules/customers/i18n/de.json +12 -0
- package/src/modules/customers/i18n/en.json +12 -0
- package/src/modules/customers/i18n/es.json +13 -1
- package/src/modules/customers/i18n/pl.json +13 -1
- package/src/modules/customers/lib/displayName.ts +16 -0
- package/src/modules/customers/lib/interactionReadModel.ts +1 -7
- package/src/modules/customers/lib/operationMetadata.ts +38 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/customers/lib/interactionReadModel.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { applyResponseEnrichers } from '@open-mercato/shared/lib/crud/enricher-runner'\nimport { loadCustomFieldValues } from '@open-mercato/shared/lib/crud/custom-fields'\nimport { normalizeCustomFieldResponse } from '@open-mercato/shared/lib/custom-fields/normalize'\nimport type { EnricherContext } from '@open-mercato/shared/lib/crud/response-enricher'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { CustomerDeal, CustomerEntity, CustomerInteraction } from '../data/entities'\nimport { User } from '@open-mercato/core/modules/auth/data/entities'\nimport {\n CUSTOMER_INTERACTION_ENTITY_ID,\n type InteractionRecord,\n} from './interactionCompatibility'\n\ntype ContainerLike = {\n resolve: (name: string) => unknown\n}\n\ntype AuthLike = {\n tenantId: string | null\n orgId: string | null\n sub?: string | null\n userId?: string | null\n keyId?: string | null\n}\n\ntype RbacServiceLike = {\n getGrantedFeatures?: (\n userId: string,\n input: { tenantId: string | null; organizationId: string | null },\n ) => Promise<string[]>\n}\n\ntype HydrateCanonicalInteractionsInput = {\n em: EntityManager\n container: ContainerLike\n auth: AuthLike\n selectedOrganizationId: string | null\n interactions: CustomerInteraction[]\n enrich?: boolean\n}\n\ntype CustomerSummary = {\n id: string\n displayName: string | null\n kind: string | null\n}\n\nfunction resolveActorId(auth: AuthLike): string {\n if (typeof auth.sub === 'string' && auth.sub.trim().length > 0) return auth.sub\n if (typeof auth.userId === 'string' && auth.userId.trim().length > 0) return auth.userId\n if (typeof auth.keyId === 'string' && auth.keyId.trim().length > 0) return auth.keyId\n return 'system'\n}\n\nfunction mergeAdditiveRecord<T extends Record<string, unknown>>(base: T, candidate: T | undefined): T {\n if (!candidate) return base\n const additions = Object.fromEntries(\n Object.entries(candidate).filter(([key]) => !(key in base)),\n ) as Partial<T>\n return {\n ...base,\n ...additions,\n }\n}\n\
|
|
5
|
-
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,6BAA6B;AACtC,SAAS,oCAAoC;AAE7C,SAAS,0BAA0B;AACnC,SAAS,cAAc,sBAA2C;AAClE,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,OAEK;AAoCP,SAAS,eAAe,MAAwB;AAC9C,MAAI,OAAO,KAAK,QAAQ,YAAY,KAAK,IAAI,KAAK,EAAE,SAAS,EAAG,QAAO,KAAK;AAC5E,MAAI,OAAO,KAAK,WAAW,YAAY,KAAK,OAAO,KAAK,EAAE,SAAS,EAAG,QAAO,KAAK;AAClF,MAAI,OAAO,KAAK,UAAU,YAAY,KAAK,MAAM,KAAK,EAAE,SAAS,EAAG,QAAO,KAAK;AAChF,SAAO;AACT;AAEA,SAAS,oBAAuD,MAAS,WAA6B;AACpG,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,YAAY,OAAO;AAAA,IACvB,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,KAAK;AAAA,EAC5D;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { applyResponseEnrichers } from '@open-mercato/shared/lib/crud/enricher-runner'\nimport { loadCustomFieldValues } from '@open-mercato/shared/lib/crud/custom-fields'\nimport { normalizeCustomFieldResponse } from '@open-mercato/shared/lib/custom-fields/normalize'\nimport type { EnricherContext } from '@open-mercato/shared/lib/crud/response-enricher'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { CustomerDeal, CustomerEntity, CustomerInteraction } from '../data/entities'\nimport { User } from '@open-mercato/core/modules/auth/data/entities'\nimport {\n CUSTOMER_INTERACTION_ENTITY_ID,\n type InteractionRecord,\n} from './interactionCompatibility'\n\ntype ContainerLike = {\n resolve: (name: string) => unknown\n}\n\ntype AuthLike = {\n tenantId: string | null\n orgId: string | null\n sub?: string | null\n userId?: string | null\n keyId?: string | null\n}\n\ntype RbacServiceLike = {\n getGrantedFeatures?: (\n userId: string,\n input: { tenantId: string | null; organizationId: string | null },\n ) => Promise<string[]>\n}\n\ntype HydrateCanonicalInteractionsInput = {\n em: EntityManager\n container: ContainerLike\n auth: AuthLike\n selectedOrganizationId: string | null\n interactions: CustomerInteraction[]\n enrich?: boolean\n}\n\ntype CustomerSummary = {\n id: string\n displayName: string | null\n kind: string | null\n}\n\nfunction resolveActorId(auth: AuthLike): string {\n if (typeof auth.sub === 'string' && auth.sub.trim().length > 0) return auth.sub\n if (typeof auth.userId === 'string' && auth.userId.trim().length > 0) return auth.userId\n if (typeof auth.keyId === 'string' && auth.keyId.trim().length > 0) return auth.keyId\n return 'system'\n}\n\nfunction mergeAdditiveRecord<T extends Record<string, unknown>>(base: T, candidate: T | undefined): T {\n if (!candidate) return base\n const additions = Object.fromEntries(\n Object.entries(candidate).filter(([key]) => !(key in base)),\n ) as Partial<T>\n return {\n ...base,\n ...additions,\n }\n}\n\nfunction normalizeInteractionCustomValues(values: Record<string, unknown> | null | undefined): Record<string, unknown> | null {\n return normalizeCustomFieldResponse(values) ?? null\n}\n\nasync function resolveUserFeatures(\n container: ContainerLike,\n userId: string,\n tenantId: string | null,\n organizationId: string | null,\n): Promise<string[] | undefined> {\n try {\n const rbac = container.resolve('rbacService') as RbacServiceLike | undefined\n if (!rbac?.getGrantedFeatures) return undefined\n return await rbac.getGrantedFeatures(userId, { tenantId, organizationId })\n } catch {\n return undefined\n }\n}\n\nexport async function buildCustomersInteractionEnricherContext(\n container: ContainerLike,\n auth: AuthLike,\n organizationId: string | null,\n): Promise<EnricherContext> {\n const userId = resolveActorId(auth)\n return {\n organizationId: organizationId ?? '',\n tenantId: auth.tenantId ?? '',\n userId,\n em: container.resolve('em'),\n container,\n userFeatures: await resolveUserFeatures(container, userId, auth.tenantId, organizationId),\n }\n}\n\nexport async function loadCustomerSummaries(\n em: EntityManager,\n entityIds: string[],\n tenantId?: string | null,\n organizationId?: string | null,\n): Promise<Map<string, CustomerSummary>> {\n if (!entityIds.length) return new Map()\n const entities = await findWithDecryption(em, CustomerEntity, { id: { $in: entityIds } }, undefined, { tenantId, organizationId })\n return new Map(\n entities.map((entity) => [\n entity.id,\n {\n id: entity.id,\n displayName: entity.displayName ?? null,\n kind: entity.kind ?? null,\n },\n ]),\n )\n}\n\nexport async function hydrateCanonicalInteractions({\n em,\n container,\n auth,\n selectedOrganizationId,\n interactions,\n enrich = false,\n}: HydrateCanonicalInteractionsInput): Promise<InteractionRecord[]> {\n if (interactions.length === 0) return []\n\n const authorIds = Array.from(\n new Set(\n interactions\n .map((interaction) =>\n typeof interaction.authorUserId === 'string' ? interaction.authorUserId : null)\n .filter((value): value is string => !!value),\n ),\n )\n const dealIds = Array.from(\n new Set(\n interactions\n .map((interaction) => (typeof interaction.dealId === 'string' ? interaction.dealId : null))\n .filter((value): value is string => !!value),\n ),\n )\n\n const tenantId = auth.tenantId ?? null\n const organizationId = selectedOrganizationId ?? null\n const [users, deals, customFieldValues] = await Promise.all([\n authorIds.length > 0 ? findWithDecryption(em, User, { id: { $in: authorIds } }, undefined, { tenantId, organizationId }) : Promise.resolve([]),\n dealIds.length > 0 ? findWithDecryption(em, CustomerDeal, { id: { $in: dealIds } }, undefined, { tenantId, organizationId }) : Promise.resolve([]),\n loadCustomFieldValues({\n em,\n entityId: CUSTOMER_INTERACTION_ENTITY_ID,\n recordIds: interactions.map((interaction) => interaction.id),\n tenantIdByRecord: Object.fromEntries(interactions.map((interaction) => [interaction.id, interaction.tenantId])),\n organizationIdByRecord: Object.fromEntries(interactions.map((interaction) => [interaction.id, interaction.organizationId])),\n tenantFallbacks: [auth.tenantId].filter((value): value is string => !!value),\n }),\n ])\n\n const userMap = new Map(\n users.map((user) => [\n user.id,\n {\n name: user.name ?? null,\n email: user.email ?? null,\n },\n ]),\n )\n const dealMap = new Map(deals.map((deal) => [deal.id, deal.title]))\n\n const baseItems: InteractionRecord[] = interactions.map((interaction) => {\n const entityId = typeof interaction.entity === 'string' ? interaction.entity : interaction.entity.id\n return {\n id: interaction.id,\n entityId,\n dealId: interaction.dealId ?? null,\n interactionType: interaction.interactionType,\n title: interaction.title ?? null,\n body: interaction.body ?? null,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt ? interaction.scheduledAt.toISOString() : null,\n occurredAt: interaction.occurredAt ? interaction.occurredAt.toISOString() : null,\n priority: interaction.priority ?? null,\n authorUserId: interaction.authorUserId ?? null,\n ownerUserId: interaction.ownerUserId ?? null,\n appearanceIcon: interaction.appearanceIcon ?? null,\n appearanceColor: interaction.appearanceColor ?? null,\n source: interaction.source ?? null,\n duration: interaction.durationMinutes ?? null,\n location: interaction.location ?? null,\n allDay: interaction.allDay ?? null,\n recurrenceRule: interaction.recurrenceRule ?? null,\n recurrenceEnd: interaction.recurrenceEnd ? interaction.recurrenceEnd.toISOString() : null,\n participants: interaction.participants ?? null,\n reminderMinutes: interaction.reminderMinutes ?? null,\n visibility: interaction.visibility ?? null,\n linkedEntities: interaction.linkedEntities ?? null,\n guestPermissions: interaction.guestPermissions ?? null,\n organizationId: interaction.organizationId,\n tenantId: interaction.tenantId,\n createdAt: interaction.createdAt.toISOString(),\n updatedAt: interaction.updatedAt.toISOString(),\n authorName: interaction.authorUserId ? userMap.get(interaction.authorUserId)?.name ?? null : null,\n authorEmail: interaction.authorUserId ? userMap.get(interaction.authorUserId)?.email ?? null : null,\n dealTitle: interaction.dealId ? dealMap.get(interaction.dealId) ?? null : null,\n customValues: normalizeInteractionCustomValues(customFieldValues[interaction.id]),\n }\n })\n\n if (!enrich) return baseItems\n\n const enricherContext = await buildCustomersInteractionEnricherContext(\n container,\n auth,\n selectedOrganizationId,\n )\n const enriched = await applyResponseEnrichers(baseItems, 'customers.interaction', enricherContext)\n return baseItems.map((item, index) => mergeAdditiveRecord(item, enriched.items[index]))\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,6BAA6B;AACtC,SAAS,oCAAoC;AAE7C,SAAS,0BAA0B;AACnC,SAAS,cAAc,sBAA2C;AAClE,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,OAEK;AAoCP,SAAS,eAAe,MAAwB;AAC9C,MAAI,OAAO,KAAK,QAAQ,YAAY,KAAK,IAAI,KAAK,EAAE,SAAS,EAAG,QAAO,KAAK;AAC5E,MAAI,OAAO,KAAK,WAAW,YAAY,KAAK,OAAO,KAAK,EAAE,SAAS,EAAG,QAAO,KAAK;AAClF,MAAI,OAAO,KAAK,UAAU,YAAY,KAAK,MAAM,KAAK,EAAE,SAAS,EAAG,QAAO,KAAK;AAChF,SAAO;AACT;AAEA,SAAS,oBAAuD,MAAS,WAA6B;AACpG,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,YAAY,OAAO;AAAA,IACvB,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,KAAK;AAAA,EAC5D;AACA,SAAO;AAAA,IACL,GAAG;AAAA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MAClD,gBAAgB,YAAY;AAAA,MAC5B,UAAU,YAAY;AAAA,MACtB,WAAW,YAAY,UAAU,YAAY;AAAA,MAC7C,WAAW,YAAY,UAAU,YAAY;AAAA,MAC7C,YAAY,YAAY,eAAe,QAAQ,IAAI,YAAY,YAAY,GAAG,QAAQ,OAAO;AAAA,MAC7F,aAAa,YAAY,eAAe,QAAQ,IAAI,YAAY,YAAY,GAAG,SAAS,OAAO;AAAA,MAC/F,WAAW,YAAY,SAAS,QAAQ,IAAI,YAAY,MAAM,KAAK,OAAO;AAAA,MAC1E,cAAc,iCAAiC,kBAAkB,YAAY,EAAE,CAAC;AAAA,IAClF;AAAA,EACF,CAAC;AAED,MAAI,CAAC,OAAQ,QAAO;AAEpB,QAAM,kBAAkB,MAAM;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,WAAW,MAAM,uBAAuB,WAAW,yBAAyB,eAAe;AACjG,SAAO,UAAU,IAAI,CAAC,MAAM,UAAU,oBAAoB,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC;AACxF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { serializeOperationMetadata } from "@open-mercato/shared/lib/commands/operationMetadata";
|
|
2
|
+
function withOperationMetadata(response, logEntry, fallback) {
|
|
3
|
+
if (!logEntry?.undoToken || !logEntry.id || !logEntry.commandId) return response;
|
|
4
|
+
response.headers.set(
|
|
5
|
+
"x-om-operation",
|
|
6
|
+
serializeOperationMetadata({
|
|
7
|
+
id: logEntry.id,
|
|
8
|
+
undoToken: logEntry.undoToken,
|
|
9
|
+
commandId: logEntry.commandId,
|
|
10
|
+
actionLabel: logEntry.actionLabel ?? null,
|
|
11
|
+
resourceKind: logEntry.resourceKind ?? fallback.resourceKind,
|
|
12
|
+
resourceId: logEntry.resourceId ?? fallback.resourceId,
|
|
13
|
+
executedAt: logEntry.createdAt instanceof Date ? logEntry.createdAt.toISOString() : (/* @__PURE__ */ new Date()).toISOString()
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
return response;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
withOperationMetadata
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=operationMetadata.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/customers/lib/operationMetadata.ts"],
|
|
4
|
+
"sourcesContent": ["import type { NextResponse } from 'next/server'\nimport { serializeOperationMetadata } from '@open-mercato/shared/lib/commands/operationMetadata'\n\nexport type OperationLogEntry = {\n undoToken?: string | null\n id?: string | null\n commandId?: string | null\n actionLabel?: string | null\n resourceKind?: string | null\n resourceId?: string | null\n createdAt?: Date | null\n}\n\nexport type OperationMetadataFallback = {\n resourceKind: string\n resourceId: string | null\n}\n\nexport function withOperationMetadata(\n response: NextResponse,\n logEntry: OperationLogEntry | null | undefined,\n fallback: OperationMetadataFallback,\n): NextResponse {\n if (!logEntry?.undoToken || !logEntry.id || !logEntry.commandId) return response\n response.headers.set(\n 'x-om-operation',\n serializeOperationMetadata({\n id: logEntry.id,\n undoToken: logEntry.undoToken,\n commandId: logEntry.commandId,\n actionLabel: logEntry.actionLabel ?? null,\n resourceKind: logEntry.resourceKind ?? fallback.resourceKind,\n resourceId: logEntry.resourceId ?? fallback.resourceId,\n executedAt: logEntry.createdAt instanceof Date ? logEntry.createdAt.toISOString() : new Date().toISOString(),\n }),\n )\n return response\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,kCAAkC;AAiBpC,SAAS,sBACd,UACA,UACA,UACc;AACd,MAAI,CAAC,UAAU,aAAa,CAAC,SAAS,MAAM,CAAC,SAAS,UAAW,QAAO;AACxE,WAAS,QAAQ;AAAA,IACf;AAAA,IACA,2BAA2B;AAAA,MACzB,IAAI,SAAS;AAAA,MACb,WAAW,SAAS;AAAA,MACpB,WAAW,SAAS;AAAA,MACpB,aAAa,SAAS,eAAe;AAAA,MACrC,cAAc,SAAS,gBAAgB,SAAS;AAAA,MAChD,YAAY,SAAS,cAAc,SAAS;AAAA,MAC5C,YAAY,SAAS,qBAAqB,OAAO,SAAS,UAAU,YAAY,KAAI,oBAAI,KAAK,GAAE,YAAY;AAAA,IAC7G,CAAC;AAAA,EACH;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -19,6 +19,8 @@ export const changed_fields = "changed_fields";
|
|
|
19
19
|
export const primary_changed_field = "primary_changed_field";
|
|
20
20
|
export const context_json = "context_json";
|
|
21
21
|
export const source_key = "source_key";
|
|
22
|
+
export const related_resource_kind = "related_resource_kind";
|
|
23
|
+
export const related_resource_id = "related_resource_id";
|
|
22
24
|
export const created_at = "created_at";
|
|
23
25
|
export const updated_at = "updated_at";
|
|
24
26
|
export const deleted_at = "deleted_at";
|
|
@@ -36,6 +36,8 @@ export const entityFieldsRegistry: Record<string, Record<string, string>> = {
|
|
|
36
36
|
"primary_changed_field": "primary_changed_field",
|
|
37
37
|
"context_json": "context_json",
|
|
38
38
|
"source_key": "source_key",
|
|
39
|
+
"related_resource_kind": "related_resource_kind",
|
|
40
|
+
"related_resource_id": "related_resource_id",
|
|
39
41
|
"created_at": "created_at",
|
|
40
42
|
"updated_at": "updated_at",
|
|
41
43
|
"deleted_at": "deleted_at"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/core",
|
|
3
|
-
"version": "0.5.1-develop.
|
|
3
|
+
"version": "0.5.1-develop.2855.9b058b7483",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -237,10 +237,10 @@
|
|
|
237
237
|
"ts-pattern": "^5.0.0"
|
|
238
238
|
},
|
|
239
239
|
"peerDependencies": {
|
|
240
|
-
"@open-mercato/shared": "0.5.1-develop.
|
|
240
|
+
"@open-mercato/shared": "0.5.1-develop.2855.9b058b7483"
|
|
241
241
|
},
|
|
242
242
|
"devDependencies": {
|
|
243
|
-
"@open-mercato/shared": "0.5.1-develop.
|
|
243
|
+
"@open-mercato/shared": "0.5.1-develop.2855.9b058b7483",
|
|
244
244
|
"@testing-library/dom": "^10.4.1",
|
|
245
245
|
"@testing-library/jest-dom": "^6.9.1",
|
|
246
246
|
"@testing-library/react": "^16.3.1",
|
|
@@ -12,6 +12,7 @@ export type ActionLogExecutionState = 'done' | 'undone' | 'failed' | 'redone'
|
|
|
12
12
|
@Index({ name: 'action_logs_source_key_idx', properties: ['tenantId', 'organizationId', 'sourceKey', 'createdAt'] })
|
|
13
13
|
@Index({ name: 'action_logs_primary_changed_field_idx', properties: ['tenantId', 'organizationId', 'primaryChangedField', 'createdAt'] })
|
|
14
14
|
@Index({ name: 'action_logs_changed_fields_idx', properties: ['changedFields'], type: 'gin' })
|
|
15
|
+
@Index({ name: 'action_logs_related_resource_idx', properties: ['tenantId', 'relatedResourceKind', 'relatedResourceId', 'createdAt'] })
|
|
15
16
|
export class ActionLog {
|
|
16
17
|
@PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })
|
|
17
18
|
id!: string
|
|
@@ -76,6 +77,12 @@ export class ActionLog {
|
|
|
76
77
|
@Property({ name: 'source_key', type: 'text', nullable: true })
|
|
77
78
|
sourceKey: ActionLogSourceKey | null = null
|
|
78
79
|
|
|
80
|
+
@Property({ name: 'related_resource_kind', type: 'text', nullable: true })
|
|
81
|
+
relatedResourceKind: string | null = null
|
|
82
|
+
|
|
83
|
+
@Property({ name: 'related_resource_id', type: 'text', nullable: true })
|
|
84
|
+
relatedResourceId: string | null = null
|
|
85
|
+
|
|
79
86
|
@Property({ name: 'created_at', type: Date, onCreate: () => new Date() })
|
|
80
87
|
createdAt: Date = new Date()
|
|
81
88
|
|
|
@@ -26,6 +26,8 @@ export const actionLogCreateSchema = baseScopeSchema.extend({
|
|
|
26
26
|
commandPayload: z.unknown().optional(),
|
|
27
27
|
snapshotBefore: z.unknown().optional(),
|
|
28
28
|
snapshotAfter: z.unknown().optional(),
|
|
29
|
+
relatedResourceKind: z.string().min(1).optional().nullable(),
|
|
30
|
+
relatedResourceId: z.string().min(1).optional().nullable(),
|
|
29
31
|
changes: recordLike,
|
|
30
32
|
context: recordLike,
|
|
31
33
|
})
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
"name": "public",
|
|
2
3
|
"namespaces": [
|
|
3
4
|
"public"
|
|
4
5
|
],
|
|
5
|
-
"name": "public",
|
|
6
6
|
"tables": [
|
|
7
7
|
{
|
|
8
|
+
"name": "access_logs",
|
|
9
|
+
"schema": "public",
|
|
8
10
|
"columns": {
|
|
9
11
|
"id": {
|
|
10
12
|
"name": "id",
|
|
@@ -183,8 +185,6 @@
|
|
|
183
185
|
"mappedType": "datetime"
|
|
184
186
|
}
|
|
185
187
|
},
|
|
186
|
-
"name": "access_logs",
|
|
187
|
-
"schema": "public",
|
|
188
188
|
"indexes": [
|
|
189
189
|
{
|
|
190
190
|
"keyName": "access_logs_actor_idx",
|
|
@@ -224,6 +224,8 @@
|
|
|
224
224
|
"nativeEnums": {}
|
|
225
225
|
},
|
|
226
226
|
{
|
|
227
|
+
"name": "action_logs",
|
|
228
|
+
"schema": "public",
|
|
227
229
|
"columns": {
|
|
228
230
|
"id": {
|
|
229
231
|
"name": "id",
|
|
@@ -561,6 +563,38 @@
|
|
|
561
563
|
"enumItems": [],
|
|
562
564
|
"mappedType": "text"
|
|
563
565
|
},
|
|
566
|
+
"related_resource_kind": {
|
|
567
|
+
"name": "related_resource_kind",
|
|
568
|
+
"type": "text",
|
|
569
|
+
"unsigned": false,
|
|
570
|
+
"autoincrement": false,
|
|
571
|
+
"primary": false,
|
|
572
|
+
"nullable": true,
|
|
573
|
+
"unique": false,
|
|
574
|
+
"length": null,
|
|
575
|
+
"precision": null,
|
|
576
|
+
"scale": null,
|
|
577
|
+
"default": null,
|
|
578
|
+
"comment": null,
|
|
579
|
+
"enumItems": [],
|
|
580
|
+
"mappedType": "text"
|
|
581
|
+
},
|
|
582
|
+
"related_resource_id": {
|
|
583
|
+
"name": "related_resource_id",
|
|
584
|
+
"type": "text",
|
|
585
|
+
"unsigned": false,
|
|
586
|
+
"autoincrement": false,
|
|
587
|
+
"primary": false,
|
|
588
|
+
"nullable": true,
|
|
589
|
+
"unique": false,
|
|
590
|
+
"length": null,
|
|
591
|
+
"precision": null,
|
|
592
|
+
"scale": null,
|
|
593
|
+
"default": null,
|
|
594
|
+
"comment": null,
|
|
595
|
+
"enumItems": [],
|
|
596
|
+
"mappedType": "text"
|
|
597
|
+
},
|
|
564
598
|
"created_at": {
|
|
565
599
|
"name": "created_at",
|
|
566
600
|
"type": "timestamptz",
|
|
@@ -610,9 +644,20 @@
|
|
|
610
644
|
"mappedType": "datetime"
|
|
611
645
|
}
|
|
612
646
|
},
|
|
613
|
-
"name": "action_logs",
|
|
614
|
-
"schema": "public",
|
|
615
647
|
"indexes": [
|
|
648
|
+
{
|
|
649
|
+
"keyName": "action_logs_related_resource_idx",
|
|
650
|
+
"columnNames": [
|
|
651
|
+
"tenant_id",
|
|
652
|
+
"related_resource_kind",
|
|
653
|
+
"related_resource_id",
|
|
654
|
+
"created_at"
|
|
655
|
+
],
|
|
656
|
+
"composite": true,
|
|
657
|
+
"constraint": false,
|
|
658
|
+
"primary": false,
|
|
659
|
+
"unique": false
|
|
660
|
+
},
|
|
616
661
|
{
|
|
617
662
|
"keyName": "action_logs_changed_fields_idx",
|
|
618
663
|
"columnNames": [
|
|
@@ -727,5 +772,6 @@
|
|
|
727
772
|
"nativeEnums": {}
|
|
728
773
|
}
|
|
729
774
|
],
|
|
775
|
+
"views": [],
|
|
730
776
|
"nativeEnums": {}
|
|
731
777
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Migration } from '@mikro-orm/migrations';
|
|
2
|
+
|
|
3
|
+
export class Migration20260423202109 extends Migration {
|
|
4
|
+
|
|
5
|
+
override up(): void | Promise<void> {
|
|
6
|
+
this.addSql(`alter table "action_logs" add "related_resource_kind" text null, add "related_resource_id" text null;`);
|
|
7
|
+
this.addSql(`create index "action_logs_related_resource_idx" on "action_logs" ("tenant_id", "related_resource_kind", "related_resource_id", "created_at");`);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
override down(): void | Promise<void> {
|
|
11
|
+
this.addSql(`drop index "action_logs_related_resource_idx";`);
|
|
12
|
+
this.addSql(`alter table "action_logs" drop column "related_resource_kind", drop column "related_resource_id";`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
|
@@ -23,6 +23,7 @@ const CORE_RETENTION_DAYS = toPositiveNumber(process.env.AUDIT_LOGS_CORE_RETENTI
|
|
|
23
23
|
const NON_CORE_RETENTION_HOURS = toPositiveNumber(process.env.AUDIT_LOGS_NON_CORE_RETENTION_HOURS, 8)
|
|
24
24
|
const CORE_RETENTION_MS = CORE_RETENTION_DAYS * 24 * 60 * 60 * 1000
|
|
25
25
|
const NON_CORE_RETENTION_MS = NON_CORE_RETENTION_HOURS * 60 * 60 * 1000
|
|
26
|
+
const UUID_REGEX = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/
|
|
26
27
|
|
|
27
28
|
let validationWarningLogged = false
|
|
28
29
|
let runtimeValidationAvailable: boolean | null = null
|
|
@@ -140,10 +141,7 @@ export class AccessLogService {
|
|
|
140
141
|
const UUID_REGEX = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/
|
|
141
142
|
const toNullableUuid = (value: unknown) => {
|
|
142
143
|
if (typeof value !== 'string' || value.length === 0) return null
|
|
143
|
-
// Extract UUID from "api_key:<uuid>" format (used by workflow authentication)
|
|
144
144
|
const candidate = value.startsWith('api_key:') ? value.slice('api_key:'.length) : value
|
|
145
|
-
// System actors (sync workers, scheduler, etc.) use non-UUID subjects like
|
|
146
|
-
// "system:...". Reject those so the uuid column stays valid.
|
|
147
145
|
return UUID_REGEX.test(candidate) ? candidate : null
|
|
148
146
|
}
|
|
149
147
|
const fields = Array.isArray(input.fields)
|
|
@@ -27,6 +27,7 @@ const isZodRuntimeMissing = (err: unknown) => err instanceof TypeError && typeof
|
|
|
27
27
|
const SORT_FIELDS = {
|
|
28
28
|
createdAt: 'action_logs.created_at',
|
|
29
29
|
} as const
|
|
30
|
+
const UUID_REGEX = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/
|
|
30
31
|
|
|
31
32
|
type ActionLogProjectionBackfillOptions = {
|
|
32
33
|
batchSize?: number
|
|
@@ -236,6 +237,8 @@ export class ActionLogService {
|
|
|
236
237
|
resourceId: data.resourceId ?? null,
|
|
237
238
|
parentResourceKind: data.parentResourceKind ?? null,
|
|
238
239
|
parentResourceId: data.parentResourceId ?? null,
|
|
240
|
+
relatedResourceKind: toOptionalString(data.relatedResourceKind) ?? null,
|
|
241
|
+
relatedResourceId: toOptionalString(data.relatedResourceId) ?? null,
|
|
239
242
|
executionState: data.executionState ?? 'done',
|
|
240
243
|
undoToken: data.undoToken ?? null,
|
|
241
244
|
commandPayload: data.commandPayload ?? null,
|
|
@@ -261,6 +264,8 @@ export class ActionLogService {
|
|
|
261
264
|
actionLabel: undefined,
|
|
262
265
|
resourceKind: undefined,
|
|
263
266
|
resourceId: undefined,
|
|
267
|
+
relatedResourceKind: null,
|
|
268
|
+
relatedResourceId: null,
|
|
264
269
|
executionState: 'done',
|
|
265
270
|
undoToken: undefined,
|
|
266
271
|
commandPayload: undefined,
|
|
@@ -274,13 +279,7 @@ export class ActionLogService {
|
|
|
274
279
|
const UUID_REGEX = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/
|
|
275
280
|
const toNullableUuid = (value: unknown) => {
|
|
276
281
|
if (typeof value !== 'string' || value.length === 0) return null
|
|
277
|
-
// Extract UUID from "api_key:<uuid>" format (used by workflow authentication).
|
|
278
282
|
const candidate = value.startsWith('api_key:') ? value.slice('api_key:'.length) : value
|
|
279
|
-
// System actors (outbound sync workers, scheduler, etc.) carry subjects like
|
|
280
|
-
// "system:example_customers_sync:outbound" that are not UUIDs. Writing them into
|
|
281
|
-
// `actor_user_id` (uuid column) trips the Postgres driver with
|
|
282
|
-
// `invalid input syntax for type uuid`. Reject anything that isn't a UUID so the
|
|
283
|
-
// action log safely records a null actor for system-originated commands.
|
|
284
283
|
return UUID_REGEX.test(candidate) ? candidate : null
|
|
285
284
|
}
|
|
286
285
|
|
|
@@ -307,6 +306,8 @@ export class ActionLogService {
|
|
|
307
306
|
resourceId: toOptionalString(input.resourceId) ?? undefined,
|
|
308
307
|
parentResourceKind: toOptionalString(input.parentResourceKind) ?? null,
|
|
309
308
|
parentResourceId: toOptionalString(input.parentResourceId) ?? null,
|
|
309
|
+
relatedResourceKind: toOptionalString(input.relatedResourceKind) ?? null,
|
|
310
|
+
relatedResourceId: toOptionalString(input.relatedResourceId) ?? null,
|
|
310
311
|
executionState: input.executionState === 'undone' || input.executionState === 'failed' ? input.executionState : 'done',
|
|
311
312
|
undoToken: toOptionalString(input.undoToken) ?? undefined,
|
|
312
313
|
commandPayload: input.commandPayload,
|
|
@@ -408,6 +409,10 @@ export class ActionLogService {
|
|
|
408
409
|
eb('action_logs.parent_resource_kind', '=', parsed.resourceKind),
|
|
409
410
|
eb('action_logs.parent_resource_id', '=', parsed.resourceId),
|
|
410
411
|
]),
|
|
412
|
+
eb.and([
|
|
413
|
+
eb('action_logs.related_resource_kind', '=', parsed.resourceKind),
|
|
414
|
+
eb('action_logs.related_resource_id', '=', parsed.resourceId),
|
|
415
|
+
]),
|
|
411
416
|
])
|
|
412
417
|
)
|
|
413
418
|
} else {
|
|
@@ -2,7 +2,6 @@ import { NextResponse } from 'next/server'
|
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import type { CommandBus } from '@open-mercato/shared/lib/commands'
|
|
4
4
|
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
5
|
-
import { serializeOperationMetadata } from '@open-mercato/shared/lib/commands/operationMetadata'
|
|
6
5
|
import { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'
|
|
7
6
|
import { validateCrudMutationGuard, runCrudMutationGuardAfterSuccess } from '@open-mercato/shared/lib/crud/mutation-guard'
|
|
8
7
|
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
@@ -14,6 +13,8 @@ import { CustomerEntity, CustomerEntityRole } from '../data/entities'
|
|
|
14
13
|
import { entityRoleCreateSchema, entityRoleUpdateSchema, entityRoleDeleteSchema, type EntityRoleCreateInput, type EntityRoleUpdateInput, type EntityRoleDeleteInput } from '../data/validators'
|
|
15
14
|
import { withScopedPayload } from './utils'
|
|
16
15
|
import { resolveCustomersRequestContext, resolveAuthActorId } from '../lib/interactionRequestContext'
|
|
16
|
+
import { deriveDisplayNameFromEmail } from '../lib/displayName'
|
|
17
|
+
import { withOperationMetadata } from '../lib/operationMetadata'
|
|
17
18
|
|
|
18
19
|
const paramsSchema = z.object({ id: z.string().uuid() })
|
|
19
20
|
const roleIdQuerySchema = z.object({ roleId: z.string().uuid() })
|
|
@@ -60,27 +61,6 @@ function buildValidationErrorResponse(error: z.ZodError, translate: Translator)
|
|
|
60
61
|
)
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
function withOperationMetadata(
|
|
64
|
-
response: NextResponse,
|
|
65
|
-
logEntry: { undoToken?: string | null; id?: string | null; commandId?: string | null; actionLabel?: string | null; resourceKind?: string | null; resourceId?: string | null; createdAt?: Date | null } | null | undefined,
|
|
66
|
-
fallback: { resourceKind: string; resourceId: string | null },
|
|
67
|
-
) {
|
|
68
|
-
if (!logEntry?.undoToken || !logEntry.id || !logEntry.commandId) return response
|
|
69
|
-
response.headers.set(
|
|
70
|
-
'x-om-operation',
|
|
71
|
-
serializeOperationMetadata({
|
|
72
|
-
id: logEntry.id,
|
|
73
|
-
undoToken: logEntry.undoToken,
|
|
74
|
-
commandId: logEntry.commandId,
|
|
75
|
-
actionLabel: logEntry.actionLabel ?? null,
|
|
76
|
-
resourceKind: logEntry.resourceKind ?? fallback.resourceKind,
|
|
77
|
-
resourceId: logEntry.resourceId ?? fallback.resourceId,
|
|
78
|
-
executedAt: logEntry.createdAt instanceof Date ? logEntry.createdAt.toISOString() : new Date().toISOString(),
|
|
79
|
-
}),
|
|
80
|
-
)
|
|
81
|
-
return response
|
|
82
|
-
}
|
|
83
|
-
|
|
84
64
|
async function buildContext(request: Request) {
|
|
85
65
|
const context = await resolveCustomersRequestContext(request)
|
|
86
66
|
return {
|
|
@@ -314,7 +294,7 @@ export function createEntityRolesHandlers(entityType: EntityType) {
|
|
|
314
294
|
)
|
|
315
295
|
: []
|
|
316
296
|
const userMap = new Map(users.map((user) => [user.id, {
|
|
317
|
-
name: user.name ?? null,
|
|
297
|
+
name: user.name ?? deriveDisplayNameFromEmail(user.email) ?? null,
|
|
318
298
|
email: user.email ?? null,
|
|
319
299
|
phone: null,
|
|
320
300
|
}]))
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
validateCrudMutationGuard,
|
|
15
15
|
} from '@open-mercato/shared/lib/crud/mutation-guard'
|
|
16
16
|
import { resolveAuthActorId } from '../../../lib/interactionRequestContext'
|
|
17
|
+
import { withOperationMetadata } from '../../../lib/operationMetadata'
|
|
17
18
|
|
|
18
19
|
export const metadata = {
|
|
19
20
|
POST: { requireAuth: true, requireFeatures: ['customers.interactions.manage'] },
|
|
@@ -56,7 +57,7 @@ export async function POST(req: Request) {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
const commandBus = ctx.container.resolve('commandBus') as CommandBus
|
|
59
|
-
await commandBus.execute<InteractionCancelInput, { interactionId: string }>(
|
|
60
|
+
const { logEntry } = await commandBus.execute<InteractionCancelInput, { interactionId: string }>(
|
|
60
61
|
'customers.interactions.cancel',
|
|
61
62
|
{ input: parsed, ctx },
|
|
62
63
|
)
|
|
@@ -73,7 +74,11 @@ export async function POST(req: Request) {
|
|
|
73
74
|
metadata: guardResult.metadata ?? null,
|
|
74
75
|
})
|
|
75
76
|
}
|
|
76
|
-
return
|
|
77
|
+
return withOperationMetadata(
|
|
78
|
+
NextResponse.json({ ok: true }),
|
|
79
|
+
logEntry,
|
|
80
|
+
{ resourceKind: 'customers.interaction', resourceId: parsed.id },
|
|
81
|
+
)
|
|
77
82
|
} catch (err) {
|
|
78
83
|
if (err instanceof CrudHttpError) {
|
|
79
84
|
return NextResponse.json(err.body, { status: err.status })
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
validateCrudMutationGuard,
|
|
15
15
|
} from '@open-mercato/shared/lib/crud/mutation-guard'
|
|
16
16
|
import { resolveAuthActorId } from '../../../lib/interactionRequestContext'
|
|
17
|
+
import { withOperationMetadata } from '../../../lib/operationMetadata'
|
|
17
18
|
|
|
18
19
|
export const metadata = {
|
|
19
20
|
POST: { requireAuth: true, requireFeatures: ['customers.interactions.manage'] },
|
|
@@ -56,7 +57,7 @@ export async function POST(req: Request) {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
const commandBus = ctx.container.resolve('commandBus') as CommandBus
|
|
59
|
-
await commandBus.execute<InteractionCompleteInput, { interactionId: string }>(
|
|
60
|
+
const { logEntry } = await commandBus.execute<InteractionCompleteInput, { interactionId: string }>(
|
|
60
61
|
'customers.interactions.complete',
|
|
61
62
|
{ input: parsed, ctx },
|
|
62
63
|
)
|
|
@@ -73,7 +74,11 @@ export async function POST(req: Request) {
|
|
|
73
74
|
metadata: guardResult.metadata ?? null,
|
|
74
75
|
})
|
|
75
76
|
}
|
|
76
|
-
return
|
|
77
|
+
return withOperationMetadata(
|
|
78
|
+
NextResponse.json({ ok: true }),
|
|
79
|
+
logEntry,
|
|
80
|
+
{ resourceKind: 'customers.interaction', resourceId: parsed.id },
|
|
81
|
+
)
|
|
77
82
|
} catch (err) {
|
|
78
83
|
if (err instanceof CrudHttpError) {
|
|
79
84
|
return NextResponse.json(err.body, { status: err.status })
|