@rise-x/apps-sdk 0.16.4 → 0.20.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 (62) hide show
  1. package/API.md +141 -0
  2. package/README.md +299 -10
  3. package/build/accessors.d.ts +2 -1
  4. package/build/accessors.js +10 -0
  5. package/build/breadcrumb.d.ts +49 -0
  6. package/build/breadcrumb.js +58 -0
  7. package/build/connectors/types.d.ts +8 -0
  8. package/build/connectors/types.js +36 -4
  9. package/build/connectors/work.js +30 -1
  10. package/build/index.d.ts +3 -1
  11. package/build/index.js +7 -1
  12. package/build/live/index.d.ts +43 -0
  13. package/build/live/index.js +183 -0
  14. package/build/liveChannel.d.ts +32 -0
  15. package/build/liveChannel.js +60 -0
  16. package/build/mockShell.d.ts +2 -0
  17. package/build/mockShell.js +1 -0
  18. package/build/query/index.d.ts +1 -0
  19. package/build/query/index.js +4 -2
  20. package/build/query/live.d.ts +14 -0
  21. package/build/query/live.js +115 -0
  22. package/build/shell/index.d.ts +2 -1
  23. package/build/shell/installShellBridge.d.ts +15 -1
  24. package/build/shell/installShellBridge.js +7 -1
  25. package/build/shell/liveHub.d.ts +25 -0
  26. package/build/shell/liveHub.js +201 -0
  27. package/build/shellBridge.d.ts +116 -1
  28. package/build/shellBridge.js +5 -1
  29. package/build/ui/classes.json +42 -42
  30. package/build/ui/components/ai.d.ts +68 -4
  31. package/build/ui/components/alert-dialog.d.ts +4 -4
  32. package/build/ui/components/app-frame.d.ts +47 -7
  33. package/build/ui/components/asset-pill.d.ts +8 -0
  34. package/build/ui/components/badge.d.ts +35 -2
  35. package/build/ui/components/button.d.ts +4 -4
  36. package/build/ui/components/calendar.d.ts +2 -2
  37. package/build/ui/components/chat-input.d.ts +4 -4
  38. package/build/ui/components/data-table.d.ts +128 -13
  39. package/build/ui/components/data-view.d.ts +94 -0
  40. package/build/ui/components/date-picker.d.ts +23 -1
  41. package/build/ui/components/file-upload.d.ts +9 -1
  42. package/build/ui/components/filter-bar.d.ts +89 -0
  43. package/build/ui/components/floating-panel.d.ts +53 -0
  44. package/build/ui/components/item.d.ts +1 -1
  45. package/build/ui/components/journey.d.ts +165 -0
  46. package/build/ui/components/nav.d.ts +52 -2
  47. package/build/ui/components/page-header.d.ts +8 -8
  48. package/build/ui/components/person.d.ts +14 -0
  49. package/build/ui/components/record-summary.d.ts +17 -0
  50. package/build/ui/components/search-dialog.d.ts +56 -0
  51. package/build/ui/components/statistic.d.ts +2 -1
  52. package/build/ui/components/table.d.ts +10 -3
  53. package/build/ui/components/toggle.d.ts +1 -1
  54. package/build/ui/demo.html +45923 -25459
  55. package/build/ui/index.d.ts +8 -0
  56. package/build/ui/standalone.js +984 -69
  57. package/build/ui/styles.css +1 -1
  58. package/build/ui/theme.css +11 -6
  59. package/live/package.json +8 -0
  60. package/package.json +10 -2
  61. package/template/AGENTS.md +6 -0
  62. package/template/src/App.tsx +4 -1
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ // Keeps this SDK's query cache current from the host's live events, so an app hears about other
3
+ // people's changes instead of polling. Does nothing on a host without live events, so keep
4
+ // the app's own refresh for those hosts.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useLiveInvalidation = useLiveInvalidation;
7
+ const react_1 = require("react");
8
+ const accessors_1 = require("../accessors");
9
+ const context_1 = require("./context");
10
+ const keys_1 = require("./keys");
11
+ const shared_1 = require("./shared");
12
+ // A form saved one field at a time is one event per field: collect a burst, refresh once.
13
+ const BATCH_MS = 300;
14
+ /**
15
+ * Marks this SDK's queries stale when a live event says what they hold changed: the work item's
16
+ * or asset's own queries and the listings (only the ones on screen refetch). A delete drops the
17
+ * item's queries, and a `resync` marks every work and asset query stale. Call it once, near the
18
+ * root of the app.
19
+ */
20
+ function useLiveInvalidation(options = {}) {
21
+ const client = (0, context_1.useAppQueryClient)();
22
+ // A key rather than the array, so an inline `flowOriginIds: [...]` doesn't subscribe each render.
23
+ const flowsKey = options.flowOriginIds?.join("\n");
24
+ (0, react_1.useEffect)(() => {
25
+ const live = (0, accessors_1.getShellLive)();
26
+ if (!live)
27
+ return;
28
+ const flows = flowsKey === undefined ? undefined : new Set(flowsKey.split("\n"));
29
+ // Id → whether it was deleted. A delete sticks over a later change in the same burst.
30
+ let works = new Map();
31
+ let assets = new Map();
32
+ let timer = null;
33
+ const mark = (ids, id, deleted) => ids.set(id, ids.get(id) || deleted);
34
+ const flush = () => {
35
+ timer = null;
36
+ invalidateChanges(client, works, assets);
37
+ works = new Map();
38
+ assets = new Map();
39
+ };
40
+ const off = live.subscribe((event) => {
41
+ switch (event.type) {
42
+ case "resync": {
43
+ const envId = (0, shared_1.getLiveEnvId)();
44
+ void client.invalidateQueries({
45
+ queryKey: keys_1.queryKeys.work.all(envId),
46
+ });
47
+ void client.invalidateQueries({
48
+ queryKey: keys_1.queryKeys.assets.all(envId),
49
+ });
50
+ return;
51
+ }
52
+ case "workData":
53
+ if (flows && event.flowOriginId && !flows.has(event.flowOriginId)) {
54
+ return;
55
+ }
56
+ mark(works, event.workId, false);
57
+ break;
58
+ case "workUpdated":
59
+ case "workDeleted":
60
+ mark(works, event.workId, event.type === "workDeleted");
61
+ break;
62
+ case "assetUpdated":
63
+ case "assetDeleted":
64
+ mark(assets, event.assetId, event.type === "assetDeleted");
65
+ break;
66
+ default:
67
+ return;
68
+ }
69
+ timer ?? (timer = setTimeout(flush, BATCH_MS));
70
+ });
71
+ return () => {
72
+ off();
73
+ if (timer !== null)
74
+ clearTimeout(timer);
75
+ };
76
+ }, [client, flowsKey]);
77
+ }
78
+ // The same keys the mutation hooks invalidate after an app's own write.
79
+ function invalidateChanges(client, works, assets) {
80
+ const envId = (0, shared_1.getLiveEnvId)();
81
+ const refresh = (queryKey, deleted) => {
82
+ if (deleted)
83
+ client.removeQueries({ queryKey });
84
+ else
85
+ void client.invalidateQueries({ queryKey });
86
+ };
87
+ for (const [workId, deleted] of works) {
88
+ refresh(keys_1.queryKeys.work.detail(envId, workId), deleted);
89
+ refresh(keys_1.queryKeys.work.dataAll(envId, workId), deleted);
90
+ refresh(keys_1.queryKeys.work.audit(envId, workId), deleted);
91
+ }
92
+ for (const [assetId, deleted] of assets) {
93
+ refresh(keys_1.queryKeys.assets.detail(envId, assetId), deleted);
94
+ }
95
+ // Listings project data, and a new or deleted item changes which rows they hold.
96
+ const listings = [
97
+ ...(works.size
98
+ ? [
99
+ keys_1.queryKeys.work.allRows(envId),
100
+ keys_1.queryKeys.work.searchAll(envId),
101
+ keys_1.queryKeys.work.relatedAll(envId),
102
+ ]
103
+ : []),
104
+ ...(assets.size
105
+ ? [
106
+ keys_1.queryKeys.assets.allRows(envId),
107
+ keys_1.queryKeys.assets.searchAll(envId),
108
+ keys_1.queryKeys.assets.quickSearchAll(envId),
109
+ keys_1.queryKeys.assets.relatedAll(envId),
110
+ ]
111
+ : []),
112
+ ];
113
+ for (const queryKey of listings)
114
+ void client.invalidateQueries({ queryKey });
115
+ }
@@ -1 +1,2 @@
1
- export { installShellBridge, getMutableShell, type InstallShellBridgeOptions, type MutableShell, } from './installShellBridge';
1
+ export { installShellBridge, getMutableShell, type InstallShellBridgeOptions, type MutableShell, } from "./installShellBridge";
2
+ export type { LiveHubConnection } from "./liveHub";
@@ -1,13 +1,27 @@
1
- import type { DianaShell, ShellEnvironment, ShellNavigate, ShellUser } from "../shellBridge";
1
+ import type { DianaShell, LiveStatus, ShellEnvironment, ShellNavigate, ShellUser } from "../shellBridge";
2
+ import { type LiveHubConnection } from "./liveHub";
2
3
  export interface MutableShell extends DianaShell {
3
4
  _setUser(user: ShellUser | null): void;
4
5
  _setEnvironment(env: ShellEnvironment | null): void;
5
6
  _setNavigate(fn: ShellNavigate): void;
7
+ /**
8
+ * Report the host's hub connection, or null while there is none, and the state it is in. Call
9
+ * it again whenever either changes. The bridge maps the hub's events for apps, moves their
10
+ * subscriptions to a new connection, and turns the state into the status every host reports.
11
+ */
12
+ _setLiveConnection(connection: LiveHubConnection | null, state: LiveStatus): void;
6
13
  }
