@open-mercato/core 0.11.1-develop.8523.1.c6b0fd2058 → 0.11.1-develop.8531.1.9c9f5e2b21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js +2 -2
  3. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js.map +2 -2
  4. package/dist/modules/entities/components/EncryptionManager.js +13 -4
  5. package/dist/modules/entities/components/EncryptionManager.js.map +2 -2
  6. package/dist/modules/messages/components/MessagesInboxPageClient.js +2 -2
  7. package/dist/modules/messages/components/MessagesInboxPageClient.js.map +2 -2
  8. package/dist/modules/messages/components/message-detail/hooks/useMessageDetails.js +2 -2
  9. package/dist/modules/messages/components/message-detail/hooks/useMessageDetails.js.map +2 -2
  10. package/dist/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.js +5 -4
  11. package/dist/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.js.map +2 -2
  12. package/dist/modules/warranty_claims/frontend/[orgSlug]/portal/claims/[id]/page.js +8 -4
  13. package/dist/modules/warranty_claims/frontend/[orgSlug]/portal/claims/[id]/page.js.map +2 -2
  14. package/dist/modules/workflows/components/run/useLiveRunUpdates.js +2 -3
  15. package/dist/modules/workflows/components/run/useLiveRunUpdates.js.map +2 -2
  16. package/dist/modules/workflows/lib/workflow-executor.js +23 -0
  17. package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
  18. package/package.json +7 -7
  19. package/src/modules/data_sync/backend/data-sync/runs/[id]/page.tsx +2 -2
  20. package/src/modules/entities/components/EncryptionManager.tsx +15 -5
  21. package/src/modules/messages/components/MessagesInboxPageClient.tsx +2 -2
  22. package/src/modules/messages/components/message-detail/hooks/useMessageDetails.ts +2 -2
  23. package/src/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.tsx +5 -4
  24. package/src/modules/warranty_claims/frontend/[orgSlug]/portal/claims/[id]/page.tsx +8 -4
  25. package/src/modules/workflows/components/run/useLiveRunUpdates.ts +2 -5
  26. package/src/modules/workflows/lib/workflow-executor.ts +23 -0
@@ -17,6 +17,8 @@ import { apiCall, readApiResultOrThrow, withScopedApiRequestHeaders } from '@ope
17
17
  import { raiseCrudError } from '@open-mercato/ui/backend/utils/serverErrors'
18
18
  import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
19
19
  import { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'
20
+ import { surfaceRecordConflict } from '@open-mercato/ui/backend/conflicts'
21
+ import { useInFlightGuard } from '@open-mercato/ui/hooks/useInFlightGuard'
20
22
  import { useCustomFieldDefs, type CustomFieldDefDto } from '@open-mercato/ui/backend/utils/customFieldDefs'
21
23
  import { Plus, Save, Trash2 } from 'lucide-react'
22
24
  import { useOrganizationScopeVersion } from '@open-mercato/shared/lib/frontend/useOrganizationScope'
@@ -275,16 +277,24 @@ export function EncryptionManager() {
275
277
  mutationPayload: payload,
276
278
  })
277
279
  },
278
- onSuccess: () => {
280
+ onSuccess: async () => {
279
281
  flash(t('entities.encryption.flash.saved', 'Encryption map saved'), 'success')
280
- void refetchMap()
282
+ await refetchMap()
281
283
  },
282
- onError: (err: any) => {
283
- const message = err?.message || t('entities.encryption.errors.save', 'Failed to save encryption map')
284
+ onError: (err: unknown) => {
285
+ if (surfaceRecordConflict(err, t, { onRefresh: () => { void refetchMap() } })) return
286
+ const message = err instanceof Error && err.message
287
+ ? err.message
288
+ : t('entities.encryption.errors.save', 'Failed to save encryption map')
284
289
  flash(message, 'error')
285
290
  },
286
291
  })
287
292
 
