@peers-app/peers-ui 0.16.1 → 0.16.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/dist/peers-services-registration.d.ts +5 -0
- package/dist/peers-services-registration.js +18 -0
- package/dist/screens/account/account-screen.js +3 -10
- package/dist/screens/setup-user.js +1 -5
- package/dist/screens/welcome-modal.js +12 -0
- package/package.json +3 -3
- package/src/peers-services-registration.ts +17 -0
- package/src/screens/account/account-screen.tsx +6 -12
- package/src/screens/setup-user.tsx +1 -6
- package/src/screens/welcome-modal.tsx +14 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Set when the user has completed challenge-response registration (ISO timestamp). */
|
|
2
|
+
export declare const registrationStatusPvar: import("@peers-app/peers-sdk").PersistentVar<string>;
|
|
3
|
+
export declare const servicesTokenPvar: import("@peers-app/peers-sdk").PersistentVar<string>;
|
|
4
|
+
/** Store JWT and local "registered" flag after a successful `registerWithPeersServices` call. */
|
|
5
|
+
export declare function persistPeersServicesRegistration(token: string): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.servicesTokenPvar = exports.registrationStatusPvar = void 0;
|
|
4
|
+
exports.persistPeersServicesRegistration = persistPeersServicesRegistration;
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
/** Set when the user has completed challenge-response registration (ISO timestamp). */
|
|
7
|
+
exports.registrationStatusPvar = (0, peers_sdk_1.userVar)("PEERS_SERVICES_REGISTERED", {
|
|
8
|
+
defaultValue: "",
|
|
9
|
+
});
|
|
10
|
+
exports.servicesTokenPvar = (0, peers_sdk_1.userVar)("PEERS_SERVICES_TOKEN", {
|
|
11
|
+
isSecret: true,
|
|
12
|
+
defaultValue: "",
|
|
13
|
+
});
|
|
14
|
+
/** Store JWT and local "registered" flag after a successful `registerWithPeersServices` call. */
|
|
15
|
+
function persistPeersServicesRegistration(token) {
|
|
16
|
+
(0, exports.servicesTokenPvar)(token);
|
|
17
|
+
(0, exports.registrationStatusPvar)(new Date().toISOString());
|
|
18
|
+
}
|
|
@@ -6,13 +6,7 @@ const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const tooltip_1 = require("../../components/tooltip");
|
|
8
8
|
const hooks_1 = require("../../hooks");
|
|
9
|
-
const
|
|
10
|
-
defaultValue: "",
|
|
11
|
-
});
|
|
12
|
-
const servicesTokenPvar = (0, peers_sdk_1.userVar)("PEERS_SERVICES_TOKEN", {
|
|
13
|
-
isSecret: true,
|
|
14
|
-
defaultValue: "",
|
|
15
|
-
});
|
|
9
|
+
const peers_services_registration_1 = require("../../peers-services-registration");
|
|
16
10
|
const INFO_TEXT = `### What does registering do?
|
|
17
11
|
|
|
18
12
|
Registering your account links your **public key** with the Peers cloud service. This enables cloud-powered features like:
|
|
@@ -30,7 +24,7 @@ Your **secret key never leaves your device**. Only your public key is shared wit
|
|
|
30
24
|
|
|
31
25
|
No. Peers works fully in local/peer-to-peer mode without registration. Cloud features simply won't be available until you register.`;
|
|
32
26
|
function AccountScreen() {
|
|
33
|
-
const [registrationStatus] = (0, hooks_1.useObservable)(registrationStatusPvar);
|
|
27
|
+
const [registrationStatus] = (0, hooks_1.useObservable)(peers_services_registration_1.registrationStatusPvar);
|
|
34
28
|
const [isRegistering, setIsRegistering] = (0, react_1.useState)(false);
|
|
35
29
|
const [error, setError] = (0, react_1.useState)(null);
|
|
36
30
|
const [success, setSuccess] = (0, react_1.useState)(null);
|
|
@@ -41,8 +35,7 @@ function AccountScreen() {
|
|
|
41
35
|
setSuccess(null);
|
|
42
36
|
try {
|
|
43
37
|
const token = await peers_sdk_1.rpcServerCalls.registerWithPeersServices();
|
|
44
|
-
|
|
45
|
-
registrationStatusPvar(new Date().toISOString());
|
|
38
|
+
(0, peers_services_registration_1.persistPeersServicesRegistration)(token);
|
|
46
39
|
setSuccess("Account registered successfully.");
|
|
47
40
|
}
|
|
48
41
|
catch (err) {
|
|
@@ -31,11 +31,7 @@ const SetupUser = () => {
|
|
|
31
31
|
.catch((err) => {
|
|
32
32
|
console.error("Error auto-installing peers-core:", err);
|
|
33
33
|
});
|
|
34
|
-
//
|
|
35
|
-
await peers_sdk_1.rpcServerCalls.registerWithPeersServices().catch((err) => {
|
|
36
|
-
console.warn("Auto-registration with peers-services deferred:", err);
|
|
37
|
-
});
|
|
38
|
-
// Success - reload the app
|
|
34
|
+
// Success - reload the app (peers-services registration runs after Welcome modal)
|
|
39
35
|
window.location.reload();
|
|
40
36
|
}
|
|
41
37
|
catch (err) {
|
|
@@ -5,6 +5,16 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const hooks_1 = require("../hooks");
|
|
8
|
+
const peers_services_registration_1 = require("../peers-services-registration");
|
|
9
|
+
async function tryRegisterPeersServicesAfterWelcome() {
|
|
10
|
+
try {
|
|
11
|
+
const token = await peers_sdk_1.rpcServerCalls.registerWithPeersServices();
|
|
12
|
+
(0, peers_services_registration_1.persistPeersServicesRegistration)(token);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
console.warn("Peers services registration after welcome modal:", err);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
8
18
|
function WelcomeModal({ colorMode, onClose }) {
|
|
9
19
|
const [displayName, setDisplayName] = (0, react_1.useState)("");
|
|
10
20
|
const [deviceName, setDeviceName] = (0, react_1.useState)("");
|
|
@@ -60,6 +70,7 @@ function WelcomeModal({ colorMode, onClose }) {
|
|
|
60
70
|
device.name = deviceName.trim();
|
|
61
71
|
await devicesTable.save(device);
|
|
62
72
|
}
|
|
73
|
+
await tryRegisterPeersServicesAfterWelcome();
|
|
63
74
|
// Mark the welcome modal as shown
|
|
64
75
|
(0, peers_sdk_1.hasShownWelcomeModal)(true);
|
|
65
76
|
onClose();
|
|
@@ -71,6 +82,7 @@ function WelcomeModal({ colorMode, onClose }) {
|
|
|
71
82
|
}
|
|
72
83
|
};
|
|
73
84
|
const handleSkip = async () => {
|
|
85
|
+
await tryRegisterPeersServicesAfterWelcome();
|
|
74
86
|
// Mark as shown even if skipped
|
|
75
87
|
(0, peers_sdk_1.hasShownWelcomeModal)(true);
|
|
76
88
|
onClose();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lint:fix": "biome check --write ."
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@peers-app/peers-sdk": "^0.16.
|
|
31
|
+
"@peers-app/peers-sdk": "^0.16.2",
|
|
32
32
|
"bootstrap": "^5.3.3",
|
|
33
33
|
"react": "^18.0.0",
|
|
34
34
|
"react-dom": "^18.0.0"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.24.5",
|
|
40
40
|
"@babel/preset-react": "^7.24.1",
|
|
41
41
|
"@babel/preset-typescript": "^7.27.1",
|
|
42
|
-
"@peers-app/peers-sdk": "0.16.
|
|
42
|
+
"@peers-app/peers-sdk": "0.16.2",
|
|
43
43
|
"@testing-library/dom": "^10.4.0",
|
|
44
44
|
"@testing-library/jest-dom": "^6.6.3",
|
|
45
45
|
"@testing-library/react": "^16.3.0",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { userVar } from "@peers-app/peers-sdk";
|
|
2
|
+
|
|
3
|
+
/** Set when the user has completed challenge-response registration (ISO timestamp). */
|
|
4
|
+
export const registrationStatusPvar = userVar<string>("PEERS_SERVICES_REGISTERED", {
|
|
5
|
+
defaultValue: "",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const servicesTokenPvar = userVar<string>("PEERS_SERVICES_TOKEN", {
|
|
9
|
+
isSecret: true,
|
|
10
|
+
defaultValue: "",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/** Store JWT and local "registered" flag after a successful `registerWithPeersServices` call. */
|
|
14
|
+
export function persistPeersServicesRegistration(token: string): void {
|
|
15
|
+
servicesTokenPvar(token);
|
|
16
|
+
registrationStatusPvar(new Date().toISOString());
|
|
17
|
+
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { rpcServerCalls
|
|
1
|
+
import { rpcServerCalls } from "@peers-app/peers-sdk";
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
import { Tooltip } from "../../components/tooltip";
|
|
4
4
|
import { useObservable } from "../../hooks";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const servicesTokenPvar = userVar<string>("PEERS_SERVICES_TOKEN", {
|
|
11
|
-
isSecret: true,
|
|
12
|
-
defaultValue: "",
|
|
13
|
-
});
|
|
5
|
+
import {
|
|
6
|
+
persistPeersServicesRegistration,
|
|
7
|
+
registrationStatusPvar,
|
|
8
|
+
} from "../../peers-services-registration";
|
|
14
9
|
|
|
15
10
|
const INFO_TEXT = `### What does registering do?
|
|
16
11
|
|
|
@@ -44,8 +39,7 @@ export function AccountScreen() {
|
|
|
44
39
|
|
|
45
40
|
try {
|
|
46
41
|
const token = await rpcServerCalls.registerWithPeersServices();
|
|
47
|
-
|
|
48
|
-
registrationStatusPvar(new Date().toISOString());
|
|
42
|
+
persistPeersServicesRegistration(token);
|
|
49
43
|
setSuccess("Account registered successfully.");
|
|
50
44
|
} catch (err) {
|
|
51
45
|
setError(`Registration failed: ${String(err)}`);
|
|
@@ -46,12 +46,7 @@ export const SetupUser = () => {
|
|
|
46
46
|
console.error("Error auto-installing peers-core:", err);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
//
|
|
50
|
-
await rpcServerCalls.registerWithPeersServices().catch((err: unknown) => {
|
|
51
|
-
console.warn("Auto-registration with peers-services deferred:", err);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Success - reload the app
|
|
49
|
+
// Success - reload the app (peers-services registration runs after Welcome modal)
|
|
55
50
|
window.location.reload();
|
|
56
51
|
} catch (err) {
|
|
57
52
|
setError(`Error creating new user: ${String(err).replaceAll("\n", " ")}`);
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
getUserContext,
|
|
5
5
|
hasShownWelcomeModal,
|
|
6
6
|
type IDevice,
|
|
7
|
+
rpcServerCalls,
|
|
7
8
|
TrustLevel,
|
|
8
9
|
thisDeviceId,
|
|
9
10
|
Users,
|
|
@@ -11,12 +12,22 @@ import {
|
|
|
11
12
|
import type React from "react";
|
|
12
13
|
import { useEffect, useState } from "react";
|
|
13
14
|
import { useObservable, usePromise } from "../hooks";
|
|
15
|
+
import { persistPeersServicesRegistration } from "../peers-services-registration";
|
|
14
16
|
|
|
15
17
|
interface WelcomeModalProps {
|
|
16
18
|
colorMode: string;
|
|
17
19
|
onClose: () => void;
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
async function tryRegisterPeersServicesAfterWelcome(): Promise<void> {
|
|
23
|
+
try {
|
|
24
|
+
const token = await rpcServerCalls.registerWithPeersServices();
|
|
25
|
+
persistPeersServicesRegistration(token);
|
|
26
|
+
} catch (err: unknown) {
|
|
27
|
+
console.warn("Peers services registration after welcome modal:", err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
export function WelcomeModal({ colorMode, onClose }: WelcomeModalProps) {
|
|
21
32
|
const [displayName, setDisplayName] = useState("");
|
|
22
33
|
const [deviceName, setDeviceName] = useState("");
|
|
@@ -79,6 +90,8 @@ export function WelcomeModal({ colorMode, onClose }: WelcomeModalProps) {
|
|
|
79
90
|
await devicesTable.save(device);
|
|
80
91
|
}
|
|
81
92
|
|
|
93
|
+
await tryRegisterPeersServicesAfterWelcome();
|
|
94
|
+
|
|
82
95
|
// Mark the welcome modal as shown
|
|
83
96
|
hasShownWelcomeModal(true);
|
|
84
97
|
|
|
@@ -91,6 +104,7 @@ export function WelcomeModal({ colorMode, onClose }: WelcomeModalProps) {
|
|
|
91
104
|
};
|
|
92
105
|
|
|
93
106
|
const handleSkip = async () => {
|
|
107
|
+
await tryRegisterPeersServicesAfterWelcome();
|
|
94
108
|
// Mark as shown even if skipped
|
|
95
109
|
hasShownWelcomeModal(true);
|
|
96
110
|
onClose();
|