@isi-ui7/bos7-shared 0.2.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.
Files changed (108) hide show
  1. package/dist/api.d.ts +4 -0
  2. package/dist/auth7/client.d.ts +26 -0
  3. package/dist/auth7/delegated-proxy.d.ts +33 -0
  4. package/dist/auth7/hooks/useAuth.d.ts +10 -0
  5. package/dist/auth7/hooks/useSession.d.ts +12 -0
  6. package/dist/auth7/index.d.ts +12 -0
  7. package/dist/auth7/provider.d.ts +13 -0
  8. package/dist/auth7/scope-guard.d.ts +5 -0
  9. package/dist/auth7/service-account.d.ts +2 -0
  10. package/dist/auth7/token-exchange.d.ts +11 -0
  11. package/dist/auth7/types.d.ts +63 -0
  12. package/dist/backend.d.ts +20 -0
  13. package/dist/crud-components.d.ts +47 -0
  14. package/dist/crud-hooks.d.ts +15 -0
  15. package/dist/crud-types.d.ts +86 -0
  16. package/dist/data-table/cursor-adapter.d.ts +74 -0
  17. package/dist/event-bus/index.d.ts +20 -0
  18. package/dist/event-bus/useEventBus.d.ts +21 -0
  19. package/dist/event-bus.d.ts +1 -0
  20. package/dist/export.d.ts +7 -0
  21. package/dist/form-layout.d.ts +39 -0
  22. package/dist/form-numeric.d.ts +35 -0
  23. package/dist/form-renderer-utils.d.ts +10 -0
  24. package/dist/form-renderer.d.ts +18 -0
  25. package/dist/form-rules.d.ts +12 -0
  26. package/dist/form-types.d.ts +130 -0
  27. package/dist/html2canvas.esm-d2sM-0Wm.js +4870 -0
  28. package/dist/i18n.d.ts +35 -0
  29. package/dist/index.d.ts +18 -0
  30. package/dist/index.es-Bylk5fh-.js +5649 -0
  31. package/dist/index.js +20779 -0
  32. package/dist/jspdf.es.min-Dzm5j8wC.js +9977 -0
  33. package/dist/jspdf.plugin.autotable-DcntYaes.js +1078 -0
  34. package/dist/modal-layout.d.ts +45 -0
  35. package/dist/nats/client.d.ts +54 -0
  36. package/dist/notif7.d.ts +21 -0
  37. package/dist/notification/routing.d.ts +4 -0
  38. package/dist/notifications-bff.d.ts +22 -0
  39. package/dist/observability/otel-init.d.ts +1 -0
  40. package/dist/page-layout.d.ts +24 -0
  41. package/dist/purify.es-CiEWEeUM.js +605 -0
  42. package/dist/shell/app-shell-layout.d.ts +70 -0
  43. package/dist/shell/branch.d.ts +6 -0
  44. package/dist/shell/interaction.d.ts +2 -0
  45. package/dist/shell/provider.d.ts +15 -0
  46. package/dist/style-contract.d.ts +72 -0
  47. package/dist/types/core.d.ts +39 -0
  48. package/dist/types/notification.d.ts +30 -0
  49. package/dist/workflow/api-client.d.ts +2 -0
  50. package/dist/workflow/backend.d.ts +9 -0
  51. package/dist/workflow/crud-client.d.ts +3 -0
  52. package/dist/workflow/notif7.d.ts +6 -0
  53. package/dist/workflow/starter.d.ts +44 -0
  54. package/dist/workflow/use-crud-form.d.ts +27 -0
  55. package/dist/workflow/use-workflow-tracker.d.ts +40 -0
  56. package/package.json +92 -0
  57. package/src/api.ts +40 -0
  58. package/src/auth7/client.ts +248 -0
  59. package/src/auth7/delegated-proxy.ts +80 -0
  60. package/src/auth7/hooks/useAuth.ts +21 -0
  61. package/src/auth7/hooks/useSession.ts +75 -0
  62. package/src/auth7/index.ts +14 -0
  63. package/src/auth7/provider.tsx +256 -0
  64. package/src/auth7/scope-guard.ts +54 -0
  65. package/src/auth7/service-account.ts +71 -0
  66. package/src/auth7/token-exchange.ts +125 -0
  67. package/src/auth7/types.ts +72 -0
  68. package/src/backend.ts +96 -0
  69. package/src/crud-components.tsx +580 -0
  70. package/src/crud-hooks.test.ts +32 -0
  71. package/src/crud-hooks.ts +31 -0
  72. package/src/crud-types.ts +64 -0
  73. package/src/data-table/cursor-adapter.ts +239 -0
  74. package/src/event-bus/index.ts +90 -0
  75. package/src/event-bus/useEventBus.ts +93 -0
  76. package/src/event-bus.ts +1 -0
  77. package/src/export.ts +62 -0
  78. package/src/form-contract.css +52 -0
  79. package/src/form-layout.tsx +90 -0
  80. package/src/form-numeric.ts +173 -0
  81. package/src/form-renderer-utils.ts +139 -0
  82. package/src/form-renderer.tsx +624 -0
  83. package/src/form-rules.ts +54 -0
  84. package/src/form-types.ts +126 -0
  85. package/src/i18n.tsx +92 -0
  86. package/src/index.ts +20 -0
  87. package/src/modal-layout.tsx +60 -0
  88. package/src/nats/client.ts +130 -0
  89. package/src/notif7.ts +76 -0
  90. package/src/notification/routing.ts +64 -0
  91. package/src/notifications-bff.ts +273 -0
  92. package/src/observability/otel-init.ts +41 -0
  93. package/src/page-layout.tsx +69 -0
  94. package/src/shell/app-shell-layout.tsx +494 -0
  95. package/src/shell/branch.ts +48 -0
  96. package/src/shell/interaction.ts +17 -0
  97. package/src/shell/provider.tsx +34 -0
  98. package/src/style-contract.test.ts +59 -0
  99. package/src/style-contract.ts +132 -0
  100. package/src/types/core.ts +46 -0
  101. package/src/types/notification.ts +35 -0
  102. package/src/workflow/api-client.ts +7 -0
  103. package/src/workflow/backend.ts +53 -0
  104. package/src/workflow/crud-client.ts +43 -0
  105. package/src/workflow/notif7.ts +28 -0
  106. package/src/workflow/starter.ts +153 -0
  107. package/src/workflow/use-crud-form.ts +176 -0
  108. package/src/workflow/use-workflow-tracker.ts +109 -0
