@bridgebrew/invitations 0.0.0-stage → 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bridgebrew
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,426 @@
1
+ // Invitations (SPEC multi-instance CAP-1, CAP-7, a Connections settings screen): a screen of Admin's System
2
+ // section. "Create invite" asks the host for a single-use Full invite (`POST /_bridge/host/invitations`, 5 minutes) and
3
+ // shows its link to copy, with what Full gives and what plain HTTP risks; the paired clients (`GET /_bridge/host/clients`)
4
+ // with their device, OS, pairing date and last request, each revoked after a confirmation (`DELETE …/clients/<id>`): its
5
+ // next request is refused.
6
+ import * as React from 'react';
7
+ import {
8
+ Badge,
9
+ Button,
10
+ Card,
11
+ Dialog,
12
+ DialogBody,
13
+ DialogClose,
14
+ DialogContent,
15
+ DialogDescription,
16
+ DialogFooter,
17
+ DialogHeader,
18
+ DialogTitle,
19
+ EmptyState,
20
+ Icon,
21
+ ScrollArea,
22
+ Section,
23
+ useToast,
24
+ copyText,
25
+ HttpError,
26
+ readJson,
27
+ formatDate,
28
+ userLocale,
29
+ } from '@bridge/ui';
30
+ import type { Context } from 'cordis';
31
+ import type {} from '@bridge/ui-renderer/client';
32
+
33
+ export const name = 'invitations';
34
+ export const inject = ['slots', 'workspace'];
35
+
36
+ interface Client {
37
+ id: string;
38
+ scope: 'full';
39
+ label: string;
40
+ deviceType: string;
41
+ os: string;
42
+ issuedAt: string;
43
+ lastSeenAt: string;
44
+ }
45
+ interface Invite {
46
+ code: string;
47
+ link: string;
48
+ expiresAt: string;
49
+ local: boolean;
50
+ }
51
+ interface Failure {
52
+ message: string;
53
+ hint?: string;
54
+ }
55
+
56
+ /** What a failed request says: `readJson`'s `HttpError` (message, hint), else the thrown error's message. */
57
+ function failureOf(cause: unknown): Failure {
58
+ if (cause instanceof HttpError) {
59
+ const { message, hint } = cause;
60
+ return { message, ...(hint !== undefined && { hint }) };
61
+ }
62
+ return { message: (cause as Error).message };
63
+ }
64
+
65
+ const relative = new Intl.RelativeTimeFormat(userLocale(), { numeric: 'auto' });
66
+ /** `iso` from now, in words: "just now", "5 minutes ago", "yesterday". */
67
+ function ago(iso: string) {
68
+ const seconds = (Date.parse(iso) - Date.now()) / 1000;
69
+ if (Math.abs(seconds) < 60) return 'just now';
70
+ for (const [unit, size] of [
71
+ ['day', 86_400],
72
+ ['hour', 3_600],
73
+ ['minute', 60],
74
+ ] as const) {
75
+ if (Math.abs(seconds) >= size) return relative.format(Math.round(seconds / size), unit);
76
+ }
77
+ return 'just now';
78
+ }
79
+ const day = (iso: string) => formatDate(iso, { day: 'numeric', month: 'short', year: 'numeric' });
80
+ const deviceIcon = (type: string) =>
81
+ type === 'mobile' || type === 'tablet' ? 'phone' : type === 'bot' ? 'bot' : 'monitor';
82
+
83
+ /** The invite just created: its link to copy, its expiry (counting down), and the warnings. */
84
+ function InviteDialog({ invite, onClose }: { invite: Invite; onClose: () => void }) {
85
+ const { toast } = useToast();
86
+ const [now, setNow] = React.useState(Date.now());
87
+ React.useEffect(() => {
88
+ const timer = setInterval(() => setNow(Date.now()), 1000);
89
+ return () => clearInterval(timer);
90
+ }, []);
91
+ const left = Math.max(0, Math.round((Date.parse(invite.expiresAt) - now) / 1000));
92
+ const copy = () =>
93
+ void copyText(invite.link).then(
94
+ () => toast({ variant: 'success', title: 'Invite link copied' }),
95
+ () =>
96
+ toast({
97
+ variant: 'error',
98
+ title: 'Not copied',
99
+ description: 'Select the link and copy it by hand.',
100
+ }),
101
+ );
102
+ return (
103
+ <Dialog
104
+ open
105
+ onOpenChange={(open) => {
106
+ if (!open) onClose();
107
+ }}
108
+ >
109
+ <DialogContent aria-label="Invite" className="w-[520px]">
110
+ <DialogHeader className="px-5 pt-4">
111
+ <DialogTitle className="text-[15px] font-semibold">Invite a client</DialogTitle>
112
+ </DialogHeader>
113
+ <DialogBody className="flex flex-col gap-3 pb-5">
114
+ <DialogDescription className="m-0 leading-5">
115
+ Paste this link in the Bridge app of the other machine (the + of its rail, Join a
116
+ Bridge). It works once.
117
+ </DialogDescription>
118
+ <div className="flex items-center gap-2">
119
+ <code
120
+ data-invite-link
121
+ className="min-w-0 flex-1 select-all break-all rounded-sm bg-hover px-2 py-1.5 font-mono text-xs text-foreground"
122
+ >
123
+ {invite.link}
124
+ </code>
125
+ <Button size="sm" variant="outline" disabled={left === 0} onClick={copy}>
126
+ <Icon name="copy" size={13} />
127
+ Copy
128
+ </Button>
129
+ </div>
130
+ <p
131
+ role="status"
132
+ data-expiry
133
+ className={
134
+ left === 0 ? 'm-0 text-[13px] text-destructive' : 'm-0 text-[13px] text-secondary'
135
+ }
136
+ >
137
+ {left === 0
138
+ ? 'This invite expired: create another one.'
139
+ : `Expires in ${Math.floor(left / 60)}:${String(left % 60).padStart(2, '0')}, at ${formatDate(invite.expiresAt, { hour: '2-digit', minute: '2-digit' })}.`}
140
+ </p>
141
+ <div
142
+ data-warning
143
+ className="flex gap-2 rounded-default border border-warning/30 bg-warning-subtle px-3 py-2 text-[13px] leading-5 text-warning-text"
144
+ >
145
+ <Icon name="triangle-alert" size={15} className="mt-0.5 shrink-0" />
146
+ <div className="flex flex-col gap-1">
147
+ <p className="m-0">
148
+ Full access: the client can administer this Bridge, its workspaces, plugins and
149
+ settings. Share it only with your own devices.
150
+ </p>
151
+ <p className="m-0">
152
+ Bridge speaks plain HTTP: on a network you do not trust, the link and the client's
153
+ key can be intercepted.
154
+ </p>
155
+ </div>
156
+ </div>
157
+ {invite.local && (
158
+ <p
159
+ data-local
160
+ className="m-0 flex gap-2 rounded-default bg-hover px-3 py-2 text-[13px] leading-5 text-secondary"
161
+ >
162
+ <Icon name="globe" size={14} className="mt-0.5 shrink-0" />
163
+ Bridge is reachable only from this machine: another device cannot use this link until
164
+ System › Network allows the network.
165
+ </p>
166
+ )}
167
+ </DialogBody>
168
+ <DialogFooter className="justify-end gap-2 px-5 py-3">
169
+ <DialogClose render={<Button variant="primary" />}>Done</DialogClose>
170
+ </DialogFooter>
171
+ </DialogContent>
172
+ </Dialog>
173
+ );
174
+ }
175
+
176
+ /** Asks before revoking `client`. */
177
+ function RevokeDialog({
178
+ client,
179
+ onClose,
180
+ revoke,
181
+ }: {
182
+ client: Client;
183
+ onClose: () => void;
184
+ revoke: (client: Client) => Promise<Failure | undefined>;
185
+ }) {
186
+ const [busy, setBusy] = React.useState(false);
187
+ const [failure, setFailure] = React.useState<Failure>();
188
+ const confirm = async () => {
189
+ setBusy(true);
190
+ const failed = await revoke(client);
191
+ setBusy(false);
192
+ if (failed) setFailure(failed);
193
+ };
194
+ return (
195
+ <Dialog
196
+ open
197
+ onOpenChange={(open) => {
198
+ if (!open && !busy) onClose();
199
+ }}
200
+ >
201
+ <DialogContent aria-label={`Revoke ${client.label}`} className="w-[440px]">
202
+ <DialogHeader className="px-5 pt-4">
203
+ <DialogTitle className="text-[15px] font-semibold">Revoke {client.label}?</DialogTitle>
204
+ </DialogHeader>
205
+ <DialogBody className="flex flex-col gap-3 pb-5">
206
+ <DialogDescription className="m-0 leading-5">
207
+ {client.label}, paired {day(client.issuedAt)}. Its next request is refused. To use this
208
+ Bridge again, it needs a new invite.
209
+ </DialogDescription>
210
+ {failure && (
211
+ <p role="alert" className="m-0 text-[13px] text-destructive">
212
+ {failure.message}
213
+ {failure.hint && <span className="block text-xs text-secondary">{failure.hint}</span>}
214
+ </p>
215
+ )}
216
+ </DialogBody>
217
+ <DialogFooter className="justify-end gap-2 px-5 py-3">
218
+ <DialogClose render={<Button variant="outline" disabled={busy} />}>Cancel</DialogClose>
219
+ <Button
220
+ variant="primary"
221
+ disabled={busy}
222
+ onClick={() => void confirm()}
223
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90 focus-visible:bg-destructive/90"
224
+ >
225
+ {busy && (
226
+ <Icon
227
+ name="loader-circle"
228
+ size={13}
229
+ className="animate-spin motion-reduce:animate-none"
230
+ />
231
+ )}
232
+ {busy ? 'Revoking…' : 'Revoke'}
233
+ </Button>
234
+ </DialogFooter>
235
+ </DialogContent>
236
+ </Dialog>
237
+ );
238
+ }
239
+
240
+ function Invitations({ ctx }: { ctx: Context }) {
241
+ const { workspace } = ctx;
242
+ const { toast } = useToast();
243
+ const [clients, setClients] = React.useState<Client[]>();
244
+ const [failure, setFailure] = React.useState<Failure>();
245
+ const [invite, setInvite] = React.useState<Invite>();
246
+ const [creating, setCreating] = React.useState(false);
247
+ const [revoking, setRevoking] = React.useState<Client>();
248
+ // ponytail: the list refreshes when the screen opens and when the invite dialog closes; live, once a status event says so.
249
+ const load = React.useCallback(async () => {
250
+ try {
251
+ const res = await workspace.fetch('/_bridge/host/clients', { cache: 'no-store' });
252
+ setClients(((await readJson(res)) as { clients: Client[] }).clients);
253
+ setFailure(undefined);
254
+ } catch (cause) {
255
+ setFailure(failureOf(cause));
256
+ }
257
+ }, []);
258
+ React.useEffect(() => {
259
+ void load();
260
+ }, []);
261
+ const create = async () => {
262
+ setCreating(true);
263
+ try {
264
+ const res = await workspace.fetch('/_bridge/host/invitations', { method: 'POST' });
265
+ setInvite((await readJson(res)) as Invite);
266
+ } catch (cause) {
267
+ const { message, hint } = failureOf(cause);
268
+ toast({
269
+ variant: 'error',
270
+ title: 'Invite not created',
271
+ description: [message, hint].filter(Boolean).join(' '),
272
+ ...(cause instanceof HttpError && { duration: 8000 }),
273
+ });
274
+ } finally {
275
+ setCreating(false);
276
+ }
277
+ };
278
+ const revoke = async (client: Client) => {
279
+ try {
280
+ const res = await workspace.fetch(`/_bridge/host/clients/${encodeURIComponent(client.id)}`, {
281
+ method: 'DELETE',
282
+ });
283
+ // A refused answer throws here (an HttpError): the dialog shows its message and hint. A 404 is already revoked.
284
+ if (!res.ok && res.status !== 404) await readJson(res);
285
+ } catch (cause) {
286
+ return failureOf(cause);
287
+ }
288
+ setRevoking(undefined);
289
+ toast({ variant: 'success', title: `${client.label} revoked` });
290
+ void load();
291
+ return undefined;
292
+ };
293
+ return (
294
+ <section
295
+ aria-label="Screen"
296
+ data-invitations
297
+ className="flex min-h-0 flex-1 flex-col overflow-hidden [:where(&)_:is(p,ul,h1,h2)]:m-0"
298
+ >
299
+ <h1 className="sr-only">Invitations</h1>
300
+ <div className="mx-auto flex min-h-0 w-full max-w-[968px] flex-1">
301
+ <ScrollArea
302
+ className="min-h-0 min-w-0 flex-1"
303
+ viewportClassName="[&>[data-slot=scroll-area-content]]:min-w-0!"
304
+ >
305
+ <div className="box-border flex w-full max-w-[720px] flex-col gap-5 px-4 pb-16 pt-5">
306
+ <Section
307
+ size="lg"
308
+ title="Invite a client"
309
+ description="Pair the Bridge app of another machine with this Bridge: its workspaces show in that app's rail, next to its own. A paired client has Full access."
310
+ actions={
311
+ <Button variant="primary" disabled={creating} onClick={() => void create()}>
312
+ {creating ? (
313
+ <Icon
314
+ name="loader-circle"
315
+ size={13}
316
+ className="animate-spin motion-reduce:animate-none"
317
+ />
318
+ ) : (
319
+ <Icon name="user-plus" size={13} />
320
+ )}
321
+ Create invite
322
+ </Button>
323
+ }
324
+ />
325
+ <Section title="Paired clients">
326
+ {failure ? (
327
+ <div
328
+ role="alert"
329
+ className="flex items-center gap-3 rounded-default border border-destructive/30 bg-destructive-subtle px-3 py-2.5"
330
+ >
331
+ <p className="min-w-0 flex-1 text-[13px] text-destructive">
332
+ The paired clients could not be loaded: {failure.message}
333
+ {failure.hint && (
334
+ <span className="block text-xs text-secondary">{failure.hint}</span>
335
+ )}
336
+ </p>
337
+ <Button size="sm" variant="outline" onClick={() => void load()}>
338
+ <Icon name="rotate-cw" size={13} />
339
+ Retry
340
+ </Button>
341
+ </div>
342
+ ) : clients === undefined ? (
343
+ <p role="status" className="flex items-center gap-2 text-[13px] text-muted">
344
+ <Icon
345
+ name="loader-circle"
346
+ size={13}
347
+ className="animate-spin motion-reduce:animate-none"
348
+ />
349
+ Loading…
350
+ </p>
351
+ ) : clients.length === 0 ? (
352
+ <EmptyState
353
+ data-empty
354
+ className="rounded-default border border-dashed border-border py-6"
355
+ >
356
+ No paired client yet. Create an invite, then paste it in the Bridge app of the
357
+ other machine.
358
+ </EmptyState>
359
+ ) : (
360
+ <Card className="p-0">
361
+ <ul aria-label="Paired clients" className="m-0 flex list-none flex-col p-0">
362
+ {clients.map((client) => (
363
+ <li
364
+ key={client.id}
365
+ data-client={client.id}
366
+ className="flex items-center gap-3 border-b border-border-subtle px-3 py-2.5 last:border-b-0"
367
+ >
368
+ <Icon
369
+ name={deviceIcon(client.deviceType)}
370
+ size={16}
371
+ className="shrink-0 text-secondary"
372
+ />
373
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">
374
+ <span className="truncate text-sm font-medium text-foreground">
375
+ {client.label}
376
+ </span>
377
+ <span className="truncate text-xs text-secondary">
378
+ {[
379
+ client.deviceType !== 'unknown' &&
380
+ client.deviceType.charAt(0).toUpperCase() +
381
+ client.deviceType.slice(1),
382
+ client.os !== 'unknown' && client.os,
383
+ ]
384
+ .filter(Boolean)
385
+ .join(' · ') || 'Unknown device'}
386
+ {' · '}Paired {day(client.issuedAt)} · Last seen{' '}
387
+ {ago(client.lastSeenAt)}
388
+ </span>
389
+ </div>
390
+ <Badge className="shrink-0">Full</Badge>
391
+ <Button
392
+ size="sm"
393
+ variant="outline"
394
+ aria-label={`Revoke ${client.label}, paired ${day(client.issuedAt)}`}
395
+ onClick={() => setRevoking(client)}
396
+ >
397
+ Revoke
398
+ </Button>
399
+ </li>
400
+ ))}
401
+ </ul>
402
+ </Card>
403
+ )}
404
+ </Section>
405
+ </div>
406
+ </ScrollArea>
407
+ </div>
408
+ {invite && (
409
+ <InviteDialog
410
+ invite={invite}
411
+ onClose={() => {
412
+ setInvite(undefined);
413
+ void load();
414
+ }}
415
+ />
416
+ )}
417
+ {revoking && (
418
+ <RevokeDialog client={revoking} onClose={() => setRevoking(undefined)} revoke={revoke} />
419
+ )}
420
+ </section>
421
+ );
422
+ }
423
+
424
+ export function apply(ctx: Context) {
425
+ ctx.slots.register({ name: 'screen', key: name }, () => <Invitations ctx={ctx} />);
426
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "//": "The page (its tests are typed with the tests project): its services through the Bridge checkout this repository links (../../bridge), the contracts of the plugins it uses from their folders here.",
3
+ "extends": "../.bridge/tsconfig.browser.json",
4
+ "include": [
5
+ ".",
6
+ "../../bridge/packages/browser-boot/src/workspace.d.ts",
7
+ "../../bridge/vendor/types/client-build-environment.d.ts",
8
+ "../../shell/browser/shell.d.ts"
9
+ ],
10
+ "exclude": [
11
+ "./**/*.test.ts",
12
+ "./**/*.test.tsx"
13
+ ]
14
+ }
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@bridgebrew/invitations",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "description": "Invites another Bridge client (the desktop app on another machine) with Full access, and lists the paired clients with revoke. Admin only.",
6
+ "keywords": [
7
+ "bridge-plugin"
8
+ ],
9
+ "type": "module",
10
+ "files": [
11
+ "*.json",
12
+ "browser/",
13
+ "!**/*.test.ts",
14
+ "!**/*.test.tsx"
15
+ ],
16
+ "bridge": {
17
+ "kind": "extension",
18
+ "category": "standard",
19
+ "browser": "./browser/browser.tsx",
20
+ "section": {
21
+ "id": "system",
22
+ "title": "System"
23
+ },
24
+ "screen": {
25
+ "id": "invitations",
26
+ "title": "Invitations",
27
+ "icon": "user-plus"
28
+ },
29
+ "provenance": "official"
30
+ },
31
+ "peerDependencies": {
32
+ "@bridge/ui": ">=0.0.1",
33
+ "cordis": "4.0.0-rc.11",
34
+ "react": "19.3.0"
35
+ },
36
+ "releaseStage": "dev",
37
+ "scripts": {
38
+ "typecheck": "bridge plugin check ."
39
+ },
40
+ "engines": {
41
+ "bridge": ">=0.0.1-nightly.20261117.1"
42
+ }
43
+ }
package/tsconfig.json ADDED
@@ -0,0 +1 @@
1
+ { "extends": "./.bridge/tsconfig.json" }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.