@peers-app/peers-ui 0.33.16 → 0.33.18
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/apps-home/apps-home.js +3 -1
- package/dist/components/router.d.ts +1 -0
- package/dist/components/router.js +1 -0
- package/dist/delegates/acts-for-you-control.d.ts +35 -0
- package/dist/delegates/acts-for-you-control.js +68 -0
- package/dist/delegates/acts-for-you-panel.d.ts +12 -0
- package/dist/delegates/acts-for-you-panel.js +76 -0
- package/dist/delegates/delegate-request-dialog.d.ts +17 -0
- package/dist/delegates/delegate-request-dialog.js +60 -0
- package/dist/delegates/delegates-ipc.d.ts +64 -0
- package/dist/delegates/delegates-ipc.js +95 -0
- package/dist/delegates/index.d.ts +4 -0
- package/dist/delegates/index.js +12 -0
- package/dist/notifications/notifications-client.d.ts +1 -1
- package/dist/screens/packages/package-info.js +2 -1
- package/dist/screens/packages/package-list.js +2 -0
- package/dist/screens/packages/package-waiting.js +5 -2
- package/package.json +3 -3
|
@@ -9,6 +9,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
9
9
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
10
10
|
const react_1 = require("react");
|
|
11
11
|
const sortablejs_1 = __importDefault(require("sortablejs"));
|
|
12
|
+
const delegates_ipc_1 = require("../delegates/delegates-ipc");
|
|
12
13
|
const use_observable_1 = require("../hooks/use-observable");
|
|
13
14
|
const use_promise_1 = require("../hooks/use-promise");
|
|
14
15
|
const local_network_offer_1 = require("../local-network/local-network-offer");
|
|
@@ -201,10 +202,11 @@ function AppsHome({ isMobile }) {
|
|
|
201
202
|
setRemoving(undefined);
|
|
202
203
|
toAdd.refresh();
|
|
203
204
|
} })), sheetOpen && ((0, jsx_runtime_1.jsx)(get_apps_sheet_1.GetAppsSheet, { groupName: groupName, packages: toAdd.packages, loadError: toAdd.error, canAdd: canManage, isMobile: isMobile, onAdd: async (entry) => {
|
|
204
|
-
await (await (0, packages_ipc_1.packagesTools)()).installPackage({
|
|
205
|
+
const { packageId } = await (await (0, packages_ipc_1.packagesTools)()).installPackage({
|
|
205
206
|
packageId: entry.packageId,
|
|
206
207
|
fromDataContextId: entry.sourceDataContextId,
|
|
207
208
|
});
|
|
209
|
+
void (0, delegates_ipc_1.offerDelegateAfterInstall)(packageId);
|
|
208
210
|
}, onClose: () => {
|
|
209
211
|
setSheetOpen(false);
|
|
210
212
|
toAdd.refresh();
|
|
@@ -2,6 +2,7 @@ import "../screens/console-logs/console-logs-list";
|
|
|
2
2
|
import "../screens/identity";
|
|
3
3
|
import "../screens/network-viewer";
|
|
4
4
|
import "../screens/data-explorer";
|
|
5
|
+
import "../delegates";
|
|
5
6
|
import "../notifications";
|
|
6
7
|
/** Render the built-in or registered UI that owns a canonicalized route. */
|
|
7
8
|
export declare function Router({ path: providedPath }?: {
|
|
@@ -56,6 +56,7 @@ require("../screens/console-logs/console-logs-list");
|
|
|
56
56
|
require("../screens/identity");
|
|
57
57
|
require("../screens/network-viewer");
|
|
58
58
|
require("../screens/data-explorer");
|
|
59
|
+
require("../delegates");
|
|
59
60
|
require("../notifications");
|
|
60
61
|
/** Render the built-in or registered UI that owns a canonicalized route. */
|
|
61
62
|
function Router({ path: providedPath } = {}) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type IDelegateGrantInfo } from "@peers-app/peers-sdk";
|
|
2
|
+
import { type ActsForYouChoice } from "./delegates-ipc";
|
|
3
|
+
/** Props for {@link ActsForYouControl}. */
|
|
4
|
+
export interface IActsForYouControlProps {
|
|
5
|
+
/** The package's name. */
|
|
6
|
+
packageName: string;
|
|
7
|
+
/** The group's name, or "Personal". */
|
|
8
|
+
dataContextName: string;
|
|
9
|
+
/** The grant as it stands on this device, if any. */
|
|
10
|
+
grant?: IDelegateGrantInfo;
|
|
11
|
+
/** The person's own level in the group; nothing above it is offered. */
|
|
12
|
+
userAccessLevel: number;
|
|
13
|
+
/** Apply a choice. A rejection is shown in the control. */
|
|
14
|
+
onChoose: (choice: ActsForYouChoice) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* When a raise ends, for "Admin until 3:40 PM": the time today, with the day otherwise.
|
|
18
|
+
*
|
|
19
|
+
* @param until Epoch milliseconds.
|
|
20
|
+
* @param now The current time.
|
|
21
|
+
*/
|
|
22
|
+
export declare function raiseEndsLabel(until: number, now?: Date): string;
|
|
23
|
+
/**
|
|
24
|
+
* What a grant lets a package do, in one line: "Read and write", "Admin until 3:40 PM, then Read
|
|
25
|
+
* and write", or "Off".
|
|
26
|
+
*
|
|
27
|
+
* @param grant The grant, if any.
|
|
28
|
+
*/
|
|
29
|
+
export declare function actsForYouSummary(grant: IDelegateGrantInfo | undefined): string;
|
|
30
|
+
/**
|
|
31
|
+
* The "Acts for you" setting for one package in one group: Off, Read only, Read and write, or
|
|
32
|
+
* Admin for an hour, until tomorrow, or always. Shown on the package's page and in the dialog a
|
|
33
|
+
* package's request opens. A choice applies at once, to this device only.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ActsForYouControl(props: IActsForYouControlProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.raiseEndsLabel = raiseEndsLabel;
|
|
4
|
+
exports.actsForYouSummary = actsForYouSummary;
|
|
5
|
+
exports.ActsForYouControl = ActsForYouControl;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const delegates_ipc_1 = require("./delegates-ipc");
|
|
10
|
+
/**
|
|
11
|
+
* When a raise ends, for "Admin until 3:40 PM": the time today, with the day otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @param until Epoch milliseconds.
|
|
14
|
+
* @param now The current time.
|
|
15
|
+
*/
|
|
16
|
+
function raiseEndsLabel(until, now = new Date()) {
|
|
17
|
+
const end = new Date(until);
|
|
18
|
+
const time = end.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
|
|
19
|
+
if (end.toDateString() === now.toDateString())
|
|
20
|
+
return time;
|
|
21
|
+
return `${end.toLocaleDateString([], { weekday: "short" })} ${time}`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What a grant lets a package do, in one line: "Read and write", "Admin until 3:40 PM, then Read
|
|
25
|
+
* and write", or "Off".
|
|
26
|
+
*
|
|
27
|
+
* @param grant The grant, if any.
|
|
28
|
+
*/
|
|
29
|
+
function actsForYouSummary(grant) {
|
|
30
|
+
if (!grant)
|
|
31
|
+
return "Off";
|
|
32
|
+
if (grant.raisedUntil !== undefined && grant.effectiveLevel > grant.level)
|
|
33
|
+
return `${(0, delegates_ipc_1.actsForYouLabel)(grant.effectiveLevel)} until ${raiseEndsLabel(grant.raisedUntil)}, then ${(0, delegates_ipc_1.actsForYouLabel)(grant.level)}`;
|
|
34
|
+
return (0, delegates_ipc_1.actsForYouLabel)(grant.effectiveLevel);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The "Acts for you" setting for one package in one group: Off, Read only, Read and write, or
|
|
38
|
+
* Admin for an hour, until tomorrow, or always. Shown on the package's page and in the dialog a
|
|
39
|
+
* package's request opens. A choice applies at once, to this device only.
|
|
40
|
+
*/
|
|
41
|
+
function ActsForYouControl(props) {
|
|
42
|
+
const { grant, userAccessLevel } = props;
|
|
43
|
+
const [busy, setBusy] = (0, react_1.useState)(false);
|
|
44
|
+
const [error, setError] = (0, react_1.useState)();
|
|
45
|
+
const [choosingAdmin, setChoosingAdmin] = (0, react_1.useState)(false);
|
|
46
|
+
const current = grant?.effectiveLevel ?? peers_sdk_1.AccessLevel.None;
|
|
47
|
+
const raised = grant?.raisedUntil !== undefined && current > (grant?.level ?? 0);
|
|
48
|
+
const choose = async (choice) => {
|
|
49
|
+
setBusy(true);
|
|
50
|
+
setError(undefined);
|
|
51
|
+
try {
|
|
52
|
+
await props.onChoose(choice);
|
|
53
|
+
setChoosingAdmin(false);
|
|
54
|
+
}
|
|
55
|
+
catch (cause) {
|
|
56
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
setBusy(false);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const option = (label, selected, onClick, disabled = false) => ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn ${selected ? "btn-primary" : "btn-outline-primary"}`, "aria-pressed": selected, disabled: busy || disabled, title: disabled ? "More than your own role in this group" : undefined, onClick: onClick, children: label }, label));
|
|
63
|
+
return ((0, jsx_runtime_1.jsxs)("div", { "data-testid": "acts-for-you-control", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-2", children: [props.packageName, " can act for you in ", props.dataContextName, ":", " ", (0, jsx_runtime_1.jsx)("strong", { children: actsForYouSummary(grant) }), raised && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm py-0", disabled: busy || (grant?.level ?? peers_sdk_1.AccessLevel.Writer) > userAccessLevel, onClick: () => void choose({ kind: "level", level: grant?.level ?? peers_sdk_1.AccessLevel.Writer }), children: "End now" }))] }), (0, jsx_runtime_1.jsxs)("fieldset", { className: "btn-group btn-group-sm flex-wrap", "aria-label": "Acts for you", children: [option("Off", !grant, () => void choose({ kind: "off" })), delegates_ipc_1.ACTS_FOR_YOU_LEVELS.map(({ level, label }) => option(label, choosingAdmin && userAccessLevel >= peers_sdk_1.AccessLevel.Admin
|
|
64
|
+
? level === peers_sdk_1.AccessLevel.Admin
|
|
65
|
+
: current === level, () => level === peers_sdk_1.AccessLevel.Admin
|
|
66
|
+
? setChoosingAdmin(true)
|
|
67
|
+
: void choose({ kind: "level", level }), level > userAccessLevel))] }), choosingAdmin && userAccessLevel >= peers_sdk_1.AccessLevel.Admin && ((0, jsx_runtime_1.jsxs)("fieldset", { className: "btn-group btn-group-sm flex-wrap mt-2", "aria-label": "Admin for", children: [option("For an hour", false, () => void choose({ kind: "admin", until: Date.now() + 60 * 60 * 1000 })), option("Until tomorrow", false, () => void choose({ kind: "admin", until: (0, delegates_ipc_1.untilTomorrow)() })), option("Always", false, () => void choose({ kind: "admin" })), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm", disabled: busy, onClick: () => setChoosingAdmin(false), children: "Cancel" })] })), error && ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger py-1 px-2 small mt-2 mb-0", role: "alert", children: error })), (0, jsx_runtime_1.jsxs)("div", { className: "form-text", children: ["With this on, ", props.packageName, " uses your other apps' tools as you, up to this level. It applies on this device only."] })] }));
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Props for {@link ActsForYouPanel}. */
|
|
2
|
+
export interface IActsForYouPanelProps {
|
|
3
|
+
packageId: string;
|
|
4
|
+
/** The package's name. */
|
|
5
|
+
packageName: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The package page's "Acts for you" setting, for the group the Packages screen shows. Shown when
|
|
9
|
+
* the package asks to act for the person or already has a grant here; a host without System
|
|
10
|
+
* Delegates shows nothing.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ActsForYouPanel(props: IActsForYouPanelProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActsForYouPanel = ActsForYouPanel;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const globals_1 = require("../globals");
|
|
8
|
+
const hooks_1 = require("../hooks");
|
|
9
|
+
const use_host_contract_1 = require("../hooks/use-host-contract");
|
|
10
|
+
const acts_for_you_control_1 = require("./acts-for-you-control");
|
|
11
|
+
const delegates_ipc_1 = require("./delegates-ipc");
|
|
12
|
+
/**
|
|
13
|
+
* The package page's "Acts for you" setting, for the group the Packages screen shows. Shown when
|
|
14
|
+
* the package asks to act for the person or already has a grant here; a host without System
|
|
15
|
+
* Delegates shows nothing.
|
|
16
|
+
*/
|
|
17
|
+
function ActsForYouPanel(props) {
|
|
18
|
+
const [dataContextId, setDataContextId] = (0, react_1.useState)();
|
|
19
|
+
(0, react_1.useEffect)(() => {
|
|
20
|
+
let cancelled = false;
|
|
21
|
+
(0, peers_sdk_1.getDefaultDataContext)().then((dataContext) => {
|
|
22
|
+
if (!cancelled)
|
|
23
|
+
setDataContextId(dataContext.dataContextId);
|
|
24
|
+
}, () => undefined);
|
|
25
|
+
return () => {
|
|
26
|
+
cancelled = true;
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
if (!dataContextId)
|
|
30
|
+
return null;
|
|
31
|
+
return (0, jsx_runtime_1.jsx)(ActsForYouPanelIn, { ...props, dataContextId: dataContextId });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The panel for one group. The consumer follows the host connection, so a reconnect gives it a
|
|
35
|
+
* live one: it reads the grant again and hears its changes.
|
|
36
|
+
*/
|
|
37
|
+
function ActsForYouPanelIn(props) {
|
|
38
|
+
const { dataContextId } = props;
|
|
39
|
+
const [groupList] = (0, hooks_1.useObservable)(globals_1.groups);
|
|
40
|
+
const { consumer } = (0, use_host_contract_1.useHostContract)((0, delegates_ipc_1.delegatesContractFor)(dataContextId));
|
|
41
|
+
const [state, setState] = (0, react_1.useState)();
|
|
42
|
+
const [refresh, setRefresh] = (0, react_1.useState)(0);
|
|
43
|
+
(0, react_1.useEffect)(() => {
|
|
44
|
+
if (!consumer)
|
|
45
|
+
return;
|
|
46
|
+
let cancelled = false;
|
|
47
|
+
consumer.tools.getGrant({ packageId: props.packageId }).then((result) => {
|
|
48
|
+
if (!cancelled)
|
|
49
|
+
setState(result);
|
|
50
|
+
}, () => {
|
|
51
|
+
if (!cancelled)
|
|
52
|
+
setState(undefined);
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
cancelled = true;
|
|
56
|
+
};
|
|
57
|
+
}, [consumer, props.packageId, refresh]);
|
|
58
|
+
(0, react_1.useEffect)(() => {
|
|
59
|
+
if (!consumer)
|
|
60
|
+
return;
|
|
61
|
+
const subscription = consumer.events.changed.subscribe((event) => {
|
|
62
|
+
if (event.packageId === props.packageId)
|
|
63
|
+
setRefresh((value) => value + 1);
|
|
64
|
+
});
|
|
65
|
+
return () => {
|
|
66
|
+
subscription.unsubscribe();
|
|
67
|
+
};
|
|
68
|
+
}, [consumer, props.packageId]);
|
|
69
|
+
if (!consumer || !state || (!state.request && !state.grant))
|
|
70
|
+
return null;
|
|
71
|
+
const group = groupList.find((entry) => entry.groupId === dataContextId);
|
|
72
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mt-3", "data-testid": "acts-for-you-panel", children: [(0, jsx_runtime_1.jsx)("hr", {}), (0, jsx_runtime_1.jsx)("h6", { children: "Acts for you" }), state.request && ((0, jsx_runtime_1.jsxs)("p", { className: "small text-muted mb-2", children: [props.packageName, " asks: \u201C", state.request.why, "\u201D"] })), (0, jsx_runtime_1.jsx)(acts_for_you_control_1.ActsForYouControl, { packageName: props.packageName, dataContextName: group?.name || "Personal", grant: state.grant, userAccessLevel: state.userAccessLevel ?? 0, onChoose: async (choice) => {
|
|
73
|
+
await (0, delegates_ipc_1.applyActsForYouChoice)(consumer, { packageId: props.packageId, dataContextId }, state.grant, choice);
|
|
74
|
+
setRefresh((value) => value + 1);
|
|
75
|
+
} })] }));
|
|
76
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IDelegatePendingRequest } from "@peers-app/peers-sdk";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { ActsForYouControl } from "./acts-for-you-control";
|
|
4
|
+
/**
|
|
5
|
+
* The "Acts for you" dialog: shown above every layout while System Delegates has an open request,
|
|
6
|
+
* which a package's `requestDelegate` or the offer after an install opens. Choosing a level
|
|
7
|
+
* applies it and closes the dialog; "Not now" closes it and changes nothing.
|
|
8
|
+
*/
|
|
9
|
+
export declare function DelegateRequestDialog(): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
/** Props for {@link DelegateRequestDialogView}. */
|
|
11
|
+
export interface IDelegateRequestDialogViewProps {
|
|
12
|
+
request: IDelegatePendingRequest;
|
|
13
|
+
onChoose: React.ComponentProps<typeof ActsForYouControl>["onChoose"];
|
|
14
|
+
onClose: () => void;
|
|
15
|
+
}
|
|
16
|
+
/** The dialog's content for one request. Focus starts on "Not now" and stays inside; Escape closes. */
|
|
17
|
+
export declare function DelegateRequestDialogView({ request, onChoose, onClose, }: IDelegateRequestDialogViewProps): React.ReactPortal;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegateRequestDialog = DelegateRequestDialog;
|
|
4
|
+
exports.DelegateRequestDialogView = DelegateRequestDialogView;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const react_dom_1 = require("react-dom");
|
|
8
|
+
const hooks_1 = require("../hooks");
|
|
9
|
+
const use_host_contract_1 = require("../hooks/use-host-contract");
|
|
10
|
+
const global_overlays_1 = require("../root-layout/global-overlays");
|
|
11
|
+
const acts_for_you_control_1 = require("./acts-for-you-control");
|
|
12
|
+
const delegates_ipc_1 = require("./delegates-ipc");
|
|
13
|
+
/**
|
|
14
|
+
* The "Acts for you" dialog: shown above every layout while System Delegates has an open request,
|
|
15
|
+
* which a package's `requestDelegate` or the offer after an install opens. Choosing a level
|
|
16
|
+
* applies it and closes the dialog; "Not now" closes it and changes nothing.
|
|
17
|
+
*/
|
|
18
|
+
function DelegateRequestDialog() {
|
|
19
|
+
const { consumer } = (0, use_host_contract_1.useHostContract)(delegates_ipc_1.delegatesContract);
|
|
20
|
+
const [request] = (0, hooks_1.useObservable)(consumer?.observables.pendingRequest ?? null);
|
|
21
|
+
if (!consumer || !request)
|
|
22
|
+
return null;
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(DelegateRequestDialogView, { request: request, onChoose: (choice) => (0, delegates_ipc_1.applyActsForYouChoice)(consumer, { packageId: request.packageId, dataContextId: request.dataContextId }, request.grant, choice), onClose: () => void consumer.tools.dismissRequest({ requestId: request.requestId }) }, request.requestId));
|
|
24
|
+
}
|
|
25
|
+
/** The dialog's content for one request. Focus starts on "Not now" and stays inside; Escape closes. */
|
|
26
|
+
function DelegateRequestDialogView({ request, onChoose, onClose, }) {
|
|
27
|
+
const notNowRef = (0, react_1.useRef)(null);
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
29
|
+
notNowRef.current?.focus();
|
|
30
|
+
}, []);
|
|
31
|
+
const name = request.packageName;
|
|
32
|
+
const onKeyDown = (event) => {
|
|
33
|
+
if (event.key === "Escape") {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
onClose();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (event.key !== "Tab")
|
|
39
|
+
return;
|
|
40
|
+
const buttons = Array.from(event.currentTarget.querySelectorAll("button:not(:disabled)"));
|
|
41
|
+
const first = buttons[0];
|
|
42
|
+
const last = buttons[buttons.length - 1];
|
|
43
|
+
if (event.shiftKey &&
|
|
44
|
+
(document.activeElement === first || document.activeElement === event.currentTarget)) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
last?.focus();
|
|
47
|
+
}
|
|
48
|
+
else if (!event.shiftKey && document.activeElement === last) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
first?.focus();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return (0, react_dom_1.createPortal)(
|
|
54
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: a pointer-only backdrop; Escape closes
|
|
55
|
+
(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
|
|
56
|
+
if (event.target === event.currentTarget)
|
|
57
|
+
onClose();
|
|
58
|
+
}, children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-delegate-request-title", onKeyDown: onKeyDown, "data-testid": "delegate-request-dialog", children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-head", children: (0, jsx_runtime_1.jsxs)("h3", { id: "peers-delegate-request-title", children: ["Let ", name, " act for you in ", request.dataContextName, "?"] }) }), (0, jsx_runtime_1.jsxs)("p", { children: [name, " asks for ", (0, delegates_ipc_1.actsForYouLabel)(request.request.level), ": \u201C", request.request.why, "\u201D"] }), (0, jsx_runtime_1.jsxs)("p", { children: ["It would use the tools your other apps provide, such as Tasks, Calendar and Notes, as you, up to the level you pick. You can change it any time on ", name, "'s page in Packages."] }), (0, jsx_runtime_1.jsx)(acts_for_you_control_1.ActsForYouControl, { packageName: name, dataContextName: request.dataContextName, grant: request.grant, userAccessLevel: request.userAccessLevel, onChoose: onChoose }), (0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-actions mt-3", children: (0, jsx_runtime_1.jsx)("button", { ref: notNowRef, type: "button", className: "btn peers-apps-ghost", onClick: onClose, children: "Not now" }) })] }) }), document.body);
|
|
59
|
+
}
|
|
60
|
+
(0, global_overlays_1.registerGlobalOverlay)("system-delegates-request", DelegateRequestDialog);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type IDelegateGrantInfo, type IDelegatesConsumer, type IHostContractConsumer } from "@peers-app/peers-sdk";
|
|
2
|
+
/** System Delegates, bound to the person's personal context: the open request, grant, revoke. */
|
|
3
|
+
export declare const delegatesContract: IHostContractConsumer<IDelegatesConsumer>;
|
|
4
|
+
/**
|
|
5
|
+
* System Delegates bound to one data context, for `getGrant` and `offerDelegate`, which act on
|
|
6
|
+
* the call's context. Stable per context, for `useHostContract`.
|
|
7
|
+
*
|
|
8
|
+
* @param dataContextId The group, or the personal context.
|
|
9
|
+
*/
|
|
10
|
+
export declare function delegatesContractFor(dataContextId: string): IHostContractConsumer<IDelegatesConsumer>;
|
|
11
|
+
/**
|
|
12
|
+
* After an install from this device, offer the "Acts for you" dialog when the package asks to
|
|
13
|
+
* act for the person and has no grant here. A host without System Delegates offers nothing.
|
|
14
|
+
*
|
|
15
|
+
* @param packageId The package just installed.
|
|
16
|
+
* @param dataContextId The group, or the personal context, it was installed in; defaults to the
|
|
17
|
+
* active group, the one `packagesTools()` installs into.
|
|
18
|
+
*/
|
|
19
|
+
export declare function offerDelegateAfterInstall(packageId: string, dataContextId?: string): Promise<void>;
|
|
20
|
+
/** One choice in the "Acts for you" control. */
|
|
21
|
+
export type ActsForYouChoice = {
|
|
22
|
+
kind: "off";
|
|
23
|
+
} | {
|
|
24
|
+
kind: "level";
|
|
25
|
+
level: number;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "admin";
|
|
28
|
+
until?: number;
|
|
29
|
+
};
|
|
30
|
+
/** The control's choices, lowest first. */
|
|
31
|
+
export declare const ACTS_FOR_YOU_LEVELS: readonly [{
|
|
32
|
+
readonly level: 20;
|
|
33
|
+
readonly label: "Read only";
|
|
34
|
+
}, {
|
|
35
|
+
readonly level: 40;
|
|
36
|
+
readonly label: "Read and write";
|
|
37
|
+
}, {
|
|
38
|
+
readonly level: 60;
|
|
39
|
+
readonly label: "Admin";
|
|
40
|
+
}];
|
|
41
|
+
/**
|
|
42
|
+
* A level as the control names it.
|
|
43
|
+
*
|
|
44
|
+
* @param level Reader, Writer or Admin.
|
|
45
|
+
*/
|
|
46
|
+
export declare function actsForYouLabel(level: number): string;
|
|
47
|
+
/**
|
|
48
|
+
* When "until tomorrow" ends: the next midnight on this device.
|
|
49
|
+
*
|
|
50
|
+
* @param now The current time.
|
|
51
|
+
*/
|
|
52
|
+
export declare function untilTomorrow(now?: Date): number;
|
|
53
|
+
/**
|
|
54
|
+
* Apply one choice to a package's grant in one context.
|
|
55
|
+
*
|
|
56
|
+
* @param consumer System Delegates.
|
|
57
|
+
* @param target The package and the context.
|
|
58
|
+
* @param grant The grant as it stands, if any.
|
|
59
|
+
* @param choice What the person chose.
|
|
60
|
+
*/
|
|
61
|
+
export declare function applyActsForYouChoice(consumer: IDelegatesConsumer, target: {
|
|
62
|
+
packageId: string;
|
|
63
|
+
dataContextId: string;
|
|
64
|
+
}, grant: IDelegateGrantInfo | undefined, choice: ActsForYouChoice): Promise<void>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACTS_FOR_YOU_LEVELS = exports.delegatesContract = void 0;
|
|
4
|
+
exports.delegatesContractFor = delegatesContractFor;
|
|
5
|
+
exports.offerDelegateAfterInstall = offerDelegateAfterInstall;
|
|
6
|
+
exports.actsForYouLabel = actsForYouLabel;
|
|
7
|
+
exports.untilTomorrow = untilTomorrow;
|
|
8
|
+
exports.applyActsForYouChoice = applyActsForYouChoice;
|
|
9
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
10
|
+
const handles = new Map();
|
|
11
|
+
/** System Delegates, bound to the person's personal context: the open request, grant, revoke. */
|
|
12
|
+
exports.delegatesContract = (0, peers_sdk_1.hostContractConsumer)((0, peers_sdk_1.getDelegatesContractDefinition)());
|
|
13
|
+
/**
|
|
14
|
+
* System Delegates bound to one data context, for `getGrant` and `offerDelegate`, which act on
|
|
15
|
+
* the call's context. Stable per context, for `useHostContract`.
|
|
16
|
+
*
|
|
17
|
+
* @param dataContextId The group, or the personal context.
|
|
18
|
+
*/
|
|
19
|
+
function delegatesContractFor(dataContextId) {
|
|
20
|
+
let handle = handles.get(dataContextId);
|
|
21
|
+
if (!handle) {
|
|
22
|
+
handle = (0, peers_sdk_1.hostContractConsumer)((0, peers_sdk_1.getDelegatesContractDefinition)(), {
|
|
23
|
+
dataContextId: async () => dataContextId,
|
|
24
|
+
});
|
|
25
|
+
handles.set(dataContextId, handle);
|
|
26
|
+
}
|
|
27
|
+
return handle;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* After an install from this device, offer the "Acts for you" dialog when the package asks to
|
|
31
|
+
* act for the person and has no grant here. A host without System Delegates offers nothing.
|
|
32
|
+
*
|
|
33
|
+
* @param packageId The package just installed.
|
|
34
|
+
* @param dataContextId The group, or the personal context, it was installed in; defaults to the
|
|
35
|
+
* active group, the one `packagesTools()` installs into.
|
|
36
|
+
*/
|
|
37
|
+
async function offerDelegateAfterInstall(packageId, dataContextId) {
|
|
38
|
+
try {
|
|
39
|
+
const id = dataContextId ?? (await (0, peers_sdk_1.getDefaultDataContext)()).dataContextId;
|
|
40
|
+
await (await delegatesContractFor(id).get()).tools.offerDelegate({ packageId });
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// An older host, or a package that can't run here: there's nothing to offer.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The control's choices, lowest first. */
|
|
47
|
+
exports.ACTS_FOR_YOU_LEVELS = [
|
|
48
|
+
{ level: peers_sdk_1.AccessLevel.Reader, label: "Read only" },
|
|
49
|
+
{ level: peers_sdk_1.AccessLevel.Writer, label: "Read and write" },
|
|
50
|
+
{ level: peers_sdk_1.AccessLevel.Admin, label: "Admin" },
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* A level as the control names it.
|
|
54
|
+
*
|
|
55
|
+
* @param level Reader, Writer or Admin.
|
|
56
|
+
*/
|
|
57
|
+
function actsForYouLabel(level) {
|
|
58
|
+
return [...exports.ACTS_FOR_YOU_LEVELS].reverse().find((entry) => level >= entry.level)?.label ?? "Off";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* When "until tomorrow" ends: the next midnight on this device.
|
|
62
|
+
*
|
|
63
|
+
* @param now The current time.
|
|
64
|
+
*/
|
|
65
|
+
function untilTomorrow(now = new Date()) {
|
|
66
|
+
const midnight = new Date(now);
|
|
67
|
+
midnight.setHours(24, 0, 0, 0);
|
|
68
|
+
return midnight.getTime();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Apply one choice to a package's grant in one context.
|
|
72
|
+
*
|
|
73
|
+
* @param consumer System Delegates.
|
|
74
|
+
* @param target The package and the context.
|
|
75
|
+
* @param grant The grant as it stands, if any.
|
|
76
|
+
* @param choice What the person chose.
|
|
77
|
+
*/
|
|
78
|
+
async function applyActsForYouChoice(consumer, target, grant, choice) {
|
|
79
|
+
if (choice.kind === "off") {
|
|
80
|
+
await consumer.tools.revoke(target);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (choice.kind === "level") {
|
|
84
|
+
await consumer.tools.grant({ ...target, level: choice.level });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (choice.until === undefined) {
|
|
88
|
+
await consumer.tools.grant({ ...target, level: peers_sdk_1.AccessLevel.Admin });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// A raise goes over the grant's own level; Admin for good becomes Read and write first.
|
|
92
|
+
if (grant && grant.level >= peers_sdk_1.AccessLevel.Admin)
|
|
93
|
+
await consumer.tools.grant({ ...target, level: peers_sdk_1.AccessLevel.Writer });
|
|
94
|
+
await consumer.tools.grant({ ...target, level: peers_sdk_1.AccessLevel.Admin, until: choice.until });
|
|
95
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.offerDelegateAfterInstall = exports.ActsForYouPanel = exports.actsForYouSummary = exports.ActsForYouControl = void 0;
|
|
4
|
+
// Registers the "Acts for you" dialog as a global overlay.
|
|
5
|
+
require("./delegate-request-dialog");
|
|
6
|
+
var acts_for_you_control_1 = require("./acts-for-you-control");
|
|
7
|
+
Object.defineProperty(exports, "ActsForYouControl", { enumerable: true, get: function () { return acts_for_you_control_1.ActsForYouControl; } });
|
|
8
|
+
Object.defineProperty(exports, "actsForYouSummary", { enumerable: true, get: function () { return acts_for_you_control_1.actsForYouSummary; } });
|
|
9
|
+
var acts_for_you_panel_1 = require("./acts-for-you-panel");
|
|
10
|
+
Object.defineProperty(exports, "ActsForYouPanel", { enumerable: true, get: function () { return acts_for_you_panel_1.ActsForYouPanel; } });
|
|
11
|
+
var delegates_ipc_1 = require("./delegates-ipc");
|
|
12
|
+
Object.defineProperty(exports, "offerDelegateAfterInstall", { enumerable: true, get: function () { return delegates_ipc_1.offerDelegateAfterInstall; } });
|
|
@@ -24,7 +24,7 @@ export declare function useNotifications(input: IListNotificationsInput, enabled
|
|
|
24
24
|
fromName?: string | undefined;
|
|
25
25
|
seenAt?: Date | undefined;
|
|
26
26
|
handledAt?: Date | undefined;
|
|
27
|
-
handledAs?: "opened" | "
|
|
27
|
+
handledAs?: "opened" | "dismissed" | "acknowledged" | "retracted" | undefined;
|
|
28
28
|
snoozedUntil?: Date | undefined;
|
|
29
29
|
muted?: boolean | undefined;
|
|
30
30
|
}[] | undefined;
|
|
@@ -6,6 +6,7 @@ const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
|
6
6
|
const input_1 = require("../../components/input");
|
|
7
7
|
const markdown_with_mentions_1 = require("../../components/markdown-with-mentions");
|
|
8
8
|
const tooltip_1 = require("../../components/tooltip");
|
|
9
|
+
const acts_for_you_panel_1 = require("../../delegates/acts-for-you-panel");
|
|
9
10
|
const hooks_1 = require("../../hooks");
|
|
10
11
|
const host_shell_consumer_1 = require("../../host-shell/host-shell-consumer");
|
|
11
12
|
const package_network_panel_1 = require("./package-network-panel");
|
|
@@ -120,6 +121,6 @@ const PackageInfo = (props) => {
|
|
|
120
121
|
await (0, peers_sdk_1.updatePackagePrefs)(pkg.packageId, {
|
|
121
122
|
followTags: val === "stable" ? "stable" : val,
|
|
122
123
|
});
|
|
123
|
-
}, children: [(0, jsx_runtime_1.jsx)("option", { value: "stable", children: "Stable" }), (0, jsx_runtime_1.jsx)("option", { value: "stable,beta", children: "Stable + Beta" })] })] })] }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-2", children: [(0, jsx_runtime_1.jsx)("hr", {}), (0, jsx_runtime_1.jsxs)("small", { children: ["Description:", (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { markdownContent: `This should be edited in the package's README.md. It will automatically update when you restart Peers or reload the package.` })] }), (0, jsx_runtime_1.jsx)(markdown_with_mentions_1.MarkdownWithMentions, { content: pkg.description || "" })] }), (0, jsx_runtime_1.jsx)(package_network_panel_1.PackageNetworkPanel, { packageId: pkg.packageId })] }));
|
|
124
|
+
}, children: [(0, jsx_runtime_1.jsx)("option", { value: "stable", children: "Stable" }), (0, jsx_runtime_1.jsx)("option", { value: "stable,beta", children: "Stable + Beta" })] })] })] }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-2", children: [(0, jsx_runtime_1.jsx)("hr", {}), (0, jsx_runtime_1.jsxs)("small", { children: ["Description:", (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { markdownContent: `This should be edited in the package's README.md. It will automatically update when you restart Peers or reload the package.` })] }), (0, jsx_runtime_1.jsx)(markdown_with_mentions_1.MarkdownWithMentions, { content: pkg.description || "" })] }), (0, jsx_runtime_1.jsx)(package_network_panel_1.PackageNetworkPanel, { packageId: pkg.packageId }), (0, jsx_runtime_1.jsx)(acts_for_you_panel_1.ActsForYouPanel, { packageId: pkg.packageId, packageName: pkg.name || pkg.packageId })] }));
|
|
124
125
|
};
|
|
125
126
|
exports.PackageInfo = PackageInfo;
|
|
@@ -8,6 +8,7 @@ const input_1 = require("../../components/input");
|
|
|
8
8
|
const lazy_list_1 = require("../../components/lazy-list");
|
|
9
9
|
const loading_indicator_1 = require("../../components/loading-indicator");
|
|
10
10
|
const tooltip_1 = require("../../components/tooltip");
|
|
11
|
+
const delegates_ipc_1 = require("../../delegates/delegates-ipc");
|
|
11
12
|
const globals_1 = require("../../globals");
|
|
12
13
|
const hooks_1 = require("../../hooks");
|
|
13
14
|
const host_shell_consumer_1 = require("../../host-shell/host-shell-consumer");
|
|
@@ -253,6 +254,7 @@ const PackageList = () => {
|
|
|
253
254
|
addingPackage(true);
|
|
254
255
|
const { packageId } = await (await (0, packages_ipc_1.packagesTools)()).installPackage({ packageId: name });
|
|
255
256
|
(0, globals_1.mainContentPath)(`packages/${packageId}`);
|
|
257
|
+
void (0, delegates_ipc_1.offerDelegateAfterInstall)(packageId);
|
|
256
258
|
}
|
|
257
259
|
catch (err) {
|
|
258
260
|
confirm(`Error installing package: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -8,6 +8,7 @@ const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const current_group_name_1 = require("../../apps-home/current-group-name");
|
|
10
10
|
const get_apps_sheet_1 = require("../../apps-home/get-apps-sheet");
|
|
11
|
+
const delegates_ipc_1 = require("../../delegates/delegates-ipc");
|
|
11
12
|
const use_observable_1 = require("../../hooks/use-observable");
|
|
12
13
|
const use_promise_1 = require("../../hooks/use-promise");
|
|
13
14
|
const tabs_state_1 = require("../../tabs-layout/tabs-state");
|
|
@@ -102,8 +103,10 @@ function useAddAction(onAdded) {
|
|
|
102
103
|
void (async () => {
|
|
103
104
|
try {
|
|
104
105
|
const tools = await (0, packages_ipc_1.packagesTools)();
|
|
105
|
-
for (const each of packages)
|
|
106
|
-
await tools.installPackage(each);
|
|
106
|
+
for (const each of packages) {
|
|
107
|
+
const { packageId } = await tools.installPackage(each);
|
|
108
|
+
void (0, delegates_ipc_1.offerDelegateAfterInstall)(packageId);
|
|
109
|
+
}
|
|
107
110
|
setState({ adding: false, added: true });
|
|
108
111
|
}
|
|
109
112
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.18",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.33.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.33.18",
|
|
40
40
|
"bootstrap": "^5.3.3",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
42
|
"react-dom": "^18.0.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/preset-react": "^7.24.1",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.1",
|
|
49
49
|
"@biomejs/biome": "2.3.11",
|
|
50
|
-
"@peers-app/peers-sdk": "0.33.
|
|
50
|
+
"@peers-app/peers-sdk": "0.33.18",
|
|
51
51
|
"@testing-library/dom": "^10.4.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.3.0",
|