@@ -0,0 +1,109 @@
1
+ 'use client';
2
+
3
+ // Client-side hook for list pages that trigger CRUD-via-workflow operations.
4
+ // Subscribes to /api/notifications/stream (notif7 SSE proxy) and fires
5
+ // onComplete when an `instance.completed` event matches a tracked instance ID.
6
+ //
7
+ // The matched ID is workflow7's instance UUID — returned by the BFF as
8
+ // `instance_id` (see respondWfStarted). NOT the idempotency key
9
+ // (`wf_instance_id`); that's a separate UUID used by the service-task layer.
10
+
11
+ import { useCallback, useEffect, useRef } from 'react';
12
+ import { useSSE } from '@isi-ui7/realtime';
13
+
14
+ // notif7's Notification struct has no JSON tags → Go field-name form
15
+ // (EventType, RefID, Payload). Lowercase variants kept for forward-compat
16
+ // if json tags are added later.
17
+ export type WfNotifEvent = {
18
+ EventType?: string;
19
+ event_type?: string;
20
+ RefID?: string;
21
+ ref_id?: string;
22
+ Payload?: { instance_id?: string; workflow_id?: string; result?: string; reason?: string };
23
+ payload?: { instance_id?: string; workflow_id?: string; result?: string; reason?: string };
24
+ };
25
+
26
+ export type WfCompletionResult = {
27
+ status: 'success' | 'error';
28
+ /** Human-readable detail from payload.result (success) or payload.reason (error). */
29
+ message?: string;
30
+ };
31
+
32
+ // Terminal event types dispatched by workflow7. instance.failed is sent when a
33
+ // service task exhausts retries; instance.cancelled when the flow is aborted.
34
+ const DEFAULT_COMPLETION_EVENTS = ['instance.completed', 'instance.cancelled', 'instance.failed'];
35
+ const ERROR_EVENT_TYPES = new Set(['instance.cancelled', 'instance.failed']);
36
+
37
+ export type UseWorkflowTrackerOptions = {
38
+ /** SSE endpoint. Default: `/api/notifications/stream`. */
39
+ streamUrl?: string;
40
+ /** Event types treated as "workflow done". Default: all three terminal event types. */
41
+ completionEventTypes?: string[];
42
+ /** Fired when a tracked instance reaches a terminal state. */
43
+ onComplete?: (instanceId: string, result: WfCompletionResult) => void;
44
+ /** Disable subscription (e.g. when the page is not visible). Default: true. */
45
+ enabled?: boolean;
46
+ };
47
+
48
+ export type UseWorkflowTrackerReturn = {
49
+ /** Register a workflow instance UUID to watch for completion. */
50
+ track: (instanceId: string | undefined) => void;
51
+ /** Read-only snapshot of currently-tracked instance IDs. */
52
+ pending: () => string[];
53
+ };
54
+
55
+ export function useWorkflowTracker(options: UseWorkflowTrackerOptions = {}): UseWorkflowTrackerReturn {
56
+ const {
57
+ streamUrl = '/api/notifications/stream',
58
+ completionEventTypes = DEFAULT_COMPLETION_EVENTS,
59
+ onComplete,
60
+ enabled = true,
61
+ } = options;
62
+
63
+ const pendingRef = useRef<Set<string>>(new Set());
64
+ const onCompleteRef = useRef(onComplete);
65
+ const completionSetRef = useRef<Set<string>>(new Set(completionEventTypes));
66
+
67
+ useEffect(() => {
68
+ onCompleteRef.current = onComplete;
69
+ }, [onComplete]);
70
+ useEffect(() => {
71
+ completionSetRef.current = new Set(completionEventTypes);
72
+ }, [completionEventTypes]);
73
+
74
+ const handleMessage = useCallback((event: MessageEvent) => {
75
+ try {
76
+ const parsed = JSON.parse(event.data) as WfNotifEvent;
77
+ const type = parsed.EventType ?? parsed.event_type ?? '';
78
+ if (!completionSetRef.current.has(type)) return;
79
+ // workflow7's notif7Dispatcher sets RefID = instance UUID and also
80
+ // duplicates it into Payload.instance_id. Read whichever arrives.
81
+ const ref =
82
+ parsed.RefID ??
83
+ parsed.ref_id ??
84
+ parsed.Payload?.instance_id ??
85
+ parsed.payload?.instance_id ??
86
+ '';
87
+ if (!ref || !pendingRef.current.has(ref)) return;
88
+ pendingRef.current.delete(ref);
89
+ const isError = ERROR_EVENT_TYPES.has(type);
90
+ const payload = parsed.Payload ?? parsed.payload;
91
+ const message = isError
92
+ ? (payload?.reason ?? undefined)
93
+ : (payload?.result ?? undefined);
94
+ onCompleteRef.current?.(ref, { status: isError ? 'error' : 'success', message });
95
+ } catch {
96
+ /* ignore non-JSON heartbeats */
97
+ }
98
+ }, []);
99
+
100
+ useSSE(streamUrl, { enabled, onMessage: handleMessage });
101
+
102
+ const track = useCallback((instanceId: string | undefined) => {
103
+ if (instanceId) pendingRef.current.add(instanceId);
104
+ }, []);
105
+
106
+ const pending = useCallback(() => Array.from(pendingRef.current), []);
107
+
108
+ return { track, pending };
109
+ }