@open-mercato/core 0.5.1-develop.2800.bfe2178a4f → 0.5.1-develop.2851.2854b4507f
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/auth/cli.js.map +2 -2
- 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/dist/modules/messages/components/MessagesInboxPageClient.js +106 -107
- package/dist/modules/messages/components/MessagesInboxPageClient.js.map +2 -2
- package/dist/modules/messages/components/useMessagesInboxBulkActions.js +235 -0
- package/dist/modules/messages/components/useMessagesInboxBulkActions.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/auth/cli.ts +1 -1
- 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
- package/src/modules/messages/components/MessagesInboxPageClient.tsx +17 -29
- package/src/modules/messages/components/useMessagesInboxBulkActions.ts +324 -0
- package/src/modules/messages/i18n/de.json +8 -0
- package/src/modules/messages/i18n/en.json +8 -0
- package/src/modules/messages/i18n/es.json +8 -0
- package/src/modules/messages/i18n/pl.json +8 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
5
|
+
import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
|
|
6
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
7
|
+
import { useGuardedMutation } from "@open-mercato/ui/backend/injection/useGuardedMutation";
|
|
8
|
+
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
|
|
9
|
+
import { toErrorMessage } from "./message-detail/utils.js";
|
|
10
|
+
const MESSAGE_BULK_REQUESTS = {
|
|
11
|
+
markRead: {
|
|
12
|
+
method: "PUT",
|
|
13
|
+
buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}/read`,
|
|
14
|
+
successKey: "messages.bulk.flash.markReadSuccess",
|
|
15
|
+
successFallback: "{count} messages marked as read.",
|
|
16
|
+
errorKey: "messages.errors.stateChangeFailed",
|
|
17
|
+
errorFallback: "Failed to update message state."
|
|
18
|
+
},
|
|
19
|
+
markUnread: {
|
|
20
|
+
method: "DELETE",
|
|
21
|
+
buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}/read`,
|
|
22
|
+
successKey: "messages.bulk.flash.markUnreadSuccess",
|
|
23
|
+
successFallback: "{count} messages marked as unread.",
|
|
24
|
+
errorKey: "messages.errors.stateChangeFailed",
|
|
25
|
+
errorFallback: "Failed to update message state."
|
|
26
|
+
},
|
|
27
|
+
archive: {
|
|
28
|
+
method: "PUT",
|
|
29
|
+
buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}/archive`,
|
|
30
|
+
successKey: "messages.bulk.flash.archiveSuccess",
|
|
31
|
+
successFallback: "{count} messages archived.",
|
|
32
|
+
errorKey: "messages.errors.stateChangeFailed",
|
|
33
|
+
errorFallback: "Failed to update message state."
|
|
34
|
+
},
|
|
35
|
+
delete: {
|
|
36
|
+
method: "DELETE",
|
|
37
|
+
buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}`,
|
|
38
|
+
successKey: "messages.bulk.flash.deleteSuccess",
|
|
39
|
+
successFallback: "{count} messages deleted.",
|
|
40
|
+
errorKey: "messages.errors.deleteFailed",
|
|
41
|
+
errorFallback: "Failed to delete message."
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function normalizeSelectionScopeValue(value) {
|
|
45
|
+
if (value == null) return void 0;
|
|
46
|
+
if (typeof value === "string") {
|
|
47
|
+
const trimmed = value.trim();
|
|
48
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
const normalized = value.map((item) => normalizeSelectionScopeValue(item)).filter((item) => item !== void 0);
|
|
52
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === "object") {
|
|
55
|
+
const normalizedEntries = Object.entries(value).sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey)).map(([key, nestedValue]) => [key, normalizeSelectionScopeValue(nestedValue)]).filter(([, nestedValue]) => nestedValue !== void 0);
|
|
56
|
+
if (normalizedEntries.length === 0) return void 0;
|
|
57
|
+
return Object.fromEntries(normalizedEntries);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
function buildMessageSelectionScopeKey(folder, page, search, filterValues) {
|
|
62
|
+
return JSON.stringify({
|
|
63
|
+
folder,
|
|
64
|
+
page,
|
|
65
|
+
search: search.trim(),
|
|
66
|
+
filters: normalizeSelectionScopeValue(filterValues) ?? {}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function runWithConcurrency(items, limit, worker) {
|
|
70
|
+
if (items.length === 0) return [];
|
|
71
|
+
const results = new Array(items.length);
|
|
72
|
+
let nextIndex = 0;
|
|
73
|
+
const runWorker = async () => {
|
|
74
|
+
while (nextIndex < items.length) {
|
|
75
|
+
const currentIndex = nextIndex;
|
|
76
|
+
nextIndex += 1;
|
|
77
|
+
try {
|
|
78
|
+
await worker(items[currentIndex]);
|
|
79
|
+
results[currentIndex] = { status: "fulfilled", value: void 0 };
|
|
80
|
+
} catch (error) {
|
|
81
|
+
results[currentIndex] = { status: "rejected", reason: error };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
await Promise.all(
|
|
86
|
+
Array.from({ length: Math.min(limit, items.length) }, () => runWorker())
|
|
87
|
+
);
|
|
88
|
+
return results;
|
|
89
|
+
}
|
|
90
|
+
function useMessagesInboxBulkActions({
|
|
91
|
+
folder,
|
|
92
|
+
page,
|
|
93
|
+
search,
|
|
94
|
+
filterValues
|
|
95
|
+
}) {
|
|
96
|
+
const t = useT();
|
|
97
|
+
const queryClient = useQueryClient();
|
|
98
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog();
|
|
99
|
+
const { runMutation, retryLastMutation } = useGuardedMutation({
|
|
100
|
+
contextId: "messages-inbox-bulk-actions"
|
|
101
|
+
});
|
|
102
|
+
const selectionScopeKey = React.useMemo(
|
|
103
|
+
() => buildMessageSelectionScopeKey(folder, page, search, filterValues),
|
|
104
|
+
[filterValues, folder, page, search]
|
|
105
|
+
);
|
|
106
|
+
const injectionContext = React.useMemo(
|
|
107
|
+
() => ({
|
|
108
|
+
folder,
|
|
109
|
+
page,
|
|
110
|
+
search: search.trim(),
|
|
111
|
+
filters: filterValues,
|
|
112
|
+
retryLastMutation
|
|
113
|
+
}),
|
|
114
|
+
[filterValues, folder, page, retryLastMutation, search]
|
|
115
|
+
);
|
|
116
|
+
const executeBulkAction = React.useCallback(async (actionId, selectedRows) => {
|
|
117
|
+
const messageIds = selectedRows.map((row) => row.id).filter((id) => id.trim().length > 0);
|
|
118
|
+
if (messageIds.length === 0) return false;
|
|
119
|
+
if (actionId === "delete") {
|
|
120
|
+
const confirmed = await confirm({
|
|
121
|
+
title: t("messages.bulk.delete.title", "Delete {count} messages?", { count: messageIds.length }),
|
|
122
|
+
description: t("messages.bulk.delete.description", "This removes the selected messages from your view."),
|
|
123
|
+
confirmText: t("messages.actions.delete", "Delete"),
|
|
124
|
+
variant: "destructive"
|
|
125
|
+
});
|
|
126
|
+
if (!confirmed) return false;
|
|
127
|
+
}
|
|
128
|
+
const requestConfig = MESSAGE_BULK_REQUESTS[actionId];
|
|
129
|
+
try {
|
|
130
|
+
const summary = await runMutation({
|
|
131
|
+
operation: async () => {
|
|
132
|
+
const results = await runWithConcurrency(messageIds, 5, async (messageId) => {
|
|
133
|
+
const call = await apiCall(requestConfig.buildUrl(messageId), {
|
|
134
|
+
method: requestConfig.method
|
|
135
|
+
});
|
|
136
|
+
if (!call.ok) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
toErrorMessage(call.result) ?? t(requestConfig.errorKey, requestConfig.errorFallback)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const failed = results.filter((result) => result.status === "rejected").length;
|
|
143
|
+
const succeeded = results.length - failed;
|
|
144
|
+
if (succeeded > 0) {
|
|
145
|
+
await queryClient.invalidateQueries({ queryKey: ["messages", "list"] });
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
action: actionId,
|
|
149
|
+
total: messageIds.length,
|
|
150
|
+
succeeded,
|
|
151
|
+
failed
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
context: {
|
|
155
|
+
actionId,
|
|
156
|
+
messageIds,
|
|
157
|
+
folder,
|
|
158
|
+
page,
|
|
159
|
+
search: search.trim(),
|
|
160
|
+
filters: filterValues,
|
|
161
|
+
retryLastMutation
|
|
162
|
+
},
|
|
163
|
+
mutationPayload: {
|
|
164
|
+
actionId,
|
|
165
|
+
messageIds
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
if (summary.succeeded === 0) {
|
|
169
|
+
flash(
|
|
170
|
+
t("messages.bulk.flash.failed", "Failed to process {count} messages.", { count: summary.failed }),
|
|
171
|
+
"error"
|
|
172
|
+
);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (summary.failed > 0) {
|
|
176
|
+
flash(
|
|
177
|
+
t("messages.bulk.flash.partial", "{succeeded} of {total} messages processed; {failed} failed.", {
|
|
178
|
+
succeeded: summary.succeeded,
|
|
179
|
+
total: summary.total,
|
|
180
|
+
failed: summary.failed
|
|
181
|
+
}),
|
|
182
|
+
"warning"
|
|
183
|
+
);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
flash(
|
|
187
|
+
t(requestConfig.successKey, requestConfig.successFallback, { count: summary.succeeded }),
|
|
188
|
+
"success"
|
|
189
|
+
);
|
|
190
|
+
return true;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
flash(
|
|
193
|
+
error instanceof Error ? error.message : t(requestConfig.errorKey, requestConfig.errorFallback),
|
|
194
|
+
"error"
|
|
195
|
+
);
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}, [confirm, filterValues, folder, page, queryClient, retryLastMutation, runMutation, search, t]);
|
|
199
|
+
const bulkActions = React.useMemo(
|
|
200
|
+
() => folder === "inbox" ? [
|
|
201
|
+
{
|
|
202
|
+
id: "messages-mark-read",
|
|
203
|
+
label: t("messages.actions.markRead", "Mark read"),
|
|
204
|
+
onExecute: (selectedRows) => executeBulkAction("markRead", selectedRows)
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "messages-mark-unread",
|
|
208
|
+
label: t("messages.actions.markUnread", "Mark unread"),
|
|
209
|
+
onExecute: (selectedRows) => executeBulkAction("markUnread", selectedRows)
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
id: "messages-archive",
|
|
213
|
+
label: t("messages.actions.archive", "Archive"),
|
|
214
|
+
onExecute: (selectedRows) => executeBulkAction("archive", selectedRows)
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
id: "messages-delete",
|
|
218
|
+
label: t("messages.actions.delete", "Delete"),
|
|
219
|
+
destructive: true,
|
|
220
|
+
onExecute: (selectedRows) => executeBulkAction("delete", selectedRows)
|
|
221
|
+
}
|
|
222
|
+
] : void 0,
|
|
223
|
+
[executeBulkAction, folder, t]
|
|
224
|
+
);
|
|
225
|
+
return {
|
|
226
|
+
bulkActions,
|
|
227
|
+
selectionScopeKey,
|
|
228
|
+
injectionContext,
|
|
229
|
+
ConfirmDialogElement
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
export {
|
|
233
|
+
useMessagesInboxBulkActions
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=useMessagesInboxBulkActions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/messages/components/useMessagesInboxBulkActions.ts"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { BulkAction } from '@open-mercato/ui/backend/DataTable'\nimport type { FilterValues } from '@open-mercato/ui/backend/FilterBar'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { toErrorMessage } from './message-detail/utils'\n\nexport type MessageFolder = 'inbox' | 'sent' | 'drafts' | 'archived' | 'all'\n\ntype MessageBulkActionId = 'markRead' | 'markUnread' | 'archive' | 'delete'\n\ntype BulkExecutionSummary = {\n action: MessageBulkActionId\n total: number\n succeeded: number\n failed: number\n}\n\ntype MessageBulkRequestConfig = {\n method: 'PUT' | 'DELETE'\n buildUrl: (messageId: string) => string\n successKey: string\n successFallback: string\n errorKey: string\n errorFallback: string\n}\n\ntype MessageInboxBulkMutationContext = {\n actionId: MessageBulkActionId\n messageIds: string[]\n folder: MessageFolder\n page: number\n search: string\n filters: FilterValues\n retryLastMutation: () => Promise<boolean>\n}\n\ntype UseMessagesInboxBulkActionsInput = {\n folder: MessageFolder\n page: number\n search: string\n filterValues: FilterValues\n}\n\ntype MessageInboxBulkRow = {\n id: string\n}\n\nconst MESSAGE_BULK_REQUESTS: Record<MessageBulkActionId, MessageBulkRequestConfig> = {\n markRead: {\n method: 'PUT',\n buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}/read`,\n successKey: 'messages.bulk.flash.markReadSuccess',\n successFallback: '{count} messages marked as read.',\n errorKey: 'messages.errors.stateChangeFailed',\n errorFallback: 'Failed to update message state.',\n },\n markUnread: {\n method: 'DELETE',\n buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}/read`,\n successKey: 'messages.bulk.flash.markUnreadSuccess',\n successFallback: '{count} messages marked as unread.',\n errorKey: 'messages.errors.stateChangeFailed',\n errorFallback: 'Failed to update message state.',\n },\n archive: {\n method: 'PUT',\n buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}/archive`,\n successKey: 'messages.bulk.flash.archiveSuccess',\n successFallback: '{count} messages archived.',\n errorKey: 'messages.errors.stateChangeFailed',\n errorFallback: 'Failed to update message state.',\n },\n delete: {\n method: 'DELETE',\n buildUrl: (messageId) => `/api/messages/${encodeURIComponent(messageId)}`,\n successKey: 'messages.bulk.flash.deleteSuccess',\n successFallback: '{count} messages deleted.',\n errorKey: 'messages.errors.deleteFailed',\n errorFallback: 'Failed to delete message.',\n },\n}\n\nfunction normalizeSelectionScopeValue(value: unknown): unknown {\n if (value == null) return undefined\n if (typeof value === 'string') {\n const trimmed = value.trim()\n return trimmed.length > 0 ? trimmed : undefined\n }\n if (Array.isArray(value)) {\n const normalized = value\n .map((item) => normalizeSelectionScopeValue(item))\n .filter((item) => item !== undefined)\n return normalized.length > 0 ? normalized : undefined\n }\n if (typeof value === 'object') {\n const normalizedEntries = Object.entries(value)\n .sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey))\n .map(([key, nestedValue]) => [key, normalizeSelectionScopeValue(nestedValue)] as const)\n .filter(([, nestedValue]) => nestedValue !== undefined)\n if (normalizedEntries.length === 0) return undefined\n return Object.fromEntries(normalizedEntries)\n }\n return value\n}\n\nfunction buildMessageSelectionScopeKey(\n folder: MessageFolder,\n page: number,\n search: string,\n filterValues: FilterValues,\n): string {\n return JSON.stringify({\n folder,\n page,\n search: search.trim(),\n filters: normalizeSelectionScopeValue(filterValues) ?? {},\n })\n}\n\nasync function runWithConcurrency<TItem>(\n items: TItem[],\n limit: number,\n worker: (item: TItem) => Promise<void>,\n): Promise<PromiseSettledResult<void>[]> {\n if (items.length === 0) return []\n\n const results: PromiseSettledResult<void>[] = new Array(items.length)\n let nextIndex = 0\n\n const runWorker = async () => {\n while (nextIndex < items.length) {\n const currentIndex = nextIndex\n nextIndex += 1\n try {\n await worker(items[currentIndex])\n results[currentIndex] = { status: 'fulfilled', value: undefined }\n } catch (error) {\n results[currentIndex] = { status: 'rejected', reason: error }\n }\n }\n }\n\n await Promise.all(\n Array.from({ length: Math.min(limit, items.length) }, () => runWorker()),\n )\n\n return results\n}\n\nexport function useMessagesInboxBulkActions<T extends MessageInboxBulkRow>({\n folder,\n page,\n search,\n filterValues,\n}: UseMessagesInboxBulkActionsInput): {\n bulkActions: BulkAction<T>[] | undefined\n selectionScopeKey: string\n injectionContext: Record<string, unknown>\n ConfirmDialogElement: React.ReactNode\n} {\n const t = useT()\n const queryClient = useQueryClient()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const { runMutation, retryLastMutation } = useGuardedMutation<MessageInboxBulkMutationContext>({\n contextId: 'messages-inbox-bulk-actions',\n })\n\n const selectionScopeKey = React.useMemo(\n () => buildMessageSelectionScopeKey(folder, page, search, filterValues),\n [filterValues, folder, page, search],\n )\n const injectionContext = React.useMemo<Record<string, unknown>>(\n () => ({\n folder,\n page,\n search: search.trim(),\n filters: filterValues,\n retryLastMutation,\n }),\n [filterValues, folder, page, retryLastMutation, search],\n )\n\n const executeBulkAction = React.useCallback(async (\n actionId: MessageBulkActionId,\n selectedRows: T[],\n ): Promise<boolean> => {\n const messageIds = selectedRows.map((row) => row.id).filter((id) => id.trim().length > 0)\n if (messageIds.length === 0) return false\n\n if (actionId === 'delete') {\n const confirmed = await confirm({\n title: t('messages.bulk.delete.title', 'Delete {count} messages?', { count: messageIds.length }),\n description: t('messages.bulk.delete.description', 'This removes the selected messages from your view.'),\n confirmText: t('messages.actions.delete', 'Delete'),\n variant: 'destructive',\n })\n if (!confirmed) return false\n }\n\n const requestConfig = MESSAGE_BULK_REQUESTS[actionId]\n\n try {\n const summary = await runMutation<BulkExecutionSummary>({\n operation: async () => {\n const results = await runWithConcurrency(messageIds, 5, async (messageId) => {\n const call = await apiCall<{ ok?: boolean }>(requestConfig.buildUrl(messageId), {\n method: requestConfig.method,\n })\n if (!call.ok) {\n throw new Error(\n toErrorMessage(call.result)\n ?? t(requestConfig.errorKey, requestConfig.errorFallback),\n )\n }\n })\n\n const failed = results.filter((result) => result.status === 'rejected').length\n const succeeded = results.length - failed\n\n if (succeeded > 0) {\n await queryClient.invalidateQueries({ queryKey: ['messages', 'list'] })\n }\n\n return {\n action: actionId,\n total: messageIds.length,\n succeeded,\n failed,\n }\n },\n context: {\n actionId,\n messageIds,\n folder,\n page,\n search: search.trim(),\n filters: filterValues,\n retryLastMutation,\n },\n mutationPayload: {\n actionId,\n messageIds,\n },\n })\n\n if (summary.succeeded === 0) {\n flash(\n t('messages.bulk.flash.failed', 'Failed to process {count} messages.', { count: summary.failed }),\n 'error',\n )\n return false\n }\n\n if (summary.failed > 0) {\n flash(\n t('messages.bulk.flash.partial', '{succeeded} of {total} messages processed; {failed} failed.', {\n succeeded: summary.succeeded,\n total: summary.total,\n failed: summary.failed,\n }),\n 'warning',\n )\n return true\n }\n\n flash(\n t(requestConfig.successKey, requestConfig.successFallback, { count: summary.succeeded }),\n 'success',\n )\n return true\n } catch (error) {\n flash(\n error instanceof Error\n ? error.message\n : t(requestConfig.errorKey, requestConfig.errorFallback),\n 'error',\n )\n return false\n }\n }, [confirm, filterValues, folder, page, queryClient, retryLastMutation, runMutation, search, t])\n\n const bulkActions = React.useMemo<BulkAction<T>[] | undefined>(\n () => folder === 'inbox'\n ? [\n {\n id: 'messages-mark-read',\n label: t('messages.actions.markRead', 'Mark read'),\n onExecute: (selectedRows: T[]) => executeBulkAction('markRead', selectedRows),\n },\n {\n id: 'messages-mark-unread',\n label: t('messages.actions.markUnread', 'Mark unread'),\n onExecute: (selectedRows: T[]) => executeBulkAction('markUnread', selectedRows),\n },\n {\n id: 'messages-archive',\n label: t('messages.actions.archive', 'Archive'),\n onExecute: (selectedRows: T[]) => executeBulkAction('archive', selectedRows),\n },\n {\n id: 'messages-delete',\n label: t('messages.actions.delete', 'Delete'),\n destructive: true,\n onExecute: (selectedRows: T[]) => executeBulkAction('delete', selectedRows),\n },\n ]\n : undefined,\n [executeBulkAction, folder, t],\n )\n\n return {\n bulkActions,\n selectionScopeKey,\n injectionContext,\n ConfirmDialogElement,\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,YAAY,WAAW;AACvB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAGrB,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,0BAA0B;AACnC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AA2C/B,MAAM,wBAA+E;AAAA,EACnF,UAAU;AAAA,IACR,QAAQ;AAAA,IACR,UAAU,CAAC,cAAc,iBAAiB,mBAAmB,SAAS,CAAC;AAAA,IACvE,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,YAAY;AAAA,IACV,QAAQ;AAAA,IACR,UAAU,CAAC,cAAc,iBAAiB,mBAAmB,SAAS,CAAC;AAAA,IACvE,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,SAAS;AAAA,IACP,QAAQ;AAAA,IACR,UAAU,CAAC,cAAc,iBAAiB,mBAAmB,SAAS,CAAC;AAAA,IACvE,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,QAAQ;AAAA,IACN,QAAQ;AAAA,IACR,UAAU,CAAC,cAAc,iBAAiB,mBAAmB,SAAS,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;AAAA,IACJ,CAAC,mBAAmB,QAAQ,CAAC;AAAA,EAC/B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
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.2851.2854b4507f",
|
|
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.2851.2854b4507f"
|
|
241
241
|
},
|
|
242
242
|
"devDependencies": {
|
|
243
|
-
"@open-mercato/shared": "0.5.1-develop.
|
|
243
|
+
"@open-mercato/shared": "0.5.1-develop.2851.2854b4507f",
|
|
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 {
|
package/src/modules/auth/cli.ts
CHANGED
|
@@ -642,7 +642,6 @@ const setPassword: ModuleCli = {
|
|
|
642
642
|
},
|
|
643
643
|
}
|
|
644
644
|
|
|
645
|
-
// Export the full CLI list
|
|
646
645
|
const syncRoleAcls: ModuleCli = {
|
|
647
646
|
command: 'sync-role-acls',
|
|
648
647
|
async run(rest) {
|
|
@@ -705,4 +704,5 @@ const syncRoleAcls: ModuleCli = {
|
|
|
705
704
|
},
|
|
706
705
|
}
|
|
707
706
|
|
|
707
|
+
// Export the full CLI list
|
|
708
708
|
export default [addUser, seedRoles, syncRoleAcls, rotateEncryptionKey, addOrganization, setupApp, listOrganizations, listTenants, listUsers, setPassword]
|
|
@@ -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 })
|