@powerhousedao/workflow 6.2.3-dev.89 → 6.2.3-dev.91
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/dist/browser/{connection-form-B6zpGmAm.js → connection-form-O02M1hkC.js} +183 -24
- package/dist/browser/connection-form-O02M1hkC.js.map +1 -0
- package/dist/browser/{editor-Yt-_V04R.js → editor-BPF_SXdt.js} +21 -14
- package/dist/browser/editor-BPF_SXdt.js.map +1 -0
- package/dist/browser/{editor-bHCkW_XB.js → editor-xBTKbbNO.js} +7 -4
- package/dist/browser/{editor-bHCkW_XB.js.map → editor-xBTKbbNO.js.map} +1 -1
- package/dist/browser/editors/connection-editor/module.js +1 -1
- package/dist/browser/editors/workflow-editor/module.js +1 -1
- package/dist/node/document-models/connection/index.mjs +67 -3
- package/dist/node/document-models/connection/index.mjs.map +1 -0
- package/dist/node/document-models/index.mjs +3 -3
- package/dist/node/document-models/workflow/index.mjs +86 -3
- package/dist/node/document-models/workflow/index.mjs.map +1 -0
- package/dist/node/editors/index.mjs +6 -4
- package/dist/node/editors/index.mjs.map +1 -0
- package/dist/node/index.mjs +5 -412
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/{module-CuTg45ct.mjs → module-BXKUB58R.mjs} +9 -4
- package/dist/node/module-BXKUB58R.mjs.map +1 -0
- package/dist/node/{module-BEEASith.mjs → module-CaBtkQmd.mjs} +16 -16
- package/dist/node/module-CaBtkQmd.mjs.map +1 -0
- package/dist/node/pieces/ai/descriptor.json +1 -1
- package/dist/node/pieces/ai/index.mjs +15 -14
- package/dist/node/pieces/ai/package.json +1 -1
- package/dist/node/pieces/reactor/descriptor.json +1 -1
- package/dist/node/pieces/reactor/package.json +1 -1
- package/dist/node/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/node/upgrade-manifests-BCCpSD1J.mjs +8 -0
- package/dist/node/{upgrade-manifests-BA5OaR4H.mjs.map → upgrade-manifests-BCCpSD1J.mjs.map} +1 -1
- package/dist/powerhouse.manifest.json +2 -2
- package/dist/types/document-models/connection/v1/actions.d.ts +1 -0
- package/dist/types/document-models/connection/v1/actions.d.ts.map +1 -1
- package/dist/types/document-models/connection/v1/module.d.ts +1 -0
- package/dist/types/document-models/connection/v1/module.d.ts.map +1 -1
- package/dist/types/document-models/document-models.d.ts +2 -0
- package/dist/types/document-models/document-models.d.ts.map +1 -1
- package/dist/types/document-models/workflow/v1/actions.d.ts +1 -0
- package/dist/types/document-models/workflow/v1/actions.d.ts.map +1 -1
- package/dist/types/document-models/workflow/v1/module.d.ts +1 -0
- package/dist/types/document-models/workflow/v1/module.d.ts.map +1 -1
- package/dist/types/editors/connection-editor/editor.d.ts.map +1 -1
- package/dist/types/editors/shared/editor-chrome.d.ts +4 -1
- package/dist/types/editors/shared/editor-chrome.d.ts.map +1 -1
- package/dist/types/editors/shared/undo-plan.d.ts +12 -5
- package/dist/types/editors/shared/undo-plan.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/document/useWorkflowModel.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/editor.d.ts.map +1 -1
- package/package.json +22 -10
- package/dist/browser/connection-form-B6zpGmAm.js.map +0 -1
- package/dist/browser/editor-Yt-_V04R.js.map +0 -1
- package/dist/node/BlockSelector-Cia1Rpwz.mjs +0 -8727
- package/dist/node/BlockSelector-Cia1Rpwz.mjs.map +0 -1
- package/dist/node/PieceMarkdown-CUSdTMH4.mjs +0 -23307
- package/dist/node/PieceMarkdown-CUSdTMH4.mjs.map +0 -1
- package/dist/node/block-type-kX-27vVt.mjs +0 -44
- package/dist/node/block-type-kX-27vVt.mjs.map +0 -1
- package/dist/node/connection-BZxipUlb.mjs +0 -90
- package/dist/node/connection-BZxipUlb.mjs.map +0 -1
- package/dist/node/connection-form-CJFKPwfg.mjs +0 -1364
- package/dist/node/connection-form-CJFKPwfg.mjs.map +0 -1
- package/dist/node/data-tree-D9jdFsaX.mjs +0 -1916
- package/dist/node/data-tree-D9jdFsaX.mjs.map +0 -1
- package/dist/node/editor-CwOjO82y.mjs +0 -3218
- package/dist/node/editor-CwOjO82y.mjs.map +0 -1
- package/dist/node/editor-NMRVprgI.mjs +0 -15573
- package/dist/node/editor-NMRVprgI.mjs.map +0 -1
- package/dist/node/editor-_c6UDRAN.mjs +0 -370
- package/dist/node/editor-_c6UDRAN.mjs.map +0 -1
- package/dist/node/editors/connection-editor/module.mjs +0 -15
- package/dist/node/editors/connection-editor/module.mjs.map +0 -1
- package/dist/node/editors/runtime/index.mjs +0 -2
- package/dist/node/editors/workflow-editor/module.mjs +0 -15
- package/dist/node/editors/workflow-editor/module.mjs.map +0 -1
- package/dist/node/editors/workflow-studio/module.mjs +0 -15
- package/dist/node/editors/workflow-studio/module.mjs.map +0 -1
- package/dist/node/graphql-D76E1YiQ.mjs +0 -14554
- package/dist/node/graphql-D76E1YiQ.mjs.map +0 -1
- package/dist/node/module-BEEASith.mjs.map +0 -1
- package/dist/node/module-CuTg45ct.mjs.map +0 -1
- package/dist/node/piece-auth-C0u0XTO8.mjs +0 -154
- package/dist/node/piece-auth-C0u0XTO8.mjs.map +0 -1
- package/dist/node/rolldown-runtime-B4iAMlE-.mjs +0 -35
- package/dist/node/runtime-queries-Ck5OoWdy.mjs +0 -3016
- package/dist/node/runtime-queries-Ck5OoWdy.mjs.map +0 -1
- package/dist/node/style.css +0 -667
- package/dist/node/trigger-text-T2D0a2Br.mjs +0 -3210
- package/dist/node/trigger-text-T2D0a2Br.mjs.map +0 -1
- package/dist/node/upgrade-manifests-BA5OaR4H.mjs +0 -8
- package/dist/node/workflow-BgURVzdc.mjs +0 -109
- package/dist/node/workflow-BgURVzdc.mjs.map +0 -1
|
@@ -1,1364 +0,0 @@
|
|
|
1
|
-
import { _ as defaultReactorConnectionConfig, h as REACTOR_CONNECTOR_ID, v as isReactorConnectorId, x as actions, y as parseReactorConnectionConfig } from "./module-BEEASith.mjs";
|
|
2
|
-
import { a as isAuthComplete, c as planForConnection, d as serviceName, i as connectorIdForPiece, l as planFromAuth, n as REACTOR_SERVICE_LABEL, r as UNKNOWN_AUTH, s as packageFromConnectorId, t as OAUTH_TOKEN, u as plansFromAuth } from "./piece-auth-C0u0XTO8.mjs";
|
|
3
|
-
import { v as runtimeKeys } from "./runtime-queries-Ck5OoWdy.mjs";
|
|
4
|
-
import { At as Button, Ct as useRuntime, Dt as ITEM_PARAM, Ft as Segmented, It as Select, Lt as Switch, M as formatWhen, Mt as FieldLabel$1, Nt as Hint$1, Pt as IconButton, Tt as useSecretStat, Ut as textInputClass, Wt as Icon, Yt as useQuery, _t as useOAuthAttempt, jt as FieldError, vt as useOAuthRedirectUri, wt as useRuntimeActions, yt as usePieceCatalog } from "./BlockSelector-Cia1Rpwz.mjs";
|
|
5
|
-
import { dispatchActions, getPHStore, setSearchParams, useDid, useDocumentById, useDrives, usePHNavigation, useReactorClient, useRenownAuth, useSearchParams, useSetSelectedNode } from "@powerhousedao/reactor-browser";
|
|
6
|
-
import { generateId } from "document-model";
|
|
7
|
-
import { useEffect, useId, useRef, useState } from "react";
|
|
8
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
import { baseReducerVersion, decide, garbageCollect, garbageCollectV2, generateId as generateId$1, setGrant, sortOperations, undo } from "@powerhousedao/shared/document-model";
|
|
10
|
-
//#region editors/shared/undo-plan.ts
|
|
11
|
-
const GROUP_PREFIX = "undo-group:";
|
|
12
|
-
function newUndoGroup() {
|
|
13
|
-
return generateId$1();
|
|
14
|
-
}
|
|
15
|
-
function groupedAction(action, group) {
|
|
16
|
-
return {
|
|
17
|
-
...action,
|
|
18
|
-
id: `${GROUP_PREFIX}${group}:${generateId$1()}`
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function undoGroupOf(action) {
|
|
22
|
-
if (!action.id.startsWith(GROUP_PREFIX)) return void 0;
|
|
23
|
-
const end = action.id.indexOf(":", 11);
|
|
24
|
-
return end > 11 ? action.id.slice(11, end) : void 0;
|
|
25
|
-
}
|
|
26
|
-
function effectiveOperations(operations, protocolVersion) {
|
|
27
|
-
const sorted = sortOperations([...operations]);
|
|
28
|
-
return (protocolVersion >= 2 ? garbageCollectV2(sorted) : garbageCollect(sorted)).filter((operation) => operation.action.type !== "NOOP");
|
|
29
|
-
}
|
|
30
|
-
function editStart(effective, last, policy) {
|
|
31
|
-
const group = undoGroupOf(effective[last].action);
|
|
32
|
-
if (!group) return last;
|
|
33
|
-
let start = last;
|
|
34
|
-
for (let index = last - 1; index >= 0; index--) {
|
|
35
|
-
const { action, error } = effective[index];
|
|
36
|
-
if (undoGroupOf(action) === group) start = index;
|
|
37
|
-
else if (!error && !policy.skip.has(action.type)) break;
|
|
38
|
-
}
|
|
39
|
-
return start;
|
|
40
|
-
}
|
|
41
|
-
function planUndo(effective, policy) {
|
|
42
|
-
for (let last = effective.length - 1; last >= 0; last--) {
|
|
43
|
-
const { action, error } = effective[last];
|
|
44
|
-
if (error || policy.skip.has(action.type)) continue;
|
|
45
|
-
const start = editStart(effective, last, policy);
|
|
46
|
-
const group = undoGroupOf(action);
|
|
47
|
-
const isMember = (candidate) => candidate === action || group !== void 0 && undoGroupOf(candidate) === group;
|
|
48
|
-
const applied = effective.slice(start).filter((operation) => !operation.error).map((operation) => operation.action);
|
|
49
|
-
const undone = applied.filter(isMember);
|
|
50
|
-
const replay = applied.filter((candidate) => !isMember(candidate)).map((candidate) => policy.replay?.(candidate, undone)).filter((kept) => kept !== void 0);
|
|
51
|
-
return {
|
|
52
|
-
undos: effective.length - start,
|
|
53
|
-
replay,
|
|
54
|
-
undone
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
function headIndex(operations) {
|
|
60
|
-
return operations.reduce((head, op) => Math.max(head, op.index), -1);
|
|
61
|
-
}
|
|
62
|
-
function editedSince(operations, head, policy) {
|
|
63
|
-
return operations.some((op) => op.index > head && op.action.type !== "NOOP" && !policy.skip.has(op.action.type));
|
|
64
|
-
}
|
|
65
|
-
function redoAction(action) {
|
|
66
|
-
return {
|
|
67
|
-
id: generateId$1(),
|
|
68
|
-
type: action.type,
|
|
69
|
-
scope: action.scope,
|
|
70
|
-
input: action.input,
|
|
71
|
-
timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString()
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function redoActions(actions) {
|
|
75
|
-
if (actions.length <= 1) return actions.map(redoAction);
|
|
76
|
-
const group = newUndoGroup();
|
|
77
|
-
return actions.map((action) => groupedAction(redoAction(action), group));
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region editors/shared/editor-chrome.tsx
|
|
81
|
-
/** Back where the user came from, else to the studio's root. */
|
|
82
|
-
function BackButton(props) {
|
|
83
|
-
const navigation = usePHNavigation();
|
|
84
|
-
const setSelectedNode = useSetSelectedNode();
|
|
85
|
-
const item = useSearchParams()[ITEM_PARAM];
|
|
86
|
-
const close = () => {
|
|
87
|
-
if (navigation.closeOpened?.()) return;
|
|
88
|
-
setSelectedNode(void 0, { search: { [ITEM_PARAM]: item } });
|
|
89
|
-
};
|
|
90
|
-
return /* @__PURE__ */ jsxs(Button, {
|
|
91
|
-
size: "sm",
|
|
92
|
-
variant: "ghost",
|
|
93
|
-
className: "-ml-1",
|
|
94
|
-
onClick: close,
|
|
95
|
-
children: [/* @__PURE__ */ jsx(Icon, {
|
|
96
|
-
name: "back",
|
|
97
|
-
className: "h-3.5 w-3.5"
|
|
98
|
-
}), props.label ?? "Back"]
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
const NO_SKIP = { skip: /* @__PURE__ */ new Set() };
|
|
102
|
-
function protocolVersion(document) {
|
|
103
|
-
try {
|
|
104
|
-
return baseReducerVersion(document.header);
|
|
105
|
-
} catch {
|
|
106
|
-
return 1;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const PAGE = 500;
|
|
110
|
-
async function globalHistory(documentId) {
|
|
111
|
-
const client = getPHStore()?.reactorClient;
|
|
112
|
-
if (!client) return [];
|
|
113
|
-
let page = await client.getOperations(documentId, {
|
|
114
|
-
branch: "main",
|
|
115
|
-
scopes: ["global"]
|
|
116
|
-
}, void 0, {
|
|
117
|
-
cursor: "",
|
|
118
|
-
limit: PAGE
|
|
119
|
-
});
|
|
120
|
-
const all = [...page.results];
|
|
121
|
-
while (page.next && page.results.length > 0) {
|
|
122
|
-
page = await page.next();
|
|
123
|
-
all.push(...page.results);
|
|
124
|
-
}
|
|
125
|
-
return all;
|
|
126
|
-
}
|
|
127
|
-
function isEditable(target) {
|
|
128
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
129
|
-
return target.isContentEditable || target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT";
|
|
130
|
-
}
|
|
131
|
-
function UndoRedo(props) {
|
|
132
|
-
const [document, dispatch] = useDocumentById(props.documentId);
|
|
133
|
-
const policy = props.policy ?? NO_SKIP;
|
|
134
|
-
const canUndo = Object.values(document?.header.revision ?? {}).some(Boolean);
|
|
135
|
-
const [undone, setUndone] = useState([]);
|
|
136
|
-
const head = useRef(-1);
|
|
137
|
-
const own = useRef(/* @__PURE__ */ new Set());
|
|
138
|
-
const busy = useRef(false);
|
|
139
|
-
const send = (list) => new Promise((resolve, reject) => dispatch(list, (errors) => reject(errors[0]), () => resolve()));
|
|
140
|
-
const stale = (history) => editedSince(history.filter((op) => !own.current.has(op.action.id)), head.current, policy);
|
|
141
|
-
const settle = async (since) => {
|
|
142
|
-
head.current = headIndex(await globalHistory(props.documentId));
|
|
143
|
-
return head.current > since;
|
|
144
|
-
};
|
|
145
|
-
const run = (task) => {
|
|
146
|
-
if (!document || busy.current) return;
|
|
147
|
-
busy.current = true;
|
|
148
|
-
task().catch(() => void 0).finally(() => {
|
|
149
|
-
busy.current = false;
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
const doUndo = () => run(async () => {
|
|
153
|
-
const history = await globalHistory(props.documentId);
|
|
154
|
-
const plan = planUndo(effectiveOperations(history, protocolVersion(document)), policy);
|
|
155
|
-
if (!plan) return;
|
|
156
|
-
const keep = !stale(history);
|
|
157
|
-
try {
|
|
158
|
-
await send([...Array.from({ length: plan.undos }, () => undo()), ...plan.replay]);
|
|
159
|
-
} finally {
|
|
160
|
-
if (await settle(headIndex(history))) setUndone((list) => [...keep ? list : [], plan.undone]);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
const doRedo = () => run(async () => {
|
|
164
|
-
const last = undone.at(-1);
|
|
165
|
-
if (!last) return;
|
|
166
|
-
const history = await globalHistory(props.documentId);
|
|
167
|
-
if (stale(history)) {
|
|
168
|
-
setUndone([]);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const again = redoActions(last);
|
|
172
|
-
for (const action of again) own.current.add(action.id);
|
|
173
|
-
try {
|
|
174
|
-
await send(again);
|
|
175
|
-
} finally {
|
|
176
|
-
if (await settle(headIndex(history))) setUndone((list) => list.slice(0, -1));
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
const latest = useRef({
|
|
180
|
-
doUndo,
|
|
181
|
-
doRedo,
|
|
182
|
-
stale
|
|
183
|
-
});
|
|
184
|
-
useEffect(() => {
|
|
185
|
-
latest.current = {
|
|
186
|
-
doUndo,
|
|
187
|
-
doRedo,
|
|
188
|
-
stale
|
|
189
|
-
};
|
|
190
|
-
});
|
|
191
|
-
const revision = JSON.stringify(document?.header.revision ?? {});
|
|
192
|
-
const pending = undone.length > 0;
|
|
193
|
-
useEffect(() => {
|
|
194
|
-
if (!pending || busy.current) return;
|
|
195
|
-
let active = true;
|
|
196
|
-
globalHistory(props.documentId).then((history) => {
|
|
197
|
-
if (active && !busy.current && latest.current.stale(history)) setUndone([]);
|
|
198
|
-
});
|
|
199
|
-
return () => {
|
|
200
|
-
active = false;
|
|
201
|
-
};
|
|
202
|
-
}, [
|
|
203
|
-
revision,
|
|
204
|
-
pending,
|
|
205
|
-
props.documentId
|
|
206
|
-
]);
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
const onKeyDown = (event) => {
|
|
209
|
-
if (!(event.metaKey || event.ctrlKey) || event.altKey) return;
|
|
210
|
-
if (isEditable(event.target)) return;
|
|
211
|
-
const key = event.key.toLowerCase();
|
|
212
|
-
if (key === "z" && !event.shiftKey) {
|
|
213
|
-
event.preventDefault();
|
|
214
|
-
event.stopPropagation();
|
|
215
|
-
latest.current.doUndo();
|
|
216
|
-
} else if (key === "z" && event.shiftKey || key === "y") {
|
|
217
|
-
event.preventDefault();
|
|
218
|
-
event.stopPropagation();
|
|
219
|
-
latest.current.doRedo();
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
window.addEventListener("keydown", onKeyDown, true);
|
|
223
|
-
return () => window.removeEventListener("keydown", onKeyDown, true);
|
|
224
|
-
}, []);
|
|
225
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
226
|
-
className: "flex items-center",
|
|
227
|
-
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
228
|
-
icon: "undo",
|
|
229
|
-
label: "Undo",
|
|
230
|
-
disabled: !canUndo,
|
|
231
|
-
onClick: doUndo
|
|
232
|
-
}), /* @__PURE__ */ jsx(IconButton, {
|
|
233
|
-
icon: "redo",
|
|
234
|
-
label: "Redo",
|
|
235
|
-
disabled: undone.length === 0,
|
|
236
|
-
onClick: doRedo
|
|
237
|
-
})]
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region editors/connection-editor/connection-callbacks.ts
|
|
242
|
-
function connectionCallbacks(state, dispatch) {
|
|
243
|
-
return {
|
|
244
|
-
setName: (name) => {
|
|
245
|
-
dispatch(actions.setConnectionName({ name }));
|
|
246
|
-
dispatch(actions.setName(name));
|
|
247
|
-
},
|
|
248
|
-
pickPiece: (piece) => {
|
|
249
|
-
const plan = planFromAuth(piece.auth);
|
|
250
|
-
if (plan.authType === "UNKNOWN") return;
|
|
251
|
-
dispatch(actions.setConnector({
|
|
252
|
-
connectorId: connectorIdForPiece(piece.name),
|
|
253
|
-
authType: plan.authType
|
|
254
|
-
}));
|
|
255
|
-
},
|
|
256
|
-
setAuthType: (authType, keep) => {
|
|
257
|
-
dispatch(actions.setConnector({
|
|
258
|
-
connectorId: state.connectorId,
|
|
259
|
-
authType
|
|
260
|
-
}));
|
|
261
|
-
for (const name of Object.keys(configFields(state.config))) if (!keep.config.includes(name)) dispatch(actions.removeConfigValue({ name }));
|
|
262
|
-
for (const ref of state.secretRefs) if (!keep.secrets.includes(ref.name)) dispatch(actions.removeSecretRef({ id: ref.id }));
|
|
263
|
-
},
|
|
264
|
-
setConfigValue: (name, value) => {
|
|
265
|
-
dispatch(value === void 0 ? actions.removeConfigValue({ name }) : actions.setConfigValue({
|
|
266
|
-
name,
|
|
267
|
-
value
|
|
268
|
-
}));
|
|
269
|
-
},
|
|
270
|
-
setSecretRef: (name, ref) => {
|
|
271
|
-
const existing = state.secretRefs.find((entry) => entry.name === name);
|
|
272
|
-
dispatch(actions.setSecretRef({
|
|
273
|
-
id: existing?.id ?? generateId(),
|
|
274
|
-
name,
|
|
275
|
-
ref
|
|
276
|
-
}));
|
|
277
|
-
},
|
|
278
|
-
removeSecretRef: (name) => {
|
|
279
|
-
const existing = state.secretRefs.find((entry) => entry.name === name);
|
|
280
|
-
if (existing) dispatch(actions.removeSecretRef({ id: existing.id }));
|
|
281
|
-
},
|
|
282
|
-
setStatus: (status) => {
|
|
283
|
-
dispatch(actions.recordCheckResult({
|
|
284
|
-
status,
|
|
285
|
-
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
286
|
-
}));
|
|
287
|
-
},
|
|
288
|
-
pickReactor: () => {
|
|
289
|
-
dispatch(actions.setConnector({
|
|
290
|
-
connectorId: REACTOR_CONNECTOR_ID,
|
|
291
|
-
authType: "REACTOR"
|
|
292
|
-
}));
|
|
293
|
-
dispatch(actions.setConfig({ config: defaultReactorConnectionConfig() }));
|
|
294
|
-
dispatch(actions.recordCheckResult({
|
|
295
|
-
status: "OK",
|
|
296
|
-
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
297
|
-
}));
|
|
298
|
-
},
|
|
299
|
-
setReactorAccess: (access) => {
|
|
300
|
-
if (parseReactorConnectionConfig(state.config).ok) dispatch(access === "read" ? actions.setConfigValue({
|
|
301
|
-
name: "access",
|
|
302
|
-
value: "read"
|
|
303
|
-
}) : actions.removeConfigValue({ name: "access" }));
|
|
304
|
-
else dispatch(actions.setConfig({ config: {
|
|
305
|
-
...defaultReactorConnectionConfig(),
|
|
306
|
-
...access === "read" ? { access } : {}
|
|
307
|
-
} }));
|
|
308
|
-
if (state.status === "UNCONFIGURED") dispatch(actions.recordCheckResult({
|
|
309
|
-
status: "OK",
|
|
310
|
-
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
311
|
-
}));
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
function configFields(config) {
|
|
316
|
-
return config !== null && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
317
|
-
}
|
|
318
|
-
//#endregion
|
|
319
|
-
//#region editors/connection-editor/status.ts
|
|
320
|
-
const CONNECTION_STATUS_STYLES = {
|
|
321
|
-
OK: "bg-wf-ok/12 text-wf-ok",
|
|
322
|
-
ERROR: "bg-wf-fail/12 text-wf-fail",
|
|
323
|
-
REVOKED: "bg-wf-fail/12 text-wf-fail",
|
|
324
|
-
UNCONFIGURED: "bg-wf-warn/12 text-wf-warn"
|
|
325
|
-
};
|
|
326
|
-
const CONNECTION_STATUS_LABEL = {
|
|
327
|
-
OK: "Connected",
|
|
328
|
-
ERROR: "Error",
|
|
329
|
-
REVOKED: "Revoked",
|
|
330
|
-
UNCONFIGURED: "Not set up"
|
|
331
|
-
};
|
|
332
|
-
const AUTH_TYPE_LABEL = {
|
|
333
|
-
[UNKNOWN_AUTH]: "Not supported by this runtime",
|
|
334
|
-
NONE: "None",
|
|
335
|
-
SECRET_TEXT: "API key",
|
|
336
|
-
BASIC_AUTH: "Username and password",
|
|
337
|
-
CUSTOM_AUTH: "Keys and tokens",
|
|
338
|
-
OAUTH2: "OAuth 2",
|
|
339
|
-
OIDC: "OpenID Connect",
|
|
340
|
-
REACTOR: "Reactor access"
|
|
341
|
-
};
|
|
342
|
-
function isReactorConnection(connection) {
|
|
343
|
-
return connection.authType === "REACTOR" && connection.connectorId === "@powerhousedao/reactor#reactor";
|
|
344
|
-
}
|
|
345
|
-
function reactorConnections(connections) {
|
|
346
|
-
return connections.filter(isReactorConnection);
|
|
347
|
-
}
|
|
348
|
-
function signInRequired(access, signedIn) {
|
|
349
|
-
return access?.authEnforcement === true && !signedIn;
|
|
350
|
-
}
|
|
351
|
-
function switchboardGrantId(identity) {
|
|
352
|
-
return `switchboard:${identity.address ?? identity.key}`;
|
|
353
|
-
}
|
|
354
|
-
const SWITCHBOARD_DOCUMENT_OPERATIONS = [
|
|
355
|
-
"DELETE_DOCUMENT",
|
|
356
|
-
"ADD_RELATIONSHIP",
|
|
357
|
-
"REMOVE_RELATIONSHIP"
|
|
358
|
-
];
|
|
359
|
-
function switchboardGrants(identity, authConditions) {
|
|
360
|
-
if (!identity) return [];
|
|
361
|
-
const principal = authConditions ? { match: { eq: [{ attr: "subject.key" }, { lit: identity.key }] } } : identity.address ? { address: identity.address } : null;
|
|
362
|
-
if (!principal) return [];
|
|
363
|
-
const grant = (id, capability) => ({
|
|
364
|
-
id,
|
|
365
|
-
description: "Lets the Switchboard apply workflow writes",
|
|
366
|
-
effect: "allow",
|
|
367
|
-
principal,
|
|
368
|
-
capability
|
|
369
|
-
});
|
|
370
|
-
return [grant(switchboardGrantId(identity), {
|
|
371
|
-
can: "execute",
|
|
372
|
-
scope: "global"
|
|
373
|
-
}), grant(`${switchboardGrantId(identity)}:document`, {
|
|
374
|
-
can: "execute",
|
|
375
|
-
scope: "document",
|
|
376
|
-
operation: [...SWITCHBOARD_DOCUMENT_OPERATIONS]
|
|
377
|
-
})];
|
|
378
|
-
}
|
|
379
|
-
function switchboardMayWrite(auth, identity) {
|
|
380
|
-
const id = switchboardGrantId(identity);
|
|
381
|
-
const ids = new Set(auth?.grants.map((grant) => grant.id));
|
|
382
|
-
if (ids.has(id) && ids.has(`${id}:document`)) return true;
|
|
383
|
-
const subject = identity.address ? { address: identity.address } : {};
|
|
384
|
-
return decide(auth, subject, {
|
|
385
|
-
verb: "execute",
|
|
386
|
-
scope: "global"
|
|
387
|
-
}) === "allow" && SWITCHBOARD_DOCUMENT_OPERATIONS.every((operation) => decide(auth, subject, {
|
|
388
|
-
verb: "execute",
|
|
389
|
-
scope: "document",
|
|
390
|
-
operation
|
|
391
|
-
}) === "allow");
|
|
392
|
-
}
|
|
393
|
-
function canChangeGrants(auth, subject) {
|
|
394
|
-
return decide(auth, subject, {
|
|
395
|
-
verb: "execute",
|
|
396
|
-
scope: "auth",
|
|
397
|
-
operation: "SET_GRANT"
|
|
398
|
-
}) === "allow";
|
|
399
|
-
}
|
|
400
|
-
function planGrants(ids, authOf, subject) {
|
|
401
|
-
const plan = {
|
|
402
|
-
grantable: [],
|
|
403
|
-
noPermission: [],
|
|
404
|
-
notHere: []
|
|
405
|
-
};
|
|
406
|
-
for (const id of ids) {
|
|
407
|
-
const auth = authOf(id);
|
|
408
|
-
if (auth === null) plan.notHere.push(id);
|
|
409
|
-
else if (canChangeGrants(auth, subject)) plan.grantable.push(id);
|
|
410
|
-
else plan.noPermission.push(id);
|
|
411
|
-
}
|
|
412
|
-
return plan;
|
|
413
|
-
}
|
|
414
|
-
function accessMismatch(requireReactor, access) {
|
|
415
|
-
return requireReactor === "write" && access === "read" ? "Writes, but this connection allows reads only" : null;
|
|
416
|
-
}
|
|
417
|
-
//#endregion
|
|
418
|
-
//#region editors/workflow-editor/ui/reactor-view.ts
|
|
419
|
-
function shortAddress(address) {
|
|
420
|
-
return address.length <= 12 ? address : `${address.slice(0, 6)}…${address.slice(-4)}`;
|
|
421
|
-
}
|
|
422
|
-
function publisherOf(operations) {
|
|
423
|
-
let latest;
|
|
424
|
-
for (const operation of operations) {
|
|
425
|
-
if (operation.action.type !== "PUBLISH_WORKFLOW") continue;
|
|
426
|
-
if (operation.error) continue;
|
|
427
|
-
if (!latest || operation.index > latest.index) latest = operation;
|
|
428
|
-
}
|
|
429
|
-
if (!latest) return void 0;
|
|
430
|
-
const signer = latest.action.context?.signer;
|
|
431
|
-
const address = signer?.user?.address;
|
|
432
|
-
return address && signer.signatures?.length ? address : null;
|
|
433
|
-
}
|
|
434
|
-
function runsAsText(publisher, loading, hostAddress) {
|
|
435
|
-
if (loading) return null;
|
|
436
|
-
if (publisher && hostAddress && publisher.toLowerCase() === hostAddress.toLowerCase()) return "Published by the Switchboard: runs get no reactor access while document permissions are enforced.";
|
|
437
|
-
if (publisher === void 0) return "Not published yet: runs will act as whoever publishes.";
|
|
438
|
-
if (publisher === null) return "Published unsigned: runs get no reactor access while document permissions are enforced.";
|
|
439
|
-
return `Runs as ${shortAddress(publisher)} (last publisher)`;
|
|
440
|
-
}
|
|
441
|
-
function missingInPublished(blocks) {
|
|
442
|
-
return blocks.filter((block) => block.requireReactor && !block.reactorConnectionId).map((block) => block.label);
|
|
443
|
-
}
|
|
444
|
-
//#endregion
|
|
445
|
-
//#region editors/workflow-editor/reactor-hooks.ts
|
|
446
|
-
function useReactorAccess() {
|
|
447
|
-
const { client, queryClient } = useRuntime();
|
|
448
|
-
const { address } = useRenownAuth();
|
|
449
|
-
return useQuery({
|
|
450
|
-
queryKey: runtimeKeys.reactorAccess(client.url, address ?? null),
|
|
451
|
-
queryFn: () => client.fetchReactorAccess(),
|
|
452
|
-
staleTime: 3e5
|
|
453
|
-
}, queryClient).data;
|
|
454
|
-
}
|
|
455
|
-
function useSignInGate() {
|
|
456
|
-
const access = useReactorAccess();
|
|
457
|
-
const auth = useRenownAuth();
|
|
458
|
-
const did = useDid();
|
|
459
|
-
const signedIn = auth.status === "authorized" && Boolean(auth.address);
|
|
460
|
-
return {
|
|
461
|
-
required: signInRequired(access, signedIn),
|
|
462
|
-
signedIn,
|
|
463
|
-
pending: auth.pending || auth.status === "checking",
|
|
464
|
-
login: () => auth.login(),
|
|
465
|
-
access,
|
|
466
|
-
subject: {
|
|
467
|
-
...auth.address ? { address: auth.address } : {},
|
|
468
|
-
...did ? { key: did } : {}
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
function useDocumentAuths(ids) {
|
|
473
|
-
const { client: runtime, queryClient } = useRuntime();
|
|
474
|
-
const reactor = useReactorClient();
|
|
475
|
-
const query = useQuery({
|
|
476
|
-
queryKey: [
|
|
477
|
-
runtime.url,
|
|
478
|
-
"documentAuth",
|
|
479
|
-
[...ids].sort()
|
|
480
|
-
],
|
|
481
|
-
queryFn: async () => new Map(await Promise.all(ids.map(async (id) => {
|
|
482
|
-
try {
|
|
483
|
-
return [id, (await reactor.get(id)).state.auth];
|
|
484
|
-
} catch {
|
|
485
|
-
return [id, null];
|
|
486
|
-
}
|
|
487
|
-
}))),
|
|
488
|
-
enabled: ids.length > 0 && Boolean(reactor),
|
|
489
|
-
staleTime: 0,
|
|
490
|
-
gcTime: 0
|
|
491
|
-
}, queryClient);
|
|
492
|
-
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
493
|
-
if (!reactor) return new Map(ids.map((id) => [id, null]));
|
|
494
|
-
return query.data;
|
|
495
|
-
}
|
|
496
|
-
async function grantOnDocuments(ids, grants) {
|
|
497
|
-
return Promise.all(ids.map(async (id) => {
|
|
498
|
-
let failure;
|
|
499
|
-
try {
|
|
500
|
-
if (!await dispatchActions(grants.map((grant) => setGrant({ grant })), id, (errors) => {
|
|
501
|
-
failure = errors[0]?.message ?? "The grant was refused";
|
|
502
|
-
}) && !failure) failure = "The grant was not applied";
|
|
503
|
-
} catch (error) {
|
|
504
|
-
failure = error instanceof Error ? error.message : String(error);
|
|
505
|
-
}
|
|
506
|
-
return failure ? {
|
|
507
|
-
id,
|
|
508
|
-
error: failure
|
|
509
|
-
} : { id };
|
|
510
|
-
}));
|
|
511
|
-
}
|
|
512
|
-
function useReactorAccessDenial(workflowId, refresh) {
|
|
513
|
-
const { client, queryClient } = useRuntime();
|
|
514
|
-
return useQuery({
|
|
515
|
-
queryKey: [...runtimeKeys.reactorDenial(client.url, workflowId ?? ""), refresh],
|
|
516
|
-
queryFn: () => client.fetchReactorAccessDenial(workflowId),
|
|
517
|
-
enabled: Boolean(workflowId),
|
|
518
|
-
refetchInterval: 15e3,
|
|
519
|
-
staleTime: 0
|
|
520
|
-
}, queryClient).data ?? null;
|
|
521
|
-
}
|
|
522
|
-
function usePublisher(workflowId, publishedVersion) {
|
|
523
|
-
const { client: runtime, queryClient } = useRuntime();
|
|
524
|
-
const reactor = useReactorClient();
|
|
525
|
-
const query = useQuery({
|
|
526
|
-
queryKey: [
|
|
527
|
-
runtime.url,
|
|
528
|
-
"publisher",
|
|
529
|
-
workflowId,
|
|
530
|
-
publishedVersion ?? 0
|
|
531
|
-
],
|
|
532
|
-
queryFn: async () => {
|
|
533
|
-
const operations = [];
|
|
534
|
-
let page = await reactor.getOperations(workflowId, { scopes: ["global"] }, { actionTypes: ["PUBLISH_WORKFLOW"] });
|
|
535
|
-
for (;;) {
|
|
536
|
-
operations.push(...page.results);
|
|
537
|
-
if (!page.next || page.results.length === 0) break;
|
|
538
|
-
try {
|
|
539
|
-
page = await page.next();
|
|
540
|
-
} catch {
|
|
541
|
-
break;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
const found = publisherOf(operations);
|
|
545
|
-
return found === void 0 ? "" : found;
|
|
546
|
-
},
|
|
547
|
-
enabled: Boolean(workflowId && reactor),
|
|
548
|
-
staleTime: Infinity
|
|
549
|
-
}, queryClient);
|
|
550
|
-
if (query.status === "error") return {
|
|
551
|
-
publisher: void 0,
|
|
552
|
-
loading: false
|
|
553
|
-
};
|
|
554
|
-
if (query.status === "pending") return {
|
|
555
|
-
publisher: void 0,
|
|
556
|
-
loading: Boolean(workflowId && reactor)
|
|
557
|
-
};
|
|
558
|
-
return {
|
|
559
|
-
publisher: query.data === "" ? void 0 : query.data,
|
|
560
|
-
loading: false
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region editors/workflow-editor/ui/document-options.ts
|
|
565
|
-
function documentOptions(drives) {
|
|
566
|
-
const seen = /* @__PURE__ */ new Map();
|
|
567
|
-
for (const drive of drives) {
|
|
568
|
-
const driveName = drive.state.global.name || drive.header.name || "";
|
|
569
|
-
for (const node of drive.state.global.nodes) {
|
|
570
|
-
if (node.kind.toUpperCase() !== "FILE" || seen.has(node.id)) continue;
|
|
571
|
-
seen.set(node.id, {
|
|
572
|
-
value: node.id,
|
|
573
|
-
label: node.name || node.id,
|
|
574
|
-
description: [node.documentType, driveName].filter(Boolean).join(" · ")
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
return [...seen.values()].sort((a, b) => a.label.localeCompare(b.label));
|
|
579
|
-
}
|
|
580
|
-
//#endregion
|
|
581
|
-
//#region editors/workflow-editor/ui/SignInPrompt.tsx
|
|
582
|
-
function SignInPrompt(props) {
|
|
583
|
-
const { gate } = props;
|
|
584
|
-
if (!gate.required) return null;
|
|
585
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
586
|
-
role: "note",
|
|
587
|
-
"aria-label": "Sign in required",
|
|
588
|
-
className: "flex items-start gap-2.5 rounded-md border border-solid border-wf-warn/30 bg-wf-warn/10 px-3 py-2.5",
|
|
589
|
-
children: [
|
|
590
|
-
/* @__PURE__ */ jsx(Icon, {
|
|
591
|
-
name: "lock",
|
|
592
|
-
className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-wf-warn"
|
|
593
|
-
}),
|
|
594
|
-
/* @__PURE__ */ jsxs("p", {
|
|
595
|
-
className: "min-w-0 flex-1 text-xs leading-relaxed text-foreground",
|
|
596
|
-
children: ["This Switchboard enforces document permissions. ", props.reason]
|
|
597
|
-
}),
|
|
598
|
-
/* @__PURE__ */ jsx(Button, {
|
|
599
|
-
size: "sm",
|
|
600
|
-
variant: "primary",
|
|
601
|
-
disabled: gate.pending,
|
|
602
|
-
onClick: gate.login,
|
|
603
|
-
children: gate.pending ? "Signing in…" : "Sign in"
|
|
604
|
-
})
|
|
605
|
-
]
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
//#endregion
|
|
609
|
-
//#region editors/workflow-editor/ui/SwitchboardGrants.tsx
|
|
610
|
-
function NamedList(props) {
|
|
611
|
-
if (props.ids.length === 0) return null;
|
|
612
|
-
return /* @__PURE__ */ jsxs("div", { children: [
|
|
613
|
-
/* @__PURE__ */ jsx("p", {
|
|
614
|
-
className: "text-xs font-medium text-foreground",
|
|
615
|
-
children: props.heading
|
|
616
|
-
}),
|
|
617
|
-
/* @__PURE__ */ jsx("ul", {
|
|
618
|
-
"aria-label": props.label,
|
|
619
|
-
className: "mt-1",
|
|
620
|
-
children: props.ids.map((id) => /* @__PURE__ */ jsx("li", {
|
|
621
|
-
className: "truncate text-xs text-foreground",
|
|
622
|
-
children: props.names.get(id) ?? id
|
|
623
|
-
}, id))
|
|
624
|
-
}),
|
|
625
|
-
/* @__PURE__ */ jsx("p", {
|
|
626
|
-
className: "mt-1 text-xs text-muted-foreground",
|
|
627
|
-
children: props.next
|
|
628
|
-
})
|
|
629
|
-
] });
|
|
630
|
-
}
|
|
631
|
-
function SwitchboardGrants() {
|
|
632
|
-
const gate = useSignInGate();
|
|
633
|
-
const options = documentOptions(useDrives() ?? []);
|
|
634
|
-
const [chosen, setChosen] = useState([]);
|
|
635
|
-
const auths = useDocumentAuths(chosen);
|
|
636
|
-
const [busy, setBusy] = useState(false);
|
|
637
|
-
const [outcomes, setOutcomes] = useState([]);
|
|
638
|
-
const access = gate.access;
|
|
639
|
-
if (!access?.authEnforcement) return null;
|
|
640
|
-
const identity = access.reactorIdentity;
|
|
641
|
-
const grants = switchboardGrants(identity, access.authConditions);
|
|
642
|
-
const names = new Map(options.map((option) => [option.value, option.label]));
|
|
643
|
-
const header = /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h4", {
|
|
644
|
-
className: "text-[13px] font-medium text-foreground",
|
|
645
|
-
children: "Switchboard grants"
|
|
646
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
647
|
-
className: "mt-0.5 text-xs text-muted-foreground",
|
|
648
|
-
children: "With document permissions enforced, a write lands only when the Switchboard may make it too. Grant it on each document steps write."
|
|
649
|
-
})] });
|
|
650
|
-
if (!gate.signedIn) return /* @__PURE__ */ jsxs("section", {
|
|
651
|
-
"aria-label": "Switchboard grants",
|
|
652
|
-
className: "flex flex-col gap-3",
|
|
653
|
-
children: [header, /* @__PURE__ */ jsx(SignInPrompt, {
|
|
654
|
-
gate: {
|
|
655
|
-
...gate,
|
|
656
|
-
required: true
|
|
657
|
-
},
|
|
658
|
-
reason: "Sign in to grant the Switchboard on documents."
|
|
659
|
-
})]
|
|
660
|
-
});
|
|
661
|
-
if (!identity || grants.length === 0) return /* @__PURE__ */ jsxs("section", {
|
|
662
|
-
"aria-label": "Switchboard grants",
|
|
663
|
-
className: "flex flex-col gap-3",
|
|
664
|
-
children: [header, /* @__PURE__ */ jsx("p", {
|
|
665
|
-
className: "text-xs text-wf-warn",
|
|
666
|
-
children: "The Switchboard does not say who it signs as, so it can't be granted from here."
|
|
667
|
-
})]
|
|
668
|
-
});
|
|
669
|
-
const done = new Set(outcomes.filter((outcome) => !outcome.error).map((outcome) => outcome.id));
|
|
670
|
-
const failed = new Map(outcomes.flatMap((outcome) => outcome.error ? [[outcome.id, outcome.error]] : []));
|
|
671
|
-
const granted = chosen.filter((id) => {
|
|
672
|
-
if (done.has(id)) return true;
|
|
673
|
-
const auth = auths?.get(id);
|
|
674
|
-
return auths?.has(id) && auth !== null && switchboardMayWrite(auth, identity);
|
|
675
|
-
});
|
|
676
|
-
const pending = chosen.filter((id) => !granted.includes(id));
|
|
677
|
-
const plan = auths ? planGrants(pending, (id) => auths.get(id), gate.subject) : null;
|
|
678
|
-
const grantOn = (ids) => {
|
|
679
|
-
setBusy(true);
|
|
680
|
-
grantOnDocuments(ids, grants).then((next) => setOutcomes((previous) => [...previous.filter((outcome) => !ids.includes(outcome.id)), ...next])).finally(() => setBusy(false));
|
|
681
|
-
};
|
|
682
|
-
return /* @__PURE__ */ jsxs("section", {
|
|
683
|
-
"aria-label": "Switchboard grants",
|
|
684
|
-
className: "flex flex-col gap-3",
|
|
685
|
-
children: [
|
|
686
|
-
header,
|
|
687
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
688
|
-
/* @__PURE__ */ jsx(FieldLabel$1, {
|
|
689
|
-
label: "Documents",
|
|
690
|
-
optional: true
|
|
691
|
-
}),
|
|
692
|
-
/* @__PURE__ */ jsx(Select, {
|
|
693
|
-
ariaLabel: "Documents to grant on",
|
|
694
|
-
multiple: true,
|
|
695
|
-
searchable: true,
|
|
696
|
-
value: chosen,
|
|
697
|
-
options,
|
|
698
|
-
placeholder: "Choose documents",
|
|
699
|
-
emptyText: "No documents in this Connect's drives.",
|
|
700
|
-
onChange: setChosen
|
|
701
|
-
}),
|
|
702
|
-
/* @__PURE__ */ jsx(Hint$1, { text: "Grants are per document; a drive's grants do not cover its documents." })
|
|
703
|
-
] }),
|
|
704
|
-
chosen.length > 0 && !plan ? /* @__PURE__ */ jsx("div", { className: "h-10 animate-pulse rounded-md bg-foreground/5" }) : null,
|
|
705
|
-
granted.length > 0 ? /* @__PURE__ */ jsx("ul", {
|
|
706
|
-
"aria-label": "Documents the Switchboard may write",
|
|
707
|
-
className: "flex flex-col gap-1",
|
|
708
|
-
children: granted.map((id) => /* @__PURE__ */ jsxs("li", {
|
|
709
|
-
className: "flex items-center gap-2 text-xs",
|
|
710
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
711
|
-
className: "min-w-0 flex-1 truncate text-foreground",
|
|
712
|
-
children: names.get(id) ?? id
|
|
713
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
714
|
-
className: "text-wf-ok",
|
|
715
|
-
children: "Granted"
|
|
716
|
-
})]
|
|
717
|
-
}, id))
|
|
718
|
-
}) : null,
|
|
719
|
-
plan && plan.grantable.length > 0 ? /* @__PURE__ */ jsx("ul", {
|
|
720
|
-
className: "flex flex-col gap-1",
|
|
721
|
-
children: plan.grantable.map((id) => /* @__PURE__ */ jsxs("li", {
|
|
722
|
-
className: "flex items-center gap-2 text-xs",
|
|
723
|
-
children: [
|
|
724
|
-
/* @__PURE__ */ jsx("span", {
|
|
725
|
-
className: "min-w-0 flex-1 truncate text-foreground",
|
|
726
|
-
children: names.get(id) ?? id
|
|
727
|
-
}),
|
|
728
|
-
failed.has(id) ? /* @__PURE__ */ jsx("span", {
|
|
729
|
-
className: "truncate text-wf-fail",
|
|
730
|
-
title: failed.get(id),
|
|
731
|
-
children: failed.get(id)
|
|
732
|
-
}) : null,
|
|
733
|
-
/* @__PURE__ */ jsx(Button, {
|
|
734
|
-
size: "sm",
|
|
735
|
-
disabled: busy,
|
|
736
|
-
"aria-label": `Grant the Switchboard on ${names.get(id) ?? id}`,
|
|
737
|
-
onClick: () => grantOn([id]),
|
|
738
|
-
children: "Grant"
|
|
739
|
-
})
|
|
740
|
-
]
|
|
741
|
-
}, id))
|
|
742
|
-
}) : null,
|
|
743
|
-
plan && plan.grantable.length > 1 ? /* @__PURE__ */ jsx(Button, {
|
|
744
|
-
size: "sm",
|
|
745
|
-
variant: "primary",
|
|
746
|
-
disabled: busy,
|
|
747
|
-
className: "self-start",
|
|
748
|
-
onClick: () => grantOn(plan.grantable),
|
|
749
|
-
children: busy ? "Granting…" : `Grant all ${plan.grantable.length}`
|
|
750
|
-
}) : null,
|
|
751
|
-
plan ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(NamedList, {
|
|
752
|
-
label: "Documents you may not grant on",
|
|
753
|
-
heading: "You don't have permission to change grants on these:",
|
|
754
|
-
next: "Ask each document's admin to grant the Switchboard.",
|
|
755
|
-
ids: plan.noPermission,
|
|
756
|
-
names
|
|
757
|
-
}), /* @__PURE__ */ jsx(NamedList, {
|
|
758
|
-
label: "Documents not in this drive",
|
|
759
|
-
heading: "Not in this Connect, so they can't be granted from here:",
|
|
760
|
-
next: "Open the drive that holds them and grant there, or ask its admin.",
|
|
761
|
-
ids: plan.notHere,
|
|
762
|
-
names
|
|
763
|
-
})] }) : null
|
|
764
|
-
]
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
//#endregion
|
|
768
|
-
//#region editors/connection-editor/ReactorConnectionSettings.tsx
|
|
769
|
-
function ReactorConnectionSettings(props) {
|
|
770
|
-
const parsed = parseReactorConnectionConfig(props.state.config);
|
|
771
|
-
const current = parsed.ok ? parsed.config : { endpoint: "local" };
|
|
772
|
-
const [error, setError] = useState(parsed.ok ? null : parsed.error);
|
|
773
|
-
const save = (access) => {
|
|
774
|
-
setError(null);
|
|
775
|
-
props.callbacks.setReactorAccess(access);
|
|
776
|
-
};
|
|
777
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
778
|
-
className: "flex flex-col gap-5 border-t border-solid border-foreground/10 pt-5",
|
|
779
|
-
children: [
|
|
780
|
-
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
781
|
-
className: "text-[13px] font-semibold text-foreground",
|
|
782
|
-
children: "Reactor access"
|
|
783
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
784
|
-
className: "mt-0.5 text-xs text-muted-foreground",
|
|
785
|
-
children: "Each workflow's runs act as its last publisher, and reach only what this connection allows and that person may do."
|
|
786
|
-
})] }),
|
|
787
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
788
|
-
/* @__PURE__ */ jsx(FieldLabel$1, { label: "Access" }),
|
|
789
|
-
/* @__PURE__ */ jsx(Segmented, {
|
|
790
|
-
value: current.access === "read" ? "read" : "write",
|
|
791
|
-
options: [{
|
|
792
|
-
value: "write",
|
|
793
|
-
label: "Read and write"
|
|
794
|
-
}, {
|
|
795
|
-
value: "read",
|
|
796
|
-
label: "Read only"
|
|
797
|
-
}],
|
|
798
|
-
onChange: (value) => save(value === "read" ? "read" : "write")
|
|
799
|
-
}),
|
|
800
|
-
/* @__PURE__ */ jsx(Hint$1, { text: "Read only refuses every write, whatever the step declares." })
|
|
801
|
-
] }),
|
|
802
|
-
/* @__PURE__ */ jsx(FieldError, { children: error }),
|
|
803
|
-
/* @__PURE__ */ jsx(SwitchboardGrants, {})
|
|
804
|
-
]
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
//#endregion
|
|
808
|
-
//#region editors/connection-editor/connection-form.tsx
|
|
809
|
-
const inputClass = textInputClass;
|
|
810
|
-
function FieldLabel(props) {
|
|
811
|
-
return /* @__PURE__ */ jsx(FieldLabel$1, {
|
|
812
|
-
label: props.field.displayName,
|
|
813
|
-
optional: !props.field.required
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
function Hint(props) {
|
|
817
|
-
return /* @__PURE__ */ jsx(Hint$1, { text: props.children ?? "" });
|
|
818
|
-
}
|
|
819
|
-
function ConfigField(props) {
|
|
820
|
-
const { field, value } = props;
|
|
821
|
-
if (field.inputType === "CHECKBOX") return /* @__PURE__ */ jsx(Switch, {
|
|
822
|
-
checked: Boolean(value),
|
|
823
|
-
onChange: (checked) => props.onCommit(checked),
|
|
824
|
-
label: field.displayName,
|
|
825
|
-
description: field.description
|
|
826
|
-
});
|
|
827
|
-
if (field.inputType === "STATIC_DROPDOWN") return /* @__PURE__ */ jsxs("div", { children: [
|
|
828
|
-
/* @__PURE__ */ jsx(FieldLabel, { field }),
|
|
829
|
-
/* @__PURE__ */ jsx(Select, {
|
|
830
|
-
value: typeof value === "string" ? value : "",
|
|
831
|
-
options: (field.options ?? []).map((option) => ({
|
|
832
|
-
value: String(option.value),
|
|
833
|
-
label: option.label
|
|
834
|
-
})),
|
|
835
|
-
clearable: !field.required,
|
|
836
|
-
onChange: (next) => props.onCommit(next || void 0)
|
|
837
|
-
}),
|
|
838
|
-
/* @__PURE__ */ jsx(Hint, { children: field.description })
|
|
839
|
-
] });
|
|
840
|
-
return /* @__PURE__ */ jsxs("label", {
|
|
841
|
-
className: "block",
|
|
842
|
-
children: [
|
|
843
|
-
/* @__PURE__ */ jsx(FieldLabel, { field }),
|
|
844
|
-
/* @__PURE__ */ jsx("input", {
|
|
845
|
-
className: inputClass,
|
|
846
|
-
type: field.inputType === "NUMBER" ? "number" : "text",
|
|
847
|
-
defaultValue: typeof value === "string" || typeof value === "number" ? value : "",
|
|
848
|
-
spellCheck: false,
|
|
849
|
-
onBlur: (event) => {
|
|
850
|
-
const raw = event.target.value.trim();
|
|
851
|
-
if (raw === "") props.onCommit(void 0);
|
|
852
|
-
else if (field.inputType === "NUMBER") props.onCommit(Number(raw));
|
|
853
|
-
else props.onCommit(raw);
|
|
854
|
-
}
|
|
855
|
-
}),
|
|
856
|
-
/* @__PURE__ */ jsx(Hint, { children: field.description })
|
|
857
|
-
]
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
const SECRET_REF_PREFIX = "secret://v1:";
|
|
861
|
-
function isManagedRef(ref) {
|
|
862
|
-
return ref.startsWith(SECRET_REF_PREFIX);
|
|
863
|
-
}
|
|
864
|
-
function SavedSecret(props) {
|
|
865
|
-
const { stat, fresh } = props;
|
|
866
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
867
|
-
className: "flex items-center gap-3 rounded-lg border border-solid border-foreground/10 bg-muted/40 px-3 py-2.5",
|
|
868
|
-
title: stat?.label ?? void 0,
|
|
869
|
-
children: [
|
|
870
|
-
/* @__PURE__ */ jsx("span", {
|
|
871
|
-
className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-wf-ok/12 text-wf-ok",
|
|
872
|
-
children: /* @__PURE__ */ jsx(Icon, {
|
|
873
|
-
name: "lock",
|
|
874
|
-
className: "h-4 w-4"
|
|
875
|
-
})
|
|
876
|
-
}),
|
|
877
|
-
/* @__PURE__ */ jsxs("span", {
|
|
878
|
-
className: "min-w-0 flex-1",
|
|
879
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
880
|
-
"aria-hidden": true,
|
|
881
|
-
className: "block font-mono text-sm leading-5 tracking-[0.08em] text-foreground",
|
|
882
|
-
children: "••••••••••••"
|
|
883
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
884
|
-
className: "block text-xs text-muted-foreground",
|
|
885
|
-
children: stat === void 0 ? "Checking the saved value…" : fresh ? /* @__PURE__ */ jsxs("span", {
|
|
886
|
-
className: "inline-flex items-center gap-1 font-medium text-wf-ok",
|
|
887
|
-
children: [/* @__PURE__ */ jsx(Icon, {
|
|
888
|
-
name: "check",
|
|
889
|
-
className: "h-3 w-3"
|
|
890
|
-
}), "Saved just now"]
|
|
891
|
-
}) : /* @__PURE__ */ jsxs("span", {
|
|
892
|
-
title: new Date(stat.updatedAt).toLocaleString(),
|
|
893
|
-
children: [
|
|
894
|
-
"Saved ",
|
|
895
|
-
formatWhen(stat.updatedAt),
|
|
896
|
-
stat.version > 1 ? `, version ${stat.version}` : ""
|
|
897
|
-
]
|
|
898
|
-
})
|
|
899
|
-
})]
|
|
900
|
-
}),
|
|
901
|
-
/* @__PURE__ */ jsx(Button, {
|
|
902
|
-
size: "sm",
|
|
903
|
-
onClick: props.onReplace,
|
|
904
|
-
children: "Replace"
|
|
905
|
-
}),
|
|
906
|
-
/* @__PURE__ */ jsx(IconButton, {
|
|
907
|
-
icon: "trash",
|
|
908
|
-
label: "Remove saved value",
|
|
909
|
-
onClick: props.onRemove
|
|
910
|
-
})
|
|
911
|
-
]
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
function SecretField(props) {
|
|
915
|
-
const { field, refValue } = props;
|
|
916
|
-
const inputId = useId();
|
|
917
|
-
const managed = isManagedRef(refValue);
|
|
918
|
-
const stat = useSecretStat(refValue, managed);
|
|
919
|
-
const actions = useRuntimeActions();
|
|
920
|
-
const [value, setValue] = useState("");
|
|
921
|
-
const [reveal, setReveal] = useState(false);
|
|
922
|
-
const [busy, setBusy] = useState(false);
|
|
923
|
-
const [error, setError] = useState(null);
|
|
924
|
-
const [editing, setEditing] = useState(false);
|
|
925
|
-
const [justSaved, setJustSaved] = useState(false);
|
|
926
|
-
const [advanced, setAdvanced] = useState(false);
|
|
927
|
-
const [separate, setSeparate] = useState(false);
|
|
928
|
-
const foreign = !!stat?.ownerId && stat.ownerId !== props.connectionId;
|
|
929
|
-
const stored = managed && stat !== null && stat?.status !== "DELETED" && !foreign;
|
|
930
|
-
const problem = !refValue ? null : stat?.status === "DELETED" ? "The saved value was deleted on the switchboard. Paste a new one." : stat === null ? "The saved reference no longer resolves. Paste the value again." : foreign ? "This secret belongs to another connection; enter it again." : null;
|
|
931
|
-
const showEditor = !stored || editing;
|
|
932
|
-
const cancel = () => {
|
|
933
|
-
setValue("");
|
|
934
|
-
setError(null);
|
|
935
|
-
setEditing(false);
|
|
936
|
-
setReveal(false);
|
|
937
|
-
};
|
|
938
|
-
const save = () => {
|
|
939
|
-
if (!value || busy) return;
|
|
940
|
-
const { connectionId } = props;
|
|
941
|
-
if (!connectionId) {
|
|
942
|
-
setError("Save the connection before entering its secrets.");
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
setBusy(true);
|
|
946
|
-
setError(null);
|
|
947
|
-
const label = `${props.connectionName || "connection"} · ${field.displayName}`;
|
|
948
|
-
(stored && !separate && stat?.ownerId === connectionId && stat.manageable ? actions.rotateSecret(refValue, value) : actions.createSecret(connectionId, value, label)).then((result) => {
|
|
949
|
-
cancel();
|
|
950
|
-
setJustSaved(true);
|
|
951
|
-
if (result.ref !== refValue) props.onCommit(result.ref);
|
|
952
|
-
}).catch((requestError) => {
|
|
953
|
-
setError(requestError instanceof Error ? requestError.message : String(requestError));
|
|
954
|
-
}).finally(() => setBusy(false));
|
|
955
|
-
};
|
|
956
|
-
return /* @__PURE__ */ jsxs("div", { children: [
|
|
957
|
-
/* @__PURE__ */ jsx(FieldLabel$1, {
|
|
958
|
-
htmlFor: showEditor ? inputId : void 0,
|
|
959
|
-
label: field.displayName,
|
|
960
|
-
optional: !field.required,
|
|
961
|
-
needsValue: field.required && !stored,
|
|
962
|
-
action: /* @__PURE__ */ jsx("button", {
|
|
963
|
-
type: "button",
|
|
964
|
-
className: "text-xs text-muted-foreground hover:text-foreground",
|
|
965
|
-
"aria-expanded": advanced,
|
|
966
|
-
onClick: () => setAdvanced((open) => !open),
|
|
967
|
-
children: advanced ? "Hide reference" : "Reference"
|
|
968
|
-
})
|
|
969
|
-
}),
|
|
970
|
-
stored && !editing ? /* @__PURE__ */ jsx(SavedSecret, {
|
|
971
|
-
stat,
|
|
972
|
-
fresh: justSaved,
|
|
973
|
-
onReplace: () => {
|
|
974
|
-
setJustSaved(false);
|
|
975
|
-
setEditing(true);
|
|
976
|
-
},
|
|
977
|
-
onRemove: props.onRemove
|
|
978
|
-
}) : null,
|
|
979
|
-
problem ? /* @__PURE__ */ jsxs("p", {
|
|
980
|
-
className: "mb-2 flex items-start gap-2 rounded-md bg-wf-warn/10 px-3 py-2 text-xs text-wf-warn",
|
|
981
|
-
children: [/* @__PURE__ */ jsx(Icon, {
|
|
982
|
-
name: "alert",
|
|
983
|
-
className: "mt-px h-3.5 w-3.5"
|
|
984
|
-
}), problem]
|
|
985
|
-
}) : null,
|
|
986
|
-
showEditor ? /* @__PURE__ */ jsxs("div", {
|
|
987
|
-
className: "flex items-center gap-2",
|
|
988
|
-
children: [
|
|
989
|
-
/* @__PURE__ */ jsxs("div", {
|
|
990
|
-
className: "relative min-w-0 flex-1",
|
|
991
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
992
|
-
id: inputId,
|
|
993
|
-
className: `${inputClass} pr-9 ${value && !reveal ? "font-mono tracking-wider" : ""}`,
|
|
994
|
-
type: reveal ? "text" : "password",
|
|
995
|
-
value,
|
|
996
|
-
disabled: busy,
|
|
997
|
-
autoFocus: editing,
|
|
998
|
-
placeholder: stored ? `Paste the new ${field.displayName.toLowerCase()}` : `Paste the ${field.displayName.toLowerCase()}`,
|
|
999
|
-
autoComplete: "off",
|
|
1000
|
-
spellCheck: false,
|
|
1001
|
-
onChange: (event) => setValue(event.target.value),
|
|
1002
|
-
onKeyDown: (event) => {
|
|
1003
|
-
if (event.key === "Enter") save();
|
|
1004
|
-
if (event.key === "Escape" && editing) cancel();
|
|
1005
|
-
}
|
|
1006
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
1007
|
-
className: "absolute inset-y-0 right-1 flex items-center",
|
|
1008
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1009
|
-
icon: reveal ? "eyeOff" : "eye",
|
|
1010
|
-
label: `${reveal ? "Hide" : "Show"} ${field.displayName}`,
|
|
1011
|
-
onClick: () => setReveal((shown) => !shown)
|
|
1012
|
-
})
|
|
1013
|
-
})]
|
|
1014
|
-
}),
|
|
1015
|
-
/* @__PURE__ */ jsx(Button, {
|
|
1016
|
-
variant: "primary",
|
|
1017
|
-
"aria-label": `Save ${field.displayName}`,
|
|
1018
|
-
disabled: !value || busy,
|
|
1019
|
-
onClick: save,
|
|
1020
|
-
children: busy ? "Saving…" : "Save"
|
|
1021
|
-
}),
|
|
1022
|
-
editing ? /* @__PURE__ */ jsx(Button, {
|
|
1023
|
-
variant: "ghost",
|
|
1024
|
-
onClick: cancel,
|
|
1025
|
-
children: "Cancel"
|
|
1026
|
-
}) : null,
|
|
1027
|
-
problem ? /* @__PURE__ */ jsx(IconButton, {
|
|
1028
|
-
icon: "trash",
|
|
1029
|
-
label: "Remove saved value",
|
|
1030
|
-
onClick: props.onRemove
|
|
1031
|
-
}) : null
|
|
1032
|
-
]
|
|
1033
|
-
}) : null,
|
|
1034
|
-
/* @__PURE__ */ jsx(FieldError, { children: error }),
|
|
1035
|
-
/* @__PURE__ */ jsx(Hint, { children: field.description }),
|
|
1036
|
-
advanced ? /* @__PURE__ */ jsxs("div", {
|
|
1037
|
-
className: "mt-3 flex flex-col gap-3 rounded-lg border border-dashed border-foreground/15 px-3 py-3",
|
|
1038
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [
|
|
1039
|
-
/* @__PURE__ */ jsx(FieldLabel$1, {
|
|
1040
|
-
htmlFor: `${inputId}-ref`,
|
|
1041
|
-
label: "Secret reference"
|
|
1042
|
-
}),
|
|
1043
|
-
/* @__PURE__ */ jsx("input", {
|
|
1044
|
-
id: `${inputId}-ref`,
|
|
1045
|
-
className: `${inputClass} font-mono text-xs`,
|
|
1046
|
-
defaultValue: refValue,
|
|
1047
|
-
placeholder: "secret://v1:…",
|
|
1048
|
-
spellCheck: false,
|
|
1049
|
-
onBlur: (event) => {
|
|
1050
|
-
const ref = event.target.value.trim();
|
|
1051
|
-
if (!ref || ref === refValue) return;
|
|
1052
|
-
if (!isManagedRef(ref)) {
|
|
1053
|
-
setError("Only secret://v1: references resolve. To store a value, paste it above instead.");
|
|
1054
|
-
return;
|
|
1055
|
-
}
|
|
1056
|
-
setError(null);
|
|
1057
|
-
props.onCommit(ref);
|
|
1058
|
-
}
|
|
1059
|
-
}, refValue),
|
|
1060
|
-
/* @__PURE__ */ jsx(Hint$1, { text: "Point at a secret that already exists on the switchboard, for example one shared with another connection." })
|
|
1061
|
-
] }), stored ? /* @__PURE__ */ jsx(Switch, {
|
|
1062
|
-
checked: separate,
|
|
1063
|
-
onChange: setSeparate,
|
|
1064
|
-
label: "Save replacements as a separate secret",
|
|
1065
|
-
description: "Leaves the current secret untouched for anything else that uses it, instead of adding a new version."
|
|
1066
|
-
}) : null]
|
|
1067
|
-
}) : null
|
|
1068
|
-
] });
|
|
1069
|
-
}
|
|
1070
|
-
const RETURN_PARAM = "ph_oauth";
|
|
1071
|
-
function returnedState() {
|
|
1072
|
-
if (typeof window === "undefined") return null;
|
|
1073
|
-
return new URL(window.location.href).searchParams.get(RETURN_PARAM);
|
|
1074
|
-
}
|
|
1075
|
-
function clearReturnedState() {
|
|
1076
|
-
if (returnedState() === null) return;
|
|
1077
|
-
setSearchParams({ [RETURN_PARAM]: void 0 }, { replace: true });
|
|
1078
|
-
}
|
|
1079
|
-
function CopyField(props) {
|
|
1080
|
-
const [copied, setCopied] = useState(false);
|
|
1081
|
-
return /* @__PURE__ */ jsxs("div", { children: [
|
|
1082
|
-
/* @__PURE__ */ jsx(FieldLabel$1, { label: props.label }),
|
|
1083
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1084
|
-
className: "flex items-center gap-2",
|
|
1085
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
1086
|
-
className: `${inputClass} font-mono text-xs`,
|
|
1087
|
-
readOnly: true,
|
|
1088
|
-
value: props.value,
|
|
1089
|
-
onFocus: (event) => event.target.select()
|
|
1090
|
-
}), /* @__PURE__ */ jsx(IconButton, {
|
|
1091
|
-
icon: copied ? "check" : "copy",
|
|
1092
|
-
label: `Copy ${props.label.toLowerCase()}`,
|
|
1093
|
-
onClick: () => {
|
|
1094
|
-
navigator.clipboard.writeText(props.value).then(() => {
|
|
1095
|
-
setCopied(true);
|
|
1096
|
-
setTimeout(() => setCopied(false), 1500);
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
})]
|
|
1100
|
-
}),
|
|
1101
|
-
/* @__PURE__ */ jsx(Hint$1, { text: props.hint })
|
|
1102
|
-
] });
|
|
1103
|
-
}
|
|
1104
|
-
function OAuthConnect(props) {
|
|
1105
|
-
const { connectionId, state } = props;
|
|
1106
|
-
const actions = useRuntimeActions();
|
|
1107
|
-
const redirect = useOAuthRedirectUri();
|
|
1108
|
-
const [attemptState, setAttemptState] = useState(returnedState);
|
|
1109
|
-
const [error, setError] = useState(null);
|
|
1110
|
-
const [starting, setStarting] = useState(false);
|
|
1111
|
-
const popup = useRef(null);
|
|
1112
|
-
const polled = useOAuthAttempt(attemptState);
|
|
1113
|
-
const ours = polled != null && polled.connectionId === connectionId;
|
|
1114
|
-
const attempt = ours ? polled : null;
|
|
1115
|
-
const finished = polled === null || polled !== void 0 && !ours || attempt?.status === "OK" || attempt?.status === "ERROR";
|
|
1116
|
-
useEffect(() => {
|
|
1117
|
-
if (ours || polled === null) clearReturnedState();
|
|
1118
|
-
}, [ours, polled]);
|
|
1119
|
-
useEffect(() => {
|
|
1120
|
-
if (!finished) return;
|
|
1121
|
-
popup.current?.close();
|
|
1122
|
-
popup.current = null;
|
|
1123
|
-
}, [finished]);
|
|
1124
|
-
const signedIn = state.secretRefs.some((ref) => ref.name === OAUTH_TOKEN);
|
|
1125
|
-
const redirectUri = redirect.data ?? void 0;
|
|
1126
|
-
const waiting = attemptState !== null && !finished;
|
|
1127
|
-
const connect = () => {
|
|
1128
|
-
if (!connectionId || starting) return;
|
|
1129
|
-
setError(null);
|
|
1130
|
-
setStarting(true);
|
|
1131
|
-
const opened = window.open("about:blank", "ph-oauth", "popup,width=520,height=700");
|
|
1132
|
-
popup.current = opened;
|
|
1133
|
-
actions.startOAuth(connectionId, {
|
|
1134
|
-
redirectUri,
|
|
1135
|
-
...opened ? {} : { returnUrl: window.location.href }
|
|
1136
|
-
}).then((started) => {
|
|
1137
|
-
if (opened) {
|
|
1138
|
-
opened.location.href = started.authorizationUrl;
|
|
1139
|
-
setAttemptState(started.state);
|
|
1140
|
-
} else window.location.assign(started.authorizationUrl);
|
|
1141
|
-
}).catch((startError) => {
|
|
1142
|
-
opened?.close();
|
|
1143
|
-
popup.current = null;
|
|
1144
|
-
setError(startError instanceof Error ? startError.message : String(startError));
|
|
1145
|
-
}).finally(() => setStarting(false));
|
|
1146
|
-
};
|
|
1147
|
-
const cancel = () => {
|
|
1148
|
-
popup.current?.close();
|
|
1149
|
-
popup.current = null;
|
|
1150
|
-
setAttemptState(null);
|
|
1151
|
-
};
|
|
1152
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1153
|
-
className: "flex flex-col gap-5 border-t border-solid border-foreground/10 pt-5",
|
|
1154
|
-
children: [
|
|
1155
|
-
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
1156
|
-
className: "text-[13px] font-semibold text-foreground",
|
|
1157
|
-
children: "Sign in"
|
|
1158
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
1159
|
-
className: "mt-0.5 text-xs text-muted-foreground",
|
|
1160
|
-
children: "Uses your own OAuth app. Register the redirect URL below with it, fill in its client ID and secret, then connect."
|
|
1161
|
-
})] }),
|
|
1162
|
-
redirect.data ? /* @__PURE__ */ jsx(CopyField, {
|
|
1163
|
-
label: "Redirect URL",
|
|
1164
|
-
value: redirect.data,
|
|
1165
|
-
hint: "Add this as an authorized redirect URI in the service's developer console."
|
|
1166
|
-
}) : redirect.data === null ? /* @__PURE__ */ jsx("p", {
|
|
1167
|
-
className: "rounded-md bg-wf-warn/10 px-3 py-2 text-xs text-wf-warn",
|
|
1168
|
-
children: "This switchboard serves no OAuth callback, so it cannot sign in."
|
|
1169
|
-
}) : null,
|
|
1170
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1171
|
-
className: "flex items-center gap-3",
|
|
1172
|
-
children: [
|
|
1173
|
-
/* @__PURE__ */ jsx(Button, {
|
|
1174
|
-
variant: signedIn ? "secondary" : "primary",
|
|
1175
|
-
disabled: !connectionId || !props.ready || starting || waiting || !redirectUri,
|
|
1176
|
-
onClick: connect,
|
|
1177
|
-
children: starting ? "Opening…" : waiting ? "Waiting for sign-in…" : signedIn ? "Reconnect" : "Connect"
|
|
1178
|
-
}),
|
|
1179
|
-
waiting ? /* @__PURE__ */ jsx(Button, {
|
|
1180
|
-
variant: "ghost",
|
|
1181
|
-
onClick: cancel,
|
|
1182
|
-
children: "Cancel"
|
|
1183
|
-
}) : null,
|
|
1184
|
-
/* @__PURE__ */ jsx("span", {
|
|
1185
|
-
className: "text-xs text-muted-foreground",
|
|
1186
|
-
children: attempt?.status === "OK" ? `Signed in${state.accountLabel ? ` as ${state.accountLabel}` : ""}` : signedIn && !waiting ? state.accountLabel ? `Signed in as ${state.accountLabel}` : "Signed in" : !connectionId ? "Open the connection to sign in." : !props.ready ? "Fill in the client ID and secret first." : ""
|
|
1187
|
-
})
|
|
1188
|
-
]
|
|
1189
|
-
}),
|
|
1190
|
-
/* @__PURE__ */ jsx(FieldError, { children: error ?? (attempt?.status === "ERROR" ? attempt.error : null) })
|
|
1191
|
-
]
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
function methodLabel(plan) {
|
|
1195
|
-
return plan.displayName && plan.displayName !== "Connection" ? plan.displayName : AUTH_TYPE_LABEL[plan.authType];
|
|
1196
|
-
}
|
|
1197
|
-
function ConnectionForm(props) {
|
|
1198
|
-
const { state, callbacks } = props;
|
|
1199
|
-
const reactor = isReactorConnectorId(state.connectorId);
|
|
1200
|
-
const catalogQuery = usePieceCatalog();
|
|
1201
|
-
const catalog = catalogQuery.data ?? (catalogQuery.isError ? [] : null);
|
|
1202
|
-
const packageName = packageFromConnectorId(state.connectorId);
|
|
1203
|
-
const piece = catalog?.find((entry) => entry.name === packageName);
|
|
1204
|
-
const plans = piece ? plansFromAuth(piece.auth) : [];
|
|
1205
|
-
const plan = piece ? planForConnection(piece.auth, state.authType) : {
|
|
1206
|
-
authType: state.authType,
|
|
1207
|
-
configFields: [],
|
|
1208
|
-
secretFields: state.secretRefs.map((ref) => ({
|
|
1209
|
-
name: ref.name,
|
|
1210
|
-
displayName: ref.name,
|
|
1211
|
-
required: false
|
|
1212
|
-
})),
|
|
1213
|
-
supported: state.authType !== "OIDC"
|
|
1214
|
-
};
|
|
1215
|
-
const boundService = serviceName(state.connectorId, catalog);
|
|
1216
|
-
const config = state.config ?? {};
|
|
1217
|
-
const refByName = new Map(state.secretRefs.map((ref) => [ref.name, ref.ref]));
|
|
1218
|
-
const maybeMarkConfigured = (nextConfig, nextRefs) => {
|
|
1219
|
-
if (!plan.supported || plan.oauth2) return;
|
|
1220
|
-
const complete = isAuthComplete(plan, nextConfig, nextRefs);
|
|
1221
|
-
if (complete && state.status === "UNCONFIGURED") callbacks.setStatus("OK");
|
|
1222
|
-
else if (!complete && state.status === "OK") callbacks.setStatus("UNCONFIGURED");
|
|
1223
|
-
};
|
|
1224
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1225
|
-
className: "flex flex-col gap-6",
|
|
1226
|
-
children: [
|
|
1227
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
1228
|
-
/* @__PURE__ */ jsx(FieldLabel$1, { label: "Service" }),
|
|
1229
|
-
boundService !== null ? /* @__PURE__ */ jsxs("div", {
|
|
1230
|
-
role: "group",
|
|
1231
|
-
"aria-label": "Service",
|
|
1232
|
-
className: "flex items-center gap-2 py-1.5 text-sm text-foreground",
|
|
1233
|
-
children: [piece?.logoUrl ? /* @__PURE__ */ jsx("img", {
|
|
1234
|
-
src: piece.logoUrl,
|
|
1235
|
-
alt: "",
|
|
1236
|
-
className: "h-4 w-4 shrink-0 object-contain"
|
|
1237
|
-
}) : null, /* @__PURE__ */ jsx("span", {
|
|
1238
|
-
className: "truncate",
|
|
1239
|
-
children: boundService
|
|
1240
|
-
})]
|
|
1241
|
-
}) : /* @__PURE__ */ jsx(Select, {
|
|
1242
|
-
value: "",
|
|
1243
|
-
loading: catalog === null,
|
|
1244
|
-
placeholder: "Choose the service to connect",
|
|
1245
|
-
options: [...props.offerReactor !== false ? [{
|
|
1246
|
-
value: REACTOR_CONNECTOR_ID,
|
|
1247
|
-
label: REACTOR_SERVICE_LABEL,
|
|
1248
|
-
description: "Lets a step read or write documents on this Switchboard"
|
|
1249
|
-
}] : [], ...(catalog ?? []).map((entry) => ({
|
|
1250
|
-
value: entry.name,
|
|
1251
|
-
label: entry.displayName,
|
|
1252
|
-
...planFromAuth(entry.auth).authType === "UNKNOWN" ? {
|
|
1253
|
-
disabled: true,
|
|
1254
|
-
description: AUTH_TYPE_LABEL[UNKNOWN_AUTH]
|
|
1255
|
-
} : { description: entry.description },
|
|
1256
|
-
icon: entry.logoUrl ? /* @__PURE__ */ jsx("img", {
|
|
1257
|
-
src: entry.logoUrl,
|
|
1258
|
-
alt: "",
|
|
1259
|
-
loading: "lazy",
|
|
1260
|
-
className: "h-4 w-4 shrink-0 object-contain"
|
|
1261
|
-
}) : void 0
|
|
1262
|
-
}))],
|
|
1263
|
-
onChange: (name) => {
|
|
1264
|
-
if (name === "@powerhousedao/reactor#reactor") {
|
|
1265
|
-
callbacks.pickReactor();
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
|
-
const picked = catalog?.find((entry) => entry.name === name);
|
|
1269
|
-
if (picked) callbacks.pickPiece(picked);
|
|
1270
|
-
}
|
|
1271
|
-
}),
|
|
1272
|
-
piece ? /* @__PURE__ */ jsx(Hint$1, { text: piece.description }) : null
|
|
1273
|
-
] }),
|
|
1274
|
-
reactor ? /* @__PURE__ */ jsx(ReactorConnectionSettings, {
|
|
1275
|
-
state,
|
|
1276
|
-
callbacks
|
|
1277
|
-
}) : null,
|
|
1278
|
-
!reactor && plans.length > 1 ? /* @__PURE__ */ jsxs("div", { children: [
|
|
1279
|
-
/* @__PURE__ */ jsx(FieldLabel$1, { label: "Sign in with" }),
|
|
1280
|
-
/* @__PURE__ */ jsx(Select, {
|
|
1281
|
-
value: plan.authType,
|
|
1282
|
-
options: plans.map((option) => ({
|
|
1283
|
-
value: option.authType,
|
|
1284
|
-
label: methodLabel(option),
|
|
1285
|
-
description: option.supported || option.authType === "UNKNOWN" ? AUTH_TYPE_LABEL[option.authType] : "Not supported yet",
|
|
1286
|
-
disabled: !option.supported
|
|
1287
|
-
})),
|
|
1288
|
-
onChange: (value) => {
|
|
1289
|
-
const authType = value;
|
|
1290
|
-
const next = plans.find((option) => option.authType === authType);
|
|
1291
|
-
if (!next) return;
|
|
1292
|
-
callbacks.setAuthType(authType, {
|
|
1293
|
-
config: next.configFields.map((field) => field.name),
|
|
1294
|
-
secrets: next.secretFields.map((field) => field.name)
|
|
1295
|
-
});
|
|
1296
|
-
if (isAuthComplete(next, config, refByName)) callbacks.setStatus("OK");
|
|
1297
|
-
}
|
|
1298
|
-
}),
|
|
1299
|
-
plan.description ? /* @__PURE__ */ jsx(Hint$1, { text: plan.description }) : null
|
|
1300
|
-
] }) : null,
|
|
1301
|
-
plan.supported || reactor ? null : /* @__PURE__ */ jsx("p", {
|
|
1302
|
-
className: "rounded-md bg-wf-warn/10 px-3 py-2 text-xs text-wf-warn",
|
|
1303
|
-
children: plan.authType === "UNKNOWN" ? `${plan.declaredType ?? "This sign-in method"}: not supported by this runtime.` : `${plan.authType} connections are not executable by the workflow runtime yet.`
|
|
1304
|
-
}),
|
|
1305
|
-
plan.configFields.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
1306
|
-
className: "flex flex-col gap-5 border-t border-solid border-foreground/10 pt-5",
|
|
1307
|
-
children: [/* @__PURE__ */ jsx("h3", {
|
|
1308
|
-
className: "text-[13px] font-semibold text-foreground",
|
|
1309
|
-
children: "Configuration"
|
|
1310
|
-
}), plan.configFields.map((field) => /* @__PURE__ */ jsx(ConfigField, {
|
|
1311
|
-
field,
|
|
1312
|
-
value: config[field.name],
|
|
1313
|
-
onCommit: (value) => {
|
|
1314
|
-
callbacks.setConfigValue(field.name, value);
|
|
1315
|
-
maybeMarkConfigured({
|
|
1316
|
-
...config,
|
|
1317
|
-
[field.name]: value
|
|
1318
|
-
}, refByName);
|
|
1319
|
-
}
|
|
1320
|
-
}, field.name))]
|
|
1321
|
-
}) : null,
|
|
1322
|
-
plan.secretFields.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
1323
|
-
className: "flex flex-col gap-5 border-t border-solid border-foreground/10 pt-5",
|
|
1324
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
1325
|
-
className: "text-[13px] font-semibold text-foreground",
|
|
1326
|
-
children: "Credentials"
|
|
1327
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
1328
|
-
className: "mt-0.5 text-xs text-muted-foreground",
|
|
1329
|
-
children: "Saved encrypted on the switchboard. This connection only keeps a reference, so nobody reading it can see the values."
|
|
1330
|
-
})] }), plan.secretFields.map((field) => /* @__PURE__ */ jsx(SecretField, {
|
|
1331
|
-
field,
|
|
1332
|
-
connectionId: props.connectionId,
|
|
1333
|
-
connectionName: state.name,
|
|
1334
|
-
refValue: refByName.get(field.name) ?? "",
|
|
1335
|
-
onCommit: (ref) => {
|
|
1336
|
-
callbacks.setSecretRef(field.name, ref);
|
|
1337
|
-
const nextRefs = new Map(refByName);
|
|
1338
|
-
nextRefs.set(field.name, ref);
|
|
1339
|
-
maybeMarkConfigured(config, nextRefs);
|
|
1340
|
-
},
|
|
1341
|
-
onRemove: () => {
|
|
1342
|
-
callbacks.removeSecretRef(field.name);
|
|
1343
|
-
const nextRefs = new Map(refByName);
|
|
1344
|
-
nextRefs.delete(field.name);
|
|
1345
|
-
maybeMarkConfigured(config, nextRefs);
|
|
1346
|
-
}
|
|
1347
|
-
}, field.name))]
|
|
1348
|
-
}) : null,
|
|
1349
|
-
plan.oauth2 && plan.supported ? /* @__PURE__ */ jsx(OAuthConnect, {
|
|
1350
|
-
connectionId: props.connectionId,
|
|
1351
|
-
state,
|
|
1352
|
-
ready: isAuthComplete(plan, config, refByName)
|
|
1353
|
-
}) : null,
|
|
1354
|
-
state.lastError ? /* @__PURE__ */ jsx("p", {
|
|
1355
|
-
className: "rounded-md bg-wf-fail/10 px-3 py-2 text-xs text-wf-fail",
|
|
1356
|
-
children: state.lastError
|
|
1357
|
-
}) : null
|
|
1358
|
-
]
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
//#endregion
|
|
1362
|
-
export { useSignInGate as a, accessMismatch as c, CONNECTION_STATUS_STYLES as d, connectionCallbacks as f, newUndoGroup as g, groupedAction as h, useReactorAccessDenial as i, reactorConnections as l, UndoRedo as m, SignInPrompt as n, missingInPublished as o, BackButton as p, usePublisher as r, runsAsText as s, ConnectionForm as t, CONNECTION_STATUS_LABEL as u };
|
|
1363
|
-
|
|
1364
|
-
//# sourceMappingURL=connection-form-CJFKPwfg.mjs.map
|