@hanzo/app 0.2.28 → 0.2.29

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/Betas.d.ts CHANGED
@@ -4,6 +4,10 @@ export declare function useBetas(): {
4
4
  open: (id: string) => boolean;
5
5
  /** Whether they asked for it. */
6
6
  asked: (id: string) => boolean;
7
+ /** Whether it is a public beta, one an admin promoted (lib/optin). */
8
+ promoted: (id: string) => boolean;
9
+ /** Their organization turned experimental features off. */
10
+ blocked: boolean;
7
11
  /** Ask for these apps. */
8
12
  request: (ids: string[]) => Promise<void>;
9
13
  /** The cloud has answered for this reader. */
package/dist/Betas.js CHANGED
@@ -13,6 +13,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  // stamped with the time and stated on the event plane under the person and the
14
14
  // org, so the request reaches the team where it works the person.
15
15
  //
16
+ // WHICH ARE PUBLIC is lib/optin's answer: a public beta is one an admin promoted,
17
+ // on for a reader who opted in to experimental features unless their
18
+ // organization turned that off. The cloud still says who is in, through the same
19
+ // GET /v1/flag/platform, so `opens` stays the one predicate; a public beta only
20
+ // reads as one, and says how to turn it on instead of asking for access.
21
+ //
16
22
  // Signed out, still loading, or on any error nothing is open: a flags outage
17
23
  // cannot leak an unfinished app.
18
24
  import { useCallback, useEffect, useState, useSyncExternalStore } from 'react';
@@ -24,7 +30,8 @@ import { Button, Dialog, DialogContent, DialogTitle, Text, XStack, YStack } from
24
30
  import { api } from './lib/api.js';
25
31
  import { BETAS, GROUPS, opens } from './lib/betas.js';
26
32
  import { bearer, scope, superAdmin } from './lib/session.js';
27
- const NONE = { flags: {}, asked: [] };
33
+ import { CHANGED, optin } from './lib/optin.js';
34
+ const NONE = { flags: {}, asked: [], public: [], blocked: false };
28
35
  /** A group's heading as the list draws it: authored English, drawn through `t`. */
29
36
  const HEADING = {
30
37
  Business: phrase('Business'),
@@ -52,9 +59,10 @@ function read(token) {
52
59
  reading = Promise.all([
53
60
  get('/v1/flag/platform').catch(() => null),
54
61
  get('/v1/marketing/beta').catch(() => null),
62
+ optin().catch(() => null),
55
63
  ])
56
- .then(([f, b]) => {
57
- held = { token, said: { flags: f?.flags ?? {}, asked: b?.betas ?? [] }, at: Date.now() };
64
+ .then(([f, b, o]) => {
65
+ held = { token, said: { flags: f?.flags ?? {}, asked: b?.betas ?? [], public: o?.public ?? [], blocked: o?.blocked ?? false }, at: Date.now() };
58
66
  })
59
67
  .finally(() => {
60
68
  reading = null;
@@ -82,9 +90,18 @@ export function useBetas() {
82
90
  if (token && (!held || held.token !== token || Date.now() - held.at > FRESH))
83
91
  void read(token);
84
92
  }, [token]);
93
+ // A change of the opt-in changes what the cloud opens: read it all again.
94
+ useEffect(() => {
95
+ if (!token)
96
+ return;
97
+ const again = () => void read(token);
98
+ window.addEventListener(CHANGED, again);
99
+ return () => window.removeEventListener(CHANGED, again);
100
+ }, [token]);
85
101
  const said = token && now?.token === token ? now.said : NONE;
86
102
  const open = useCallback((id) => opens(id, said.flags, sudo || local), [said, sudo, local]);
87
103
  const asked = useCallback((id) => said.asked.includes(id), [said]);
104
+ const promoted = useCallback((id) => said.public.includes(id), [said]);
88
105
  const request = useCallback(async (ids) => {
89
106
  const r = await fetch(`${api()}/v1/marketing/beta/request`, {
90
107
  method: 'POST',
@@ -99,7 +116,7 @@ export function useBetas() {
99
116
  tell();
100
117
  }
101
118
  }, [token, t]);
102
- return { open, asked, request, ready: Boolean(token) && now?.token === token };
119
+ return { open, asked, promoted, blocked: said.blocked, request, ready: Boolean(token) && now?.token === token };
103
120
  }
104
121
  /**
105
122
  * Whether this page is served from a developer's own machine, where every app
@@ -115,12 +132,15 @@ function here() {
115
132
  /** One app's action: Open where it may, Requested once asked, else Request access. */
116
133
  function Ask({ beta, go }) {
117
134
  const { t } = useI18n();
118
- const { open, asked, request } = useBetas();
135
+ const { open, asked, promoted, blocked, request } = useBetas();
119
136
  const [busy, setBusy] = useState(false);
120
137
  const [wrong, setWrong] = useState(null);
121
138
  if (open(beta.id)) {
122
139
  return beta.href && go ? (_jsx(Button, { size: "sm", rounded: 999, onPress: () => go(beta.href), "data-slot": "beta-open", children: t('Open') })) : (_jsx(Text, { fontSize: "$2", color: "$color11", "data-slot": "beta-on", children: t('You’re in') }));
123
140
  }
141
+ if (promoted(beta.id)) {
142
+ return (_jsx(Text, { fontSize: "$2", color: "$color11", text: "right", maxW: 200, "data-slot": "beta-optin", children: t(blocked ? 'Turned off by your organization' : 'Turn on experimental features in Settings') }));
143
+ }
124
144
  if (asked(beta.id)) {
125
145
  return (_jsx(Text, { fontSize: "$2", color: "$color11", "data-slot": "beta-requested", children: t('Requested') }));
126
146
  }
@@ -135,7 +155,8 @@ function Ask({ beta, go }) {
135
155
  /** Every app in beta, by group, each with its action. */
136
156
  export function BetasList({ go }) {
137
157
  const { t } = useI18n();
138
- return (_jsx(YStack, { gap: "$4", "data-slot": "betas", children: GROUPS.map((group) => (_jsxs(YStack, { gap: "$2", children: [_jsx(Text, { fontSize: "$1", color: "$color10", textTransform: "uppercase", letterSpacing: 0.6, children: t(HEADING[group]) }), BETAS.filter((b) => b.group === group).map((b) => (_jsxs(XStack, { items: "center", gap: "$3", "data-beta": b.id, children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "500", children: b.name }), _jsx(Text, { fontSize: "$2", color: "$color11", children: t(b.line) })] }), _jsx(Ask, { beta: b, go: go })] }, b.id)))] }, group))) }));
158
+ const { promoted } = useBetas();
159
+ return (_jsx(YStack, { gap: "$4", "data-slot": "betas", children: GROUPS.map((group) => (_jsxs(YStack, { gap: "$2", children: [_jsx(Text, { fontSize: "$1", color: "$color10", textTransform: "uppercase", letterSpacing: 0.6, children: t(HEADING[group]) }), BETAS.filter((b) => b.group === group).map((b) => (_jsxs(XStack, { items: "center", gap: "$3", "data-beta": b.id, children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Text, { fontSize: "$3", fontWeight: "500", children: b.name }), promoted(b.id) ? (_jsx(Text, { fontSize: "$1", color: "$color11", "data-slot": "beta-public", children: t('Public beta') })) : null] }), _jsx(Text, { fontSize: "$2", color: "$color11", children: t(b.line) })] }), _jsx(Ask, { beta: b, go: go })] }, b.id)))] }, group))) }));
139
160
  }
