@colveor/admin 0.0.0-stage → 0.5.2
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/LICENSE.md +106 -0
- package/TAILWINDADMIN-LICENSE +21 -0
- package/dist/account/data.d.ts +1 -0
- package/dist/account/data.js +44 -0
- package/dist/account/profile.d.ts +6 -0
- package/dist/account/profile.js +118 -0
- package/dist/account/sessions.d.ts +1 -0
- package/dist/account/sessions.js +26 -0
- package/dist/account/shared.d.ts +26 -0
- package/dist/account/shared.js +44 -0
- package/dist/account/two-factor.d.ts +5 -0
- package/dist/account/two-factor.js +60 -0
- package/dist/actions.d.ts +39 -0
- package/dist/actions.js +81 -0
- package/dist/api/audit.gen.d.ts +80 -0
- package/dist/api/audit.gen.js +43 -0
- package/dist/api/auth.gen.d.ts +537 -0
- package/dist/api/auth.gen.js +313 -0
- package/dist/api/errors.gen.d.ts +16 -0
- package/dist/api/errors.gen.js +2 -0
- package/dist/api/gormx.gen.d.ts +60 -0
- package/dist/api/gormx.gen.js +16 -0
- package/dist/api/health.gen.d.ts +103 -0
- package/dist/api/health.gen.js +23 -0
- package/dist/api/index.gen.d.ts +21 -0
- package/dist/api/index.gen.js +22 -0
- package/dist/api/invitations.gen.d.ts +128 -0
- package/dist/api/invitations.gen.js +57 -0
- package/dist/api/ledger.gen.d.ts +269 -0
- package/dist/api/ledger.gen.js +113 -0
- package/dist/api/msgtemplate.gen.d.ts +31 -0
- package/dist/api/msgtemplate.gen.js +2 -0
- package/dist/api/notifications.gen.d.ts +66 -0
- package/dist/api/notifications.gen.js +28 -0
- package/dist/api/outbox.gen.d.ts +8 -0
- package/dist/api/outbox.gen.js +2 -0
- package/dist/api/queue.gen.d.ts +112 -0
- package/dist/api/queue.gen.js +15 -0
- package/dist/api/rbac.gen.d.ts +406 -0
- package/dist/api/rbac.gen.js +191 -0
- package/dist/api/reauth.gen.d.ts +289 -0
- package/dist/api/reauth.gen.js +122 -0
- package/dist/api/recorded_payments.gen.d.ts +171 -0
- package/dist/api/recorded_payments.gen.js +79 -0
- package/dist/api/sessions.gen.d.ts +64 -0
- package/dist/api/sessions.gen.js +48 -0
- package/dist/api/settings.gen.d.ts +147 -0
- package/dist/api/settings.gen.js +69 -0
- package/dist/api/storage.gen.d.ts +327 -0
- package/dist/api/storage.gen.js +208 -0
- package/dist/api/support_access.gen.d.ts +155 -0
- package/dist/api/support_access.gen.js +131 -0
- package/dist/api/users.gen.d.ts +407 -0
- package/dist/api/users.gen.js +159 -0
- package/dist/api/verification.gen.d.ts +427 -0
- package/dist/api/verification.gen.js +280 -0
- package/dist/api/webhooks.gen.d.ts +110 -0
- package/dist/api/webhooks.gen.js +45 -0
- package/dist/auth-layout.d.ts +9 -0
- package/dist/auth-layout.js +5 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.js +72 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +82 -0
- package/dist/dates.d.ts +4 -0
- package/dist/dates.js +16 -0
- package/dist/header.d.ts +12 -0
- package/dist/header.js +105 -0
- package/dist/icons.d.ts +2 -0
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +42 -0
- package/dist/kit/avatar.d.ts +5 -0
- package/dist/kit/avatar.js +16 -0
- package/dist/kit/badge.d.ts +10 -0
- package/dist/kit/badge.js +31 -0
- package/dist/kit/card.d.ts +12 -0
- package/dist/kit/card.js +7 -0
- package/dist/kit/code-area.d.ts +15 -0
- package/dist/kit/code-area.js +69 -0
- package/dist/kit/dropdown.d.ts +26 -0
- package/dist/kit/dropdown.js +67 -0
- package/dist/kit/filter-tabs.d.ts +9 -0
- package/dist/kit/filter-tabs.js +7 -0
- package/dist/kit/modal.d.ts +8 -0
- package/dist/kit/modal.js +15 -0
- package/dist/kit/page-header.d.ts +13 -0
- package/dist/kit/page-header.js +13 -0
- package/dist/kit/search.d.ts +4 -0
- package/dist/kit/search.js +16 -0
- package/dist/kit/tooltip.d.ts +17 -0
- package/dist/kit/tooltip.js +52 -0
- package/dist/message-editor.d.ts +9 -0
- package/dist/message-editor.js +80 -0
- package/dist/money.d.ts +10 -0
- package/dist/money.js +17 -0
- package/dist/next.d.ts +6 -0
- package/dist/next.js +19 -0
- package/dist/pages/account.d.ts +1 -0
- package/dist/pages/account.js +47 -0
- package/dist/pages/audit.d.ts +1 -0
- package/dist/pages/audit.js +88 -0
- package/dist/pages/forgot-password.d.ts +1 -0
- package/dist/pages/forgot-password.js +73 -0
- package/dist/pages/ledger.d.ts +1 -0
- package/dist/pages/ledger.js +132 -0
- package/dist/pages/roles.d.ts +1 -0
- package/dist/pages/roles.js +102 -0
- package/dist/pages/settings.d.ts +1 -0
- package/dist/pages/settings.js +86 -0
- package/dist/pages/sign-in.d.ts +5 -0
- package/dist/pages/sign-in.js +117 -0
- package/dist/pages/status.d.ts +1 -0
- package/dist/pages/status.js +122 -0
- package/dist/pages/support.d.ts +1 -0
- package/dist/pages/support.js +90 -0
- package/dist/pages/teams.d.ts +1 -0
- package/dist/pages/teams.js +94 -0
- package/dist/pages/users.d.ts +1 -0
- package/dist/pages/users.js +158 -0
- package/dist/pages/webhooks.d.ts +1 -0
- package/dist/pages/webhooks.js +88 -0
- package/dist/permissions.d.ts +5 -0
- package/dist/permissions.js +31 -0
- package/dist/proof.d.ts +10 -0
- package/dist/proof.js +78 -0
- package/dist/proxy.d.ts +10 -0
- package/dist/proxy.js +166 -0
- package/dist/retry.d.ts +8 -0
- package/dist/retry.js +30 -0
- package/dist/router.d.ts +13 -0
- package/dist/router.js +14 -0
- package/dist/setting-fields.d.ts +12 -0
- package/dist/setting-fields.js +102 -0
- package/dist/setting-list.d.ts +22 -0
- package/dist/setting-list.js +78 -0
- package/dist/shell.d.ts +40 -0
- package/dist/shell.js +97 -0
- package/dist/support.d.ts +37 -0
- package/dist/support.js +76 -0
- package/dist/table.d.ts +40 -0
- package/dist/table.js +73 -0
- package/dist/ui.d.ts +39 -0
- package/dist/ui.js +56 -0
- package/dist/user-actions.d.ts +30 -0
- package/dist/user-actions.js +129 -0
- package/dist/user-roles.d.ts +4 -0
- package/dist/user-roles.js +51 -0
- package/dist/user-row-menu.d.ts +14 -0
- package/dist/user-row-menu.js +45 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/package.json +59 -4
- package/README.md +0 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Colveor Go — Proprietary Software License
|
|
2
|
+
|
|
3
|
+
**Copyright © 2026. All rights reserved.**
|
|
4
|
+
|
|
5
|
+
- **Software:** Colveor Go
|
|
6
|
+
- **License Type:** Proprietary
|
|
7
|
+
- **Usage:** Restricted — All rights reserved
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 1. Ownership and Intellectual Property
|
|
12
|
+
|
|
13
|
+
Colveor Go, including its source code, object code, architecture, algorithms, documentation, and associated materials, is proprietary software.
|
|
14
|
+
|
|
15
|
+
All rights, title, and interest in the software remain with the respective copyright owner, except for rights expressly granted in a separate written agreement.
|
|
16
|
+
|
|
17
|
+
No ownership, copyright, or intellectual property rights are transferred to any user, licensee, client, organization, or third party by accessing or using the software.
|
|
18
|
+
|
|
19
|
+
## 2. Limited Permission to Use
|
|
20
|
+
|
|
21
|
+
The copyright owner may grant specific individuals, organizations, or projects permission to access and use Colveor Go for authorized purposes.
|
|
22
|
+
|
|
23
|
+
Unless otherwise agreed in a separate written license, such permission is:
|
|
24
|
+
|
|
25
|
+
- **Limited** to the authorized purpose.
|
|
26
|
+
- **Non-exclusive**, meaning the copyright owner may authorize others.
|
|
27
|
+
- **Non-transferable**, meaning the recipient cannot transfer the permission to another party.
|
|
28
|
+
- **Revocable**, subject to applicable law and contractual obligations.
|
|
29
|
+
|
|
30
|
+
Access to the repository does not automatically grant permission to use the software for unrelated projects or purposes outside the authorized scope.
|
|
31
|
+
|
|
32
|
+
## 3. Restrictions
|
|
33
|
+
|
|
34
|
+
Unless expressly authorized in writing by the copyright owner, no recipient may:
|
|
35
|
+
|
|
36
|
+
- Redistribute, publish, sublicense, sell, rent, lease, or commercially exploit the software or substantial portions of it.
|
|
37
|
+
- Copy or incorporate the software into another product for distribution outside the authorized scope.
|
|
38
|
+
- Modify, adapt, reverse engineer, decompile, or disassemble the software, except to the extent such restrictions are prohibited by applicable law or expressly permitted in writing.
|
|
39
|
+
- Remove or alter copyright notices, ownership notices, or license terms.
|
|
40
|
+
- Claim authorship or ownership of the original software or its proprietary components.
|
|
41
|
+
- Share repository access, credentials, source code, or copies with unauthorized persons.
|
|
42
|
+
- Use protected confidential information or materials to create or distribute an unauthorized competing implementation.
|
|
43
|
+
|
|
44
|
+
## 4. Client Projects and Third-Party Access
|
|
45
|
+
|
|
46
|
+
Permission to access or use Colveor Go for one project does not automatically authorize its use in other projects.
|
|
47
|
+
|
|
48
|
+
Any client, contractor, organization, or third party must obtain the appropriate authorization before accessing or using the software.
|
|
49
|
+
|
|
50
|
+
A separate written agreement may specify:
|
|
51
|
+
|
|
52
|
+
- Permitted projects and users.
|
|
53
|
+
- Authorized deployment environments.
|
|
54
|
+
- Modification and distribution rights.
|
|
55
|
+
- Commercial usage terms.
|
|
56
|
+
- Ownership of customizations and derivative works.
|
|
57
|
+
|
|
58
|
+
The copyright owner retains ownership of Colveor Go unless a separate written agreement expressly states otherwise.
|
|
59
|
+
|
|
60
|
+
## 5. Contributions and Modifications
|
|
61
|
+
|
|
62
|
+
No contribution, modification, enhancement, or derivative work automatically transfers ownership of the original Colveor Go software.
|
|
63
|
+
|
|
64
|
+
Ownership of contributions and derivative works will be determined by applicable law and any relevant written agreements between the parties.
|
|
65
|
+
|
|
66
|
+
Recipients may not assume that permission to modify the software grants permission to distribute their modifications.
|
|
67
|
+
|
|
68
|
+
## 6. Confidentiality
|
|
69
|
+
|
|
70
|
+
Where the software or related materials are disclosed as confidential information under an applicable agreement or law, recipients must protect that information and must not disclose or use it beyond the authorized purpose.
|
|
71
|
+
|
|
72
|
+
This section does not independently make information confidential where it is not otherwise protected by applicable law or agreement.
|
|
73
|
+
|
|
74
|
+
## 7. Termination
|
|
75
|
+
|
|
76
|
+
Permission to use the software may be terminated in accordance with the applicable license agreement and law, including where a recipient materially breaches its terms.
|
|
77
|
+
|
|
78
|
+
Upon termination, the recipient must stop using the software and, where legally required or contractually agreed, return or securely delete unauthorized copies, subject to applicable legal retention obligations.
|
|
79
|
+
|
|
80
|
+
Termination does not extinguish rights or obligations that accrued before termination or provisions that are intended to survive termination.
|
|
81
|
+
|
|
82
|
+
## 8. Disclaimer of Warranty
|
|
83
|
+
|
|
84
|
+
To the maximum extent permitted by applicable law, the software is provided **"AS IS"** and **"AS AVAILABLE,"** without warranties of any kind, whether express or implied, including warranties of merchantability, fitness for a particular purpose, and non-infringement.
|
|
85
|
+
|
|
86
|
+
## 9. Limitation of Liability
|
|
87
|
+
|
|
88
|
+
To the maximum extent permitted by applicable law, the copyright owner shall not be liable for indirect, incidental, special, consequential, or punitive damages arising from the use of or inability to use the software.
|
|
89
|
+
|
|
90
|
+
Nothing in this license excludes or limits liability that cannot lawfully be excluded or limited.
|
|
91
|
+
|
|
92
|
+
## 10. Reservation of Rights
|
|
93
|
+
|
|
94
|
+
All rights not expressly granted in writing are reserved by the copyright owner.
|
|
95
|
+
|
|
96
|
+
Nothing in this license grants a patent license, trademark license, or other intellectual property license except as expressly stated.
|
|
97
|
+
|
|
98
|
+
## 11. Governing Law
|
|
99
|
+
|
|
100
|
+
The governing law and dispute-resolution arrangements shall be those specified in a separately executed written agreement. In the absence of such an agreement, applicable law will determine the governing law and competent forum.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## All Rights Reserved
|
|
105
|
+
|
|
106
|
+
Unauthorized use, copying, modification, or distribution may violate applicable intellectual property laws and contractual obligations.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tailwindadmin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function DataTab(): import("react").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Your data (docs/account-lifecycle.md): download it, or delete the account
|
|
4
|
+
// after the grace period (cancel until then). Both ask to confirm it's you.
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { useAction } from "../actions";
|
|
7
|
+
import { ApiError, api, call } from "../client";
|
|
8
|
+
import { formatDate } from "../dates";
|
|
9
|
+
import { Messages, Section, secondary, useStep } from "./shared";
|
|
10
|
+
export function DataTab() {
|
|
11
|
+
const [deletion, setDeletion] = useState(null);
|
|
12
|
+
const { run, dialogs } = useAction();
|
|
13
|
+
const { step, error, notice, busy } = useStep();
|
|
14
|
+
const load = () => api
|
|
15
|
+
.get("/v1/me/deletion")
|
|
16
|
+
.then(setDeletion)
|
|
17
|
+
.catch((err) => {
|
|
18
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
19
|
+
setDeletion(null);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
load();
|
|
24
|
+
}, []);
|
|
25
|
+
const download = () => step(async () => {
|
|
26
|
+
const data = await run((o) => call("/v1/me/export", { ...o, method: "GET" }));
|
|
27
|
+
const url = URL.createObjectURL(new Blob([JSON.stringify(data, null, 2)], { type: "application/json" }));
|
|
28
|
+
const a = document.createElement("a");
|
|
29
|
+
a.href = url;
|
|
30
|
+
a.download = "my-account.json";
|
|
31
|
+
a.click();
|
|
32
|
+
URL.revokeObjectURL(url);
|
|
33
|
+
}, "Your data is downloaded.");
|
|
34
|
+
const request = () => window.confirm("Delete your account? You can cancel until the date shown next.") &&
|
|
35
|
+
step(async () => {
|
|
36
|
+
await run((o) => api.post("/v1/me/deletion", undefined, o));
|
|
37
|
+
await load();
|
|
38
|
+
});
|
|
39
|
+
const cancel = () => step(async () => {
|
|
40
|
+
await api.delete("/v1/me/deletion");
|
|
41
|
+
setDeletion(null);
|
|
42
|
+
}, "Your account won't be deleted.");
|
|
43
|
+
return (_jsxs("div", { className: "space-y-6", children: [_jsx(Messages, { error: error, notice: notice }), _jsx(Section, { title: "Download your data", about: "Everything kept about your account, as a JSON file.", children: _jsx("button", { type: "button", disabled: busy, className: secondary, onClick: download, children: "Download" }) }), _jsx(Section, { title: "Delete your account", about: "Your other devices are signed out at once.", children: deletion === null ? (_jsx("button", { type: "button", disabled: busy, onClick: request, className: "rounded-lg border border-red-300 px-4 py-2.5 text-sm text-red-600 transition hover:bg-red-50 disabled:opacity-40", children: "Delete my account" })) : (_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsxs("p", { className: "text-sm text-gray-700 dark:text-gray-300", children: ["Your account will be deleted on ", formatDate(deletion.due_at), ".", deletion.blocked && ` It waits: ${Object.values(deletion.blocked).join(" ")}`] }), _jsx("button", { type: "button", disabled: busy, className: secondary, onClick: cancel, children: "Keep my account" })] })) }), dialogs] }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// The account's profile (PATCH /v1/profile) and password
|
|
4
|
+
// (POST /v1/auth/change-password).
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { api } from "../client";
|
|
7
|
+
import { Dialog } from "../ui";
|
|
8
|
+
import { input, Labelled, Messages, primary, Section, secondary, useStep } from "./shared";
|
|
9
|
+
export function ProfileTab({ me, onSaved }) {
|
|
10
|
+
const p = me.details;
|
|
11
|
+
const [editing, setEditing] = useState(null);
|
|
12
|
+
const { step, error, notice, busy } = useStep();
|
|
13
|
+
const name = p?.display_name || [p?.first_name, p?.last_name].filter(Boolean).join(" ") || me.email || "";
|
|
14
|
+
const initials = name
|
|
15
|
+
.split(/\s+/)
|
|
16
|
+
.map((w) => w[0])
|
|
17
|
+
.join("")
|
|
18
|
+
.slice(0, 2)
|
|
19
|
+
.toUpperCase() || "?";
|
|
20
|
+
const place = [p?.address?.city, p?.address?.country].filter(Boolean).join(", ");
|
|
21
|
+
const save = (event) => {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
const f = new FormData(event.currentTarget);
|
|
24
|
+
const text = (k) => String(f.get(k) ?? "").trim() || undefined;
|
|
25
|
+
const body = editing === "personal"
|
|
26
|
+
? {
|
|
27
|
+
first_name: text("first_name"),
|
|
28
|
+
last_name: text("last_name"),
|
|
29
|
+
display_name: text("display_name"),
|
|
30
|
+
occupation: text("occupation"),
|
|
31
|
+
website_url: text("website_url"),
|
|
32
|
+
timezone: text("timezone"),
|
|
33
|
+
}
|
|
34
|
+
: {
|
|
35
|
+
address: {
|
|
36
|
+
address_line_1: text("address_line_1"),
|
|
37
|
+
address_line_2: text("address_line_2"),
|
|
38
|
+
city: text("city"),
|
|
39
|
+
state: text("state"),
|
|
40
|
+
postal_code: text("postal_code"),
|
|
41
|
+
country: text("country"),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
step(async () => {
|
|
45
|
+
await api.patch("/v1/profile", body);
|
|
46
|
+
setEditing(null);
|
|
47
|
+
onSaved();
|
|
48
|
+
}, "Your profile is saved.");
|
|
49
|
+
};
|
|
50
|
+
return (_jsxs("div", { className: "space-y-6", children: [_jsx(Messages, { error: error, notice: notice }), _jsxs("section", { className: "flex animate-fade-in flex-col items-center gap-6 rounded-2xl border border-gray-200 bg-white p-6 sm:flex-row dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsx("span", { className: "flex size-20 shrink-0 items-center justify-center rounded-full bg-brand-500 text-2xl font-medium text-white shadow-md ring-4 ring-brand-50 dark:ring-brand-500/20", children: initials }), _jsxs("div", { className: "text-center sm:text-left", children: [_jsx("h2", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: name }), _jsxs("p", { className: "mt-1 flex flex-wrap items-center justify-center gap-x-3 gap-y-1 text-sm text-gray-500 sm:justify-start dark:text-gray-400", children: [p?.occupation && _jsx("span", { children: p.occupation }), p?.occupation && place && _jsx("span", { className: "h-4 w-px bg-gray-300 dark:bg-gray-700" }), place && _jsx("span", { children: place }), p?.timezone && _jsxs("span", { children: ["\u00B7 ", p.timezone] })] })] })] }), _jsxs("div", { className: "grid gap-6 xl:grid-cols-2", children: [_jsx(InfoCard, { title: "Personal information", onEdit: () => setEditing("personal"), rows: [
|
|
51
|
+
["First name", p?.first_name],
|
|
52
|
+
["Last name", p?.last_name],
|
|
53
|
+
["Display name", p?.display_name],
|
|
54
|
+
["Role or job", p?.occupation],
|
|
55
|
+
["Email", me.email],
|
|
56
|
+
["Phone", me.phone],
|
|
57
|
+
["Website", p?.website_url],
|
|
58
|
+
["Time zone", p?.timezone],
|
|
59
|
+
] }), _jsx(InfoCard, { title: "Address", onEdit: () => setEditing("address"), rows: [
|
|
60
|
+
["Address", p?.address?.address_line_1],
|
|
61
|
+
["", p?.address?.address_line_2],
|
|
62
|
+
["City", p?.address?.city],
|
|
63
|
+
["State or region", p?.address?.state],
|
|
64
|
+
["Postal code", p?.address?.postal_code],
|
|
65
|
+
["Country", p?.address?.country],
|
|
66
|
+
] })] }), editing !== null && (_jsx(Dialog, { title: editing === "personal" ? "Edit personal information" : "Edit address", children: _jsxs("form", { onSubmit: save, className: "grid gap-4 sm:grid-cols-2", children: [(editing === "personal"
|
|
67
|
+
? [
|
|
68
|
+
["first_name", "First name", p?.first_name],
|
|
69
|
+
["last_name", "Last name", p?.last_name],
|
|
70
|
+
["display_name", "Display name", p?.display_name],
|
|
71
|
+
["occupation", "Role or job", p?.occupation],
|
|
72
|
+
["website_url", "Website", p?.website_url],
|
|
73
|
+
[
|
|
74
|
+
"timezone",
|
|
75
|
+
"Time zone",
|
|
76
|
+
p?.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
77
|
+
],
|
|
78
|
+
]
|
|
79
|
+
: [
|
|
80
|
+
["address_line_1", "Address", p?.address?.address_line_1],
|
|
81
|
+
["address_line_2", "Address, line 2", p?.address?.address_line_2],
|
|
82
|
+
["city", "City", p?.address?.city],
|
|
83
|
+
["state", "State or region", p?.address?.state],
|
|
84
|
+
["postal_code", "Postal code", p?.address?.postal_code],
|
|
85
|
+
["country", "Country", p?.address?.country],
|
|
86
|
+
]).map(([field, label, value]) => (_jsx(Labelled, { label: label ?? "", htmlFor: `edit-${field}`, children: _jsx("input", { id: `edit-${field}`, name: field, defaultValue: value, type: field === "website_url" ? "url" : "text", className: input }) }, field))), _jsxs("div", { className: "flex justify-end gap-3 sm:col-span-2", children: [_jsx("button", { type: "button", className: secondary, onClick: () => setEditing(null), children: "Cancel" }), _jsx("button", { type: "submit", disabled: busy, className: primary, children: "Save" })] })] }) }))] }));
|
|
87
|
+
}
|
|
88
|
+
function InfoCard(props) {
|
|
89
|
+
return (_jsxs("section", { className: "animate-fade-in rounded-2xl border border-gray-200 bg-white p-6 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsxs("div", { className: "mb-5 flex items-center justify-between", children: [_jsx("h3", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: props.title }), _jsxs("button", { type: "button", onClick: props.onEdit, className: "flex items-center gap-2 rounded-full border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-all duration-200 hover:border-brand-500 hover:bg-brand-500 hover:text-white dark:border-gray-700 dark:text-gray-300", children: [_jsx("svg", { width: 16, height: 16, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M4 20h4L18.5 9.5a2.1 2.1 0 00-3-3L5 17v3z", stroke: "currentColor", strokeWidth: 1.6, strokeLinejoin: "round" }) }), "Edit"] })] }), _jsx("dl", { className: "grid gap-x-8 gap-y-5 sm:grid-cols-2", children: props.rows
|
|
90
|
+
.filter(([label, value]) => label !== "" || (value ?? "") !== "")
|
|
91
|
+
.map(([label, value]) => (_jsxs("div", { children: [_jsx("dt", { className: "text-xs text-gray-500 dark:text-gray-400", children: label }), _jsx("dd", { className: "mt-1 text-sm font-medium break-words text-gray-800 dark:text-white/90", children: value || "—" })] }, label || value))) })] }));
|
|
92
|
+
}
|
|
93
|
+
export function PasswordTab() {
|
|
94
|
+
const { step, error, notice, busy } = useStep();
|
|
95
|
+
const change = (event) => {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
const form = event.currentTarget;
|
|
98
|
+
const f = new FormData(form);
|
|
99
|
+
if (f.get("new_password") !== f.get("again")) {
|
|
100
|
+
step(async () => {
|
|
101
|
+
throw new Error("The two new passwords aren't the same.");
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
step(async () => {
|
|
106
|
+
await api.post("/v1/auth/change-password", {
|
|
107
|
+
current_password: f.get("current_password"),
|
|
108
|
+
new_password: f.get("new_password"),
|
|
109
|
+
});
|
|
110
|
+
form.reset();
|
|
111
|
+
}, "Your password is changed.");
|
|
112
|
+
};
|
|
113
|
+
return (_jsxs(Section, { title: "Change password", about: "Use one you don't use anywhere else.", children: [_jsx(Messages, { error: error, notice: notice }), _jsxs("form", { onSubmit: change, className: "max-w-md space-y-5", children: [[
|
|
114
|
+
["current_password", "Current password", "current-password"],
|
|
115
|
+
["new_password", "New password", "new-password"],
|
|
116
|
+
["again", "New password again", "new-password"],
|
|
117
|
+
].map(([name, label, auto]) => (_jsx(Labelled, { label: label, htmlFor: `pw-${name}`, children: _jsx("input", { id: `pw-${name}`, name: name, type: "password", required: true, autoComplete: auto, className: input }) }, name))), _jsx("button", { type: "submit", disabled: busy, className: primary, children: "Change password" })] })] }));
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function SessionsTab(): import("react").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// The devices signed in to the account (GET /v1/sessions): sign one out,
|
|
4
|
+
// or every other one (each asks to confirm it's you).
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { useAction } from "../actions";
|
|
7
|
+
import { api } from "../client";
|
|
8
|
+
import { formatDateTime } from "../dates";
|
|
9
|
+
import { Messages, Section, secondary, useStep } from "./shared";
|
|
10
|
+
export function SessionsTab() {
|
|
11
|
+
const [list, setList] = useState(null);
|
|
12
|
+
const { run, dialogs } = useAction();
|
|
13
|
+
const { step, error, notice, busy } = useStep();
|
|
14
|
+
const load = () => api
|
|
15
|
+
.get("/v1/sessions")
|
|
16
|
+
.then((r) => setList(r.sessions))
|
|
17
|
+
.catch(() => setList([]));
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
load();
|
|
20
|
+
}, []);
|
|
21
|
+
const end = (path, done) => step(async () => {
|
|
22
|
+
await run((o) => api.delete(path, o));
|
|
23
|
+
await load();
|
|
24
|
+
}, done);
|
|
25
|
+
return (_jsxs(Section, { title: "Where you're signed in", about: "Sign out a device you don't recognise.", children: [_jsx(Messages, { error: error, notice: notice }), _jsx("ul", { className: "divide-y divide-gray-100 dark:divide-gray-800", children: list?.map((s) => (_jsxs("li", { className: "flex flex-wrap items-center justify-between gap-3 py-3", children: [_jsxs("div", { children: [_jsxs("p", { className: "text-sm font-medium text-gray-800 dark:text-white/90", children: [s.device_name || s.device_type || "A browser", s.current && (_jsx("span", { className: "ml-2 rounded-full bg-brand-50 px-2 py-0.5 text-xs text-brand-500", children: "this one" }))] }), _jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: [s.last_ip, " \u00B7 last seen ", formatDateTime(s.last_seen_at)] })] }), !s.current && (_jsx("button", { type: "button", disabled: busy, className: secondary, onClick: () => end(`/v1/sessions/${s.id}`, "That device is signed out."), children: "Sign out" }))] }, s.id))) }), (list?.length ?? 0) > 1 && (_jsx("button", { type: "button", disabled: busy, className: `${secondary} mt-4`, onClick: () => end("/v1/sessions", "Every other device is signed out."), children: "Sign out every other device" })), dialogs] }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export declare const input = "h-11 w-full rounded-lg border border-gray-300 bg-transparent px-4 text-sm text-gray-800 transition focus:border-brand-300 focus:outline-none focus:ring-3 focus:ring-brand-500/10 disabled:opacity-60 dark:border-gray-700 dark:text-white/90";
|
|
3
|
+
export declare const primary = "rounded-lg bg-brand-500 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-brand-600 disabled:opacity-40";
|
|
4
|
+
export declare const secondary = "rounded-lg border border-gray-300 px-4 py-2.5 text-sm text-gray-700 transition hover:bg-gray-50 disabled:opacity-40 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-white/5";
|
|
5
|
+
/** A section of a tab: title, what it's for, then its content. */
|
|
6
|
+
export declare function Section(props: {
|
|
7
|
+
title: string;
|
|
8
|
+
about?: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
/** Runs a step, keeping what went wrong (not a closed dialog) and "busy". */
|
|
12
|
+
export declare function useStep(): {
|
|
13
|
+
step: (fn: () => Promise<unknown>, done?: string) => Promise<void>;
|
|
14
|
+
error: string;
|
|
15
|
+
notice: string;
|
|
16
|
+
busy: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function Messages({ error, notice }: {
|
|
19
|
+
error: string;
|
|
20
|
+
notice: string;
|
|
21
|
+
}): import("react").JSX.Element;
|
|
22
|
+
export declare function Labelled(props: {
|
|
23
|
+
label: string;
|
|
24
|
+
htmlFor: string;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
// What the account tabs share.
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { Cancelled } from "../actions";
|
|
6
|
+
export const input = "h-11 w-full rounded-lg border border-gray-300 bg-transparent px-4 text-sm text-gray-800 transition focus:border-brand-300 focus:outline-none focus:ring-3 focus:ring-brand-500/10 disabled:opacity-60 dark:border-gray-700 dark:text-white/90";
|
|
7
|
+
export const primary = "rounded-lg bg-brand-500 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-brand-600 disabled:opacity-40";
|
|
8
|
+
export const secondary = "rounded-lg border border-gray-300 px-4 py-2.5 text-sm text-gray-700 transition hover:bg-gray-50 disabled:opacity-40 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-white/5";
|
|
9
|
+
/** A section of a tab: title, what it's for, then its content. */
|
|
10
|
+
export function Section(props) {
|
|
11
|
+
return (_jsxs("section", { className: "animate-fade-in rounded-2xl border border-gray-200 bg-white p-6 dark:border-gray-800 dark:bg-white/[0.03]", children: [_jsx("h2", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: props.title }), props.about && (_jsx("p", { className: "mt-1 text-sm text-gray-500 dark:text-gray-400", children: props.about })), _jsx("div", { className: "mt-5", children: props.children })] }));
|
|
12
|
+
}
|
|
13
|
+
/** Runs a step, keeping what went wrong (not a closed dialog) and "busy". */
|
|
14
|
+
export function useStep() {
|
|
15
|
+
const [error, setError] = useState("");
|
|
16
|
+
const [notice, setNotice] = useState("");
|
|
17
|
+
const [busy, setBusy] = useState(false);
|
|
18
|
+
const step = async (fn, done) => {
|
|
19
|
+
setError("");
|
|
20
|
+
setNotice("");
|
|
21
|
+
setBusy(true);
|
|
22
|
+
try {
|
|
23
|
+
await fn();
|
|
24
|
+
if (done) {
|
|
25
|
+
setNotice(done);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
if (!(err instanceof Cancelled)) {
|
|
30
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
setBusy(false);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return { step, error, notice, busy };
|
|
38
|
+
}
|
|
39
|
+
export function Messages({ error, notice }) {
|
|
40
|
+
return (_jsxs(_Fragment, { children: [error !== "" && (_jsx("p", { role: "alert", className: "mb-4 rounded-lg bg-red-50 px-4 py-3 text-sm text-red-600", children: error })), notice !== "" && (_jsx("p", { className: "mb-4 animate-slide-down rounded-lg bg-green-50 px-4 py-3 text-sm text-green-700 dark:bg-green-500/15 dark:text-green-500", children: notice }))] }));
|
|
41
|
+
}
|
|
42
|
+
export function Labelled(props) {
|
|
43
|
+
return (_jsxs("div", { children: [_jsx("label", { htmlFor: props.htmlFor, className: "mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-400", children: props.label }), props.children] }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Two-step verification (docs/two-factor.md): an authenticator app, set up
|
|
4
|
+
// with a QR code; two-factor sign-in on or off; recovery codes. Each change
|
|
5
|
+
// asks the user to confirm it's them (useAction, reauth.required).
|
|
6
|
+
import qrcode from "qrcode-generator";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { useAction } from "../actions";
|
|
9
|
+
import { api, signOut } from "../client";
|
|
10
|
+
import { CodeInput } from "../ui";
|
|
11
|
+
import { Messages, primary, Section, secondary, useStep } from "./shared";
|
|
12
|
+
export function TwoFactorTab({ me, onSaved }) {
|
|
13
|
+
const [methods, setMethods] = useState([]);
|
|
14
|
+
const [setup, setSetup] = useState(null);
|
|
15
|
+
const [code, setCode] = useState("");
|
|
16
|
+
const [codes, setCodes] = useState([]);
|
|
17
|
+
const [signedOut, setSignedOut] = useState(false);
|
|
18
|
+
const { run, dialogs } = useAction();
|
|
19
|
+
const { step, error, notice, busy } = useStep();
|
|
20
|
+
const hasApp = methods.includes("totp");
|
|
21
|
+
const load = () => api
|
|
22
|
+
.get("/v1/reauth/methods")
|
|
23
|
+
.then((r) => setMethods(r.methods))
|
|
24
|
+
.catch(() => setMethods([]));
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
load();
|
|
27
|
+
}, []);
|
|
28
|
+
const start = () => step(async () => {
|
|
29
|
+
setSetup(await api.post("/v1/reauth/totp"));
|
|
30
|
+
setCode("");
|
|
31
|
+
});
|
|
32
|
+
const confirm = (value) => step(async () => {
|
|
33
|
+
await run((o) => api.post("/v1/reauth/totp/confirm", { code: value }, o));
|
|
34
|
+
setSetup(null);
|
|
35
|
+
await load();
|
|
36
|
+
}, "Your authenticator app is added.");
|
|
37
|
+
const removeApp = () => step(async () => {
|
|
38
|
+
await run((o) => api.delete("/v1/reauth/totp", o));
|
|
39
|
+
await load();
|
|
40
|
+
}, "The authenticator app is removed.");
|
|
41
|
+
const setTwoFactor = (enabled) => step(async () => {
|
|
42
|
+
const res = await run((o) => api.put("/v1/reauth/2fa", { enabled }, o));
|
|
43
|
+
setCodes(res.recovery_codes ?? []);
|
|
44
|
+
setSignedOut(res.signed_out);
|
|
45
|
+
onSaved();
|
|
46
|
+
}, enabled ? "Two-step sign-in is on." : "Two-step sign-in is off.");
|
|
47
|
+
const newCodes = () => step(async () => {
|
|
48
|
+
const res = await run((o) => api.post("/v1/reauth/recovery-codes", undefined, o));
|
|
49
|
+
setCodes(res.recovery_codes);
|
|
50
|
+
});
|
|
51
|
+
return (_jsxs("div", { className: "space-y-6", children: [_jsx(Messages, { error: error, notice: notice }), _jsx(Section, { title: "Authenticator app", about: "Google Authenticator, Microsoft Authenticator, 1Password: a new code every 30 seconds.", children: setup !== null ? (_jsxs("div", { className: "grid animate-slide-in gap-6 md:grid-cols-[auto_1fr] md:items-start", children: [_jsx("img", { src: qrDataURL(setup.otpauth_url), alt: "Scan with your authenticator app", className: "size-44 rounded-lg border border-gray-200 bg-white p-2" }), _jsxs("div", { className: "space-y-4", children: [_jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: ["Scan the code with the app, or type this key:", " ", _jsx("span", { className: "font-mono text-gray-800 dark:text-white/90", children: setup.secret }), ". Then enter the code the app shows."] }), _jsx(CodeInput, { value: code, onChange: setCode, onComplete: confirm, disabled: busy }), _jsxs("div", { className: "flex gap-3", children: [_jsx("button", { type: "button", disabled: busy, className: primary, onClick: () => confirm(code), children: "Add the app" }), _jsx("button", { type: "button", className: secondary, onClick: () => setSetup(null), children: "Cancel" })] })] })] })) : hasApp ? (_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsx("span", { className: "text-sm text-green-700 dark:text-green-500", children: "Added" }), _jsx("button", { type: "button", disabled: busy, className: secondary, onClick: removeApp, children: "Remove" })] })) : (_jsx("button", { type: "button", disabled: busy, className: primary, onClick: start, children: "Set up an authenticator app" })) }), _jsxs(Section, { title: "Two-step sign-in", about: "Signing in also asks for a second proof: a code from the app, your email or phone, or a PIN. It needs two such ways set up.", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsx("span", { className: `rounded-full px-2.5 py-0.5 text-xs font-medium ${me.mfa_enabled
|
|
52
|
+
? "bg-green-50 text-green-700 dark:bg-green-500/15 dark:text-green-500"
|
|
53
|
+
: "bg-gray-100 text-gray-600 dark:bg-white/5 dark:text-gray-400"}`, children: me.mfa_enabled ? "On" : "Off" }), _jsxs("div", { className: "flex gap-3", children: [me.mfa_enabled && (_jsx("button", { type: "button", disabled: busy, className: secondary, onClick: newCodes, children: "New recovery codes" })), _jsx("button", { type: "button", disabled: busy, className: me.mfa_enabled ? secondary : primary, onClick: () => setTwoFactor(!me.mfa_enabled), children: me.mfa_enabled ? "Turn off" : "Turn on" })] })] }), codes.length > 0 && (_jsxs("div", { className: "mt-5 animate-slide-down rounded-xl bg-gray-50 p-4 dark:bg-white/5", children: [_jsx("p", { className: "text-sm text-gray-700 dark:text-gray-300", children: "Your recovery codes: keep them somewhere safe. Each works once, if you lose your second factor. They are shown only now." }), _jsx("ul", { className: "mt-3 grid grid-cols-2 gap-2 font-mono text-sm text-gray-800 sm:grid-cols-4 dark:text-white/90", children: codes.map((c) => (_jsx("li", { children: c }, c))) })] })), signedOut && (_jsxs("div", { className: "mt-4 flex flex-wrap items-center justify-between gap-3 text-sm text-gray-600 dark:text-gray-400", children: ["Turning it on signed you out everywhere: save your codes, then sign in again.", _jsx("button", { type: "button", className: primary, onClick: () => signOut(), children: "Sign in again" })] }))] }), dialogs] }));
|
|
54
|
+
}
|
|
55
|
+
function qrDataURL(text) {
|
|
56
|
+
const qr = qrcode(0, "M");
|
|
57
|
+
qr.addData(text);
|
|
58
|
+
qr.make();
|
|
59
|
+
return qr.createDataURL(5, 2);
|
|
60
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type SendOptions } from "./client";
|
|
3
|
+
/** Thrown by run when the user closes a dialog instead of answering it. */
|
|
4
|
+
export declare class Cancelled extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
/** Asks why a change is made: the reason goes to the audit log. */
|
|
8
|
+
export declare function ReasonDialog(props: {
|
|
9
|
+
onReason(reason: string): void;
|
|
10
|
+
onCancel(): void;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export interface StepUpProps {
|
|
13
|
+
/** The action the API names in reauth.required (data.action). */
|
|
14
|
+
action: string;
|
|
15
|
+
/** The methods it allows (data.methods); all the user's when empty. */
|
|
16
|
+
methods?: string[];
|
|
17
|
+
onToken(token: string): void;
|
|
18
|
+
onCancel(): void;
|
|
19
|
+
}
|
|
20
|
+
/** "Confirm it's you": re-authenticates for one action, for a token. */
|
|
21
|
+
export declare function StepUp({ action, methods, onToken, onCancel }: StepUpProps): import("react").JSX.Element;
|
|
22
|
+
/**
|
|
23
|
+
* run(send) calls send with the options a change needs, asking for a
|
|
24
|
+
* reason or a re-authentication when the API refuses without one, then
|
|
25
|
+
* sending again. Render dialogs in the page.
|
|
26
|
+
*
|
|
27
|
+
* const { run, dialogs } = useAction()
|
|
28
|
+
* await run((o) => api.patch(`/v1/settings/${key}`, { value }, o))
|
|
29
|
+
*/
|
|
30
|
+
export declare function useAction(): {
|
|
31
|
+
run<T>(send: (options: SendOptions) => Promise<T>): Promise<T>;
|
|
32
|
+
dialogs: ReactNode;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A key for one change, for a form that sends it itself: the same key
|
|
36
|
+
* while the same request is resent (a network error), a new one once it is
|
|
37
|
+
* done or changed (renew).
|
|
38
|
+
*/
|
|
39
|
+
export declare function useIdempotencyKey(): [key: string, renew: () => void];
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Changes that need more than a click: a reason for the audit log
|
|
4
|
+
// (X-Reason), a re-authentication (X-Reauth-Token), a key that makes a
|
|
5
|
+
// resent request run once (Idempotency-Key). useAction asks for the first
|
|
6
|
+
// two when the API says so, and retries.
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { api } from "./client";
|
|
9
|
+
import { ProofForm } from "./proof";
|
|
10
|
+
import { sendAsking } from "./retry";
|
|
11
|
+
import { Button, Dialog, Field } from "./ui";
|
|
12
|
+
/** Thrown by run when the user closes a dialog instead of answering it. */
|
|
13
|
+
export class Cancelled extends Error {
|
|
14
|
+
constructor() {
|
|
15
|
+
super("cancelled");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Asks why a change is made: the reason goes to the audit log. */
|
|
19
|
+
export function ReasonDialog(props) {
|
|
20
|
+
const onSubmit = (event) => {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
const reason = String(new FormData(event.currentTarget).get("reason")).trim();
|
|
23
|
+
if (reason !== "") {
|
|
24
|
+
props.onReason(reason);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return (_jsx(Dialog, { title: "Why are you making this change?", children: _jsxs("form", { className: "space-y-4", onSubmit: onSubmit, children: [_jsx(Field, { label: "Reason (kept in the audit log)", name: "reason", multiline: true }), _jsx(Button, { type: "submit", children: "Continue" }), _jsx(Button, { quiet: true, onClick: props.onCancel, children: "Cancel" })] }) }));
|
|
28
|
+
}
|
|
29
|
+
/** "Confirm it's you": re-authenticates for one action, for a token. */
|
|
30
|
+
export function StepUp({ action, methods, onToken, onCancel }) {
|
|
31
|
+
const [own, setOwn] = useState(null);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
api
|
|
34
|
+
.get("/v1/reauth/methods")
|
|
35
|
+
.then((res) => setOwn(res.methods))
|
|
36
|
+
.catch(() => setOwn([]));
|
|
37
|
+
}, []);
|
|
38
|
+
// The user's methods, narrowed to those the action allows.
|
|
39
|
+
const usable = own?.filter((m) => methods === undefined || methods.length === 0 || methods.includes(m));
|
|
40
|
+
return (_jsxs(Dialog, { title: "Confirm it's you", children: [usable !== undefined && (_jsx(ProofForm, { methods: usable, sendCode: async (channel) => {
|
|
41
|
+
const sent = await api.post("/v1/reauth/codes", { channel }, { idempotencyKey: crypto.randomUUID() });
|
|
42
|
+
return sent.data.verification_id;
|
|
43
|
+
}, submit: async (proof) => {
|
|
44
|
+
const res = await api.post("/v1/reauth/tokens", {
|
|
45
|
+
...proof,
|
|
46
|
+
action,
|
|
47
|
+
});
|
|
48
|
+
onToken(res.reauth_token);
|
|
49
|
+
} })), _jsx("div", { className: "mt-2", children: _jsx(Button, { quiet: true, onClick: onCancel, children: "Cancel" }) })] }));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* run(send) calls send with the options a change needs, asking for a
|
|
53
|
+
* reason or a re-authentication when the API refuses without one, then
|
|
54
|
+
* sending again. Render dialogs in the page.
|
|
55
|
+
*
|
|
56
|
+
* const { run, dialogs } = useAction()
|
|
57
|
+
* await run((o) => api.patch(`/v1/settings/${key}`, { value }, o))
|
|
58
|
+
*/
|
|
59
|
+
export function useAction() {
|
|
60
|
+
const [ask, setAsk] = useState(null);
|
|
61
|
+
const reason = () => new Promise((resolve, reject) => setAsk({ kind: "reason", resolve, reject: () => reject(new Cancelled()) })).finally(() => setAsk(null));
|
|
62
|
+
const stepUp = (action, methods) => new Promise((resolve, reject) => setAsk({ kind: "stepUp", action, methods, resolve, reject: () => reject(new Cancelled()) })).finally(() => setAsk(null));
|
|
63
|
+
const run = (send) => sendAsking(send, { reason, stepUp });
|
|
64
|
+
let dialogs = null;
|
|
65
|
+
if (ask?.kind === "reason") {
|
|
66
|
+
dialogs = _jsx(ReasonDialog, { onReason: ask.resolve, onCancel: ask.reject });
|
|
67
|
+
}
|
|
68
|
+
else if (ask?.kind === "stepUp") {
|
|
69
|
+
dialogs = (_jsx(StepUp, { action: ask.action, methods: ask.methods, onToken: ask.resolve, onCancel: ask.reject }));
|
|
70
|
+
}
|
|
71
|
+
return { run, dialogs };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A key for one change, for a form that sends it itself: the same key
|
|
75
|
+
* while the same request is resent (a network error), a new one once it is
|
|
76
|
+
* done or changed (renew).
|
|
77
|
+
*/
|
|
78
|
+
export function useIdempotencyKey() {
|
|
79
|
+
const [key, setKey] = useState(() => crypto.randomUUID());
|
|
80
|
+
return [key, () => setKey(crypto.randomUUID())];
|
|
81
|
+
}
|