293
+ const saveGuard = useInFlightGuard()
294
+ const handleSave = () => {
295
+ void saveGuard.run(() => mutation.mutateAsync()).catch(() => undefined)
296
+ }
297
+
288
298
  const addField = () => {
289
299
  setHasUserEdited(true)
290
300
  setFields((prev) => [...prev, { id: buildRowId(), field: '', hashField: null }])
@@ -485,7 +495,7 @@ export function EncryptionManager() {
485
495
  <div className="flex justify-end">
486
496
  <Button
487
497
  type="button"
488
- onClick={() => mutation.mutate()}
498
+ onClick={handleSave}
489
499
  disabled={mutation.isPending || loadingEntities || !!entitiesError || !selectedEntityId}
490
500
  >
491
501
  <Save className="mr-2 h-4 w-4" />
@@ -14,7 +14,7 @@ import type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar
14
14
  import { Button } from '@open-mercato/ui/primitives/button'
15
15
  import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
16
16
  import { flash } from '@open-mercato/ui/backend/FlashMessages'
17
- import { useAppEvent } from '@open-mercato/ui/backend/injection/useAppEvent'
17
+ import { BRIDGE_RECONNECTED_EVENT_ID, useAppEvent } from '@open-mercato/ui/backend/injection/useAppEvent'
18
18
  import { useAppEventCoalesced } from '@open-mercato/ui/backend/injection/useAppEventCoalesced'
19
19
  import { Archive, ChevronDown, FilePenLine, Inbox, Layers, Send } from 'lucide-react'
20
20
  import { getMessageUiComponentRegistry } from './utils/typeUiRegistry'
@@ -95,7 +95,7 @@ export function MessagesInboxPageClient() {
95
95
  useAppEventCoalesced('messages.message.*', invalidateMessageListQueries, [invalidateMessageListQueries])
96
96
 
97
97
  // Reconnect means events were missed while offline, so it refreshes uncoalesced.
98
- useAppEvent('om:bridge:reconnected', invalidateMessageListQueries, [invalidateMessageListQueries])
98
+ useAppEvent(BRIDGE_RECONNECTED_EVENT_ID, invalidateMessageListQueries, [invalidateMessageListQueries])
99
99
 
100
100
  const [folder, setFolder] = React.useState<MessageFolder>('inbox')
101
101
  const [folderMenuOpen, setFolderMenuOpen] = React.useState(false)
@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation'
5
5
  import { useQueryClient } from '@tanstack/react-query'
6
6
  import { useT } from '@open-mercato/shared/lib/i18n/context'
7
7
  import { useOrganizationScopeVersion } from '@open-mercato/shared/lib/frontend/useOrganizationScope'
8
- import { useAppEvent } from '@open-mercato/ui/backend/injection/useAppEvent'
8
+ import { BRIDGE_RECONNECTED_EVENT_ID, useAppEvent } from '@open-mercato/ui/backend/injection/useAppEvent'
9
9
  import { useMessageDetailsQueries } from './useMessageDetailsQueries'
10
10
  import { useMessageDetailsActions } from './useMessageDetailsActions'
11
11
  import { useMessageDetailsConversation } from './useMessageDetailsConversation'
@@ -44,7 +44,7 @@ export function useMessageDetails(id: string) {
44
44
  )
45
45
 
46
46
  useAppEvent(
47
- 'om:bridge:reconnected',
47
+ BRIDGE_RECONNECTED_EVENT_ID,
48
48
  () => {
49
49
  void queryClient.invalidateQueries({ queryKey: ['messages', 'detail', id] })
50
50
  },
@@ -19,7 +19,7 @@ import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
19
19
  import { usePortalContext } from '@open-mercato/ui/portal/PortalContext'
20
20
  import { PortalCard } from '@open-mercato/ui/portal/components/PortalCard'
21
21
  import { PortalEmptyState } from '@open-mercato/ui/portal/components/PortalEmptyState'
22
- import { usePortalAppEvent } from '@open-mercato/ui/portal/hooks/usePortalAppEvent'
22
+ import { usePortalLiveRefetch } from '@open-mercato/ui/portal/hooks/usePortalLiveRefetch'
23
23
  import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
24
24
  import {
25
25
  ATTACHMENT_ACCEPT_TYPES,
@@ -147,9 +147,10 @@ export default function PortalSupportTicketDetailPage({ params }: Props) {
147
147
  void load()
148
148
  }, [load])
149
149
 
150
- usePortalAppEvent(PORTAL_SUPPORT_UPDATED_EVENT, (event) => {
151
- if (readPortalTicketIdFromEvent(event) === params.id) void load()
152
- }, [load, params.id])
150
+ usePortalLiveRefetch(PORTAL_SUPPORT_UPDATED_EVENT, () => void load(), {
151
+ filter: (event) => readPortalTicketIdFromEvent(event) === params.id,
152
+ deps: [load, params.id],
153
+ })
153
154
 
154
155
  const clearFailed = React.useCallback((fileName: string) => {
155
156
  forgetFailedUpload(params.id, fileName)
@@ -32,6 +32,7 @@ import { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimi
32
32
  import { usePortalContext } from '@open-mercato/ui/portal/PortalContext'
33
33
  import { PortalEmptyState } from '@open-mercato/ui/portal/components/PortalEmptyState'
34
34
  import { usePortalAppEvent } from '@open-mercato/ui/portal/hooks/usePortalAppEvent'
35
+ import { usePortalLiveRefetch } from '@open-mercato/ui/portal/hooks/usePortalLiveRefetch'
35
36
 
36
37
  type Props = { params: { orgSlug: string; id: string } }
37
38
 
@@ -419,10 +420,13 @@ export default function WarrantyClaimPortalDetailPage({ params }: Props) {
419
420
  if (user) void loadClaim()
420
421
  }, [loadClaim, user])
421
422
 
422
- usePortalAppEvent('warranty_claims.claim.portal_status_changed', (event) => {
423
- if (!user || event.payload.claimId !== params.id) return
424
- void loadClaim(false)
425
- })
423
+ usePortalLiveRefetch(
424
+ 'warranty_claims.claim.portal_status_changed',
425
+ () => {
426
+ if (user) void loadClaim(false)
427
+ },
428
+ { filter: (event) => event.payload.claimId === params.id },
429
+ )
426
430
 
427
431
  usePortalAppEvent('warranty_claims.claim.comment_added', (event) => {
428
432
  if (!user || event.payload.claimId !== params.id) return
@@ -1,10 +1,7 @@
1
1
  'use client'
2
2
 
3
3
  import * as React from 'react'
4
- import { useAppEvent } from '@open-mercato/ui/backend/injection/useAppEvent'
5
-
6
- /** The DOM Event Bridge dispatches this after re-establishing a dropped SSE stream. */
7
- const BRIDGE_RECONNECTED_EVENT = 'om:bridge:reconnected'
4
+ import { BRIDGE_RECONNECTED_EVENT_ID, useAppEvent } from '@open-mercato/ui/backend/injection/useAppEvent'
8
5
 
9
6
  /**
10
7
  * A busy tenant can advance dozens of instances a second, and every step
@@ -79,7 +76,7 @@ export function useLiveRunUpdates({
79
76
  )
80
77
 
81
78
  useAppEvent(
82
- BRIDGE_RECONNECTED_EVENT,
79
+ BRIDGE_RECONNECTED_EVENT_ID,
83
80
  () => {
84
81
  if (!enabled) return
85
82
  scheduleRefresh()
@@ -13,8 +13,10 @@
13
13
  import { EntityManager, LockMode } from '@mikro-orm/core'
14
14
  import type { EntityManager as PostgreSqlEntityManager } from '@mikro-orm/postgresql'
15
15
  import type { AwilixContainer } from 'awilix'
16
+ import { z } from 'zod'
16
17
  import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
17
18
  import {
19
+ StepInstance,
18
20
  UserTask,
19
21
  WorkflowDefinition,
20
22
  WorkflowInstance,
@@ -2052,6 +2054,27 @@ export async function getWorkflowInstance(
2052
2054
  return em.findOne(WorkflowInstance, { id: instanceId })
2053
2055
  }
2054
2056
 
2057
+ const workflowStepInstanceIdSchema = z.string().uuid()
2058
+
2059
+ /** Verify that the exact step occurrence belongs to the named live workflow instance and scope. */
2060
+ export async function hasWorkflowStepReference(
2061
+ em: PostgreSqlEntityManager,
2062
+ scope: { tenantId: string; organizationId: string },
2063
+ workflowInstanceId: string,
2064
+ stepId: string,
2065
+ stepInstanceId: string,
2066
+ ): Promise<boolean> {
2067
+ if (!workflowStepInstanceIdSchema.safeParse(stepInstanceId).success) return false
2068
+ const workflow = await findOneWithDecryption(
2069
+ em, WorkflowInstance, { id: workflowInstanceId, ...scope, deletedAt: null }, { fields: ['id'] }, scope,
2070
+ )
2071
+ if (!workflow) return false
2072
+ const step = await findOneWithDecryption(
2073
+ em, StepInstance, { id: stepInstanceId, workflowInstanceId, stepId, ...scope }, { fields: ['id'] }, scope,
2074
+ )
2075
+ return step != null
2076
+ }
2077
+
2055
2078
  async function getWorkflowInstanceForExecution(
2056
2079
  em: EntityManager,
2057
2080
  instanceId: string,