@antelopejs/dms-automation 0.3.1 → 0.4.0

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/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  AntelopeJS DMS module that provides a visual automation builder under `/modules/automation`. Author procedures as node graphs (triggers, actions, data nodes), wire trigger and data edges, and run them in response to events such as cron schedules and webhooks.
10
10
 
11
- It runs on `@antelopejs/dms` 0.7.21 (`@antelopejs/interface-dms` 0.5.13) and `@antelopejs/dms-frontend` 0.5.
11
+ It runs on `@antelopejs/dms` 0.9 (`@antelopejs/interface-dms` 0.7) and `@antelopejs/dms-frontend` 0.6: its pages read their data with the DMS's `useApiData`, which renders it on the server and hands it to the browser, and reads it again when the page refreshes. Webhook triggers are called on the API's public origin (`apiBaseUrl`), not through the frontend server.
12
12
 
13
13
  ## Pages
14
14
 
@@ -121,7 +121,8 @@ async function act(row: AttentionRow, change: Change, undo: Change, message: str
121
121
  busy.value = row.procedureId
122
122
  try {
123
123
  await $authFetch(change.url, { method: change.method, body: change.body })
124
- refreshPageBlocks()
124
+ // The row keeps its spinner until the page shows the change.
125
+ await refreshPageBlocks()
125
126
  toast.add({
126
127
  title: processI18n(message, { name: row.name }),
127
128
  color: 'success',
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from 'vue'
2
+ import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'
3
3
  import type { NodeKindEntry, PortRef } from '../composables/useAutomationNodeKinds'
4
4
  import type { JsonSchema } from '../composables/useGraphConnect'
5
5
 
@@ -84,11 +84,17 @@ const { confirm } = useConfirm()
84
84
  const route = useDmsRoute()
85
85
  const router = useDmsRouter()
86
86
 
87
- const entries = ref<CatalogEntry[]>([])
88
- const usage = ref<Record<string, TypeUsage[]>>({})
89
- const loading = ref(true)
90
- const error = ref<string | null>(null)
91
- const selectedId = ref<string | null>(null)
87
+ // The catalog and where its entries are used, read with the page.
88
+ const listRead = useApiData<CatalogEntry[] | NodeKindEntry[]>(`${props.apiUrl}/${ENDPOINTS[props.kind]}`)
89
+ const usageRead = useApiData<Record<string, TypeUsage[]>>(`${props.apiUrl}/library/usage/${props.kind}`)
90
+ const usage = computed(() => usageRead.data.value ?? {})
91
+ const loading = computed(() => listRead.pending.value || usageRead.pending.value)
92
+ const error = computed(() => {
93
+ const failure = listRead.error.value ?? usageRead.error.value
94
+ return failure ? describeApiError(failure) : null
95
+ })
96
+ // The entry picked in this view, else the URL's (`?item=`).
97
+ const picked = ref<string | null>(null)
92
98
  const query = ref('')
93
99
  const saving = ref(false)
94
100
  const showAllUses = ref(false)
@@ -126,26 +132,21 @@ function queryItem(): string | null {
126
132
  return typeof q === 'string' && q ? q : null
127
133
  }
128
134
 
129
- async function load() {
130
- loading.value = true
131
- try {
132
- const [listed, uses] = await Promise.all([
133
- $authFetch<CatalogEntry[] | NodeKindEntry[]>(`${props.apiUrl}/${ENDPOINTS[props.kind]}`),
134
- $authFetch<Record<string, TypeUsage[]>>(`${props.apiUrl}/library/usage/${props.kind}`),
135
- ])
136
- entries.value = props.kind === 'flow' ? flowEntries(listed as NodeKindEntry[]) : (listed as CatalogEntry[])
137
- usage.value = uses
138
- error.value = null
139
- const wanted = selectedId.value ?? queryItem()
140
- selectedId.value = entries.value.some((e) => e.id === wanted) ? wanted : (groups.value[0]?.[1][0]?.id ?? null)
141
- } catch (e) {
142
- error.value = describeApiError(e)
143
- } finally {
144
- loading.value = false
145
- }
135
+ const entries = computed<CatalogEntry[]>(() => {
136
+ const listed = listRead.data.value ?? []
137
+ return props.kind === 'flow' ? flowEntries(listed as NodeKindEntry[]) : (listed as CatalogEntry[])
138
+ })
139
+
140
+ function load() {
141
+ void Promise.all([listRead.refresh(), usageRead.refresh()])
146
142
  }
147
143
 
148
- onMounted(load)
144
+ /** Shows a write at once: the catalog's data is replaced, never changed in place. */
145
+ function replaceEntry(id: string, change: Partial<CatalogEntry>) {
146
+ const listed = listRead.data.value
147
+ if (!listed || props.kind === 'flow') return
148
+ listRead.data.value = (listed as CatalogEntry[]).map((entry) => (entry.id === id ? { ...entry, ...change } : entry))
149
+ }
149
150
 
150
151
  /**
151
152
  * The heading an entry is listed under: its module (built-in first), and for
@@ -183,11 +184,17 @@ const groups = computed(() => {
183
184
  return [...map.entries()].sort(([a], [b]) => rank(a) - rank(b) || a.localeCompare(b))
184
185
  })
185
186
 
187
+ /** The entry whose detail is shown: the one picked, else the first listed. */
188
+ const selectedId = computed<string | null>(() => {
189
+ const wanted = picked.value ?? queryItem()
190
+ return entries.value.some((e) => e.id === wanted) ? wanted : (groups.value[0]?.[1][0]?.id ?? null)
191
+ })
192
+
186
193
  // A search hiding the picked entry moves the detail to the first one shown.
187
194
  watch(groups, (shown) => {
188
195
  if (loading.value || shown.length === 0) return
189
196
  if (!shown.some(([, items]) => items.some((e) => e.id === selectedId.value))) {
190
- selectedId.value = shown[0]![1][0]!.id
197
+ picked.value = shown[0]![1][0]!.id
191
198
  }
192
199
  })
193
200
 
@@ -200,7 +207,7 @@ watch(selectedId, (id) => {
200
207
 
201
208
  /** Below the two-column width the detail sits under the list: bring it into view. */
202
209
  async function select(id: string) {
203
- selectedId.value = id
210
+ picked.value = id
204
211
  await nextTick()
205
212
  if (detail.value && list.value && detail.value.offsetTop > list.value.offsetTop) {
206
213
  detail.value.scrollIntoView({ behavior: 'smooth', block: 'start' })
@@ -240,7 +247,7 @@ async function setEnabled(enabled: boolean) {
240
247
  method: 'PUT',
241
248
  body: { enabled },
242
249
  })
243
- entry.enabled = enabled
250
+ replaceEntry(entry.id, { enabled })
244
251
  toast.add({
245
252
  title: t(enabled ? 'dms_automation.library.enabledToast' : 'dms_automation.library.disabledToast', {
246
253
  name: processI18n(entry.name),
@@ -23,7 +23,6 @@ const { t } = useI18n()
23
23
  const triggerNodeId = ref<string | undefined>(undefined)
24
24
  const payload = ref('{}')
25
25
  const source = ref<string | null>(null)
26
- const loadingPayload = ref(false)
27
26
  const submitting = ref(false)
28
27
  const PAYLOAD_ID = 'run-now-payload'
29
28
  const ROW = { layout: 'stack', spacing: 'list', inset: false } as const
@@ -37,33 +36,43 @@ const triggerItems = computed(() =>
37
36
  props.triggers.map((trigger) => ({ label: processText(trigger.text), value: trigger.nodeId ?? '' })),
38
37
  )
39
38
 
40
- async function loadPayload() {
41
- loadingPayload.value = true
42
- try {
43
- const query = triggerNodeId.value ? `?triggerNodeId=${encodeURIComponent(triggerNodeId.value)}` : ''
44
- const res = await $authFetch<{ last: { runId: string; payload: unknown } | null }>(
45
- `${props.apiUrl}/procedures/${props.procedureId}/last-payload${query}`,
46
- )
47
- payload.value = JSON.stringify(res.last?.payload ?? {}, null, 2)
48
- source.value = res.last?.runId ?? null
49
- } catch {
50
- payload.value = '{}'
51
- source.value = null
52
- } finally {
53
- loadingPayload.value = false
54
- }
39
+ interface LastPayload {
40
+ last: { runId: string; payload: unknown } | null
55
41
  }
56
42
 
43
+ // The last real payload of the trigger picked, read once the dialog opens and
44
+ // again when another trigger is picked. Under a key of its own, apart from the
45
+ // builder dock's read of the same URL: each copies its answers into its own
46
+ // editable field. The page's refreshes leave the draft payload alone.
47
+ const lastPayloadRead = useApiData<LastPayload>(
48
+ () => `dms-automation-run-now-payload:${props.procedureId}:${triggerNodeId.value ?? ''}`,
49
+ ({ $authFetch, signal }) =>
50
+ $authFetch<LastPayload>(`${props.apiUrl}/procedures/${props.procedureId}/last-payload`, {
51
+ query: triggerNodeId.value ? { triggerNodeId: triggerNodeId.value } : {},
52
+ signal,
53
+ }),
54
+ { immediate: false, refreshOnPageRefresh: false },
55
+ )
56
+ const loadingPayload = computed(() => lastPayloadRead.pending.value)
57
+
58
+ // Each answer, or failure, fills the payload in.
59
+ watch(
60
+ () => lastPayloadRead.status.value,
61
+ (status) => {
62
+ if (status !== 'success' && status !== 'error') return
63
+ const last = status === 'error' ? null : (lastPayloadRead.data.value?.last ?? null)
64
+ payload.value = JSON.stringify(last?.payload ?? {}, null, 2)
65
+ source.value = last?.runId ?? null
66
+ },
67
+ )
68
+
57
69
  watch(open, (isOpen) => {
58
70
  if (!isOpen) return
59
71
  fieldErrors.clear()
60
72
  triggerNodeId.value = props.triggers.find((tr) => tr.typeId === 'manual')?.nodeId ?? props.triggers[0]?.nodeId
61
- void loadPayload()
73
+ void lastPayloadRead.execute()
62
74
  })
63
75
  watch(payload, () => fieldErrors.clear('payload'))
64
- watch(triggerNodeId, () => {
65
- if (open.value) void loadPayload()
66
- })
67
76
 
68
77
  async function submit() {
69
78
  let body: unknown