@peers-app/peers-ui 0.23.14 → 0.25.0
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/biome.json +2 -2
- package/dist/components/qr-scanner.d.ts +18 -0
- package/dist/components/qr-scanner.js +165 -0
- package/dist/components/router.d.ts +1 -1
- package/dist/components/router.js +1 -1
- package/dist/root-layout/root-layout-host.js +18 -19
- package/dist/root-layout/root-layout-host.test.js +14 -9
- package/dist/screens/account/account-screen.js +52 -1
- package/dist/screens/contacts/contact-list.js +28 -1
- package/dist/screens/contacts/index.d.ts +0 -2
- package/dist/screens/contacts/index.js +0 -2
- package/dist/screens/device-pairing/device-pairing.d.ts +2 -4
- package/dist/screens/device-pairing/device-pairing.js +127 -128
- package/dist/screens/device-pairing/device-pairing.test.js +51 -15
- package/dist/screens/device-pairing/index.d.ts +0 -1
- package/dist/screens/device-pairing/index.js +0 -1
- package/dist/screens/groups/group-details.js +2 -6
- package/dist/screens/groups/group-invite-panel.d.ts +14 -0
- package/dist/screens/groups/group-invite-panel.js +125 -0
- package/dist/screens/groups/group-members.js +9 -103
- package/dist/screens/invites/accept-invite.d.ts +11 -0
- package/dist/screens/invites/accept-invite.js +114 -0
- package/dist/screens/invites/index.d.ts +7 -0
- package/dist/screens/{join-group → invites}/index.js +8 -3
- package/dist/screens/invites/invite-capture.d.ts +34 -0
- package/dist/screens/invites/invite-capture.js +94 -0
- package/dist/screens/invites/invite-share.d.ts +15 -0
- package/dist/screens/invites/invite-share.js +40 -0
- package/dist/screens/invites/invites-ipc.d.ts +10 -0
- package/dist/screens/invites/invites-ipc.js +61 -0
- package/dist/screens/invites/invites-screen.d.ts +9 -0
- package/dist/screens/invites/invites-screen.js +36 -0
- package/dist/screens/invites/pending-invites-list.d.ts +29 -0
- package/dist/screens/invites/pending-invites-list.js +156 -0
- package/dist/screens/settings/settings-page.js +1 -1
- package/dist/screens/setup-user.js +4 -18
- package/dist/system-apps/index.d.ts +1 -1
- package/dist/system-apps/index.js +5 -5
- package/dist/system-apps/{join-group.app.d.ts → invites.app.d.ts} +1 -1
- package/dist/system-apps/invites.app.js +9 -0
- package/package.json +4 -3
- package/src/components/qr-scanner.tsx +180 -0
- package/src/components/router.tsx +1 -1
- package/src/root-layout/root-layout-host.test.tsx +18 -13
- package/src/root-layout/root-layout-host.tsx +23 -21
- package/src/screens/account/account-screen.tsx +89 -2
- package/src/screens/contacts/contact-list.tsx +64 -4
- package/src/screens/contacts/index.ts +0 -2
- package/src/screens/device-pairing/device-pairing.test.tsx +61 -16
- package/src/screens/device-pairing/device-pairing.tsx +283 -208
- package/src/screens/device-pairing/index.ts +0 -1
- package/src/screens/groups/group-details.tsx +1 -41
- package/src/screens/groups/group-invite-panel.tsx +316 -0
- package/src/screens/groups/group-members.tsx +15 -177
- package/src/screens/invites/accept-invite.tsx +271 -0
- package/src/screens/invites/index.ts +9 -0
- package/src/screens/invites/invite-capture.ts +107 -0
- package/src/screens/invites/invite-share.tsx +104 -0
- package/src/screens/invites/invites-ipc.ts +74 -0
- package/src/screens/invites/invites-screen.tsx +78 -0
- package/src/screens/invites/pending-invites-list.tsx +224 -0
- package/src/screens/settings/settings-page.tsx +2 -2
- package/src/screens/setup-user.tsx +29 -47
- package/src/system-apps/index.ts +3 -3
- package/src/system-apps/invites.app.ts +8 -0
- package/dist/screens/contacts/user-connect-invite.d.ts +0 -118
- package/dist/screens/contacts/user-connect-invite.js +0 -264
- package/dist/screens/contacts/user-connect-invite.test.d.ts +0 -1
- package/dist/screens/contacts/user-connect-invite.test.js +0 -215
- package/dist/screens/contacts/user-connect.d.ts +0 -8
- package/dist/screens/contacts/user-connect.js +0 -487
- package/dist/screens/contacts/user-connect.test.d.ts +0 -1
- package/dist/screens/contacts/user-connect.test.js +0 -291
- package/dist/screens/device-pairing/device-pairing-invite.d.ts +0 -10
- package/dist/screens/device-pairing/device-pairing-invite.js +0 -50
- package/dist/screens/device-pairing/device-pairing-invite.test.d.ts +0 -1
- package/dist/screens/device-pairing/device-pairing-invite.test.js +0 -30
- package/dist/screens/groups/group-invite-listener.d.ts +0 -14
- package/dist/screens/groups/group-invite-listener.js +0 -93
- package/dist/screens/join-group/index.d.ts +0 -2
- package/dist/screens/join-group/join-group.d.ts +0 -12
- package/dist/screens/join-group/join-group.js +0 -102
- package/dist/system-apps/join-group.app.js +0 -9
- package/src/screens/contacts/user-connect-invite.test.ts +0 -256
- package/src/screens/contacts/user-connect-invite.ts +0 -332
- package/src/screens/contacts/user-connect.test.tsx +0 -382
- package/src/screens/contacts/user-connect.tsx +0 -883
- package/src/screens/device-pairing/device-pairing-invite.test.ts +0 -50
- package/src/screens/device-pairing/device-pairing-invite.ts +0 -55
- package/src/screens/groups/group-invite-listener.tsx +0 -282
- package/src/screens/join-group/index.ts +0 -4
- package/src/screens/join-group/join-group.tsx +0 -296
- package/src/system-apps/join-group.app.ts +0 -8
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Invite URL and pending-intent helpers for the user-connect QR/link flow.
|
|
4
|
-
*
|
|
5
|
-
* Invite codes stay in the URL fragment (never the HTTP query) and are moved
|
|
6
|
-
* into tab-scoped sessionStorage before startup route restoration can persist
|
|
7
|
-
* them into `mainContentPath`.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.DEFAULT_USER_CONNECT_BASE_URL = exports.USER_CONNECT_INVITE_STORAGE_KEY = void 0;
|
|
11
|
-
exports.buildUserConnectInviteUrl = buildUserConnectInviteUrl;
|
|
12
|
-
exports.extractUserConnectCodeFromFragment = extractUserConnectCodeFromFragment;
|
|
13
|
-
exports.normalizeUserConnectCode = normalizeUserConnectCode;
|
|
14
|
-
exports.isUserConnectIntentFresh = isUserConnectIntentFresh;
|
|
15
|
-
exports.stripUserConnectCodeFromUrl = stripUserConnectCodeFromUrl;
|
|
16
|
-
exports.writeUserConnectPendingIntent = writeUserConnectPendingIntent;
|
|
17
|
-
exports.readUserConnectPendingIntent = readUserConnectPendingIntent;
|
|
18
|
-
exports.consumeUserConnectPendingIntent = consumeUserConnectPendingIntent;
|
|
19
|
-
exports.clearUserConnectPendingIntent = clearUserConnectPendingIntent;
|
|
20
|
-
exports.captureUserConnectInviteFromLocation = captureUserConnectInviteFromLocation;
|
|
21
|
-
exports.hasPendingUserConnectInvite = hasPendingUserConnectInvite;
|
|
22
|
-
exports.buildUserConnectShareText = buildUserConnectShareText;
|
|
23
|
-
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
24
|
-
/** sessionStorage key for a captured inbound invite. */
|
|
25
|
-
exports.USER_CONNECT_INVITE_STORAGE_KEY = "peers.userConnectInvite";
|
|
26
|
-
/** Default production launch origin used when building shareable invite links. */
|
|
27
|
-
exports.DEFAULT_USER_CONNECT_BASE_URL = "https://peers.app";
|
|
28
|
-
/**
|
|
29
|
-
* Build the canonical shareable invite URL.
|
|
30
|
-
* Keeps the bearer code in the fragment and uses `?app` so signed-out PWA
|
|
31
|
-
* recipients receive the app shell instead of the marketing landing page.
|
|
32
|
-
* @param code Connection code (formatted or raw)
|
|
33
|
-
* @param baseUrl Launch origin (no trailing slash); defaults to peers.app
|
|
34
|
-
* @returns Absolute invite URL
|
|
35
|
-
*/
|
|
36
|
-
function buildUserConnectInviteUrl(code, baseUrl = exports.DEFAULT_USER_CONNECT_BASE_URL) {
|
|
37
|
-
const normalized = normalizeUserConnectCode(code);
|
|
38
|
-
if (!normalized) {
|
|
39
|
-
throw new Error("Invalid connection code");
|
|
40
|
-
}
|
|
41
|
-
const formatted = (0, peers_sdk_1.formatConnectionCode)(normalized);
|
|
42
|
-
const origin = baseUrl.replace(/\/$/, "");
|
|
43
|
-
return `${origin}/?app#contacts/connect?code=${encodeURIComponent(formatted)}`;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Extract a connection code from a `contacts/connect` hash fragment.
|
|
47
|
-
* Accepts `#contacts/connect?code=…` or `contacts/connect?code=…`.
|
|
48
|
-
* @param hashOrPath Hash or path fragment from `location.hash` / a full URL
|
|
49
|
-
* @returns Raw code string from the query, or null when the route is not an invite
|
|
50
|
-
*/
|
|
51
|
-
function extractUserConnectCodeFromFragment(hashOrPath) {
|
|
52
|
-
const raw = hashOrPath.startsWith("#") ? hashOrPath.slice(1) : hashOrPath;
|
|
53
|
-
const [pathPart, queryPart] = raw.split("?");
|
|
54
|
-
if (pathPart !== "contacts/connect") {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
if (!queryPart) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const params = new URLSearchParams(queryPart);
|
|
61
|
-
const code = params.get("code");
|
|
62
|
-
if (code === null) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
const decoded = code.trim();
|
|
66
|
-
return decoded.length > 0 ? decoded : null;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Validate and normalize a connection code to 12 Crockford characters.
|
|
70
|
-
* @param code Candidate code (formatted or raw)
|
|
71
|
-
* @returns Normalized code, or null when invalid
|
|
72
|
-
*/
|
|
73
|
-
function normalizeUserConnectCode(code) {
|
|
74
|
-
const trimmed = code.trim().toUpperCase();
|
|
75
|
-
const isRaw = /^[0-9ABCDEFGHJKMNPQRSTVWXYZ]{12}$/.test(trimmed);
|
|
76
|
-
const isFormatted = /^[0-9ABCDEFGHJKMNPQRSTVWXYZ]{4}-[0-9ABCDEFGHJKMNPQRSTVWXYZ]{4}-[0-9ABCDEFGHJKMNPQRSTVWXYZ]{4}$/.test(trimmed);
|
|
77
|
-
if (!isRaw && !isFormatted) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const compact = trimmed.replaceAll("-", "");
|
|
81
|
-
if (!(0, peers_sdk_1.isValidConnectionCode)(compact)) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
return (0, peers_sdk_1.parseConnectionCode)(compact).code;
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Whether a pending intent is still within the local invite TTL.
|
|
93
|
-
* @param intent Captured intent
|
|
94
|
-
* @param nowMs Current epoch ms (injectable for tests)
|
|
95
|
-
* @returns True when the intent has not expired
|
|
96
|
-
*/
|
|
97
|
-
function isUserConnectIntentFresh(intent, nowMs = Date.now()) {
|
|
98
|
-
return intent.capturedAt <= nowMs && nowMs - intent.capturedAt < peers_sdk_1.USER_CONNECT_TTL_MS;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Replace the visible URL so the bearer code is no longer in the address bar.
|
|
102
|
-
* Leaves `?app` and a non-sensitive `#contacts/connect` route shell when present.
|
|
103
|
-
* @param locationLike Browser location (defaults to `window.location`)
|
|
104
|
-
* @param historyLike History API (defaults to `window.history`)
|
|
105
|
-
*/
|
|
106
|
-
function stripUserConnectCodeFromUrl(locationLike = window.location, historyLike = window.history) {
|
|
107
|
-
if (!locationLike.hash.includes("code=")) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const path = locationLike.hash.startsWith("#")
|
|
111
|
-
? locationLike.hash.slice(1).split("?")[0]
|
|
112
|
-
: locationLike.hash.split("?")[0];
|
|
113
|
-
const nextHash = path === "contacts/connect" ? "#contacts/connect" : "";
|
|
114
|
-
const nextUrl = `${locationLike.pathname}${locationLike.search}${nextHash}`;
|
|
115
|
-
historyLike.replaceState(historyLike.state ?? null, "", nextUrl);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Persist a pending invite in tab-scoped sessionStorage.
|
|
119
|
-
* @param intent Valid intent to store
|
|
120
|
-
* @param storage Storage backend (defaults to sessionStorage)
|
|
121
|
-
*/
|
|
122
|
-
function writeUserConnectPendingIntent(intent, storage = sessionStorage) {
|
|
123
|
-
const payload = intent;
|
|
124
|
-
storage.setItem(exports.USER_CONNECT_INVITE_STORAGE_KEY, JSON.stringify(payload));
|
|
125
|
-
}
|
|
126
|
-
function writeErrorMarker(error, capturedAt, storage) {
|
|
127
|
-
const payload = { error, capturedAt };
|
|
128
|
-
storage.setItem(exports.USER_CONNECT_INVITE_STORAGE_KEY, JSON.stringify(payload));
|
|
129
|
-
}
|
|
130
|
-
function parseStoredPayload(raw) {
|
|
131
|
-
try {
|
|
132
|
-
const parsed = JSON.parse(raw);
|
|
133
|
-
const marker = parsed;
|
|
134
|
-
if (marker.error === "invalid" || marker.error === "expired") {
|
|
135
|
-
const capturedAt = marker.capturedAt;
|
|
136
|
-
if (typeof capturedAt !== "number" || !Number.isFinite(capturedAt)) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
return { error: marker.error, capturedAt };
|
|
140
|
-
}
|
|
141
|
-
if (typeof parsed.code === "string" &&
|
|
142
|
-
typeof parsed.capturedAt === "number" &&
|
|
143
|
-
Number.isFinite(parsed.capturedAt)) {
|
|
144
|
-
return {
|
|
145
|
-
code: parsed.code,
|
|
146
|
-
capturedAt: parsed.capturedAt,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Read a pending invite without consuming it.
|
|
157
|
-
* Expired entries are cleared. Invalid markers remain until consumed/cleared
|
|
158
|
-
* so the connection screen can show recovery UI.
|
|
159
|
-
* @param storage Storage backend
|
|
160
|
-
* @param nowMs Current epoch ms
|
|
161
|
-
* @returns Capture result
|
|
162
|
-
*/
|
|
163
|
-
function readUserConnectPendingIntent(storage = sessionStorage, nowMs = Date.now()) {
|
|
164
|
-
const raw = storage.getItem(exports.USER_CONNECT_INVITE_STORAGE_KEY);
|
|
165
|
-
if (!raw) {
|
|
166
|
-
return { ok: false, reason: "none" };
|
|
167
|
-
}
|
|
168
|
-
const parsed = parseStoredPayload(raw);
|
|
169
|
-
if (!parsed) {
|
|
170
|
-
writeErrorMarker("invalid", nowMs, storage);
|
|
171
|
-
return { ok: false, reason: "invalid" };
|
|
172
|
-
}
|
|
173
|
-
if ("error" in parsed) {
|
|
174
|
-
return { ok: false, reason: parsed.error };
|
|
175
|
-
}
|
|
176
|
-
const normalized = normalizeUserConnectCode(parsed.code);
|
|
177
|
-
if (!normalized) {
|
|
178
|
-
writeErrorMarker("invalid", parsed.capturedAt, storage);
|
|
179
|
-
return { ok: false, reason: "invalid" };
|
|
180
|
-
}
|
|
181
|
-
const intent = {
|
|
182
|
-
code: normalized,
|
|
183
|
-
capturedAt: parsed.capturedAt,
|
|
184
|
-
};
|
|
185
|
-
if (!isUserConnectIntentFresh(intent, nowMs)) {
|
|
186
|
-
writeErrorMarker("expired", parsed.capturedAt, storage);
|
|
187
|
-
return { ok: false, reason: "expired" };
|
|
188
|
-
}
|
|
189
|
-
return { ok: true, intent };
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Read and remove a pending invite in one step (one-time consumption).
|
|
193
|
-
* @param storage Storage backend
|
|
194
|
-
* @param nowMs Current epoch ms
|
|
195
|
-
* @returns Capture result for the consumed intent
|
|
196
|
-
*/
|
|
197
|
-
function consumeUserConnectPendingIntent(storage = sessionStorage, nowMs = Date.now()) {
|
|
198
|
-
const result = readUserConnectPendingIntent(storage, nowMs);
|
|
199
|
-
storage.removeItem(exports.USER_CONNECT_INVITE_STORAGE_KEY);
|
|
200
|
-
return result;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Remove any pending invite from sessionStorage.
|
|
204
|
-
* @param storage Storage backend
|
|
205
|
-
*/
|
|
206
|
-
function clearUserConnectPendingIntent(storage = sessionStorage) {
|
|
207
|
-
storage.removeItem(exports.USER_CONNECT_INVITE_STORAGE_KEY);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Capture an inbound invite from the current location into sessionStorage and
|
|
211
|
-
* strip the code from the address bar. Safe to call multiple times; a second
|
|
212
|
-
* call with no code in the URL leaves existing storage alone.
|
|
213
|
-
* @param options Optional location/history/storage/clock overrides for tests
|
|
214
|
-
* @returns Capture result
|
|
215
|
-
*/
|
|
216
|
-
function captureUserConnectInviteFromLocation(options) {
|
|
217
|
-
const locationLike = options?.locationLike ?? window.location;
|
|
218
|
-
const historyLike = options?.historyLike ?? window.history;
|
|
219
|
-
const storage = options?.storage ?? sessionStorage;
|
|
220
|
-
const nowMs = options?.nowMs ?? Date.now();
|
|
221
|
-
const extracted = extractUserConnectCodeFromFragment(locationLike.hash);
|
|
222
|
-
if (extracted === null) {
|
|
223
|
-
const rawFragment = locationLike.hash.startsWith("#")
|
|
224
|
-
? locationLike.hash.slice(1)
|
|
225
|
-
: locationLike.hash;
|
|
226
|
-
const [path, query = ""] = rawFragment.split("?");
|
|
227
|
-
if (path === "contacts/connect" && new URLSearchParams(query).has("code")) {
|
|
228
|
-
stripUserConnectCodeFromUrl(locationLike, historyLike);
|
|
229
|
-
writeErrorMarker("invalid", nowMs, storage);
|
|
230
|
-
return { ok: false, reason: "invalid" };
|
|
231
|
-
}
|
|
232
|
-
return readUserConnectPendingIntent(storage, nowMs);
|
|
233
|
-
}
|
|
234
|
-
stripUserConnectCodeFromUrl(locationLike, historyLike);
|
|
235
|
-
const normalized = normalizeUserConnectCode(extracted);
|
|
236
|
-
if (!normalized) {
|
|
237
|
-
writeErrorMarker("invalid", nowMs, storage);
|
|
238
|
-
return { ok: false, reason: "invalid" };
|
|
239
|
-
}
|
|
240
|
-
const intent = { code: normalized, capturedAt: nowMs };
|
|
241
|
-
writeUserConnectPendingIntent(intent, storage);
|
|
242
|
-
return { ok: true, intent };
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Whether sessionStorage currently holds a fresh, valid pending invite.
|
|
246
|
-
* @param storage Storage backend
|
|
247
|
-
* @param nowMs Current epoch ms
|
|
248
|
-
*/
|
|
249
|
-
function hasPendingUserConnectInvite(storage = sessionStorage, nowMs = Date.now()) {
|
|
250
|
-
return readUserConnectPendingIntent(storage, nowMs).ok;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Share text for the Web Share API / clipboard companion copy.
|
|
254
|
-
* @param inviteUrl Canonical invite URL
|
|
255
|
-
* @returns Human-readable share body
|
|
256
|
-
*/
|
|
257
|
-
function buildUserConnectShareText(inviteUrl) {
|
|
258
|
-
return [
|
|
259
|
-
"Connect with me on Peers:",
|
|
260
|
-
inviteUrl,
|
|
261
|
-
"",
|
|
262
|
-
"Both of us need Peers open. This invite expires in 10 minutes.",
|
|
263
|
-
].join("\n");
|
|
264
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
4
|
-
const user_connect_invite_1 = require("./user-connect-invite");
|
|
5
|
-
function createMemoryStorage() {
|
|
6
|
-
const map = new Map();
|
|
7
|
-
return {
|
|
8
|
-
get length() {
|
|
9
|
-
return map.size;
|
|
10
|
-
},
|
|
11
|
-
clear() {
|
|
12
|
-
map.clear();
|
|
13
|
-
},
|
|
14
|
-
getItem(key) {
|
|
15
|
-
return map.get(key) ?? null;
|
|
16
|
-
},
|
|
17
|
-
key(index) {
|
|
18
|
-
return [...map.keys()][index] ?? null;
|
|
19
|
-
},
|
|
20
|
-
removeItem(key) {
|
|
21
|
-
map.delete(key);
|
|
22
|
-
},
|
|
23
|
-
setItem(key, value) {
|
|
24
|
-
map.set(key, value);
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
describe("user-connect-invite", () => {
|
|
29
|
-
const validCode = "ABCD1234EFGH";
|
|
30
|
-
const formattedCode = "ABCD-1234-EFGH";
|
|
31
|
-
describe("normalizeUserConnectCode", () => {
|
|
32
|
-
it("accepts formatted and unformatted valid codes", () => {
|
|
33
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)(validCode)).toBe(validCode);
|
|
34
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)(formattedCode)).toBe(validCode);
|
|
35
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)("abcd-1234-efgh")).toBe(validCode);
|
|
36
|
-
});
|
|
37
|
-
it("rejects invalid alphabet and length", () => {
|
|
38
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)("ABCD1234EFG")).toBeNull();
|
|
39
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)("ABCD1234EFGHI")).toBeNull();
|
|
40
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)("ABCD1234EFGI")).toBeNull(); // I invalid in Crockford
|
|
41
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)("A-B-C-D-1-2-3-4-E-F-G-H")).toBeNull();
|
|
42
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)("ABCD 1234 EFGH")).toBeNull();
|
|
43
|
-
expect((0, user_connect_invite_1.normalizeUserConnectCode)("")).toBeNull();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
describe("extractUserConnectCodeFromFragment", () => {
|
|
47
|
-
it("extracts codes from contacts/connect fragments", () => {
|
|
48
|
-
expect((0, user_connect_invite_1.extractUserConnectCodeFromFragment)(`#contacts/connect?code=${formattedCode}`)).toBe(formattedCode);
|
|
49
|
-
expect((0, user_connect_invite_1.extractUserConnectCodeFromFragment)(`contacts/connect?code=${validCode}`)).toBe(validCode);
|
|
50
|
-
});
|
|
51
|
-
it("returns null for unrelated routes", () => {
|
|
52
|
-
expect((0, user_connect_invite_1.extractUserConnectCodeFromFragment)("#contacts/list")).toBeNull();
|
|
53
|
-
expect((0, user_connect_invite_1.extractUserConnectCodeFromFragment)("#home")).toBeNull();
|
|
54
|
-
expect((0, user_connect_invite_1.extractUserConnectCodeFromFragment)("#contacts/connect")).toBeNull();
|
|
55
|
-
expect((0, user_connect_invite_1.extractUserConnectCodeFromFragment)("")).toBeNull();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
describe("buildUserConnectInviteUrl", () => {
|
|
59
|
-
it("builds the canonical peers.app URL with ?app and fragment code", () => {
|
|
60
|
-
const url = (0, user_connect_invite_1.buildUserConnectInviteUrl)(validCode);
|
|
61
|
-
expect(url).toBe(`https://peers.app/?app#contacts/connect?code=${encodeURIComponent(formattedCode)}`);
|
|
62
|
-
expect(url.includes("?app#")).toBe(true);
|
|
63
|
-
expect(url.split("?")[1]?.startsWith("app#")).toBe(true);
|
|
64
|
-
const beforeHash = url.split("#")[0];
|
|
65
|
-
expect(beforeHash.includes(validCode)).toBe(false);
|
|
66
|
-
expect(beforeHash.includes(formattedCode)).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
it("accepts an explicit base URL without putting the code in the HTTP query", () => {
|
|
69
|
-
const url = (0, user_connect_invite_1.buildUserConnectInviteUrl)(formattedCode, "https://example.test/");
|
|
70
|
-
expect(url.startsWith("https://example.test/?app#")).toBe(true);
|
|
71
|
-
expect(url).toContain(`code=${encodeURIComponent(formattedCode)}`);
|
|
72
|
-
const query = new URL(url.split("#")[0]).searchParams;
|
|
73
|
-
expect(query.has("code")).toBe(false);
|
|
74
|
-
expect(query.has("app")).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe("sessionStorage intent lifecycle", () => {
|
|
78
|
-
it("writes, reads, and one-time consumes a pending intent", () => {
|
|
79
|
-
const storage = createMemoryStorage();
|
|
80
|
-
const now = 1_000_000;
|
|
81
|
-
(0, user_connect_invite_1.writeUserConnectPendingIntent)({ code: validCode, capturedAt: now }, storage);
|
|
82
|
-
const read = (0, user_connect_invite_1.readUserConnectPendingIntent)(storage, now + 1000);
|
|
83
|
-
expect(read).toEqual({
|
|
84
|
-
ok: true,
|
|
85
|
-
intent: { code: validCode, capturedAt: now },
|
|
86
|
-
});
|
|
87
|
-
expect((0, user_connect_invite_1.hasPendingUserConnectInvite)(storage, now + 1000)).toBe(true);
|
|
88
|
-
const consumed = (0, user_connect_invite_1.consumeUserConnectPendingIntent)(storage, now + 1000);
|
|
89
|
-
expect(consumed).toEqual({
|
|
90
|
-
ok: true,
|
|
91
|
-
intent: { code: validCode, capturedAt: now },
|
|
92
|
-
});
|
|
93
|
-
expect(storage.getItem(user_connect_invite_1.USER_CONNECT_INVITE_STORAGE_KEY)).toBeNull();
|
|
94
|
-
expect((0, user_connect_invite_1.consumeUserConnectPendingIntent)(storage, now + 1000)).toEqual({
|
|
95
|
-
ok: false,
|
|
96
|
-
reason: "none",
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
it("expires stale intents using the shared TTL", () => {
|
|
100
|
-
const storage = createMemoryStorage();
|
|
101
|
-
const now = 1_000_000;
|
|
102
|
-
(0, user_connect_invite_1.writeUserConnectPendingIntent)({ code: validCode, capturedAt: now }, storage);
|
|
103
|
-
expect((0, user_connect_invite_1.readUserConnectPendingIntent)(storage, now + peers_sdk_1.USER_CONNECT_TTL_MS)).toEqual({
|
|
104
|
-
ok: false,
|
|
105
|
-
reason: "expired",
|
|
106
|
-
});
|
|
107
|
-
expect((0, user_connect_invite_1.consumeUserConnectPendingIntent)(storage, now + peers_sdk_1.USER_CONNECT_TTL_MS)).toEqual({
|
|
108
|
-
ok: false,
|
|
109
|
-
reason: "expired",
|
|
110
|
-
});
|
|
111
|
-
expect(storage.getItem(user_connect_invite_1.USER_CONNECT_INVITE_STORAGE_KEY)).toBeNull();
|
|
112
|
-
});
|
|
113
|
-
it("rejects implausible future capture timestamps", () => {
|
|
114
|
-
const storage = createMemoryStorage();
|
|
115
|
-
(0, user_connect_invite_1.writeUserConnectPendingIntent)({ code: validCode, capturedAt: 20_000 }, storage);
|
|
116
|
-
expect((0, user_connect_invite_1.readUserConnectPendingIntent)(storage, 10_000)).toEqual({
|
|
117
|
-
ok: false,
|
|
118
|
-
reason: "expired",
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
it("treats malformed stored data as invalid", () => {
|
|
122
|
-
const storage = createMemoryStorage();
|
|
123
|
-
storage.setItem(user_connect_invite_1.USER_CONNECT_INVITE_STORAGE_KEY, "{not-json");
|
|
124
|
-
expect((0, user_connect_invite_1.readUserConnectPendingIntent)(storage)).toEqual({ ok: false, reason: "invalid" });
|
|
125
|
-
expect((0, user_connect_invite_1.consumeUserConnectPendingIntent)(storage)).toEqual({
|
|
126
|
-
ok: false,
|
|
127
|
-
reason: "invalid",
|
|
128
|
-
});
|
|
129
|
-
expect(storage.getItem(user_connect_invite_1.USER_CONNECT_INVITE_STORAGE_KEY)).toBeNull();
|
|
130
|
-
});
|
|
131
|
-
it("clears pending intent explicitly", () => {
|
|
132
|
-
const storage = createMemoryStorage();
|
|
133
|
-
(0, user_connect_invite_1.writeUserConnectPendingIntent)({ code: validCode, capturedAt: Date.now() }, storage);
|
|
134
|
-
(0, user_connect_invite_1.clearUserConnectPendingIntent)(storage);
|
|
135
|
-
expect((0, user_connect_invite_1.readUserConnectPendingIntent)(storage)).toEqual({ ok: false, reason: "none" });
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
describe("capture and URL cleanup", () => {
|
|
139
|
-
it("captures a valid invite, stores it, and strips the code from the URL", () => {
|
|
140
|
-
const storage = createMemoryStorage();
|
|
141
|
-
let replacedUrl = "";
|
|
142
|
-
const locationLike = {
|
|
143
|
-
pathname: "/",
|
|
144
|
-
search: "?app",
|
|
145
|
-
hash: `#contacts/connect?code=${formattedCode}`,
|
|
146
|
-
};
|
|
147
|
-
const historyLike = {
|
|
148
|
-
state: null,
|
|
149
|
-
replaceState: (_state, _title, url) => {
|
|
150
|
-
replacedUrl = String(url ?? "");
|
|
151
|
-
locationLike.hash = replacedUrl.includes("#") ? `#${replacedUrl.split("#")[1]}` : "";
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
const result = (0, user_connect_invite_1.captureUserConnectInviteFromLocation)({
|
|
155
|
-
locationLike,
|
|
156
|
-
historyLike,
|
|
157
|
-
storage,
|
|
158
|
-
nowMs: 5_000,
|
|
159
|
-
});
|
|
160
|
-
expect(result).toEqual({
|
|
161
|
-
ok: true,
|
|
162
|
-
intent: { code: validCode, capturedAt: 5_000 },
|
|
163
|
-
});
|
|
164
|
-
expect(replacedUrl).toBe("/?app#contacts/connect");
|
|
165
|
-
expect(locationLike.hash).toBe("#contacts/connect");
|
|
166
|
-
expect((0, user_connect_invite_1.hasPendingUserConnectInvite)(storage, 5_000)).toBe(true);
|
|
167
|
-
});
|
|
168
|
-
it("stores an invalid marker for malformed codes and still cleans the URL", () => {
|
|
169
|
-
const storage = createMemoryStorage();
|
|
170
|
-
const locationLike = {
|
|
171
|
-
pathname: "/",
|
|
172
|
-
search: "?app",
|
|
173
|
-
hash: "#contacts/connect?code=BAD",
|
|
174
|
-
};
|
|
175
|
-
const historyLike = {
|
|
176
|
-
state: null,
|
|
177
|
-
replaceState: (_state, _title, url) => {
|
|
178
|
-
locationLike.hash = String(url ?? "").includes("#")
|
|
179
|
-
? `#${String(url).split("#")[1]}`
|
|
180
|
-
: "";
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
expect((0, user_connect_invite_1.captureUserConnectInviteFromLocation)({
|
|
184
|
-
locationLike,
|
|
185
|
-
historyLike,
|
|
186
|
-
storage,
|
|
187
|
-
nowMs: 9_000,
|
|
188
|
-
})).toEqual({ ok: false, reason: "invalid" });
|
|
189
|
-
expect(locationLike.hash).toBe("#contacts/connect");
|
|
190
|
-
expect((0, user_connect_invite_1.readUserConnectPendingIntent)(storage, 9_000)).toEqual({
|
|
191
|
-
ok: false,
|
|
192
|
-
reason: "invalid",
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
it("stripUserConnectCodeFromUrl is a no-op without a code", () => {
|
|
196
|
-
const locationLike = { pathname: "/", search: "", hash: "#home" };
|
|
197
|
-
let calls = 0;
|
|
198
|
-
(0, user_connect_invite_1.stripUserConnectCodeFromUrl)(locationLike, {
|
|
199
|
-
state: null,
|
|
200
|
-
replaceState: () => {
|
|
201
|
-
calls += 1;
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
expect(calls).toBe(0);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
describe("buildUserConnectShareText", () => {
|
|
208
|
-
it("mentions expiry and that both people need Peers open", () => {
|
|
209
|
-
const text = (0, user_connect_invite_1.buildUserConnectShareText)("https://peers.app/?app#contacts/connect?code=X");
|
|
210
|
-
expect(text).toContain("https://peers.app/?app#contacts/connect?code=X");
|
|
211
|
-
expect(text.toLowerCase()).toContain("expire");
|
|
212
|
-
expect(text.toLowerCase()).toContain("peers open");
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Connect-to-user screen: QR invite, link share, manual code entry, and trust confirmation.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Polished Connect to user screen. Creating an invite is the default path;
|
|
6
|
-
* inbound links open a review state before connecting.
|
|
7
|
-
*/
|
|
8
|
-
export declare function UserConnect(): import("react/jsx-runtime").JSX.Element;
|