@hanzo/app 0.3.50 → 0.3.52

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.
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The account chooser: who is signed in on this browser, and a press to be any one
3
+ * of them. One view for every site that signs people in on its own origin.
4
+ *
5
+ * IAM holds a session for each person signed in here and lists them (`GET
6
+ * /v1/iam/accounts`, lib/accounts); this draws that list and decides nothing.
7
+ *
8
+ * a row the sign-in for that account: the host's `pick` (IAM's
9
+ * `resume` with the account named, then on to the code it
10
+ * answers)
11
+ * Sign out that account alone (IAM's `logout_hint`); the page is drawn
12
+ * again from what IAM still holds
13
+ * Use another account the sign-in form (`onOther`), which keeps these sessions
14
+ * Sign out of all every account, and the page the person was on
15
+ *
16
+ * What differs by site is handed in: `pick` (analytics, an app's request being
17
+ * answered), `frame` (the card around the rows) and `refusal` (how a refusal is
18
+ * said). A tab that holds tokens for an account IAM lists no session for is offered
19
+ * as the one row (`listed` false), and its Sign out is the whole sign-out.
20
+ */
21
+ import { type ComponentType, type ReactNode } from 'react';
22
+ import { type Account, type Accounts } from './lib/accounts.js';
23
+ /** The card the rows sit in; the page's own (hanzo.ai's Sheet), else a plain column. */
24
+ export type Frame = ComponentType<{
25
+ label: string;
26
+ children: ReactNode;
27
+ }>;
28
+ /** How a refusal is said; the page's own, else plain text in the alert role. */
29
+ export type Refusal = ComponentType<{
30
+ text: string | null;
31
+ }>;
32
+ export interface ChooseProps {
33
+ /** The accounts to choose among: IAM's list, else this tab's own. */
34
+ rows: Account[];
35
+ /** Whether `rows` is IAM's list, each with a session to end alone. */
36
+ listed: boolean;
37
+ known: Pick<Accounts, 'leave'>;
38
+ /** The sign-in form instead. */
39
+ onOther: () => void;
40
+ /**
41
+ * Be the account pressed: true once it is on its way, false where IAM has no
42
+ * session to spend for it (the form is then asked for the credential).
43
+ */
44
+ pick: (account: Account) => Promise<boolean>;
45
+ frame?: ComponentType<{
46
+ label: string;
47
+ children: ReactNode;
48
+ }>;
49
+ refusal?: Refusal;
50
+ /** Said above the rows (another app's request being answered). */
51
+ note?: ReactNode;
52
+ }
53
+ export declare function Choose({ rows, listed, known, onOther, pick, frame: Frame, refusal: Wrong, note }: ChooseProps): import("react").JSX.Element;
package/dist/Choose.js ADDED
@@ -0,0 +1,68 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * The account chooser: who is signed in on this browser, and a press to be any one
5
+ * of them. One view for every site that signs people in on its own origin.
6
+ *
7
+ * IAM holds a session for each person signed in here and lists them (`GET
8
+ * /v1/iam/accounts`, lib/accounts); this draws that list and decides nothing.
9
+ *
10
+ * a row the sign-in for that account: the host's `pick` (IAM's
11
+ * `resume` with the account named, then on to the code it
12
+ * answers)
13
+ * Sign out that account alone (IAM's `logout_hint`); the page is drawn
14
+ * again from what IAM still holds
15
+ * Use another account the sign-in form (`onOther`), which keeps these sessions
16
+ * Sign out of all every account, and the page the person was on
17
+ *
18
+ * What differs by site is handed in: `pick` (analytics, an app's request being
19
+ * answered), `frame` (the card around the rows) and `refusal` (how a refusal is
20
+ * said). A tab that holds tokens for an account IAM lists no session for is offered
21
+ * as the one row (`listed` false), and its Sign out is the whole sign-out.
22
+ */
23
+ import { useState } from 'react';
24
+ import { useIam } from '@hanzo/iam/react';
25
+ import { useI18n } from '@hanzo/i18n/react';
26
+ import { Text, XStack, YStack } from '@hanzo/gui';
27
+ import { Avatar, Button } from '@hanzo/ui';
28
+ import { TextLink } from '@hanzo/ui/marketing';
29
+ import { label } from './lib/accounts.js';
30
+ import { useSignOut } from './lib/signout.js';
31
+ const Plain = ({ label: name, children }) => (_jsx(YStack, { render: "section", "aria-label": name, width: "100%", maxW: 420, mx: "auto", gap: "$4", children: children }));
32
+ const Said = ({ text }) => text ? (_jsx(Text, { role: "alert", fontSize: "$3", color: "$ink", text: "center", children: text })) : null;
33
+ /** Where this page is, the request included: what a sign-out comes back to, so the page's own request is still the page's. */
34
+ const here = () => `${window.location.pathname}${window.location.search}`;
35
+ export function Choose({ rows, listed, known, onOther, pick, frame: Frame = Plain, refusal: Wrong = Said, note }) {
36
+ const { t } = useI18n();
37
+ const { user } = useIam();
38
+ const out = useSignOut(typeof window === 'undefined' ? undefined : here());
39
+ const [busy, setBusy] = useState(false);
40
+ const [wrong, setWrong] = useState(null);
41
+ const signedIn = user;
42
+ async function go(a) {
43
+ setBusy(true);
44
+ setWrong(null);
45
+ try {
46
+ if (!(await pick(a)))
47
+ onOther();
48
+ }
49
+ catch {
50
+ setWrong(t('Something went wrong. Try again.'));
51
+ setBusy(false);
52
+ }
53
+ }
54
+ async function leave(a) {
55
+ setBusy(true);
56
+ setWrong(null);
57
+ if (!listed)
58
+ return void out();
59
+ if (!(await known.leave(a, here())))
60
+ setWrong(t('Something went wrong. Try again.'));
61
+ setBusy(false);
62
+ }
63
+ return (_jsxs(Frame, { label: t('Accounts'), children: [note, _jsx(YStack, { render: "ul", "aria-label": t('Signed in on this browser'), m: 0, p: 0, gap: "$2", children: rows.map((a) => {
64
+ const { title, line } = label(a);
65
+ const who = a.email || title;
66
+ return (_jsxs(XStack, { render: "li", items: "center", gap: "$2", children: [_jsxs(XStack, { render: _jsx("button", { type: "button" }), disabled: busy, onClick: () => void go(a), "aria-label": t('Continue as {who}', { who }), "aria-current": signedIn && (a.sub === signedIn.id || a.email === signedIn.email) ? true : undefined, flex: 1, minW: 0, items: "center", gap: "$3", px: "$3", py: "$2.5", rounded: "$4", borderWidth: 1, borderColor: "$edge", bg: "transparent", cursor: "pointer", hoverStyle: { bg: '$hover' }, children: [_jsx(Avatar, { src: a.avatar || null, name: title, colorSeed: a.sub, alt: "", size: 36, width: 36, height: 36, rounded: 999 }), _jsxs(YStack, { flex: 1, minW: 0, gap: 2, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", numberOfLines: 1, text: "start", children: title }), line || a.owner ? (_jsx(Text, { fontSize: "$2", color: "$soft", numberOfLines: 1, text: "start", children: [line, a.owner].filter(Boolean).join(' · ') })) : null] })] }), _jsx(Button, { type: "button", size: "xs", variant: "ghost", disabled: busy, "aria-label": t('Sign out {name}', { name: title }), onClick: () => void leave(a), children: t('Sign out') })] }, a.sub));
67
+ }) }), _jsx(Wrong, { text: wrong }), _jsx(TextLink, { onPress: onOther, children: t('Use another account') }), rows.length > 1 ? _jsx(TextLink, { onPress: () => void out(), children: t('Sign out of all accounts') }) : null] }));
68
+ }
@@ -0,0 +1,6 @@
1
+ import { type Account } from './lib/accounts.js';
2
+ export declare function Others({ out, pick, add }: {
3
+ out: () => void | Promise<void>;
4
+ pick?: (account: Account) => void | Promise<void>;
5
+ add?: () => void | Promise<void>;
6
+ }): import("react").JSX.Element;
package/dist/Others.js ADDED
@@ -0,0 +1,24 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * The account menu's rows for the accounts signed in on this browser: each other
5
+ * account one press away, Add account, Sign out of this one alone when there are
6
+ * others, and the way out of all of them (Log out when there is one). They go
7
+ * inside a host's own `DropdownMenuContent`, after its own rows; what a press does
8
+ * is lib/accounts' unless the host hands its own (`pick`, `add`), for a site whose
9
+ * sign-in page is its own.
10
+ */
11
+ import { LogOut, UserPlus } from 'lucide-react';
12
+ import { useI18n } from '@hanzo/i18n/react';
13
+ import { Text, XStack, YStack } from '@hanzo/gui';
14
+ import { Avatar, DropdownMenuItem } from '@hanzo/ui';
15
+ import { label, useAccounts } from './lib/accounts.js';
16
+ export function Others({ out, pick, add }) {
17
+ const { t } = useI18n();
18
+ const { accounts, current, switchTo, add: start, leave } = useAccounts();
19
+ const others = accounts.filter((a) => a.sub !== current?.sub);
20
+ return (_jsxs(_Fragment, { children: [others.map((a) => {
21
+ const { title, line } = label(a);
22
+ return (_jsx(DropdownMenuItem, { onSelect: () => void (pick ?? switchTo)(a), children: _jsxs(XStack, { items: "center", gap: 8, width: "100%", children: [_jsx(Avatar, { src: a.avatar || null, name: title, colorSeed: a.sub, alt: "", size: 22, width: 22, height: 22, rounded: 999 }), _jsxs(YStack, { minW: 0, flex: 1, children: [_jsx(Text, { fontSize: "$2", color: "$ink", numberOfLines: 1, children: title }), line ? (_jsx(Text, { fontSize: "$1", color: "$soft", numberOfLines: 1, children: line })) : null] })] }) }, a.sub));
23
+ }), _jsx(DropdownMenuItem, { onSelect: () => void (add ?? start)(), children: _jsxs(XStack, { items: "center", gap: 8, width: "100%", children: [_jsx(UserPlus, { size: 15, color: "var(--muted-foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: "$2", color: "$ink", children: t('Add account') })] }) }), others.length > 0 && current ? (_jsx(DropdownMenuItem, { onSelect: () => void leave(current), children: _jsxs(XStack, { items: "center", gap: 8, width: "100%", children: [_jsx(LogOut, { size: 15, color: "var(--muted-foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: "$2", color: "$ink", children: t('Sign out {name}', { name: label(current).title }) })] }) })) : null, _jsx(DropdownMenuItem, { onSelect: () => void out(), children: _jsxs(XStack, { items: "center", gap: 8, width: "100%", children: [_jsx(LogOut, { size: 15, color: "var(--destructive)", "aria-hidden": true }), _jsx(Text, { fontSize: "$2", color: "var(--destructive)", children: others.length > 0 ? t('Sign out of all accounts') : t('Log out') })] }) })] }));
24
+ }
@@ -1,5 +1,9 @@
1
1
  import { IAM } from '@hanzo/iam';
2
- /** Whether the page in front of us is on an origin that answers IAM itself (`answers` in host.ts). */
2
+ /**
3
+ * Whether the page in front of us is on an origin that answers IAM itself: one of
4
+ * the Hanzo hosts (`answers` in host.ts) or one the host states with
5
+ * `configure({ answers })` (where.ts).
6
+ */
3
7
  export declare const here: () => boolean;
4
8
  /** The IAM client for this page; the token exchange at the callback shares its PKCE store. */
5
9
  export declare function useClient(): IAM;
@@ -13,8 +13,13 @@ import { useIam } from '@hanzo/iam/react';
13
13
  import { useSignOut as useUiSignOut } from '@hanzo/ui/auth';
14
14
  import { track } from './tags.js';
15
15
  import { answers } from './host.js';
16
- /** Whether the page in front of us is on an origin that answers IAM itself (`answers` in host.ts). */
17
- export const here = () => typeof window !== 'undefined' && answers(window.location.hostname);
16
+ import { where } from '../where.js';
17
+ /**
18
+ * Whether the page in front of us is on an origin that answers IAM itself: one of
19
+ * the Hanzo hosts (`answers` in host.ts) or one the host states with
20
+ * `configure({ answers })` (where.ts).
21
+ */
22
+ export const here = () => typeof window !== 'undefined' && (answers(window.location.hostname) || where().answers?.(window.location.hostname) === true);
18
23
  /** The IAM client for this page; the token exchange at the callback shares its PKCE store. */
19
24
  export function useClient() {
20
25
  const { config } = useIam();
package/dist/where.d.ts CHANGED
@@ -33,6 +33,14 @@ export interface Addresses {
33
33
  brand?: string;
34
34
  /** The publishable key anonymous calls carry. */
35
35
  key?: string;
36
+ /**
37
+ * Whether a host answers IAM's credential, account-list and sign-out calls on
38
+ * its own origin (lib/signout `here`), in addition to the Hanzo hosts the apps
39
+ * already know (lib/host `answers`). A site that signs people in on its own page
40
+ * and keeps IAM's session cookie there, as hanzo.market does, states it here and
41
+ * gets the account chooser and the account menu with no other change.
42
+ */
43
+ answers?: (hostname: string) => boolean;
36
44
  /**
37
45
  * Where the IAM session is kept when it is not this page's `localStorage`:
38
46
  * the `storage` the host hands its IamProvider (Hanzo Desktop's keychain).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/app",
3
- "version": "0.3.50",
3
+ "version": "0.3.52",
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",