@hanzo/app 0.3.9 → 0.3.11
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/Setup.d.ts +23 -0
- package/dist/Setup.js +73 -41
- package/package.json +1 -1
package/dist/Setup.d.ts
CHANGED
|
@@ -3,6 +3,29 @@ export declare const GITHUB_KEY = "hanzo.onboarding.github";
|
|
|
3
3
|
export declare const SLACK_KEY = "hanzo.onboarding.slack";
|
|
4
4
|
export declare const STEP_KEY = "hanzo.onboarding.step";
|
|
5
5
|
export declare const PLUGIN_KEY = "hanzo.onboarding.plugin";
|
|
6
|
+
/** What GET /v1/provider (the org's providers) and GET /v1/connection (the reader's own) say is connected. */
|
|
7
|
+
export interface Linked {
|
|
8
|
+
/** Provider ids connected, by either. */
|
|
9
|
+
ids: Set<string>;
|
|
10
|
+
/** Google addresses either names. */
|
|
11
|
+
google: string[];
|
|
12
|
+
/** GitHub, as Projects reads it: the org's App, or the reader's own link (`github-user`). */
|
|
13
|
+
github: boolean;
|
|
14
|
+
/** The reader's own GitHub link: theirs to drop, where the org's App is an org admin's. */
|
|
15
|
+
own: boolean;
|
|
16
|
+
/** Both answered, so a provider missing from them is not connected. */
|
|
17
|
+
whole: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Null when neither answered. /v1/connection lists `connections`; nothing else is read from it. */
|
|
20
|
+
export declare function linked(providersData: unknown, connectionsData: unknown): Linked | null;
|
|
21
|
+
/** Where Disconnect lets go of GitHub: the reader's own link, or the org's App accounts. */
|
|
22
|
+
export declare const leaving: (own: boolean) => "/v1/provider/github/disconnect" | "/v1/provider/github/user/disconnect";
|
|
23
|
+
/**
|
|
24
|
+
* Said on the window when GitHub's connection changes, here or on Projects and
|
|
25
|
+
* Settings (@hanzo/build, which says and hears the same name), so each reads it
|
|
26
|
+
* again without a reload. Setup hears its own word too.
|
|
27
|
+
*/
|
|
28
|
+
export declare const GITHUB_CHANGED = "hanzo:github";
|
|
6
29
|
export declare function Setup({ go }?: {
|
|
7
30
|
go?: (address: string) => void;
|
|
8
31
|
}): import("react").JSX.Element;
|
package/dist/Setup.js
CHANGED
|
@@ -40,6 +40,50 @@ export const STEP_KEY = 'hanzo.onboarding.step';
|
|
|
40
40
|
export const PLUGIN_KEY = 'hanzo.onboarding.plugin';
|
|
41
41
|
/** Where plugins and connectors live: Dev's Customize. */
|
|
42
42
|
const PLUGINS = '-/customize/plugins';
|
|
43
|
+
/** Null when neither answered. /v1/connection lists `connections`; nothing else is read from it. */
|
|
44
|
+
export function linked(providersData, connectionsData) {
|
|
45
|
+
const providers = providersData?.providers;
|
|
46
|
+
const connections = connectionsData?.connections;
|
|
47
|
+
const fromProviders = Array.isArray(providers) ? providers : null;
|
|
48
|
+
const fromConnections = Array.isArray(connections) ? connections : null;
|
|
49
|
+
if (!fromProviders && !fromConnections)
|
|
50
|
+
return null;
|
|
51
|
+
const ids = new Set();
|
|
52
|
+
const google = [];
|
|
53
|
+
const address = (id, account) => {
|
|
54
|
+
if (id === 'google' && typeof account === 'string' && account.trim())
|
|
55
|
+
google.push(account.trim().toLowerCase());
|
|
56
|
+
};
|
|
57
|
+
for (const p of fromProviders ?? []) {
|
|
58
|
+
if (!p.connected)
|
|
59
|
+
continue;
|
|
60
|
+
const id = String(p.id);
|
|
61
|
+
ids.add(id);
|
|
62
|
+
address(id, p.connection?.account);
|
|
63
|
+
}
|
|
64
|
+
for (const c of fromConnections ?? []) {
|
|
65
|
+
const id = String(c.provider);
|
|
66
|
+
ids.add(id);
|
|
67
|
+
address(id, c.account);
|
|
68
|
+
}
|
|
69
|
+
const own = ids.has('github-user');
|
|
70
|
+
return {
|
|
71
|
+
ids,
|
|
72
|
+
google,
|
|
73
|
+
github: own || ids.has('github') || ids.has('github-copilot'),
|
|
74
|
+
own,
|
|
75
|
+
whole: Boolean(fromProviders && fromConnections),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Where Disconnect lets go of GitHub: the reader's own link, or the org's App accounts. */
|
|
79
|
+
export const leaving = (own) => (own ? '/v1/provider/github/user/disconnect' : '/v1/provider/github/disconnect');
|
|
80
|
+
/**
|
|
81
|
+
* Said on the window when GitHub's connection changes, here or on Projects and
|
|
82
|
+
* Settings (@hanzo/build, which says and hears the same name), so each reads it
|
|
83
|
+
* again without a reload. Setup hears its own word too.
|
|
84
|
+
*/
|
|
85
|
+
export const GITHUB_CHANGED = 'hanzo:github';
|
|
86
|
+
const changed = () => window.dispatchEvent(new Event(GITHUB_CHANGED));
|
|
43
87
|
/** Inline Slack Mark */
|
|
44
88
|
function SlackMark({ size = 18 }) {
|
|
45
89
|
return (_jsxs("svg", { width: size, height: size, viewBox: "0 0 54 54", fill: "none", "aria-hidden": true, children: [_jsx("path", { d: "M11.379 33.9993C11.379 37.1358 8.84512 39.6507 5.7276 39.6507C2.61008 39.6507 0.0572205 37.1168 0.0572205 33.9993C0.0572205 30.8817 2.5911 28.3479 5.70862 28.3479H11.36V33.9993H11.379Z", fill: "#E01E5A" }), _jsx("path", { d: "M14.1962 33.9997C14.1962 30.8632 16.7301 28.3483 19.8476 28.3483C22.9651 28.3483 25.499 30.8822 25.499 33.9997V48.1353C25.499 51.2718 22.9651 53.7867 19.8476 53.7867C16.7301 53.7867 14.1962 51.2718 14.1962 48.1353V33.9997Z", fill: "#E01E5A" }), _jsx("path", { d: "M19.8662 11.2673C16.7296 11.2673 14.2148 8.73347 14.2148 5.61594C14.2148 2.49842 16.7486 -0.0354538 19.8662 -0.0354538C22.9837 -0.0354538 25.5175 2.49842 25.5175 5.61594V11.2673H19.8662Z", fill: "#36C5F0" }), _jsx("path", { d: "M19.8682 14.1334C23.0047 14.1334 25.5196 16.6673 25.5196 19.7848C25.5196 22.9023 22.9857 25.4362 19.8682 25.4362H5.67566C2.53916 25.4362 0.0242615 22.9023 0.0242615 19.7848C0.0242615 16.6673 2.55814 14.1334 5.67566 14.1334H19.8682Z", fill: "#36C5F0" }), _jsx("path", { d: "M42.5323 19.7853C42.5323 16.6488 45.0662 14.1339 48.1837 14.1339C51.3012 14.1339 53.8351 16.6678 53.8351 19.7853C53.8351 22.9028 51.3012 25.4367 48.1837 25.4367H42.5323V19.7853Z", fill: "#2EB67D" }), _jsx("path", { d: "M39.7126 19.7934C39.7126 22.9299 37.1787 25.4448 34.0612 25.4448C30.9436 25.4448 28.4098 22.911 28.4098 19.7934V5.61986C28.4098 2.48336 30.9436 -0.0315399 34.0612 -0.0315399C37.1787 -0.0315399 39.7126 2.48336 39.7126 5.61986V19.7934Z", fill: "#2EB67D" }), _jsx("path", { d: "M34.0376 42.482C37.1741 42.482 39.689 45.0158 39.689 48.1334C39.689 51.2509 37.1552 53.7848 34.0376 53.7848C30.9201 53.7848 28.3862 51.2509 28.3862 48.1334V42.482H34.0376Z", fill: "#ECB22E" }), _jsx("path", { d: "M34.0381 39.6507C30.9016 39.6507 28.3867 37.1168 28.3867 33.9993C28.3867 30.8818 30.9206 28.3479 34.0381 28.3479H48.2306C51.3671 28.3479 53.882 30.8818 53.882 33.9993C53.882 37.1168 51.3482 39.6507 48.2306 39.6507H34.0381Z", fill: "#ECB22E" })] }));
|
|
@@ -61,6 +105,7 @@ export function Setup({ go } = {}) {
|
|
|
61
105
|
const [errorMsg, setErrorMsg] = useState(null);
|
|
62
106
|
// A first press on Disconnect asks; the second lets go of GitHub.
|
|
63
107
|
const [dropping, setDropping] = useState(false);
|
|
108
|
+
const [githubOwn, setGithubOwn] = useState(false);
|
|
64
109
|
const [syncTurn, setSyncTurn] = useState(0);
|
|
65
110
|
const signed = isAuthenticated && Boolean(accessToken);
|
|
66
111
|
const accountList = Array.isArray(googleAccounts) ? googleAccounts : [];
|
|
@@ -105,7 +150,7 @@ export function Setup({ go } = {}) {
|
|
|
105
150
|
fetch(`${api()}/v1/tool/mcp/servers`, { headers: auth })
|
|
106
151
|
.then((r) => (r.ok ? r.json() : null))
|
|
107
152
|
.catch(() => null),
|
|
108
|
-
]).then(([integrationsData,
|
|
153
|
+
]).then(([integrationsData, connectionsData, pluginsData, serversData]) => {
|
|
109
154
|
if (!live)
|
|
110
155
|
return;
|
|
111
156
|
// A plugin the org built, or an MCP server it added: Customize's own lists.
|
|
@@ -113,45 +158,22 @@ export function Setup({ go } = {}) {
|
|
|
113
158
|
const added = Array.isArray(serversData?.servers) ? serversData.servers.length : 0;
|
|
114
159
|
if (built + added > 0)
|
|
115
160
|
setPluginDone(true);
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
: null;
|
|
119
|
-
const connectors = Array.isArray(connectorsData?.connectors)
|
|
120
|
-
? connectorsData.connectors
|
|
121
|
-
: null;
|
|
122
|
-
if (!providers && !connectors)
|
|
161
|
+
const found = linked(integrationsData, connectionsData);
|
|
162
|
+
if (!found)
|
|
123
163
|
return;
|
|
124
|
-
const connectedSet =
|
|
125
|
-
const discoveredGoogleAccounts =
|
|
126
|
-
if (providers) {
|
|
127
|
-
for (const p of providers) {
|
|
128
|
-
if (p.connected) {
|
|
129
|
-
const id = String(p.id);
|
|
130
|
-
connectedSet.add(id);
|
|
131
|
-
const conn = p.connection;
|
|
132
|
-
if (id === 'google' && typeof conn?.account === 'string' && conn.account.trim()) {
|
|
133
|
-
discoveredGoogleAccounts.push(conn.account.trim().toLowerCase());
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (connectors) {
|
|
139
|
-
for (const c of connectors) {
|
|
140
|
-
const prov = String(c.provider);
|
|
141
|
-
connectedSet.add(prov);
|
|
142
|
-
if (prov === 'google' && typeof c.account === 'string' && c.account.trim()) {
|
|
143
|
-
discoveredGoogleAccounts.push(c.account.trim().toLowerCase());
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const remoteGithub = connectedSet.has('github') || connectedSet.has('github-copilot');
|
|
164
|
+
const connectedSet = found.ids;
|
|
165
|
+
const discoveredGoogleAccounts = found.google;
|
|
148
166
|
const remoteSlack = connectedSet.has('slack');
|
|
149
167
|
const remoteGoogle = connectedSet.has('google') ||
|
|
150
168
|
connectedSet.has('gmail') ||
|
|
151
169
|
connectedSet.has('google-drive') ||
|
|
152
170
|
connectedSet.has('google-calendar');
|
|
153
|
-
|
|
154
|
-
|
|
171
|
+
// GitHub follows what is connected, both ways, so a Disconnect on Projects
|
|
172
|
+
// reads here too; a half answer only ever adds it.
|
|
173
|
+
if (found.whole || found.github)
|
|
174
|
+
setGithubDone(found.github);
|
|
175
|
+
if (found.whole || found.own)
|
|
176
|
+
setGithubOwn(found.own);
|
|
155
177
|
if (remoteSlack)
|
|
156
178
|
setSlackDone(true);
|
|
157
179
|
if (remoteGoogle)
|
|
@@ -167,7 +189,8 @@ export function Setup({ go } = {}) {
|
|
|
167
189
|
live = false;
|
|
168
190
|
};
|
|
169
191
|
}, [signed, syncTurn]);
|
|
170
|
-
// Listen for postMessage completion from /auth/callback popup
|
|
192
|
+
// Listen for postMessage completion from /auth/callback popup, focus/visibility return,
|
|
193
|
+
// and GitHub changed on this page (here, on Projects or in Settings)
|
|
171
194
|
useEffect(() => {
|
|
172
195
|
if (typeof window === 'undefined')
|
|
173
196
|
return;
|
|
@@ -189,13 +212,16 @@ export function Setup({ go } = {}) {
|
|
|
189
212
|
}
|
|
190
213
|
};
|
|
191
214
|
const onFocus = () => setSyncTurn((n) => n + 1);
|
|
215
|
+
const onGithub = () => setSyncTurn((n) => n + 1);
|
|
192
216
|
window.addEventListener('message', onMessage);
|
|
193
217
|
document.addEventListener('visibilitychange', onReturn);
|
|
194
218
|
window.addEventListener('focus', onFocus);
|
|
219
|
+
window.addEventListener(GITHUB_CHANGED, onGithub);
|
|
195
220
|
return () => {
|
|
196
221
|
window.removeEventListener('message', onMessage);
|
|
197
222
|
document.removeEventListener('visibilitychange', onReturn);
|
|
198
223
|
window.removeEventListener('focus', onFocus);
|
|
224
|
+
window.removeEventListener(GITHUB_CHANGED, onGithub);
|
|
199
225
|
};
|
|
200
226
|
}, [signed, googleAccounts]);
|
|
201
227
|
const totalDone = (githubDone ? 1 : 0) + (slackDone ? 1 : 0) + (pluginDone ? 1 : 0);
|
|
@@ -211,13 +237,17 @@ export function Setup({ go } = {}) {
|
|
|
211
237
|
return;
|
|
212
238
|
}
|
|
213
239
|
// The return page hands the answer back and closes the popup (lib/oauth);
|
|
214
|
-
// a popup closed without one still re-reads what is connected.
|
|
240
|
+
// a popup closed without one still re-reads what is connected. GitHub's is
|
|
241
|
+
// said on the page, so Projects reads it too.
|
|
215
242
|
awaitAnswer(popup, provider, (answer) => {
|
|
216
243
|
if (answer?.ok)
|
|
217
244
|
onDone();
|
|
218
245
|
else if (answer)
|
|
219
246
|
setErrorMsg(t('Could not connect {provider} right now. Please try again.', { provider: label }));
|
|
220
|
-
|
|
247
|
+
if (provider === 'github')
|
|
248
|
+
changed();
|
|
249
|
+
else
|
|
250
|
+
setSyncTurn((n) => n + 1);
|
|
221
251
|
});
|
|
222
252
|
};
|
|
223
253
|
const connectOAuthProvider = async (provider, label, onDone) => {
|
|
@@ -283,7 +313,8 @@ export function Setup({ go } = {}) {
|
|
|
283
313
|
setGithubDone(true);
|
|
284
314
|
setStep(slackDone ? 3 : 2);
|
|
285
315
|
});
|
|
286
|
-
// Let go of
|
|
316
|
+
// Let go of GitHub, so another account can be connected, as Projects does: the
|
|
317
|
+
// reader's own link first, else the org's GitHub accounts. For those the platform
|
|
287
318
|
// also removes its App from an account no other organization uses, so the next
|
|
288
319
|
// connect is a fresh install. An org admin's act: anyone else is told so.
|
|
289
320
|
const handleDisconnectGithub = async () => {
|
|
@@ -294,20 +325,21 @@ export function Setup({ go } = {}) {
|
|
|
294
325
|
setBusy('github');
|
|
295
326
|
setErrorMsg(null);
|
|
296
327
|
try {
|
|
297
|
-
const res = await fetch(`${api()}
|
|
328
|
+
const res = await fetch(`${api()}${leaving(githubOwn)}`, {
|
|
298
329
|
method: 'POST',
|
|
299
330
|
headers: { ...scope(), 'Content-Type': 'application/json' },
|
|
300
331
|
body: '{}',
|
|
301
332
|
});
|
|
302
333
|
if (!res.ok) {
|
|
303
|
-
setErrorMsg(res.status === 403
|
|
334
|
+
setErrorMsg(res.status === 403 && !githubOwn
|
|
304
335
|
? t('Only an organization admin can disconnect GitHub.')
|
|
305
336
|
: t('Could not disconnect {provider} right now. Please try again.', { provider: 'GitHub' }));
|
|
306
337
|
return;
|
|
307
338
|
}
|
|
308
339
|
setGithubDone(false);
|
|
309
340
|
setStep(1);
|
|
310
|
-
|
|
341
|
+
// Projects reads it again, and so does this card.
|
|
342
|
+
changed();
|
|
311
343
|
}
|
|
312
344
|
catch {
|
|
313
345
|
setErrorMsg(t('Could not disconnect {provider} right now. Please try again.', { provider: 'GitHub' }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|