@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.
- package/API.md +141 -0
- package/README.md +299 -10
- package/build/accessors.d.ts +2 -1
- package/build/accessors.js +10 -0
- package/build/breadcrumb.d.ts +49 -0
- package/build/breadcrumb.js +58 -0
- package/build/connectors/types.d.ts +8 -0
- package/build/connectors/types.js +36 -4
- package/build/connectors/work.js +30 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +7 -1
- package/build/live/index.d.ts +43 -0
- package/build/live/index.js +183 -0
- package/build/liveChannel.d.ts +32 -0
- package/build/liveChannel.js +60 -0
- package/build/mockShell.d.ts +2 -0
- package/build/mockShell.js +1 -0
- package/build/query/index.d.ts +1 -0
- package/build/query/index.js +4 -2
- package/build/query/live.d.ts +14 -0
- package/build/query/live.js +115 -0
- package/build/shell/index.d.ts +2 -1
- package/build/shell/installShellBridge.d.ts +15 -1
- package/build/shell/installShellBridge.js +7 -1
- package/build/shell/liveHub.d.ts +25 -0
- package/build/shell/liveHub.js +201 -0
- package/build/shellBridge.d.ts +116 -1
- package/build/shellBridge.js +5 -1
- package/build/ui/classes.json +42 -42
- package/build/ui/components/ai.d.ts +68 -4
- package/build/ui/components/alert-dialog.d.ts +4 -4
- package/build/ui/components/app-frame.d.ts +47 -7
- package/build/ui/components/asset-pill.d.ts +8 -0
- package/build/ui/components/badge.d.ts +35 -2
- package/build/ui/components/button.d.ts +4 -4
- package/build/ui/components/calendar.d.ts +2 -2
- package/build/ui/components/chat-input.d.ts +4 -4
- package/build/ui/components/data-table.d.ts +128 -13
- package/build/ui/components/data-view.d.ts +94 -0
- package/build/ui/components/date-picker.d.ts +23 -1
- package/build/ui/components/file-upload.d.ts +9 -1
- package/build/ui/components/filter-bar.d.ts +89 -0
- package/build/ui/components/floating-panel.d.ts +53 -0
- package/build/ui/components/item.d.ts +1 -1
- package/build/ui/components/journey.d.ts +165 -0
- package/build/ui/components/nav.d.ts +52 -2
- package/build/ui/components/page-header.d.ts +8 -8
- package/build/ui/components/person.d.ts +14 -0
- package/build/ui/components/record-summary.d.ts +17 -0
- package/build/ui/components/search-dialog.d.ts +56 -0
- package/build/ui/components/statistic.d.ts +2 -1
- package/build/ui/components/table.d.ts +10 -3
- package/build/ui/components/toggle.d.ts +1 -1
- package/build/ui/demo.html +45923 -25459
- package/build/ui/index.d.ts +8 -0
- package/build/ui/standalone.js +984 -69
- package/build/ui/styles.css +1 -1
- package/build/ui/theme.css +11 -6
- package/live/package.json +8 -0
- package/package.json +10 -2
- package/template/AGENTS.md +6 -0
- package/template/src/App.tsx +4 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkComponentLock } from "../shellBridge";
|
|
1
2
|
export type FlowStatus = "Active" | "Archived" | "Deleted";
|
|
2
3
|
export interface FlowSummary {
|
|
3
4
|
id: string;
|
|
@@ -34,10 +35,15 @@ export declare function mapFlowSummary(value: unknown): FlowSummary;
|
|
|
34
35
|
export declare function mapFlowAction(value: unknown): FlowAction;
|
|
35
36
|
export declare function mapFlowStep(value: unknown): FlowStep;
|
|
36
37
|
export declare function mapFlow(value: unknown, steps?: unknown[]): Flow;
|
|
38
|
+
export interface FlowConfigActionSet {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}
|
|
37
42
|
export interface FlowConfigTask {
|
|
38
43
|
id: string;
|
|
39
44
|
name: string;
|
|
40
45
|
layoutId?: string;
|
|
46
|
+
actionSets?: FlowConfigActionSet[];
|
|
41
47
|
}
|
|
42
48
|
export interface FlowConfigStep {
|
|
43
49
|
id: string;
|
|
@@ -85,6 +91,7 @@ export interface WorkAction {
|
|
|
85
91
|
displayName?: string;
|
|
86
92
|
eventName?: string;
|
|
87
93
|
canExecute?: boolean;
|
|
94
|
+
actionSetId?: string;
|
|
88
95
|
}
|
|
89
96
|
export interface WorkAttachment {
|
|
90
97
|
id: string;
|
|
@@ -105,6 +112,7 @@ export interface WorkDetail {
|
|
|
105
112
|
flowOriginId?: string;
|
|
106
113
|
status?: string;
|
|
107
114
|
state?: string;
|
|
115
|
+
activeLocks: WorkComponentLock[];
|
|
108
116
|
attachments: WorkAttachment[];
|
|
109
117
|
actions: WorkAction[];
|
|
110
118
|
}
|
|
@@ -97,8 +97,8 @@ function mapFlow(value, steps) {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
// GET /api/v4/config/flow/{id} returns flat {steps: [{stepId, stepName?,
|
|
100
|
-
// stepDisplayName?, taskId, taskName?, taskDisplayName?,
|
|
101
|
-
// group them by step preserving server order.
|
|
100
|
+
// stepDisplayName?, taskId, taskName?, taskDisplayName?, actionSetId?,
|
|
101
|
+
// actionSetName?, layoutId}]} rows; group them by step preserving server order.
|
|
102
102
|
function mapFlowConfig(flowId, value) {
|
|
103
103
|
const raw = asRecord(value);
|
|
104
104
|
const byStep = new Map();
|
|
@@ -121,11 +121,27 @@ function mapFlowConfig(flowId, value) {
|
|
|
121
121
|
nameMap.set(stepId, step.name);
|
|
122
122
|
}
|
|
123
123
|
const taskId = str(row?.taskId);
|
|
124
|
-
if (
|
|
124
|
+
if (!taskId)
|
|
125
|
+
continue;
|
|
126
|
+
let actionSets = step.tasks.find((t) => t.id === taskId)?.actionSets;
|
|
127
|
+
if (!actionSets) {
|
|
125
128
|
const name = str(row?.taskDisplayName) ?? str(row?.taskName) ?? taskId;
|
|
126
|
-
|
|
129
|
+
actionSets = [];
|
|
130
|
+
step.tasks.push({
|
|
131
|
+
id: taskId,
|
|
132
|
+
name,
|
|
133
|
+
layoutId: str(row?.layoutId),
|
|
134
|
+
actionSets,
|
|
135
|
+
});
|
|
127
136
|
nameMap.set(taskId, name);
|
|
128
137
|
}
|
|
138
|
+
const actionSetId = str(row?.actionSetId);
|
|
139
|
+
const actionSetName = str(row?.actionSetName);
|
|
140
|
+
if (actionSetId &&
|
|
141
|
+
actionSetName &&
|
|
142
|
+
!actionSets.some((a) => a.id === actionSetId)) {
|
|
143
|
+
actionSets.push({ id: actionSetId, name: actionSetName });
|
|
144
|
+
}
|
|
129
145
|
}
|
|
130
146
|
return { flowId, steps: order.map((id) => byStep.get(id)), nameMap };
|
|
131
147
|
}
|
|
@@ -164,6 +180,9 @@ function mapWorkDetail(value) {
|
|
|
164
180
|
const attachments = Array.isArray(raw.attachments)
|
|
165
181
|
? raw.attachments
|
|
166
182
|
: [];
|
|
183
|
+
const locks = Array.isArray(raw.activeLocks)
|
|
184
|
+
? raw.activeLocks
|
|
185
|
+
: [];
|
|
167
186
|
return {
|
|
168
187
|
id,
|
|
169
188
|
code: str(raw?.code),
|
|
@@ -173,6 +192,18 @@ function mapWorkDetail(value) {
|
|
|
173
192
|
flowOriginId: str(raw?.flowOriginId),
|
|
174
193
|
status: str(raw?.status),
|
|
175
194
|
state: str(raw?.state),
|
|
195
|
+
activeLocks: locks.flatMap((l) => str(l?.userId) && typeof l?.componentId === "string"
|
|
196
|
+
? [
|
|
197
|
+
{
|
|
198
|
+
workId: str(l?.workItemId) ?? id,
|
|
199
|
+
userId: String(l.userId),
|
|
200
|
+
displayName: str(l?.displayName),
|
|
201
|
+
componentId: l.componentId,
|
|
202
|
+
dataPath: str(l?.dataPath),
|
|
203
|
+
at: str(l?.utcTime),
|
|
204
|
+
},
|
|
205
|
+
]
|
|
206
|
+
: []),
|
|
176
207
|
attachments: attachments.map((a) => ({
|
|
177
208
|
id: String(a?.id ?? ""),
|
|
178
209
|
// The record's `fileName` is the storage name; the original is the one deletions queue.
|
|
@@ -188,6 +219,7 @@ function mapWorkDetail(value) {
|
|
|
188
219
|
displayName: str(a?.displayName),
|
|
189
220
|
eventName: str(a?.eventName),
|
|
190
221
|
canExecute: typeof a?.canExecute === "boolean" ? a.canExecute : undefined,
|
|
222
|
+
actionSetId: str(a?.stepId),
|
|
191
223
|
})),
|
|
192
224
|
};
|
|
193
225
|
}
|
package/build/connectors/work.js
CHANGED
|
@@ -119,12 +119,41 @@ function createWorkConnector(deps = { shell: _internal_1.requireShell }) {
|
|
|
119
119
|
throw (0, errors_1.toConnectorError)(e);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
+
// Without the action set's name, `Submit` matches the step's autosubmit event: a 200 that moves
|
|
123
|
+
// nothing. Any miss sends no name, as before, so a call that worked without one still does.
|
|
124
|
+
const resolveStepName = async (args) => {
|
|
125
|
+
try {
|
|
126
|
+
const detail = await get(args.workId, { signal: args.signal });
|
|
127
|
+
const actionSetIds = new Set((detail?.actions ?? [])
|
|
128
|
+
.filter((a) => (a.eventName ?? a.name) === args.actionName)
|
|
129
|
+
.map((a) => a.actionSetId));
|
|
130
|
+
const [actionSetId] = actionSetIds;
|
|
131
|
+
if (!detail?.flowId || actionSetIds.size !== 1 || !actionSetId) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
// The work's own flow version: the latest one may have renamed the action set.
|
|
135
|
+
const { data } = await deps
|
|
136
|
+
.shell()
|
|
137
|
+
.getApiV4("config")
|
|
138
|
+
.get(`/api/v4/config/flow/${detail.flowId}`, {
|
|
139
|
+
signal: args.signal,
|
|
140
|
+
});
|
|
141
|
+
return (0, types_1.mapFlowConfig)(detail.flowId, data ?? {})
|
|
142
|
+
.steps.flatMap((s) => s.tasks)
|
|
143
|
+
.flatMap((t) => t.actionSets ?? [])
|
|
144
|
+
.find((a) => a.id === actionSetId)?.name;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
122
150
|
const submit = async (args) => {
|
|
123
151
|
try {
|
|
152
|
+
const stepName = args.stepName ?? (await resolveStepName(args));
|
|
124
153
|
const { data } = await deps
|
|
125
154
|
.shell()
|
|
126
155
|
.getApi()
|
|
127
|
-
.post(`/api/v3/flow/submit/${args.workId}`, { stepName
|
|
156
|
+
.post(`/api/v3/flow/submit/${args.workId}`, { stepName }, { params: { eventName: args.actionName }, signal: args.signal });
|
|
128
157
|
return (0, types_1.mapWorkDetail)(data ?? {});
|
|
129
158
|
}
|
|
130
159
|
catch (e) {
|
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./shellBridge";
|
|
2
2
|
export * from "./lifecycle";
|
|
3
3
|
export { useShellUser, useShellEnvironment, useShellNavigate } from "./hooks";
|
|
4
|
-
export { getShell, getShellAi, getShellApi, getShellApiV4, getShellEnvironment, getShellUser, } from "./accessors";
|
|
4
|
+
export { getShell, getShellAi, getShellApi, getShellApiV4, getShellEnvironment, getShellLive, getShellUser, } from "./accessors";
|
|
5
|
+
export { createLiveChannel, type ComponentLockHandler, type CreateLiveChannelOptions, type LiveChannel, } from "./liveChannel";
|
|
5
6
|
export { createMockShell, isMockShell, type CreateMockShellOptions, type MockShellFixtures, } from "./mockShell";
|
|
6
7
|
export { registerTopBarActions, type TopBarAction } from "./topBar";
|
|
8
|
+
export { setShellBreadcrumb, useShellBreadcrumb, type ShellBreadcrumbBack, type ShellBreadcrumbBadge, type ShellBreadcrumbItem, } from "./breadcrumb";
|
|
7
9
|
export { APP_DEPENDENCY_KINDS, APP_MANIFEST_FILENAME, DEFAULT_APP_ENVIRONMENT, resolveAppManifest, type AgentAppDependencySource, type AgentEnvironmentIds, type AppDependencyKind, type AppDependencySource, type AppManifestSource, type AssetTypeAppDependencySource, type FlowAppDependencySource, type FlowOriginEnvironmentIds, type IntegrationAppDependencySource, type IntegrationEnvironmentIds, type ResolvedAgentDependency, type ResolvedAppDependency, type ResolvedAppManifest, type ResolvedAssetTypeDependency, type ResolvedFlowDependency, type ResolvedIntegrationDependency, } from "./manifest";
|
package/build/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.resolveAppManifest = exports.DEFAULT_APP_ENVIRONMENT = exports.APP_MANIFEST_FILENAME = exports.APP_DEPENDENCY_KINDS = exports.registerTopBarActions = exports.isMockShell = exports.createMockShell = exports.getShellUser = exports.getShellEnvironment = exports.getShellApiV4 = exports.getShellApi = exports.getShellAi = exports.getShell = exports.useShellNavigate = exports.useShellEnvironment = exports.useShellUser = void 0;
|
|
17
|
+
exports.resolveAppManifest = exports.DEFAULT_APP_ENVIRONMENT = exports.APP_MANIFEST_FILENAME = exports.APP_DEPENDENCY_KINDS = exports.useShellBreadcrumb = exports.setShellBreadcrumb = exports.registerTopBarActions = exports.isMockShell = exports.createMockShell = exports.createLiveChannel = exports.getShellUser = exports.getShellLive = exports.getShellEnvironment = exports.getShellApiV4 = exports.getShellApi = exports.getShellAi = exports.getShell = exports.useShellNavigate = exports.useShellEnvironment = exports.useShellUser = void 0;
|
|
18
18
|
__exportStar(require("./shellBridge"), exports);
|
|
19
19
|
__exportStar(require("./lifecycle"), exports);
|
|
20
20
|
var hooks_1 = require("./hooks");
|
|
@@ -27,12 +27,18 @@ Object.defineProperty(exports, "getShellAi", { enumerable: true, get: function (
|
|
|
27
27
|
Object.defineProperty(exports, "getShellApi", { enumerable: true, get: function () { return accessors_1.getShellApi; } });
|
|
28
28
|
Object.defineProperty(exports, "getShellApiV4", { enumerable: true, get: function () { return accessors_1.getShellApiV4; } });
|
|
29
29
|
Object.defineProperty(exports, "getShellEnvironment", { enumerable: true, get: function () { return accessors_1.getShellEnvironment; } });
|
|
30
|
+
Object.defineProperty(exports, "getShellLive", { enumerable: true, get: function () { return accessors_1.getShellLive; } });
|
|
30
31
|
Object.defineProperty(exports, "getShellUser", { enumerable: true, get: function () { return accessors_1.getShellUser; } });
|
|
32
|
+
var liveChannel_1 = require("./liveChannel");
|
|
33
|
+
Object.defineProperty(exports, "createLiveChannel", { enumerable: true, get: function () { return liveChannel_1.createLiveChannel; } });
|
|
31
34
|
var mockShell_1 = require("./mockShell");
|
|
32
35
|
Object.defineProperty(exports, "createMockShell", { enumerable: true, get: function () { return mockShell_1.createMockShell; } });
|
|
33
36
|
Object.defineProperty(exports, "isMockShell", { enumerable: true, get: function () { return mockShell_1.isMockShell; } });
|
|
34
37
|
var topBar_1 = require("./topBar");
|
|
35
38
|
Object.defineProperty(exports, "registerTopBarActions", { enumerable: true, get: function () { return topBar_1.registerTopBarActions; } });
|
|
39
|
+
var breadcrumb_1 = require("./breadcrumb");
|
|
40
|
+
Object.defineProperty(exports, "setShellBreadcrumb", { enumerable: true, get: function () { return breadcrumb_1.setShellBreadcrumb; } });
|
|
41
|
+
Object.defineProperty(exports, "useShellBreadcrumb", { enumerable: true, get: function () { return breadcrumb_1.useShellBreadcrumb; } });
|
|
36
42
|
// The app-dependency RUNTIME (useAppDependencies and the bound surfaces) is
|
|
37
43
|
// deliberately absent from this barrel — it lives on the /dependencies subpath,
|
|
38
44
|
// because it binds the connector layer and that layer must not ride the root
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LiveEvent, LiveStatus, WorkComponentLock } from "../shellBridge";
|
|
2
|
+
export type { LiveApi, LiveEvent, LiveStatus, SetComponentLockArgs, WorkComponentLock, } from "../shellBridge";
|
|
3
|
+
/** What `useLiveStatus` reports: the host's status, or `unavailable` when it offers no live events. */
|
|
4
|
+
export type LiveAvailability = LiveStatus | "unavailable";
|
|
5
|
+
/**
|
|
6
|
+
* The host's live connection state. Re-renders on a change. `unavailable` means the host offers
|
|
7
|
+
* no live events at all, so keep whatever fallback you have; `connected` is the only state in
|
|
8
|
+
* which events arrive.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useLiveStatus(): LiveAvailability;
|
|
11
|
+
/**
|
|
12
|
+
* Calls `handler` with each live event while the component is mounted. The latest `handler` is
|
|
13
|
+
* always the one called, so an inline function does not subscribe again. Events arrive for every
|
|
14
|
+
* work item and asset the user can see, across their ecosystems, and are best-effort: a `resync`
|
|
15
|
+
* event says some were missed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useLiveEvents(handler: (event: LiveEvent) => void, options?: {
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
}): void;
|
|
20
|
+
/** How often an open editor says its lock again, so the platform can tell a lock is still held. */
|
|
21
|
+
export declare const LOCK_REFRESH_MS = 60000;
|
|
22
|
+
/**
|
|
23
|
+
* Shows that the user is editing: takes a component lock on `workId` while `active`, says it again
|
|
24
|
+
* every {@link LOCK_REFRESH_MS} and after a reconnect, and releases it when `active` ends or the
|
|
25
|
+
* component unmounts. Others see it through `useWorkLocks`.
|
|
26
|
+
*
|
|
27
|
+
* `componentId` identifies the editor and must be a GUID. Use the same one for the same editor in
|
|
28
|
+
* every session, so other users' screens can tell which editor is open. The platform keeps one
|
|
29
|
+
* lock per user per work, so this lock and one the host's own editor takes for the same user
|
|
30
|
+
* replace each other. Several holds in one app are fine: the most recent shows, and releasing it
|
|
31
|
+
* takes the previous one again.
|
|
32
|
+
*
|
|
33
|
+
* Advisory only: it never gates a write, and it does nothing on a host without live events.
|
|
34
|
+
* Without a connection the lock is not sent, and the app keeps working.
|
|
35
|
+
*/
|
|
36
|
+
export declare function useComponentLock(workId: string | undefined, componentId: string, active: boolean, dataPath?: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Who has an editor open on this work right now: every user's lock, yours included. Starts from
|
|
39
|
+
* the locks on a fresh read of the work and follows `lock` events, so it stays current without
|
|
40
|
+
* polling. Empty on a host without live events. A lock from a closed browser can linger on
|
|
41
|
+
* the platform, so compare `at` with the age you are willing to believe.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useWorkLocks(workId: string | undefined): WorkComponentLock[];
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOCK_REFRESH_MS = void 0;
|
|
4
|
+
exports.useLiveStatus = useLiveStatus;
|
|
5
|
+
exports.useLiveEvents = useLiveEvents;
|
|
6
|
+
exports.useComponentLock = useComponentLock;
|
|
7
|
+
exports.useWorkLocks = useWorkLocks;
|
|
8
|
+
// @rise-x/apps-sdk/live: live platform events and editor presence, over the host's own
|
|
9
|
+
// connection.
|
|
10
|
+
//
|
|
11
|
+
// The host owns the connection and turns what it hears into `LiveEvent`s; these hooks subscribe
|
|
12
|
+
// an app to them. Nothing here opens a connection or polls. On a host that offers no live
|
|
13
|
+
// events every hook is inert, so an app keeps working from its own reads. To keep this SDK's query
|
|
14
|
+
// cache current from the same events, use `useLiveInvalidation` from `@rise-x/apps-sdk/query`.
|
|
15
|
+
//
|
|
16
|
+
// Not re-exported from the package root: the root barrel stays free of anything that reads the
|
|
17
|
+
// connectors.
|
|
18
|
+
const react_1 = require("react");
|
|
19
|
+
const accessors_1 = require("../accessors");
|
|
20
|
+
const work_1 = require("../connectors/work");
|
|
21
|
+
const NOOP = () => { };
|
|
22
|
+
// Module-level so the subscription is stable across renders. The bridge is read on each call,
|
|
23
|
+
// because it can finish wiring after the first render.
|
|
24
|
+
const subscribeToStatus = (onChange) => (0, accessors_1.getShellLive)()?.subscribeStatus(onChange) ?? NOOP;
|
|
25
|
+
const readStatus = () => (0, accessors_1.getShellLive)()?.getStatus() ?? "unavailable";
|
|
26
|
+
/**
|
|
27
|
+
* The host's live connection state. Re-renders on a change. `unavailable` means the host offers
|
|
28
|
+
* no live events at all, so keep whatever fallback you have; `connected` is the only state in
|
|
29
|
+
* which events arrive.
|
|
30
|
+
*/
|
|
31
|
+
function useLiveStatus() {
|
|
32
|
+
return (0, react_1.useSyncExternalStore)(subscribeToStatus, readStatus, readStatus);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Calls `handler` with each live event while the component is mounted. The latest `handler` is
|
|
36
|
+
* always the one called, so an inline function does not subscribe again. Events arrive for every
|
|
37
|
+
* work item and asset the user can see, across their ecosystems, and are best-effort: a `resync`
|
|
38
|
+
* event says some were missed.
|
|
39
|
+
*/
|
|
40
|
+
function useLiveEvents(handler, options = {}) {
|
|
41
|
+
const latest = (0, react_1.useRef)(handler);
|
|
42
|
+
// Updated after commit, so a render React throws away never replaces the live handler.
|
|
43
|
+
(0, react_1.useEffect)(() => {
|
|
44
|
+
latest.current = handler;
|
|
45
|
+
});
|
|
46
|
+
const enabled = options.enabled ?? true;
|
|
47
|
+
(0, react_1.useEffect)(() => {
|
|
48
|
+
if (!enabled)
|
|
49
|
+
return;
|
|
50
|
+
return (0, accessors_1.getShellLive)()?.subscribe((event) => latest.current(event));
|
|
51
|
+
}, [enabled]);
|
|
52
|
+
}
|
|
53
|
+
// The platform keeps one lock per user per work, so a second editor's lock replaces the first and
|
|
54
|
+
// releasing either would clear both. Holds on the same work therefore stack: the most recent one
|
|
55
|
+
// is the lock the platform sees, and releasing it takes the one beneath again.
|
|
56
|
+
const holds = new Map();
|
|
57
|
+
const last = (stack) => stack ? stack[stack.length - 1] : undefined;
|
|
58
|
+
const topHold = (workId) => last(holds.get(workId));
|
|
59
|
+
/** How often an open editor says its lock again, so the platform can tell a lock is still held. */
|
|
60
|
+
exports.LOCK_REFRESH_MS = 60000;
|
|
61
|
+
// Presence is advisory: a read-only user, or a connection that dropped, simply has none.
|
|
62
|
+
function send(live, workId, hold, locked) {
|
|
63
|
+
live
|
|
64
|
+
.setComponentLock({
|
|
65
|
+
workId,
|
|
66
|
+
componentId: hold.componentId,
|
|
67
|
+
dataPath: hold.dataPath,
|
|
68
|
+
locked,
|
|
69
|
+
})
|
|
70
|
+
.catch(NOOP);
|
|
71
|
+
}
|
|
72
|
+
function release(live, workId, hold) {
|
|
73
|
+
const wasTop = topHold(workId) === hold;
|
|
74
|
+
const rest = (holds.get(workId) ?? []).filter((h) => h !== hold);
|
|
75
|
+
if (rest.length)
|
|
76
|
+
holds.set(workId, rest);
|
|
77
|
+
else
|
|
78
|
+
holds.delete(workId);
|
|
79
|
+
// A hold beneath the top is not what the platform shows, so releasing it changes nothing there.
|
|
80
|
+
if (!wasTop)
|
|
81
|
+
return;
|
|
82
|
+
const next = last(rest);
|
|
83
|
+
if (next)
|
|
84
|
+
send(live, workId, next, true);
|
|
85
|
+
else
|
|
86
|
+
send(live, workId, hold, false);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Shows that the user is editing: takes a component lock on `workId` while `active`, says it again
|
|
90
|
+
* every {@link LOCK_REFRESH_MS} and after a reconnect, and releases it when `active` ends or the
|
|
91
|
+
* component unmounts. Others see it through `useWorkLocks`.
|
|
92
|
+
*
|
|
93
|
+
* `componentId` identifies the editor and must be a GUID. Use the same one for the same editor in
|
|
94
|
+
* every session, so other users' screens can tell which editor is open. The platform keeps one
|
|
95
|
+
* lock per user per work, so this lock and one the host's own editor takes for the same user
|
|
96
|
+
* replace each other. Several holds in one app are fine: the most recent shows, and releasing it
|
|
97
|
+
* takes the previous one again.
|
|
98
|
+
*
|
|
99
|
+
* Advisory only: it never gates a write, and it does nothing on a host without live events.
|
|
100
|
+
* Without a connection the lock is not sent, and the app keeps working.
|
|
101
|
+
*/
|
|
102
|
+
function useComponentLock(workId, componentId, active, dataPath) {
|
|
103
|
+
(0, react_1.useEffect)(() => {
|
|
104
|
+
const live = (0, accessors_1.getShellLive)();
|
|
105
|
+
if (!live || !workId || !active)
|
|
106
|
+
return;
|
|
107
|
+
const hold = { componentId, dataPath };
|
|
108
|
+
holds.set(workId, [...(holds.get(workId) ?? []), hold]);
|
|
109
|
+
const say = () => {
|
|
110
|
+
if (topHold(workId) === hold)
|
|
111
|
+
send(live, workId, hold, true);
|
|
112
|
+
};
|
|
113
|
+
say();
|
|
114
|
+
// Locks live in the platform's memory and are not replayed after a reconnect: say it again.
|
|
115
|
+
const off = live.subscribe((event) => {
|
|
116
|
+
if (event.type === "resync")
|
|
117
|
+
say();
|
|
118
|
+
});
|
|
119
|
+
const refresh = setInterval(say, exports.LOCK_REFRESH_MS);
|
|
120
|
+
return () => {
|
|
121
|
+
clearInterval(refresh);
|
|
122
|
+
off();
|
|
123
|
+
release(live, workId, hold);
|
|
124
|
+
};
|
|
125
|
+
}, [workId, componentId, active, dataPath]);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Who has an editor open on this work right now: every user's lock, yours included. Starts from
|
|
129
|
+
* the locks on a fresh read of the work and follows `lock` events, so it stays current without
|
|
130
|
+
* polling. Empty on a host without live events. A lock from a closed browser can linger on
|
|
131
|
+
* the platform, so compare `at` with the age you are willing to believe.
|
|
132
|
+
*/
|
|
133
|
+
function useWorkLocks(workId) {
|
|
134
|
+
const [locks, setLocks] = (0, react_1.useState)([]);
|
|
135
|
+
(0, react_1.useEffect)(() => {
|
|
136
|
+
setLocks([]);
|
|
137
|
+
const live = (0, accessors_1.getShellLive)();
|
|
138
|
+
if (!live || !workId)
|
|
139
|
+
return;
|
|
140
|
+
// The read in flight. A newer read (after a resync) or unmount aborts it, so an older answer
|
|
141
|
+
// never lands over a newer one, and no read outlives the component.
|
|
142
|
+
let reading = null;
|
|
143
|
+
// Users whose lock an event has already reported: the event is newer than the read.
|
|
144
|
+
const reported = new Set();
|
|
145
|
+
const seed = async () => {
|
|
146
|
+
reading?.abort();
|
|
147
|
+
const controller = (reading = new AbortController());
|
|
148
|
+
try {
|
|
149
|
+
const detail = await work_1.work.get(workId, { signal: controller.signal });
|
|
150
|
+
if (controller.signal.aborted || !detail)
|
|
151
|
+
return;
|
|
152
|
+
setLocks((current) => [
|
|
153
|
+
...detail.activeLocks.filter((l) => !reported.has(l.userId)),
|
|
154
|
+
...current.filter((l) => reported.has(l.userId)),
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// Presence is advisory: without the read, only new lock events show.
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const off = live.subscribe((event) => {
|
|
162
|
+
if (event.type === "resync") {
|
|
163
|
+
reported.clear();
|
|
164
|
+
void seed();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (event.type !== "lock" || event.workId !== workId)
|
|
168
|
+
return;
|
|
169
|
+
reported.add(event.userId);
|
|
170
|
+
const { type: _type, locked, ...lock } = event;
|
|
171
|
+
setLocks((current) => {
|
|
172
|
+
const others = current.filter((l) => l.userId !== lock.userId);
|
|
173
|
+
return locked ? [...others, lock] : others;
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
void seed();
|
|
177
|
+
return () => {
|
|
178
|
+
reading?.abort();
|
|
179
|
+
off();
|
|
180
|
+
};
|
|
181
|
+
}, [workId]);
|
|
182
|
+
return locks;
|
|
183
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LiveApi, LiveEvent, LiveStatus, SetComponentLockArgs } from "./shellBridge";
|
|
2
|
+
export type ComponentLockHandler = (args: SetComponentLockArgs) => Promise<void>;
|
|
3
|
+
export interface CreateLiveChannelOptions {
|
|
4
|
+
/** The starting status. Default `connecting`. */
|
|
5
|
+
status?: LiveStatus;
|
|
6
|
+
/** How a lock reaches the platform. Without one, `setComponentLock` rejects. */
|
|
7
|
+
setComponentLock?: ComponentLockHandler;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A {@link LiveApi} plus the controls that feed it: `emit` an event to every subscriber,
|
|
11
|
+
* `setStatus` as the connection moves.
|
|
12
|
+
*
|
|
13
|
+
* Hosts get one from the bridge, driven by their connection. For standalone development, build
|
|
14
|
+
* one, pass it to `createMockShell({ live })`, and `emit` events by hand.
|
|
15
|
+
*/
|
|
16
|
+
export interface LiveChannel {
|
|
17
|
+
readonly api: LiveApi;
|
|
18
|
+
/** Deliver an event to every subscriber. A listener that throws does not stop the rest. */
|
|
19
|
+
emit(event: LiveEvent): void;
|
|
20
|
+
/**
|
|
21
|
+
* Report the connection state. Listeners fire on a change only. Moving to `connected` after an
|
|
22
|
+
* earlier connection also emits `{ type: "resync" }`, because events sent in between were lost;
|
|
23
|
+
* the first connection does not.
|
|
24
|
+
*/
|
|
25
|
+
setStatus(status: LiveStatus): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function callSafely<T>(listener: (value: T) => void, value: T): void;
|
|
28
|
+
/**
|
|
29
|
+
* Router-free and connector-free on purpose: the mock shell builds one for standalone dev, and
|
|
30
|
+
* the mock shell rides the root barrel.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createLiveChannel(options?: CreateLiveChannelOptions): LiveChannel;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callSafely = callSafely;
|
|
4
|
+
exports.createLiveChannel = createLiveChannel;
|
|
5
|
+
// Every app in the shell listens on the same channel, so one app's listener that throws must
|
|
6
|
+
// neither stop the listeners after it nor reach the host's connection handling.
|
|
7
|
+
function callSafely(listener, value) {
|
|
8
|
+
try {
|
|
9
|
+
listener(value);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error("[@rise-x/apps-sdk] a live listener threw; other listeners still run.", error);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Router-free and connector-free on purpose: the mock shell builds one for standalone dev, and
|
|
17
|
+
* the mock shell rides the root barrel.
|
|
18
|
+
*/
|
|
19
|
+
function createLiveChannel(options = {}) {
|
|
20
|
+
let status = options.status ?? "connecting";
|
|
21
|
+
// A channel created `connected` has had its connection from the start.
|
|
22
|
+
let hasConnected = status === "connected";
|
|
23
|
+
const lockHandler = options.setComponentLock ?? null;
|
|
24
|
+
const eventListeners = new Set();
|
|
25
|
+
const statusListeners = new Set();
|
|
26
|
+
// A copy: a listener that unsubscribes while being called must not skip its neighbour.
|
|
27
|
+
const notify = (listeners, value) => {
|
|
28
|
+
for (const listener of [...listeners])
|
|
29
|
+
callSafely(listener, value);
|
|
30
|
+
};
|
|
31
|
+
const subscribe = (listeners, listener) => {
|
|
32
|
+
listeners.add(listener);
|
|
33
|
+
return () => {
|
|
34
|
+
listeners.delete(listener);
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const emit = (event) => notify(eventListeners, event);
|
|
38
|
+
return {
|
|
39
|
+
api: {
|
|
40
|
+
getStatus: () => status,
|
|
41
|
+
subscribeStatus: (listener) => subscribe(statusListeners, listener),
|
|
42
|
+
subscribe: (listener) => subscribe(eventListeners, listener),
|
|
43
|
+
setComponentLock: (args) => lockHandler
|
|
44
|
+
? lockHandler(args)
|
|
45
|
+
: Promise.reject(new Error("[@rise-x/apps-sdk] component locks are not available on this live channel")),
|
|
46
|
+
},
|
|
47
|
+
emit,
|
|
48
|
+
setStatus(next) {
|
|
49
|
+
if (next === status)
|
|
50
|
+
return;
|
|
51
|
+
status = next;
|
|
52
|
+
notify(statusListeners, next);
|
|
53
|
+
if (next !== "connected")
|
|
54
|
+
return;
|
|
55
|
+
if (hasConnected)
|
|
56
|
+
emit({ type: "resync" });
|
|
57
|
+
hasConnected = true;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
package/build/mockShell.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LiveChannel } from "./liveChannel";
|
|
1
2
|
import { type ResolvedAppManifest } from "./manifest";
|
|
2
3
|
import type { DianaShell, ShellAiApi, ShellEnvironment, ShellUser } from "./shellBridge";
|
|
3
4
|
export interface MockShellFixtures {
|
|
@@ -17,6 +18,7 @@ export interface CreateMockShellOptions {
|
|
|
17
18
|
apiV4?: DianaShell["getApiV4"];
|
|
18
19
|
fixtures?: MockShellFixtures;
|
|
19
20
|
ai?: ShellAiApi | null;
|
|
21
|
+
live?: LiveChannel;
|
|
20
22
|
dependencies?: ResolvedAppManifest["dependencies"];
|
|
21
23
|
}
|
|
22
24
|
export declare function createMockShell(overrides?: CreateMockShellOptions): DianaShell;
|
package/build/mockShell.js
CHANGED
|
@@ -211,6 +211,7 @@ function createMockShell(overrides = {}) {
|
|
|
211
211
|
// Standalone dev has no cache, outbox or sync engine — null is the honest answer for both.
|
|
212
212
|
getOffline: () => null,
|
|
213
213
|
getCache: () => null,
|
|
214
|
+
getLive: () => overrides.live?.api ?? null,
|
|
214
215
|
navigate,
|
|
215
216
|
};
|
|
216
217
|
// Untyped marker so SDK internals (e.g. the query layer's dev diagnostics)
|
package/build/query/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { AppQueryProvider, useAppQueryClient } from "./context";
|
|
|
5
5
|
export { getLiveEnvId, invalidateAppSdkQueries, type SdkMutationOptions, type SdkQueryOptions, } from "./shared";
|
|
6
6
|
export { createQueryLayer, type QueryLayer } from "./layer";
|
|
7
7
|
export { prefetchAppDependencies } from "./dependencies";
|
|
8
|
+
export { useLiveInvalidation, type LiveInvalidationOptions } from "./live";
|
|
8
9
|
export { createFlowQueries, flowQueries, useFlow, useFlowConfig, useFlowLayout, useFlows, useFlowTask, type FindTaskQueryArgs, type FlowQueries, type ListFlowsQueryArgs, } from "./flows";
|
|
9
10
|
export { createWorkQueries, dedupeRows, useDeleteWork, usePatchWorkData, useRelatedWork, useStartWork, useSubmitWork, useWork, useWorkAudit, useWorkData, useWorkRows, useWorkSearch, workQueries, type DeleteWorkVariables, type ListRelatedWorkQueryArgs, type ListWorkRowsQueryArgs, type PatchWorkDataVariables, type SearchWorkQueryArgs, type StartWorkVariables, type SubmitWorkVariables, type WorkQueries, } from "./work";
|
|
10
11
|
export { assetQueries, createAssetQueries, useAsset, useAssetQuickSearch, useAssetRows, useAssetSearch, useAssetTypes, useCloneAsset, useCreateAsset, useDeleteAsset, useRelatedAssets, useStartEditAsset, type AssetQueries, type CloneAssetVariables, type CreateAssetVariables, type DeleteAssetVariables, type ListAssetRowsQueryArgs, type ListRelatedAssetsQueryArgs, type QuickSearchAssetsQueryArgs, type SearchAssetsQueryArgs, type StartEditAssetVariables, } from "./assets";
|
package/build/query/index.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
// Deliberately NOT re-exported from the package root: apps that don't import
|
|
22
22
|
// this subpath never load react-query.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.
|
|
25
|
-
exports.ConnectorError = exports.useUpdateAgent = exports.useRenameAgentChat = exports.useDeleteAgentChat = exports.useDeleteAgent = exports.useCreateAgent = exports.useAgents = exports.useAgentChats = void 0;
|
|
24
|
+
exports.useAgentChat = exports.useAgent = exports.createAgentQueries = exports.agentQueries = exports.useStartEditAsset = exports.useRelatedAssets = exports.useDeleteAsset = exports.useCreateAsset = exports.useCloneAsset = exports.useAssetTypes = exports.useAssetSearch = exports.useAssetRows = exports.useAssetQuickSearch = exports.useAsset = exports.createAssetQueries = exports.assetQueries = exports.workQueries = exports.useWorkSearch = exports.useWorkRows = exports.useWorkData = exports.useWorkAudit = exports.useWork = exports.useSubmitWork = exports.useStartWork = exports.useRelatedWork = exports.usePatchWorkData = exports.useDeleteWork = exports.dedupeRows = exports.createWorkQueries = exports.useFlowTask = exports.useFlows = exports.useFlowLayout = exports.useFlowConfig = exports.useFlow = exports.flowQueries = exports.createFlowQueries = exports.useLiveInvalidation = exports.prefetchAppDependencies = exports.createQueryLayer = exports.invalidateAppSdkQueries = exports.getLiveEnvId = exports.useAppQueryClient = exports.AppQueryProvider = exports.shouldRetryConnectorError = exports.getFallbackAppClient = exports.createAppQueryClient = exports.searchCacheShape = exports.QUERY_KEY_ROOT = exports.queryKeys = exports.normalizeArgs = void 0;
|
|
25
|
+
exports.ConnectorError = exports.useUpdateAgent = exports.useRenameAgentChat = exports.useDeleteAgentChat = exports.useDeleteAgent = exports.useCreateAgent = exports.useAgents = exports.useAgentChats = exports.useAgentChatMessages = void 0;
|
|
26
26
|
var keys_1 = require("./keys");
|
|
27
27
|
Object.defineProperty(exports, "normalizeArgs", { enumerable: true, get: function () { return keys_1.normalizeArgs; } });
|
|
28
28
|
Object.defineProperty(exports, "queryKeys", { enumerable: true, get: function () { return keys_1.queryKeys; } });
|
|
@@ -46,6 +46,8 @@ var layer_1 = require("./layer");
|
|
|
46
46
|
Object.defineProperty(exports, "createQueryLayer", { enumerable: true, get: function () { return layer_1.createQueryLayer; } });
|
|
47
47
|
var dependencies_1 = require("./dependencies");
|
|
48
48
|
Object.defineProperty(exports, "prefetchAppDependencies", { enumerable: true, get: function () { return dependencies_1.prefetchAppDependencies; } });
|
|
49
|
+
var live_1 = require("./live");
|
|
50
|
+
Object.defineProperty(exports, "useLiveInvalidation", { enumerable: true, get: function () { return live_1.useLiveInvalidation; } });
|
|
49
51
|
var flows_1 = require("./flows");
|
|
50
52
|
Object.defineProperty(exports, "createFlowQueries", { enumerable: true, get: function () { return flows_1.createFlowQueries; } });
|
|
51
53
|
Object.defineProperty(exports, "flowQueries", { enumerable: true, get: function () { return flows_1.flowQueries; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface LiveInvalidationOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Only data writes in these flows, by flow origin id, refresh queries. A change that names no
|
|
4
|
+
* flow (`workUpdated`, `workDeleted`, an asset change, a write that named none) always does.
|
|
5
|
+
*/
|
|
6
|
+
flowOriginIds?: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Marks this SDK's queries stale when a live event says what they hold changed: the work item's
|
|
10
|
+
* or asset's own queries and the listings (only the ones on screen refetch). A delete drops the
|
|
11
|
+
* item's queries, and a `resync` marks every work and asset query stale. Call it once, near the
|
|
12
|
+
* root of the app.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useLiveInvalidation(options?: LiveInvalidationOptions): void;
|