@hanzo/app 0.2.40 → 0.2.42
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/App.js +1 -1
- package/dist/Setup.js +16 -12
- package/dist/lib/oauth.d.ts +43 -0
- package/dist/lib/oauth.js +121 -0
- package/package.json +1 -1
package/dist/App.js
CHANGED
|
@@ -274,5 +274,5 @@ function Window({ bar, betas }) {
|
|
|
274
274
|
// inline-style: the slide, a transform with no logical form whose sign and distance the drawer writes on the element itself, a drag every frame (Drawer.tsx).
|
|
275
275
|
style: drawer.slide ?? undefined, flex: 1, minW: 0, minH: 0, paddingInlineEnd: "var(--pane-gap)", pb: "var(--pane-gap)",
|
|
276
276
|
// The gap above the pane is the gap at its end and foot; a window's own bar above it is that gap.
|
|
277
|
-
pt: bar ? 0 : 'var(--pane-gap)', "$max-md": { p: 0 }, children: [drawer.slide ? _jsx(Lift, {}) : null, _jsx(YStack, { height: "100%", "$max-md": { display: 'none' }, children: _jsx(Rail, { host: host, mode: mode, at: where, inside: inside, open: !closed, toggle: bar ? undefined : flip, onChat: toChat, onDev: toDev, onStudio: toStudio, onTabs: toTabs, go: move, onOrg: org }) }), closed || alone ? null : (_jsx(YStack, { "$max-md": { display: 'none' }, children: _jsx(Column, { host: host, mode: mode, thread: thread, go: move, onShut: () => setClosed(true), onSeek: seek, onBack: back, places: sidebar }) })), _jsxs(YStack, { "data-slot": "stage", flex: 1, minW: 0, minH: 0, marginInlineStart: closed || alone ? 0 : 'var(--pane-gap)', "$max-md": { marginInlineStart: 0, pb: `max(var(--pane-gap), ${FOOT})` }, children: [bar ? null : _jsx(Top, { host: host, mode: mode, places: sidebar, open: drawer.state !== 'shut', go: move, onMenu: drawer.open, onChat: toChat, onDev: toDev }), _jsx(XStack, { "data-slot": "panes", flex: 1, minW: 0, minH: 0, children: mode === 'chat' ? (_jsx(Paned, { framed: true, children: _jsx(Chat, {}) })) : mode === 'tabs' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(Suspense, { fallback: null, children: _jsx(Terminals, {}) }) })) : mode === 'studio' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(YStack, { flex: 1, minH: 0, height: "100%", children: _jsx(Suspense, { fallback: null, children: _jsx(Studio, { host: maker, rail: false }) }) }) })) : at.mode === 'hosted' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(Suspense, { fallback: null, children: _jsx(Hosted, { id: at.id, go: move }) }) })) : mode === 'beta' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflowY: "auto", overflowX: "hidden", flex: 1, minW: 0, minH: 0, p: "$4", $md: { p: '$6' }, children: betas ?? (_jsx(Suspense, { fallback: null, children: _jsx(Betas, { go: move }) })) })) : (_jsx(YStack, { render: "main", "data-slot": "pane", ...(run ? null : { ...pane(), overflow: 'hidden' }), flex: 1, minW: 0, minH: 0, children: plans ? null : _jsx(Builder, { host: host, rail: false }) })) })] })] }), drawer.state === 'shut' ? null : (_jsx(Layer, { drawer: drawer, top: bar ? BAR : 0, children: _jsxs(XStack, { flex: 1, minH: 0, children: [_jsx(YStack, { "data-slot": "drawer-rail", shrink: 0, children: _jsx(Rail, { host: host, mode: mode, at: where, inside: inside, open: true, onChat: toChat, onDev: toDev, onStudio: toStudio, onTabs: toTabs, go: move, onOrg: org }) }), _jsx(YStack, { flex: 1, minW: 0, children: _jsx(Column, { host: host, mode: mode, thread: thread, go: move, onShut: shut, onSeek: seek, onBack: back, drawer: true, places: sidebar }) })] }) })), finding ? _jsx(Palette, { go: move, onClose: found, mode: mode, host: host }) : null, learning ? _jsx(Learning, { open: true, onClose: () => setLearning(false) }) : null] }) }) }) }));
|
|
277
|
+
pt: bar ? 0 : 'var(--pane-gap)', "$max-md": { p: 0 }, children: [drawer.slide ? _jsx(Lift, {}) : null, _jsx(YStack, { height: "100%", "$max-md": { display: 'none' }, children: _jsx(Rail, { host: host, mode: mode, at: where, inside: inside, open: !closed, toggle: bar ? undefined : flip, onChat: toChat, onDev: toDev, onStudio: toStudio, onTabs: toTabs, go: move, onOrg: org }) }), closed || alone ? null : (_jsx(YStack, { "$max-md": { display: 'none' }, children: _jsx(Column, { host: host, mode: mode, thread: thread, go: move, onShut: () => setClosed(true), onSeek: seek, onBack: back, places: sidebar }) })), _jsxs(YStack, { "data-slot": "stage", flex: 1, minW: 0, minH: 0, marginInlineStart: closed || alone ? 0 : 'var(--pane-gap)', "$max-md": { marginInlineStart: 0, pb: `max(var(--pane-gap), ${FOOT})` }, children: [bar ? null : _jsx(Top, { host: host, mode: mode, places: sidebar, open: drawer.state !== 'shut', go: move, onMenu: drawer.open, onChat: toChat, onDev: toDev }), _jsx(XStack, { "data-slot": "panes", flex: 1, minW: 0, minH: 0, children: mode === 'chat' ? (_jsx(Paned, { framed: true, children: _jsx(Chat, {}) })) : mode === 'tabs' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(Suspense, { fallback: null, children: _jsx(Terminals, {}) }) })) : mode === 'studio' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(YStack, { flex: 1, minH: 0, height: "100%", children: _jsx(Suspense, { fallback: null, children: _jsx(Studio, { host: maker, rail: false }) }) }) })) : at.mode === 'hosted' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(Suspense, { fallback: null, children: _jsx(Hosted, { id: at.id, go: move }) }) })) : mode === 'beta' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflowY: "auto", overflowX: "hidden", flex: 1, minW: 0, minH: 0, p: "$4", $md: { p: '$6' }, children: betas ?? (_jsx(Suspense, { fallback: null, children: _jsx(Betas, { go: move }) })) })) : (_jsx(YStack, { render: "main", "data-slot": "pane", ...(run ? null : { ...pane(), overflow: 'hidden' }), flex: 1, minW: 0, minH: 0, children: plans ? null : _jsx(Builder, { host: host, rail: false }) })) })] })] }), drawer.state === 'shut' ? null : (_jsx(Layer, { drawer: drawer, top: bar ? BAR : 0, children: _jsxs(XStack, { flex: 1, minH: 0, children: [_jsx(YStack, { "data-slot": "drawer-rail", shrink: 0, pt: "$2", children: _jsx(Rail, { host: host, mode: mode, at: where, inside: inside, open: true, onChat: toChat, onDev: toDev, onStudio: toStudio, onTabs: toTabs, go: move, onOrg: org }) }), _jsx(YStack, { flex: 1, minW: 0, children: _jsx(Column, { host: host, mode: mode, thread: thread, go: move, onShut: shut, onSeek: seek, onBack: back, drawer: true, places: sidebar }) })] }) })), finding ? _jsx(Palette, { go: move, onClose: found, mode: mode, host: host }) : null, learning ? _jsx(Learning, { open: true, onClose: () => setLearning(false) }) : null] }) }) }) }));
|
|
278
278
|
}
|
package/dist/Setup.js
CHANGED
|
@@ -31,6 +31,7 @@ import { enter } from './lib/destination.js';
|
|
|
31
31
|
import { brand, site } from './where.js';
|
|
32
32
|
import { GOOGLE_ACCOUNTS_KEY, GOOGLE_KEY, accounts, connect, drop, keep } from './lib/gmail.js';
|
|
33
33
|
import { GOOD } from './lib/mix.js';
|
|
34
|
+
import { RETURN, awaitAnswer } from './lib/oauth.js';
|
|
34
35
|
export const LATER_KEY = 'hanzo.onboarding.later';
|
|
35
36
|
export const GITHUB_KEY = 'hanzo.onboarding.github';
|
|
36
37
|
export const SLACK_KEY = 'hanzo.onboarding.slack';
|
|
@@ -199,20 +200,21 @@ export function Setup({ go } = {}) {
|
|
|
199
200
|
const activeStep = step === 1 || step === 2 || step === 3 ? step : 1;
|
|
200
201
|
if (later && !modalOpen)
|
|
201
202
|
return null;
|
|
202
|
-
const openOAuthPopup = (authorizeUrl, provider, onDone) => {
|
|
203
|
+
const openOAuthPopup = (authorizeUrl, provider, label, onDone) => {
|
|
203
204
|
const popup = window.open(authorizeUrl, `hanzo-oauth-${provider}`, 'width=600,height=700');
|
|
204
205
|
if (!popup) {
|
|
205
206
|
window.open(authorizeUrl, '_blank', 'noopener,noreferrer');
|
|
207
|
+
return;
|
|
206
208
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
}
|
|
209
|
+
// The return page hands the answer back and closes the popup (lib/oauth);
|
|
210
|
+
// a popup closed without one still re-reads what is connected.
|
|
211
|
+
awaitAnswer(popup, provider, (answer) => {
|
|
212
|
+
if (answer?.ok)
|
|
213
|
+
onDone();
|
|
214
|
+
else if (answer)
|
|
215
|
+
setErrorMsg(t('Could not connect {provider} right now. Please try again.', { provider: label }));
|
|
216
|
+
setSyncTurn((n) => n + 1);
|
|
217
|
+
});
|
|
216
218
|
};
|
|
217
219
|
const connectOAuthProvider = async (provider, label, onDone) => {
|
|
218
220
|
if (!signed) {
|
|
@@ -238,7 +240,9 @@ export function Setup({ go } = {}) {
|
|
|
238
240
|
const res = await fetch(`${api()}/v1/provider/${provider}/connect`, {
|
|
239
241
|
method: 'POST',
|
|
240
242
|
headers: { ...scope(), 'Content-Type': 'application/json' },
|
|
241
|
-
|
|
243
|
+
// Without a return the callback lands on the console's /connectors,
|
|
244
|
+
// where the popup stays open; RETURN is the page that closes it.
|
|
245
|
+
body: JSON.stringify({ return: RETURN }),
|
|
242
246
|
});
|
|
243
247
|
if (!res.ok) {
|
|
244
248
|
let detail = '';
|
|
@@ -257,7 +261,7 @@ export function Setup({ go } = {}) {
|
|
|
257
261
|
}
|
|
258
262
|
const j = (await res.json());
|
|
259
263
|
if (j.authorizeUrl) {
|
|
260
|
-
openOAuthPopup(j.authorizeUrl, provider, onDone);
|
|
264
|
+
openOAuthPopup(j.authorizeUrl, provider, label, onDone);
|
|
261
265
|
}
|
|
262
266
|
else if (j.connected) {
|
|
263
267
|
onDone();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider's OAuth in a popup, and its answer back in the window that opened it.
|
|
3
|
+
*
|
|
4
|
+
* `/v1/provider/:provider/connect` answers an authorize URL; the provider sends the
|
|
5
|
+
* browser to api.hanzo.ai's callback, which 302s to the return page the connect
|
|
6
|
+
* named with `connected=<provider>&account=<label>` or `error=<provider>&reason=<why>`
|
|
7
|
+
* on its query. A connect that names no return lands on the console's /connectors,
|
|
8
|
+
* a whole other app on another origin: the popup stayed open there and the opener
|
|
9
|
+
* never heard. So the connect names `RETURN`, this site's registered return page
|
|
10
|
+
* (cloud brand.Info.Returns), where the site's first script (hanzo.ai app/page.tsx
|
|
11
|
+
* `RETURNED`) hands the answer to the opener and closes the popup.
|
|
12
|
+
*
|
|
13
|
+
* The answer arrives three ways, whichever reaches first: a `message` from the
|
|
14
|
+
* popup (same origin only), a `BroadcastChannel` post or a `storage` write for an
|
|
15
|
+
* opener the popup lost (`window.opener` is null after a cross-origin-isolated
|
|
16
|
+
* page). The opener also reads the popup's address itself once it is back on
|
|
17
|
+
* this origin, and closes it, so a popup that cannot close itself still does.
|
|
18
|
+
*/
|
|
19
|
+
/** The return page the connect names: hanzo.ai's Settings → Integrations, registered with the API. */
|
|
20
|
+
export declare const RETURN = "https://hanzo.ai/?at=-/settings/integrations";
|
|
21
|
+
/** The message, channel and storage key one answer travels by. */
|
|
22
|
+
export declare const RETURNED = "hanzo-oauth-return";
|
|
23
|
+
/** What the provider answered. */
|
|
24
|
+
export type Answer = {
|
|
25
|
+
type: typeof RETURNED;
|
|
26
|
+
provider: string;
|
|
27
|
+
ok: true;
|
|
28
|
+
account: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: typeof RETURNED;
|
|
31
|
+
provider: string;
|
|
32
|
+
ok: false;
|
|
33
|
+
reason: string;
|
|
34
|
+
};
|
|
35
|
+
/** The answer a return page's query carries, or null when it carries none. */
|
|
36
|
+
export declare function answered(search: string): Answer | null;
|
|
37
|
+
/** `data` as an answer for `provider`, or null when it is anything else. */
|
|
38
|
+
export declare function heard(data: unknown, provider: string): Answer | null;
|
|
39
|
+
/**
|
|
40
|
+
* Wait for `provider`'s answer to the popup. `done` is called once: with the
|
|
41
|
+
* answer, or with null when the popup closed without one. Answers the cleanup.
|
|
42
|
+
*/
|
|
43
|
+
export declare function awaitAnswer(popup: Window, provider: string, done: (answer: Answer | null) => void): () => void;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider's OAuth in a popup, and its answer back in the window that opened it.
|
|
3
|
+
*
|
|
4
|
+
* `/v1/provider/:provider/connect` answers an authorize URL; the provider sends the
|
|
5
|
+
* browser to api.hanzo.ai's callback, which 302s to the return page the connect
|
|
6
|
+
* named with `connected=<provider>&account=<label>` or `error=<provider>&reason=<why>`
|
|
7
|
+
* on its query. A connect that names no return lands on the console's /connectors,
|
|
8
|
+
* a whole other app on another origin: the popup stayed open there and the opener
|
|
9
|
+
* never heard. So the connect names `RETURN`, this site's registered return page
|
|
10
|
+
* (cloud brand.Info.Returns), where the site's first script (hanzo.ai app/page.tsx
|
|
11
|
+
* `RETURNED`) hands the answer to the opener and closes the popup.
|
|
12
|
+
*
|
|
13
|
+
* The answer arrives three ways, whichever reaches first: a `message` from the
|
|
14
|
+
* popup (same origin only), a `BroadcastChannel` post or a `storage` write for an
|
|
15
|
+
* opener the popup lost (`window.opener` is null after a cross-origin-isolated
|
|
16
|
+
* page). The opener also reads the popup's address itself once it is back on
|
|
17
|
+
* this origin, and closes it, so a popup that cannot close itself still does.
|
|
18
|
+
*/
|
|
19
|
+
/** The return page the connect names: hanzo.ai's Settings → Integrations, registered with the API. */
|
|
20
|
+
export const RETURN = 'https://hanzo.ai/?at=-/settings/integrations';
|
|
21
|
+
/** The message, channel and storage key one answer travels by. */
|
|
22
|
+
export const RETURNED = 'hanzo-oauth-return';
|
|
23
|
+
/** The answer a return page's query carries, or null when it carries none. */
|
|
24
|
+
export function answered(search) {
|
|
25
|
+
const q = new URLSearchParams(search);
|
|
26
|
+
const ok = q.get('connected');
|
|
27
|
+
if (ok)
|
|
28
|
+
return { type: RETURNED, provider: ok, ok: true, account: q.get('account') ?? '' };
|
|
29
|
+
const failed = q.get('error');
|
|
30
|
+
if (failed && q.has('reason'))
|
|
31
|
+
return { type: RETURNED, provider: failed, ok: false, reason: q.get('reason') ?? '' };
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/** `data` as an answer for `provider`, or null when it is anything else. */
|
|
35
|
+
export function heard(data, provider) {
|
|
36
|
+
if (!data || typeof data !== 'object')
|
|
37
|
+
return null;
|
|
38
|
+
const a = data;
|
|
39
|
+
if (a.type !== RETURNED || a.provider !== provider || typeof a.ok !== 'boolean')
|
|
40
|
+
return null;
|
|
41
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
42
|
+
return a.ok ? { type: RETURNED, provider, ok: true, account: text(a.account) } : { type: RETURNED, provider, ok: false, reason: text(a.reason) };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Wait for `provider`'s answer to the popup. `done` is called once: with the
|
|
46
|
+
* answer, or with null when the popup closed without one. Answers the cleanup.
|
|
47
|
+
*/
|
|
48
|
+
export function awaitAnswer(popup, provider, done) {
|
|
49
|
+
let over = false;
|
|
50
|
+
let channel = null;
|
|
51
|
+
const finish = (answer) => {
|
|
52
|
+
if (over)
|
|
53
|
+
return;
|
|
54
|
+
over = true;
|
|
55
|
+
stop();
|
|
56
|
+
try {
|
|
57
|
+
if (!popup.closed)
|
|
58
|
+
popup.close();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* already gone */
|
|
62
|
+
}
|
|
63
|
+
done(answer);
|
|
64
|
+
};
|
|
65
|
+
const onMessage = (ev) => {
|
|
66
|
+
if (ev.origin !== window.location.origin)
|
|
67
|
+
return;
|
|
68
|
+
const a = heard(ev.data, provider);
|
|
69
|
+
if (a)
|
|
70
|
+
finish(a);
|
|
71
|
+
};
|
|
72
|
+
const onStorage = (ev) => {
|
|
73
|
+
if (ev.key !== RETURNED || !ev.newValue)
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
const a = heard(JSON.parse(ev.newValue), provider);
|
|
77
|
+
if (a)
|
|
78
|
+
finish(a);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
/* not an answer */
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const timer = window.setInterval(() => {
|
|
85
|
+
if (popup.closed) {
|
|
86
|
+
finish(null);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
// Cross-origin (the provider, api.hanzo.ai) until the return page: reading throws.
|
|
91
|
+
if (popup.location.origin !== window.location.origin)
|
|
92
|
+
return;
|
|
93
|
+
const a = answered(popup.location.search);
|
|
94
|
+
if (a && a.provider === provider)
|
|
95
|
+
finish(a);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
/* still away */
|
|
99
|
+
}
|
|
100
|
+
}, 250);
|
|
101
|
+
const stop = () => {
|
|
102
|
+
window.clearInterval(timer);
|
|
103
|
+
window.removeEventListener('message', onMessage);
|
|
104
|
+
window.removeEventListener('storage', onStorage);
|
|
105
|
+
channel?.close();
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener('message', onMessage);
|
|
108
|
+
window.addEventListener('storage', onStorage);
|
|
109
|
+
if (typeof BroadcastChannel !== 'undefined') {
|
|
110
|
+
channel = new BroadcastChannel(RETURNED);
|
|
111
|
+
channel.onmessage = (ev) => {
|
|
112
|
+
const a = heard(ev.data, provider);
|
|
113
|
+
if (a)
|
|
114
|
+
finish(a);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return () => {
|
|
118
|
+
over = true;
|
|
119
|
+
stop();
|
|
120
|
+
};
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.42",
|
|
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",
|