@hanzo/build 0.2.92 → 0.2.93

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.
@@ -66,6 +66,18 @@ export declare function connect(t: Target, back?: string): Promise<string>;
66
66
  /** Finish the connect GitHub's return handed this page as `grant`. */
67
67
  export declare function complete(t: Target, grant: string): Promise<Connection>;
68
68
  export declare function disconnect(t: Target): Promise<void>;
69
+ /**
70
+ * Said on the window when this page changes the GitHub connection (a connect
71
+ * finished, a link or an App account let go), so every surface showing it
72
+ * reads it again: Projects' line, Settings' Integrations, and the Hanzo app's
73
+ * Quick setup (@hanzo/app Setup), which says it too. A name the two packages
74
+ * agree on, so neither imports the other.
75
+ */
76
+ export declare const CHANGED = "hanzo:github";
77
+ /** Say the GitHub connection changed. */
78
+ export declare function changed(): void;
79
+ /** Run `again` each time the GitHub connection changed; the answer stops it. */
80
+ export declare function heard(again: () => void): () => void;
69
81
  /** A GitHub account the platform's App is installed on, as this org sees it. */
70
82
  export interface Installation {
71
83
  login: string;
package/lib/api/github.js CHANGED
@@ -90,6 +90,24 @@ export async function complete(t, grant) {
90
90
  export async function disconnect(t) {
91
91
  await call(t, 'POST', '/v1/provider/github/user/disconnect');
92
92
  }
93
+ /**
94
+ * Said on the window when this page changes the GitHub connection (a connect
95
+ * finished, a link or an App account let go), so every surface showing it
96
+ * reads it again: Projects' line, Settings' Integrations, and the Hanzo app's
97
+ * Quick setup (@hanzo/app Setup), which says it too. A name the two packages
98
+ * agree on, so neither imports the other.
99
+ */
100
+ export const CHANGED = 'hanzo:github';
101
+ /** Say the GitHub connection changed. */
102
+ export function changed() {
103
+ if (typeof window !== 'undefined')
104
+ window.dispatchEvent(new Event(CHANGED));
105
+ }
106
+ /** Run `again` each time the GitHub connection changed; the answer stops it. */
107
+ export function heard(again) {
108
+ window.addEventListener(CHANGED, again);
109
+ return () => window.removeEventListener(CHANGED, again);
110
+ }
93
111
  /** The accounts this org has bound the App on. An org admin adds one through `/v1/provider/github/connect`. */
94
112
  export async function installations(t) {
95
113
  const raw = obj(await call(t, 'GET', '/v1/provider/github/installations'));
package/lib/back.d.ts CHANGED
@@ -24,6 +24,7 @@ export declare function here(): string;
24
24
  export declare const named: (id: string) => string;
25
25
  /**
26
26
  * Finish what a return carried, once a person is signed in: `say` gets the
27
- * sentence, and `after` runs once something was connected.
27
+ * sentence, and `after` runs once something was connected. GitHub's own
28
+ * readers hear `changed` instead (api/github.ts `heard`).
28
29
  */
29
- export declare function useBack(t: Target, signed: boolean, say: (note: string) => void, after: () => void): void;
30
+ export declare function useBack(t: Target, signed: boolean, say: (note: string) => void, after?: () => void): void;
package/lib/back.js CHANGED
@@ -10,12 +10,14 @@
10
10
  * ?error=<provider>&reason=<why> either, refused
11
11
  *
12
12
  * `useBack` reads that answer once, takes it off the address so a reload does
13
- * not replay it, finishes a GitHub grant, and says what happened.
13
+ * not replay it, finishes a GitHub grant, and says what happened. GitHub
14
+ * connected either way is said on the window too (`changed`), so every surface
15
+ * showing GitHub reads it again, the Hanzo app's Quick setup among them.
14
16
  */
15
17
  import { phrase } from '@hanzo/i18n';
16
18
  import { useI18n } from '@hanzo/i18n/react';
17
19
  import { useEffect } from 'react';
18
- import { complete } from './api/github.js';
20
+ import { changed, complete } from './api/github.js';
19
21
  /** The query keys a return carries its answer in. */
20
22
  export const ANSWER = ['complete', 'grant', 'connected', 'account', 'error', 'reason'];
21
23
  /** The answer a return carried in `search`, or null when it carried none. */
@@ -61,7 +63,8 @@ const NAMES = { github: 'GitHub', slack: 'Slack' };
61
63
  export const named = (id) => NAMES[id] ?? (id ? id[0].toUpperCase() + id.slice(1) : phrase('The connection'));
62
64
  /**
63
65
  * Finish what a return carried, once a person is signed in: `say` gets the
64
- * sentence, and `after` runs once something was connected.
66
+ * sentence, and `after` runs once something was connected. GitHub's own
67
+ * readers hear `changed` instead (api/github.ts `heard`).
65
68
  */
66
69
  export function useBack(t, signed, say, after) {
67
70
  const { t: words } = useI18n();
@@ -83,14 +86,18 @@ export function useBack(t, signed, say, after) {
83
86
  say(l.account
84
87
  ? words('{provider} is connected as {account}', { provider: words(named(l.provider)), account: l.account })
85
88
  : words('{provider} is connected', { provider: words(named(l.provider)) }));
86
- after();
89
+ // The org's App, installed on a GitHub account.
90
+ if (l.provider === 'github')
91
+ changed();
92
+ after?.();
87
93
  return;
88
94
  }
89
95
  if (l.provider !== 'github')
90
96
  return;
91
97
  complete(t, l.grant).then((c) => {
92
98
  say(c.connected ? words('Connected as @{login}', { login: c.login }) : words('GitHub did not connect; connect again'));
93
- after();
99
+ changed();
100
+ after?.();
94
101
  }, (e) => say(e.message));
95
102
  // Once per landing: the address is clean after the first run.
96
103
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/lib/forge.js CHANGED
@@ -30,7 +30,7 @@ import { useHost, useTarget } from './host.js';
30
30
  import { path } from './route.js';
31
31
  import { Customize } from './customize/index.js';
32
32
  import { Sync } from './sync.js';
33
- import { connect, connection, disconnect as unlink, grants, installations, linked, syncIssues } from './api/github.js';
33
+ import { changed, connect, connection, disconnect as unlink, grants, heard, installations, linked, syncIssues } from './api/github.js';
34
34
  import { disconnect } from './api/provider.js';
35
35
  import { here, useBack } from './back.js';
36
36
  import { Out } from './out.js';
@@ -155,6 +155,9 @@ function Choice({ label, icon, says, onPress }) {
155
155
  * Disconnect lets go of it, so another account can be connected: the person's own
156
156
  * link, or (for an org admin) the org's App accounts, which the platform also
157
157
  * uninstalls on GitHub. It asks once before doing either.
158
+ *
159
+ * A change made here, in Settings or in the Hanzo app's Quick setup is said on
160
+ * the window (api/github.ts `changed`), and this line reads it again.
158
161
  */
159
162
  function GitHubLink({ onSync }) {
160
163
  const host = useHost();
@@ -166,10 +169,13 @@ function GitHubLink({ onSync }) {
166
169
  const [note, setNote] = useState('');
167
170
  const [busy, setBusy] = useState(false);
168
171
  const [asking, setAsking] = useState(false);
169
- useBack(target, true, setNote, () => {
170
- me.reload();
171
- installed.reload();
172
- });
172
+ const { reload: readMe } = me;
173
+ const { reload: readInstalled } = installed;
174
+ useEffect(() => heard(() => {
175
+ readMe();
176
+ readInstalled();
177
+ }), [readMe, readInstalled]);
178
+ useBack(target, true, setNote);
173
179
  const c = me.value ? linked(me.value, installed.value) : null;
174
180
  // A connection that cannot be read says nothing here: Sync from GitHub above still works.
175
181
  if (me.error || !c || !c.configured)
@@ -195,8 +201,7 @@ function GitHubLink({ onSync }) {
195
201
  await (own ? unlink(target) : disconnect(target, 'github'));
196
202
  setAsking(false);
197
203
  setNote(t('GitHub is disconnected. Connect it again to choose another account.'));
198
- me.reload();
199
- installed.reload();
204
+ changed();
200
205
  }
201
206
  catch (e) {
202
207
  setNote(e.message);
@@ -8,7 +8,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
8
  * and the platform's callback brings the person back here with the answer
9
9
  * (../back.ts), which this page finishes and reports. Anyone connects their own
10
10
  * GitHub; installing the App and connecting Slack are an org admin's, which is
11
- * the platform's rule.
11
+ * the platform's rule. A GitHub change made here, on Projects or in the Hanzo
12
+ * app's Quick setup is said on the window (../api/github.ts `changed`), and
13
+ * this page reads GitHub again.
12
14
  *
13
15
  * Its words are the reader's language (@hanzo/i18n `t`); an account's,
14
16
  * a channel's and a provider's names, and the platform's own notes, are drawn
@@ -18,9 +20,9 @@ import { SizableText, XStack, YStack } from '@hanzo/gui';
18
20
  import { useI18n } from '@hanzo/i18n/react';
19
21
  import { Github, Hash, Lock, Megaphone, Slack } from '@hanzogui/lucide-icons-2';
20
22
  import { Button } from '@hanzo/ui';
21
- import { useState } from 'react';
23
+ import { useEffect, useState } from 'react';
22
24
  import { told } from '../api/call.js';
23
- import { connect, connection, disconnect as unlinkGithub, installations } from '../api/github.js';
25
+ import { changed, connect, connection, disconnect as unlinkGithub, heard, installations } from '../api/github.js';
24
26
  import { authorize, channels, disconnect, read, SOCIAL } from '../api/provider.js';
25
27
  import { here, useBack } from '../back.js';
26
28
  import { useRead } from '../data.js';
@@ -39,9 +41,13 @@ export function Integrations() {
39
41
  const social = useSocial(signed, SOCIAL.map((p) => p.id));
40
42
  const [working, setWorking] = useState(false);
41
43
  const [note, setNote] = useState('');
44
+ const { reload: readMine } = mine;
45
+ const { reload: readInstalled } = installed;
46
+ useEffect(() => heard(() => {
47
+ readMine();
48
+ readInstalled();
49
+ }), [readMine, readInstalled]);
42
50
  useBack(target, signed, setNote, () => {
43
- mine.reload();
44
- installed.reload();
45
51
  slack.reload();
46
52
  social.reload();
47
53
  });
@@ -85,7 +91,7 @@ export function Integrations() {
85
91
  ? t('This deployment cannot connect GitHub yet.')
86
92
  : me.connected
87
93
  ? t('Connected as @{login}', { login: me.login })
88
- : t('Not connected'), trailing: me?.configured ? (me.connected ? (_jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void act(() => unlinkGithub(target), t('Your GitHub is disconnected'), mine.reload), children: t('Disconnect') })) : (_jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void away(() => connect(target, here())), children: t('Connect') }))) : null }), installed.error ? (_jsx(Row, { title: t('App installations'), detail: told(installed.error, t) })) : (installed.value.map((i) => (_jsx(Row, { leading: _jsx(Github, { size: 16 }), title: i.login, detail: [i.type, i.grant === 'all' ? t('every repository') : i.grant === 'selected' ? t('selected repositories') : ''].filter(Boolean).join(' · '), trailing: _jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(SizableText, { size: "$1", color: i.connected ? '$ink' : '$soft', children: i.connected ? t('Installed') : t('Removed on GitHub') }), host.admin ? (_jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void act(() => disconnect(target, 'github', i.login), t('@{login} is disconnected', { login: i.login }), installed.reload), children: t('Disconnect') })) : null] }) }, i.login)))), !installed.error && !installed.loading && installed.value.length === 0 ? (_jsx(Row, { title: t('No GitHub accounts installed'), detail: t('Install the App on a GitHub account to bring its repositories here.') })) : null] }), host.admin ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void away(() => authorize(target, 'github', here())), children: t('Install on a GitHub account') }) })) : (_jsx(SizableText, { size: "$1", color: "$soft", children: t('An org admin installs the App on a GitHub account.') }))] }), _jsxs(Group, { title: "Slack", detail: t('Talk to Hanzo from your workspace’s channels.'), children: [_jsxs(Card, { children: [_jsx(Row, { first: true, leading: _jsx(Slack, { size: 16 }), title: s?.connected && s.account ? s.account : 'Slack', detail: slack.error
94
+ : t('Not connected'), trailing: me?.configured ? (me.connected ? (_jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void act(() => unlinkGithub(target), t('Your GitHub is disconnected'), changed), children: t('Disconnect') })) : (_jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void away(() => connect(target, here())), children: t('Connect') }))) : null }), installed.error ? (_jsx(Row, { title: t('App installations'), detail: told(installed.error, t) })) : (installed.value.map((i) => (_jsx(Row, { leading: _jsx(Github, { size: 16 }), title: i.login, detail: [i.type, i.grant === 'all' ? t('every repository') : i.grant === 'selected' ? t('selected repositories') : ''].filter(Boolean).join(' · '), trailing: _jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(SizableText, { size: "$1", color: i.connected ? '$ink' : '$soft', children: i.connected ? t('Installed') : t('Removed on GitHub') }), host.admin ? (_jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void act(() => disconnect(target, 'github', i.login), t('@{login} is disconnected', { login: i.login }), changed), children: t('Disconnect') })) : null] }) }, i.login)))), !installed.error && !installed.loading && installed.value.length === 0 ? (_jsx(Row, { title: t('No GitHub accounts installed'), detail: t('Install the App on a GitHub account to bring its repositories here.') })) : null] }), host.admin ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "outline", disabled: working, onPress: () => void away(() => authorize(target, 'github', here())), children: t('Install on a GitHub account') }) })) : (_jsx(SizableText, { size: "$1", color: "$soft", children: t('An org admin installs the App on a GitHub account.') }))] }), _jsxs(Group, { title: "Slack", detail: t('Talk to Hanzo from your workspace’s channels.'), children: [_jsxs(Card, { children: [_jsx(Row, { first: true, leading: _jsx(Slack, { size: 16 }), title: s?.connected && s.account ? s.account : 'Slack', detail: slack.error
89
95
  ? told(slack.error, t)
90
96
  : !s
91
97
  ? t('Reading…')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/build",
3
- "version": "0.2.92",
3
+ "version": "0.2.93",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "description": "Hanzo Build — say what you want, watch it built, deployed and running. The builder as a component, mounted by the Hanzo app at hanzo.ai.",