@peers-app/peers-ui 0.16.1 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,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 registrationStatusPvar = (0, peers_sdk_1.userVar)("PEERS_SERVICES_REGISTERED", {
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
- servicesTokenPvar(token);
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) {
@@ -52,9 +45,9 @@ function AccountScreen() {
52
45
  setIsRegistering(false);
53
46
  }
54
47
  };
55
- return ((0, jsx_runtime_1.jsxs)("div", { className: "container-fluid p-3", style: { maxWidth: 600 }, children: [(0, jsx_runtime_1.jsxs)("h4", { className: "mb-3 d-flex align-items-center gap-2", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-person-circle" }), "Account"] }), error && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger alert-dismissible", role: "alert", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-exclamation-triangle me-2" }), error, (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", onClick: () => setError(null), "aria-label": "Close" })] })), success && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-success alert-dismissible", role: "alert", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-circle me-2" }), success, (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", onClick: () => setSuccess(null), "aria-label": "Close" })] })), (0, jsx_runtime_1.jsx)("div", { className: "card", children: (0, jsx_runtime_1.jsxs)("div", { className: "card-body", children: [(0, jsx_runtime_1.jsxs)("h5", { className: "card-title d-flex align-items-center gap-2", children: ["Peers Services Registration", (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { markdownContent: INFO_TEXT })] }), isRegistered ? ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-2", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-circle-fill text-success", style: { fontSize: "1.2em" } }), (0, jsx_runtime_1.jsx)("span", { children: "Registered" })] }), (0, jsx_runtime_1.jsxs)("small", { className: "text-muted", children: ["Registered on", " ", new Date(registrationStatus).toLocaleDateString(undefined, {
48
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "container-fluid p-3", style: { maxWidth: 600 }, children: [(0, jsx_runtime_1.jsxs)("h4", { className: "mb-3 d-flex align-items-center gap-2", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-person-circle" }), "Account"] }), error && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger alert-dismissible", role: "alert", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-exclamation-triangle me-2" }), error, (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", onClick: () => setError(null), "aria-label": "Close" })] })), success && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-success alert-dismissible", role: "alert", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-circle me-2" }), success, (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", onClick: () => setSuccess(null), "aria-label": "Close" })] })), (0, jsx_runtime_1.jsx)("div", { className: "card", children: (0, jsx_runtime_1.jsxs)("div", { className: "card-body", children: [(0, jsx_runtime_1.jsxs)("h5", { className: "card-title d-flex align-items-center gap-2", children: ["Peers Services Registration", (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { markdownContent: INFO_TEXT })] }), isRegistered ? ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-2", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-circle-fill text-success", style: { fontSize: "1.2em" } }), (0, jsx_runtime_1.jsx)("span", { children: "Registered" })] }), (0, jsx_runtime_1.jsxs)("small", { className: "text-muted d-block mb-3", children: ["Registered on", " ", new Date(registrationStatus).toLocaleDateString(undefined, {
56
49
  year: "numeric",
57
50
  month: "long",
58
51
  day: "numeric",
59
- })] })] })) : ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { className: "text-muted mb-3", children: "Register your account to enable cloud-powered features like the AI assistant." }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary", onClick: handleRegister, disabled: isRegistering, children: isRegistering ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "spinner-border spinner-border-sm me-2" }), "Registering..."] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-cloud-upload me-2" }), "Register Account"] })) })] }))] }) })] }));
52
+ })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary btn-sm", onClick: handleRegister, disabled: isRegistering, children: isRegistering ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "spinner-border spinner-border-sm me-2" }), "Refreshing..."] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-arrow-clockwise me-2" }), "Refresh Token"] })) })] })) : ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { className: "text-muted mb-3", children: "Register your account to enable cloud-powered features like the AI assistant." }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary", onClick: handleRegister, disabled: isRegistering, children: isRegistering ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "spinner-border spinner-border-sm me-2" }), "Registering..."] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-cloud-upload me-2" }), "Register Account"] })) })] }))] }) })] }));
60
53
  }
@@ -31,11 +31,7 @@ const SetupUser = () => {
31
31
  .catch((err) => {
32
32
  console.error("Error auto-installing peers-core:", err);
33
33
  });
34
- // Register with peers-services
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.1",
3
+ "version": "0.16.3",
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.1",
31
+ "@peers-app/peers-sdk": "^0.16.3",
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.1",
42
+ "@peers-app/peers-sdk": "0.16.3",
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, userVar } from "@peers-app/peers-sdk";
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
- const registrationStatusPvar = userVar<string>("PEERS_SERVICES_REGISTERED", {
7
- defaultValue: "",
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
- servicesTokenPvar(token);
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)}`);
@@ -100,7 +94,7 @@ export function AccountScreen() {
100
94
  <i className="bi bi-check-circle-fill text-success" style={{ fontSize: "1.2em" }} />
101
95
  <span>Registered</span>
102
96
  </div>
103
- <small className="text-muted">
97
+ <small className="text-muted d-block mb-3">
104
98
  Registered on{" "}
105
99
  {new Date(registrationStatus as string).toLocaleDateString(undefined, {
106
100
  year: "numeric",
@@ -108,6 +102,24 @@ export function AccountScreen() {
108
102
  day: "numeric",
109
103
  })}
110
104
  </small>
105
+ <button
106
+ type="button"
107
+ className="btn btn-outline-secondary btn-sm"
108
+ onClick={handleRegister}
109
+ disabled={isRegistering}
110
+ >
111
+ {isRegistering ? (
112
+ <>
113
+ <span className="spinner-border spinner-border-sm me-2" />
114
+ Refreshing...
115
+ </>
116
+ ) : (
117
+ <>
118
+ <i className="bi bi-arrow-clockwise me-2" />
119
+ Refresh Token
120
+ </>
121
+ )}
122
+ </button>
111
123
  </div>
112
124
  ) : (
113
125
  <div>
@@ -46,12 +46,7 @@ export const SetupUser = () => {
46
46
  console.error("Error auto-installing peers-core:", err);
47
47
  });
48
48
 
49
- // Register with peers-services
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();