@hanzo/app 0.3.9 → 0.3.10

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 CHANGED
@@ -3,6 +3,23 @@ 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";
6
23
  export declare function Setup({ go }?: {
7
24
  go?: (address: string) => void;
8
25
  }): import("react").JSX.Element;
package/dist/Setup.js CHANGED
@@ -40,6 +40,43 @@ 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');
43
80
  /** Inline Slack Mark */
44
81
  function SlackMark({ size = 18 }) {
45
82
  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 +98,7 @@ export function Setup({ go } = {}) {
61
98
  const [errorMsg, setErrorMsg] = useState(null);
62
99
  // A first press on Disconnect asks; the second lets go of GitHub.
63
100
  const [dropping, setDropping] = useState(false);
101
+ const [githubOwn, setGithubOwn] = useState(false);
64
102
  const [syncTurn, setSyncTurn] = useState(0);
65
103
  const signed = isAuthenticated && Boolean(accessToken);
66
104
  const accountList = Array.isArray(googleAccounts) ? googleAccounts : [];
@@ -105,7 +143,7 @@ export function Setup({ go } = {}) {
105
143
  fetch(`${api()}/v1/tool/mcp/servers`, { headers: auth })
106
144
  .then((r) => (r.ok ? r.json() : null))
107
145
  .catch(() => null),
108
- ]).then(([integrationsData, connectorsData, pluginsData, serversData]) => {
146
+ ]).then(([integrationsData, connectionsData, pluginsData, serversData]) => {
109
147
  if (!live)
110
148
  return;
111
149
  // A plugin the org built, or an MCP server it added: Customize's own lists.
@@ -113,45 +151,22 @@ export function Setup({ go } = {}) {
113
151
  const added = Array.isArray(serversData?.servers) ? serversData.servers.length : 0;
114
152
  if (built + added > 0)
115
153
  setPluginDone(true);
116
- const providers = Array.isArray(integrationsData?.providers)
117
- ? integrationsData.providers
118
- : null;
119
- const connectors = Array.isArray(connectorsData?.connectors)
120
- ? connectorsData.connectors
121
- : null;
122
- if (!providers && !connectors)
154
+ const found = linked(integrationsData, connectionsData);
155
+ if (!found)
123
156
  return;
124
- const connectedSet = new Set();
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');
157
+ const connectedSet = found.ids;
158
+ const discoveredGoogleAccounts = found.google;
148
159
  const remoteSlack = connectedSet.has('slack');
149
160
  const remoteGoogle = connectedSet.has('google') ||
150
161
  connectedSet.has('gmail') ||
151
162
  connectedSet.has('google-drive') ||
152
163
  connectedSet.has('google-calendar');
153
- if (remoteGithub)
154
- setGithubDone(true);
164
+ // GitHub follows what is connected, both ways, so a Disconnect on Projects
165
+ // reads here too; a half answer only ever adds it.
166
+ if (found.whole || found.github)
167
+ setGithubDone(found.github);
168
+ if (found.whole || found.own)
169
+ setGithubOwn(found.own);
155
170
  if (remoteSlack)
156
171
  setSlackDone(true);
157
172
  if (remoteGoogle)
@@ -283,7 +298,8 @@ export function Setup({ go } = {}) {
283
298
  setGithubDone(true);
284
299
  setStep(slackDone ? 3 : 2);
285
300
  });
286
- // Let go of the org's GitHub accounts, so another can be connected. The platform
301
+ // Let go of GitHub, so another account can be connected, as Projects does: the
302
+ // reader's own link first, else the org's GitHub accounts. For those the platform
287
303
  // also removes its App from an account no other organization uses, so the next
288
304
  // connect is a fresh install. An org admin's act: anyone else is told so.
289
305
  const handleDisconnectGithub = async () => {
@@ -294,13 +310,13 @@ export function Setup({ go } = {}) {
294
310
  setBusy('github');
295
311
  setErrorMsg(null);
296
312
  try {
297
- const res = await fetch(`${api()}/v1/provider/github/disconnect`, {
313
+ const res = await fetch(`${api()}${leaving(githubOwn)}`, {
298
314
  method: 'POST',
299
315
  headers: { ...scope(), 'Content-Type': 'application/json' },
300
316
  body: '{}',
301
317
  });
302
318
  if (!res.ok) {
303
- setErrorMsg(res.status === 403
319
+ setErrorMsg(res.status === 403 && !githubOwn
304
320
  ? t('Only an organization admin can disconnect GitHub.')
305
321
  : t('Could not disconnect {provider} right now. Please try again.', { provider: 'GitHub' }));
306
322
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/app",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
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",