140
161
  /** The Betas list in a dialog, from the rail's More. */
141
162
  export function BetasDialog({ open, onOpenChange, go }) {
@@ -26,6 +26,7 @@ import { showSettings } from './open.js';
26
26
  import { Look } from './look.js';
27
27
  import { ProviderMark } from './ProviderMark.js';
28
28
  import { bearer, org, pick } from './lib/session.js';
29
+ import { Experimental } from './experimental.js';
29
30
  import { site } from './where.js';
30
31
  import { named, ROWS } from './Settings.js';
31
32
  /** A choice among a few: a hairline edge and a corner. The fill and the edge's
@@ -49,7 +50,7 @@ function Pane({ id, note }) {
49
50
  if (id === 'apps' || id === 'channels')
50
51
  return _jsx(Catalog, { tab: id });
51
52
  if (id === 'general')
52
- return _jsx(Look, {});
53
+ return (_jsxs(YStack, { gap: "$5", children: [_jsx(Look, {}), _jsx(Experimental, {})] }));
53
54
  if (id === 'account')
54
55
  return _jsx(Account, {});
55
56
  if (id === 'billing')
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The opt-in to what is experimental (lib/optin): on, the reader gets every
3
+ * public beta; their team or organization can turn it off for everyone in it,
4
+ * and then the switch is held off with a note. Signed out there is nothing to
5
+ * choose, so nothing is drawn.
6
+ */
7
+ export declare function Experimental(): import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The General pane's switch for what is experimental (SettingsPane.tsx draws it
4
+ // under Look). Its own module so it is drawn and tested without the pane's world.
5
+ import { useEffect, useState } from 'react';
6
+ import { useI18n } from '@hanzo/i18n/react';
7
+ import { useIam } from '@hanzo/iam/react';
8
+ import { Switch, Text, XStack, YStack } from '@hanzo/ui';
9
+ import { opt, optin } from './lib/optin.js';
10
+ /**
11
+ * The opt-in to what is experimental (lib/optin): on, the reader gets every
12
+ * public beta; their team or organization can turn it off for everyone in it,
13
+ * and then the switch is held off with a note. Signed out there is nothing to
14
+ * choose, so nothing is drawn.
15
+ */
16
+ export function Experimental() {
17
+ const { t } = useI18n();
18
+ const { isAuthenticated } = useIam();
19
+ const [held, setHeld] = useState(null);
20
+ const [busy, setBusy] = useState(false);
21
+ const [wrong, setWrong] = useState(null);
22
+ useEffect(() => {
23
+ if (!isAuthenticated)
24
+ return;
25
+ let live = true;
26
+ optin()
27
+ .then((o) => live && setHeld(o))
28
+ .catch((e) => live && setWrong(e instanceof Error ? e.message : String(e)));
29
+ return () => {
30
+ live = false;
31
+ };
32
+ }, [isAuthenticated]);
33
+ if (!isAuthenticated)
34
+ return null;
35
+ const blocked = held?.blocked === true;
36
+ const title = t('Automatically opt-in for future experimental features');
37
+ return (_jsxs(YStack, { p: "$3", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", gap: "$2", "data-slot": "optin", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", children: [_jsxs(YStack, { flex: 1, pr: "$2", children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: title }), _jsx(Text, { fontSize: "$2", color: "$soft", children: t('Automatically opt into new experimental features, unless disabled by your team or organization') })] }), _jsx(Switch, { "aria-label": title, checked: held?.on === true && !blocked, disabled: !held || busy || blocked, onCheckedChange: (on) => {
38
+ setBusy(true);
39
+ setWrong(null);
40
+ opt(on)
41
+ .then(setHeld)
42
+ .catch((e) => setWrong(e instanceof Error ? e.message : String(e)))
43
+ .finally(() => setBusy(false));
44
+ } })] }), blocked ? (_jsx(Text, { fontSize: "$2", color: "$soft", "data-slot": "optin-blocked", children: t('Turned off by your team or organization.') })) : null, wrong ? (_jsx(Text, { fontSize: "$2", color: "$red10", children: t(wrong) })) : null] }));
45
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * OPTING IN TO WHAT IS EXPERIMENTAL: the one client for the reader's choice and
3
+ * their organization's block.
4
+ *
5
+ * A beta is PRIVATE (a SuperAdmin grants it, person by person) or PUBLIC (an
6
+ * admin promoted it). A reader who opts in gets every public beta, unless their
7
+ * organization turned it off; staff get every beta. Who is in is still the
8
+ * cloud's answer at GET /v1/flag/platform, so `opens` (lib/betas) stays the one
9
+ * predicate; this module only reads and writes the choice.
10
+ *
11
+ * GET /v1/flag/optin {on, blocked, public: [<beta id>]} 401 signed out
12
+ * PUT /v1/flag/optin {on} -> the same shape 403 when blocked and on
13
+ * PUT /v1/flag/optin/org {blocked} -> {blocked} an org admin or a SuperAdmin
14
+ *
15
+ * A refusal is said in words a person can act on, never as a status code: each
16
+ * is authored English (`phrase`), so a caller draws it through `t`.
17
+ */
18
+ /** The reader's choice, their organization's block, and the betas that are public. */
19
+ export interface Optin {
20
+ /** The reader opted in. */
21
+ on: boolean;
22
+ /** Their organization turned it off for everyone in it. */
23
+ blocked: boolean;
24
+ /** The ids (lib/betas) of the public betas. */
25
+ public: string[];
26
+ }
27
+ /** Fired on window after the choice or the block changes, so a list can read again. */
28
+ export declare const CHANGED = "hanzo.optin";
29
+ /** The reader's choice as the cloud holds it. */
30
+ export declare function optin(): Promise<Optin>;
31
+ /** Opt the reader in or out. Refused while their organization has it turned off. */
32
+ export declare function opt(on: boolean): Promise<Optin>;
33
+ /** Turn experimental features off, or back on, for everyone in the organization in scope. */
34
+ export declare function block(blocked: boolean): Promise<{
35
+ blocked: boolean;
36
+ }>;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * OPTING IN TO WHAT IS EXPERIMENTAL: the one client for the reader's choice and
3
+ * their organization's block.
4
+ *
5
+ * A beta is PRIVATE (a SuperAdmin grants it, person by person) or PUBLIC (an
6
+ * admin promoted it). A reader who opts in gets every public beta, unless their
7
+ * organization turned it off; staff get every beta. Who is in is still the
8
+ * cloud's answer at GET /v1/flag/platform, so `opens` (lib/betas) stays the one
9
+ * predicate; this module only reads and writes the choice.
10
+ *
11
+ * GET /v1/flag/optin {on, blocked, public: [<beta id>]} 401 signed out
12
+ * PUT /v1/flag/optin {on} -> the same shape 403 when blocked and on
13
+ * PUT /v1/flag/optin/org {blocked} -> {blocked} an org admin or a SuperAdmin
14
+ *
15
+ * A refusal is said in words a person can act on, never as a status code: each
16
+ * is authored English (`phrase`), so a caller draws it through `t`.
17
+ */
18
+ import { phrase } from '@hanzo/i18n';
19
+ import { api } from './api.js';
20
+ import { scope } from './session.js';
21
+ /** Fired on window after the choice or the block changes, so a list can read again. */
22
+ export const CHANGED = 'hanzo.optin';
23
+ const SIGNED_OUT = phrase('Sign in to choose experimental features.');
24
+ async function call(path, init, words) {
25
+ let res;
26
+ try {
27
+ res = await fetch(`${api()}${path}`, { ...init, headers: { ...(init?.body ? { 'Content-Type': 'application/json' } : {}), ...scope() } });
28
+ }
29
+ catch {
30
+ throw new Error(words.offline);
31
+ }
32
+ if (res.status === 401)
33
+ throw new Error(SIGNED_OUT);
34
+ if (res.status === 403 && words.refused)
35
+ throw new Error(words.refused);
36
+ if (!res.ok)
37
+ throw new Error(words.failed);
38
+ return res.json();
39
+ }
40
+ const told = () => {
41
+ if (typeof window !== 'undefined')
42
+ window.dispatchEvent(new Event(CHANGED));
43
+ };
44
+ function shape(body) {
45
+ const b = (body ?? {});
46
+ return { on: b.on === true, blocked: b.blocked === true, public: Array.isArray(b.public) ? b.public.filter((id) => typeof id === 'string') : [] };
47
+ }
48
+ /** The reader's choice as the cloud holds it. */
49
+ export async function optin() {
50
+ return shape(await call('/v1/flag/optin', undefined, {
51
+ offline: phrase('Your experimental features setting could not be read. Check your connection and try again.'),
52
+ failed: phrase('Your experimental features setting could not be read. Try again in a moment.'),
53
+ }));
54
+ }
55
+ /** Opt the reader in or out. Refused while their organization has it turned off. */
56
+ export async function opt(on) {
57
+ const out = shape(await call('/v1/flag/optin', { method: 'PUT', body: JSON.stringify({ on }) }, {
58
+ offline: phrase('Your choice was not saved. Check your connection and try again.'),
59
+ failed: phrase('Your choice was not saved. Try again in a moment.'),
60
+ refused: phrase('Your team or organization has turned experimental features off.'),
61
+ }));
62
+ told();
63
+ return out;
64
+ }
65
+ /** Turn experimental features off, or back on, for everyone in the organization in scope. */
66
+ export async function block(blocked) {
67
+ const b = (await call('/v1/flag/optin/org', { method: 'PUT', body: JSON.stringify({ blocked }) }, {
68
+ offline: phrase('The organization setting was not saved. Check your connection and try again.'),
69
+ failed: phrase('The organization setting was not saved. Try again in a moment.'),
70
+ refused: phrase('Only an admin of this organization can change this for everyone in it.'),
71
+ }));
72
+ told();
73
+ return { blocked: b?.blocked === true };
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/app",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
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",