7
14
  export type InstallShellBridgeOptions = Pick<DianaShell, "getApi" | "getApiV4"> & {
8
15
  getAi?: DianaShell["getAi"];
9
16
  getOffline?: DianaShell["getOffline"];
10
17
  getCache?: DianaShell["getCache"];
18
+ /**
19
+ * Whether this host has a hub connection to wire (through `_setLiveConnection`). Defaults to
20
+ * true: `getLive()` then answers a channel whose status is `connecting` until the host wires a
21
+ * connection. A host with no hub passes false, and `getLive()` answers null, so an app keeps
22
+ * its own reads rather than wait for a connection that never comes.
23
+ */
24
+ live?: boolean;
11
25
  };
12
26
  export declare function installShellBridge(options: InstallShellBridgeOptions): void;
13
27
  export declare function getMutableShell(): MutableShell | null;
@@ -4,6 +4,7 @@ exports.installShellBridge = installShellBridge;
4
4
  exports.getMutableShell = getMutableShell;
5
5
  const react_router_dom_1 = require("react-router-dom");
6
6
  const shellBridge_1 = require("../shellBridge");
7
+ const liveHub_1 = require("./liveHub");
7
8
  function createSubscribers() {
8
9
  const listeners = new Set();
9
10
  return {
@@ -56,12 +57,13 @@ function isEqualEnvironment(a, b) {
56
57
  function installShellBridge(options) {
57
58
  if (window.__DIANA_SHELL__)
58
59
  return;
59
- const { getApi, getApiV4, getAi = () => null, getOffline = () => null, getCache = () => null, } = options;
60
+ const { getApi, getApiV4, getAi = () => null, getOffline = () => null, getCache = () => null, live = true, } = options;
60
61
  let currentUser = null;
61
62
  let currentEnvironment = null;
62
63
  let navigate = defaultNavigate;
63
64
  const userSubs = createSubscribers();
64
65
  const envSubs = createSubscribers();
66
+ const liveHub = live ? (0, liveHub_1.createLiveHub)() : null;
65
67
  // Stable shim so apps can hold onto shell.navigate across re-renders —
66
68
  // internally delegates to whichever NavigateFunction the router currently owns.
67
69
  // Branch on typeof to pick the right overload instead of casting.
@@ -82,6 +84,7 @@ function installShellBridge(options) {
82
84
  getAi,
83
85
  getOffline,
84
86
  getCache,
87
+ getLive: () => liveHub?.api ?? null,
85
88
  navigate: navigateShim,
86
89
  _setUser(user) {
87
90
  if (isEqualUser(currentUser, user))
@@ -98,6 +101,9 @@ function installShellBridge(options) {
98
101
  _setNavigate(fn) {
99
102
  navigate = fn;
100
103
  },
104
+ _setLiveConnection(connection, state) {
105
+ liveHub?.update(connection, state);
106
+ },
101
107
  };
102
108
  window.__DIANA_SHELL__ = shell;
103
109
  }
@@ -0,0 +1,25 @@
1
+ import type { LiveApi, LiveEvent, LiveStatus } from "../shellBridge";
2
+ /** The part of a SignalR hub connection the bridge uses. A `HubConnection` fits as it is. */
3
+ export interface LiveHubConnection {
4
+ on(method: string, handler: (...args: unknown[]) => void): void;
5
+ off(method: string, handler: (...args: unknown[]) => void): void;
6
+ invoke(method: string, ...args: unknown[]): Promise<unknown>;
7
+ }
8
+ /** The hub events apps see, by their wire names. Everything else on the connection is the host's. */
9
+ export declare const LIVE_HUB_EVENTS: readonly ["DataPatch", "DataObjectPatch", "WorkUpdated", "WorkDeleted", "EntityUpdated", "EntityDeleted", "ComponentLockUpdated"];
10
+ /**
11
+ * Turns one hub event into the event an app sees. Null for an event that is not for apps (a
12
+ * patch to a resource that is not a work item) or a payload that is not what the platform sends:
13
+ * a push from the server must never throw into the connection.
14
+ */
15
+ export declare function mapLiveEvent(name: string, payload: unknown): LiveEvent | null;
16
+ export interface LiveHub {
17
+ readonly api: LiveApi;
18
+ /**
19
+ * Report the connection the host holds now, or null while there is none, and the state it is
20
+ * in. Call it again whenever either changes.
21
+ */
22
+ update(connection: LiveHubConnection | null, state: LiveStatus): void;
23
+ }
24
+ /** The live channel a host's bridge offers, fed from whichever hub connection the host holds. */
25
+ export declare function createLiveHub(): LiveHub;
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIVE_HUB_EVENTS = void 0;
4
+ exports.mapLiveEvent = mapLiveEvent;
5
+ exports.createLiveHub = createLiveHub;
6
+ // The host side of the live channel. Every host goes through this one module, so an app cannot
7
+ // tell which host it runs in: one mapping from the hub's events to `LiveEvent`s, one rule for the
8
+ // status values, one way to send a lock. A host only reports its connection and that
9
+ // connection's state (`_setLiveConnection` on the mutable shell).
10
+ const liveChannel_1 = require("../liveChannel");
11
+ /** The hub events apps see, by their wire names. Everything else on the connection is the host's. */
12
+ exports.LIVE_HUB_EVENTS = [
13
+ "DataPatch",
14
+ "DataObjectPatch",
15
+ "WorkUpdated",
16
+ "WorkDeleted",
17
+ "EntityUpdated",
18
+ "EntityDeleted",
19
+ "ComponentLockUpdated",
20
+ ];
21
+ // The wire carries the operation's enum name. A Map, so a name like "constructor" cannot match.
22
+ const OPERATIONS = new Map([
23
+ ["Set", "set"],
24
+ ["Push", "push"],
25
+ ["Pull", "pull"],
26
+ ["Unset", "unset"],
27
+ ["AddToSet", "addToSet"],
28
+ ["Merge", "merge"],
29
+ ]);
30
+ // A write that names no flow sends the empty id, which matches no flow an app holds.
31
+ const EMPTY_ID = "00000000-0000-0000-0000-000000000000";
32
+ const isWire = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
33
+ /** A non-empty string, or undefined. */
34
+ const text = (value) => typeof value === "string" && value !== "" ? value : undefined;
35
+ const idOf = (value) => {
36
+ const id = text(value);
37
+ return id === EMPTY_ID ? undefined : id;
38
+ };
39
+ // An absent field has to be absent on the event, not present and undefined.
40
+ const compact = (event) => Object.fromEntries(Object.entries(event).filter(([, value]) => value !== undefined));
41
+ function workData(p, withValue) {
42
+ if (p.resourceType !== "Work")
43
+ return null;
44
+ const workId = text(p.resourceId);
45
+ if (!workId || typeof p.path !== "string")
46
+ return null;
47
+ const operation = typeof p.operation === "string" ? OPERATIONS.get(p.operation) : undefined;
48
+ // An operation outside the SDK's vocabulary (an increment, a replace) still changed the work,
49
+ // but what travels is not the new value: report the path only.
50
+ const hasValue = withValue && operation !== undefined;
51
+ return compact({
52
+ type: "workData",
53
+ workId,
54
+ flowOriginId: idOf(p.originId),
55
+ // A write with no path wrote the whole document.
56
+ path: p.path.trim() === "" ? "$" : p.path,
57
+ operation,
58
+ hasValue,
59
+ value: hasValue && operation !== "unset" ? p.value : undefined,
60
+ userId: text(p.userId),
61
+ updateId: text(p.updateId),
62
+ ticks: typeof p.ticks === "number" ? p.ticks : undefined,
63
+ });
64
+ }
65
+ function lock(p) {
66
+ if (p.resourceType !== "Work")
67
+ return null;
68
+ const workId = text(p.resourceId);
69
+ const userId = text(p.userId);
70
+ // An unlock may carry an empty component id, and dropping it would strand the lock.
71
+ if (!workId || !userId || typeof p.componentId !== "string")
72
+ return null;
73
+ return compact({
74
+ type: "lock",
75
+ workId,
76
+ userId,
77
+ displayName: text(p.displayName),
78
+ componentId: p.componentId,
79
+ dataPath: text(p.dataPath),
80
+ at: text(p.utcTime),
81
+ locked: p.isLocked === true || p.isLocked === "true",
82
+ });
83
+ }
84
+ /**
85
+ * Turns one hub event into the event an app sees. Null for an event that is not for apps (a
86
+ * patch to a resource that is not a work item) or a payload that is not what the platform sends:
87
+ * a push from the server must never throw into the connection.
88
+ */
89
+ function mapLiveEvent(name, payload) {
90
+ switch (name) {
91
+ case "DataPatch":
92
+ return isWire(payload) ? workData(payload, true) : null;
93
+ case "DataObjectPatch":
94
+ return isWire(payload) ? workData(payload, false) : null;
95
+ case "WorkUpdated": {
96
+ if (!isWire(payload))
97
+ return null;
98
+ const workId = text(payload.id);
99
+ if (!workId)
100
+ return null;
101
+ return compact({
102
+ type: "workUpdated",
103
+ workId,
104
+ displayName: text(payload.displayName),
105
+ });
106
+ }
107
+ case "WorkDeleted": {
108
+ const workId = text(payload);
109
+ return workId ? { type: "workDeleted", workId } : null;
110
+ }
111
+ case "EntityUpdated": {
112
+ if (!isWire(payload))
113
+ return null;
114
+ const assetId = text(payload.id);
115
+ if (!assetId)
116
+ return null;
117
+ return compact({
118
+ type: "assetUpdated",
119
+ assetId,
120
+ displayName: text(payload.displayName),
121
+ });
122
+ }
123
+ case "EntityDeleted": {
124
+ const assetId = text(payload);
125
+ return assetId ? { type: "assetDeleted", assetId } : null;
126
+ }
127
+ case "ComponentLockUpdated":
128
+ return isWire(payload) ? lock(payload) : null;
129
+ default:
130
+ return null;
131
+ }
132
+ }
133
+ // How many recent write ids the hub remembers, to drop a second delivery of the same write.
134
+ const RECENT_UPDATES = 50;
135
+ /** The live channel a host's bridge offers, fed from whichever hub connection the host holds. */
136
+ function createLiveHub() {
137
+ let connection = null;
138
+ let hasConnected = false;
139
+ const recent = [];
140
+ const channel = (0, liveChannel_1.createLiveChannel)({
141
+ // Over the hub in every host, never HTTP: a lock is advisory, so without a connection the
142
+ // call rejects and the app carries on. `invoke` rather than `send`: the hub answers once it has
143
+ // handled the lock, so a failure reaches the caller instead of vanishing.
144
+ setComponentLock: async ({ workId, componentId, dataPath, locked }) => {
145
+ if (!connection || channel.api.getStatus() !== "connected") {
146
+ throw new Error("[@rise-x/apps-sdk] cannot send a component lock: the live connection is not connected");
147
+ }
148
+ await connection.invoke(locked ? "LockWorkComponent" : "UnlockWorkComponent", { workId, componentId, dataPath: dataPath ?? "" });
149
+ },
150
+ });
151
+ // A user named on a work item who also holds access through a group gets one write twice, as a
152
+ // DataPatch and a DataObjectPatch with the same updateId. The first one wins.
153
+ const isRepeat = (event) => {
154
+ if (event.type !== "workData" || !event.updateId)
155
+ return false;
156
+ if (recent.includes(event.updateId))
157
+ return true;
158
+ recent.push(event.updateId);
159
+ if (recent.length > RECENT_UPDATES)
160
+ recent.shift();
161
+ return false;
162
+ };
163
+ // One handler per hub event, moved from connection to connection.
164
+ const handlers = exports.LIVE_HUB_EVENTS.map((name) => [
165
+ name,
166
+ (...args) => {
167
+ const event = mapLiveEvent(name, args[0]);
168
+ if (event && !isRepeat(event))
169
+ channel.emit(event);
170
+ },
171
+ ]);
172
+ // `connecting` until the first connection, `reconnecting` while retrying one that was up,
173
+ // `disconnected` after a close (until a connection is back, whatever the host retries meanwhile).
174
+ const normalise = (state) => {
175
+ if (state === "connected")
176
+ return "connected";
177
+ if (!hasConnected)
178
+ return "connecting";
179
+ if (state !== "connecting")
180
+ return state;
181
+ const current = channel.api.getStatus();
182
+ return current === "connected" ? "reconnecting" : current;
183
+ };
184
+ return {
185
+ api: channel.api,
186
+ update(next, state) {
187
+ const previous = connection;
188
+ if (next !== previous) {
189
+ for (const [name, handler] of handlers)
190
+ previous?.off(name, handler);
191
+ for (const [name, handler] of handlers)
192
+ next?.on(name, handler);
193
+ connection = next;
194
+ }
195
+ const reported = next ? state : "disconnected";
196
+ channel.setStatus(normalise(reported));
197
+ if (reported === "connected")
198
+ hasConnected = true;
199
+ },
200
+ };
201
+ }
@@ -243,6 +243,115 @@ export interface OfflineApi {
243
243
  */
244
244
  subscribeFlowDownload(flowOriginId: string, listener: () => void): ShellEventUnsubscribe;
245
245
  }
246
+ /**
247
+ * The state of the host's live connection, the same in every host: `connecting` until the first
248
+ * connection is up, `reconnecting` while the host retries one that dropped, `disconnected` after
249
+ * it closed, and `connected` while events arrive. Coming back to `connected` after an earlier
250
+ * connection also sends one `resync` event.
251
+ */
252
+ export type LiveStatus = "connecting" | "connected" | "reconnecting" | "disconnected";
253
+ /**
254
+ * A user's component lock on a work item: the platform's record that they have an editor open on
255
+ * part of it. The platform keeps one lock per user per work, so a user's second lock on a work
256
+ * replaces the first, whichever editor (an app's or the host's own) took it.
257
+ */
258
+ export interface WorkComponentLock {
259
+ workId: string;
260
+ userId: string;
261
+ displayName?: string;
262
+ /** The id the locking editor identified itself with. */
263
+ componentId: string;
264
+ dataPath?: string;
265
+ /** When the lock was taken or last refreshed, as an ISO 8601 string. */
266
+ at?: string;
267
+ }
268
+ /**
269
+ * A platform change, in the SDK's own names: the host translates what its connection hears, so
270
+ * an app never depends on the platform's wire names.
271
+ *
272
+ * Events are best-effort. The platform does not replay what was sent while the connection was
273
+ * down, so a `resync` follows every reconnect: re-read what you hold. Events arrive for every
274
+ * work item and asset the user can see, in every ecosystem they belong to, so filter by the ids
275
+ * and flows you hold. Treat an event as a reason to re-read, never as the data.
276
+ */
277
+ export type LiveEvent =
278
+ /**
279
+ * One write to a work item's data document. `hasValue` is false when the platform reported
280
+ * only that the path changed: always for an object or list value, for a user who has access
281
+ * through a group, and for an operation outside {@link WorkPatchOperationName}. Read the path
282
+ * to learn the new value then.
283
+ */
284
+ {
285
+ type: "workData";
286
+ workId: string;
287
+ /** The work's flow origin id, when the write named one. */
288
+ flowOriginId?: string;
289
+ /** The `$`-rooted JSON path written, e.g. `$.section.field`. */
290
+ path: string;
291
+ /** Absent for an operation outside this vocabulary. */
292
+ operation?: WorkPatchOperationName;
293
+ hasValue: boolean;
294
+ /** What was written, when `hasValue` is true. Absent for an `unset`. */
295
+ value?: unknown;
296
+ /** The user who wrote. Your own writes come back too. */
297
+ userId?: string;
298
+ updateId?: string;
299
+ ticks?: number;
300
+ }
301
+ /**
302
+ * The work item changed in a way the platform did not itemise: created, submitted, moved to
303
+ * another step, written in bulk. Only its identity travels, so read the work to see the result.
304
+ */
305
+ | {
306
+ type: "workUpdated";
307
+ workId: string;
308
+ displayName?: string;
309
+ } | {
310
+ type: "workDeleted";
311
+ workId: string;
312
+ }
313
+ /** An asset was created or changed. Read it to see the result. */
314
+ | {
315
+ type: "assetUpdated";
316
+ assetId: string;
317
+ displayName?: string;
318
+ } | {
319
+ type: "assetDeleted";
320
+ assetId: string;
321
+ }
322
+ /** A user took (`locked: true`) or released a component lock on a work item. */
323
+ | ({
324
+ type: "lock";
325
+ locked: boolean;
326
+ } & WorkComponentLock)
327
+ /** The connection came back, so changes may have been missed: re-read what you hold, once. */
328
+ | {
329
+ type: "resync";
330
+ };
331
+ export interface SetComponentLockArgs {
332
+ workId: string;
333
+ /** A GUID that identifies the editor. Use the same one for the same editor in every session. */
334
+ componentId: string;
335
+ dataPath?: string;
336
+ /** `false` releases the user's lock on the work. */
337
+ locked: boolean;
338
+ }
339
+ /**
340
+ * Live platform events and presence, over the host's existing connection. An app never opens a
341
+ * connection of its own.
342
+ */
343
+ export interface LiveApi {
344
+ getStatus(): LiveStatus;
345
+ /** Fires when the status changes, with the new one. */
346
+ subscribeStatus(listener: (status: LiveStatus) => void): ShellEventUnsubscribe;
347
+ /** Receive every event until the returned function is called. */
348
+ subscribe(listener: (event: LiveEvent) => void): ShellEventUnsubscribe;
349
+ /**
350
+ * Take or release the user's component lock on a work item, so others see who is editing.
351
+ * Advisory: it never gates a write. Rejects while the connection is not `connected`.
352
+ */
353
+ setComponentLock(args: SetComponentLockArgs): Promise<void>;
354
+ }
246
355
  export interface DianaShell {
247
356
  version: number;
248
357
  getUser(): ShellUser | null;
@@ -258,6 +367,12 @@ export interface DianaShell {
258
367
  * that as "no local copy exists", so an app degrades to network-only rather than throwing.
259
368
  */
260
369
  getCache(): CacheApi | null;
370
+ /**
371
+ * Live platform events and presence, or null on a host that predates bridge v5 or offers no live
372
+ * events. A connection that is only down still answers, with status `disconnected`. Read it
373
+ * through `getShellLive()` or the `@rise-x/apps-sdk/live` hooks, which handle both.
374
+ */
375
+ getLive(): LiveApi | null;
261
376
  navigate: ShellNavigate;
262
377
  }
263
378
  declare global {
@@ -265,4 +380,4 @@ declare global {
265
380
  __DIANA_SHELL__?: DianaShell;
266
381
  }
267
382
  }
268
- export declare const SHELL_BRIDGE_VERSION = 4;
383
+ export declare const SHELL_BRIDGE_VERSION = 5;
@@ -8,4 +8,8 @@ exports.SHELL_BRIDGE_VERSION = void 0;
8
8
  // to call rather than comparing versions: `typeof offline.queueWorkDataUpdate === 'function'`.
9
9
  // (v3 added getAi(); v2 added the V4ApiKey arg to getApiV4.)
10
10
  // requireShell() compares the host's shell.version against this constant and warns once on mismatch.
11
- exports.SHELL_BRIDGE_VERSION = 4;
11
+ // Bumped to 5: adds getLive(), live platform events and component locks (LiveApi) over the host's
12
+ // own connection, so apps stop polling. Additive: a v4-built app keeps working on a v5 host, and a
13
+ // v5 app on an older host finds no getLive, so getShellLive() answers null and the app keeps its
14
+ // own reads.
15
+ exports.SHELL_BRIDGE_VERSION = 5;