@hyperframes/studio 0.9.26 → 0.9.28-alpha.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/dist/assets/{codec-BxQIoYb1.js → codec-D6qbrtZY.js} +1 -1
- package/dist/assets/{hyperframes-player-CPnasNX6.js → hyperframes-player-BVe9IO80.js} +1 -1
- package/dist/assets/{index-BDQdyS01.js → index-BZu8x7Q5.js} +1 -1
- package/dist/assets/{index-QCoqIBrS.js → index-Cl9fSd9I.js} +184 -184
- package/dist/assets/{index-dsfjBidg.css → index-Cq2w6U13.css} +1 -1
- package/dist/assets/{pausedVideoDecoder-CUTtHVKV.js → pausedVideoDecoder-DfnHfnL7.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/index.js +1855 -1211
- package/dist/styles.css +1 -1
- package/package.json +8 -8
- package/src/App.tsx +1 -0
- package/src/components/StudioHeader.tsx +4 -0
- package/src/components/share/QuickShare.test.tsx +548 -0
- package/src/components/share/QuickShare.tsx +102 -0
- package/src/components/share/QuickShareControls.tsx +243 -0
- package/src/components/share/ShareAudience.tsx +92 -0
- package/src/components/share/localShareClient.ts +171 -0
- package/src/components/share/localShareTelemetry.test.ts +22 -0
- package/src/components/share/localShareTelemetry.ts +13 -0
- package/src/components/share/useQuickShare.ts +189 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useMountEffect } from "../../hooks/useMountEffect";
|
|
3
|
+
import { Button, Popover } from "../ui";
|
|
4
|
+
import { shareBootstrap, safeShareUrl } from "./localShareClient";
|
|
5
|
+
import { useQuickShare } from "./useQuickShare";
|
|
6
|
+
import {
|
|
7
|
+
ShareSettings,
|
|
8
|
+
ShareNotices,
|
|
9
|
+
ShareActions,
|
|
10
|
+
ShareSourceStatus,
|
|
11
|
+
ShareLogin,
|
|
12
|
+
SharePlan,
|
|
13
|
+
} from "./QuickShareControls";
|
|
14
|
+
export function QuickShare({ beforeShare }: { beforeShare?: () => Promise<void> }) {
|
|
15
|
+
const [token, setToken] = useState<string | null>(null);
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
useMountEffect(() => {
|
|
18
|
+
if (!document.querySelector('meta[name="hyperframes-local-share"][content="1"]')) return;
|
|
19
|
+
const controller = new AbortController();
|
|
20
|
+
void shareBootstrap(controller.signal)
|
|
21
|
+
.then((value) => {
|
|
22
|
+
if (!controller.signal.aborted) setToken(value);
|
|
23
|
+
})
|
|
24
|
+
.catch(() => {});
|
|
25
|
+
return () => controller.abort();
|
|
26
|
+
});
|
|
27
|
+
if (!token) return null;
|
|
28
|
+
return (
|
|
29
|
+
<Popover
|
|
30
|
+
open={open}
|
|
31
|
+
onOpenChange={setOpen}
|
|
32
|
+
align="end"
|
|
33
|
+
aria-label="Share project"
|
|
34
|
+
trigger={<Button variant="secondary">Share</Button>}
|
|
35
|
+
className="w-96 max-w-[calc(100vw-2rem)] rounded-2xl p-4"
|
|
36
|
+
>
|
|
37
|
+
{open ? <QuickShareContent token={token} beforeShare={beforeShare} /> : null}
|
|
38
|
+
</Popover>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function QuickShareContent({
|
|
43
|
+
token,
|
|
44
|
+
beforeShare,
|
|
45
|
+
}: {
|
|
46
|
+
token: string;
|
|
47
|
+
beforeShare?: () => Promise<void>;
|
|
48
|
+
}) {
|
|
49
|
+
const model = useQuickShare(token, beforeShare);
|
|
50
|
+
const { snapshot, progress, error } = model;
|
|
51
|
+
const url = safeShareUrl(snapshot?.share.url ?? "");
|
|
52
|
+
const manageUrl = safeShareUrl(snapshot?.share.manageUrl ?? "");
|
|
53
|
+
return (
|
|
54
|
+
<div className="flex flex-col gap-3 text-step-13">
|
|
55
|
+
<div>
|
|
56
|
+
<h2 className="text-step-15 font-semibold">Share project</h2>
|
|
57
|
+
<p className="mt-1 text-step-11 text-text-3">Share the latest saved project.</p>
|
|
58
|
+
</div>
|
|
59
|
+
{snapshot ? (
|
|
60
|
+
<>
|
|
61
|
+
<ShareSettings model={model} snapshot={snapshot} />
|
|
62
|
+
<ShareNotices model={model} snapshot={snapshot} />
|
|
63
|
+
<ShareSourceStatus model={model} snapshot={snapshot} />
|
|
64
|
+
<ShareActions model={model} snapshot={snapshot} url={url} />
|
|
65
|
+
<SharePlan model={model} snapshot={snapshot} />
|
|
66
|
+
</>
|
|
67
|
+
) : null}
|
|
68
|
+
{!snapshot && !error ? <p role="status">Loading sharing…</p> : null}
|
|
69
|
+
{progress ? (
|
|
70
|
+
<p role="status">{progress} You can close this panel; keep Studio running.</p>
|
|
71
|
+
) : null}
|
|
72
|
+
<ShareLogin model={model} />
|
|
73
|
+
{error ? (
|
|
74
|
+
<p role="alert" className="text-step-11 text-text-2">
|
|
75
|
+
{error}
|
|
76
|
+
</p>
|
|
77
|
+
) : null}
|
|
78
|
+
<div className="flex flex-wrap items-center gap-2 border-t border-border pt-3">
|
|
79
|
+
{manageUrl ? (
|
|
80
|
+
<a
|
|
81
|
+
href={manageUrl}
|
|
82
|
+
target="_blank"
|
|
83
|
+
rel="noreferrer"
|
|
84
|
+
className="flex h-8 items-center rounded-full px-2 text-step-12 text-text-2 hover:bg-hover"
|
|
85
|
+
>
|
|
86
|
+
Manage sharing
|
|
87
|
+
</a>
|
|
88
|
+
) : null}
|
|
89
|
+
{url ? (
|
|
90
|
+
<a
|
|
91
|
+
href={url}
|
|
92
|
+
target="_blank"
|
|
93
|
+
rel="noreferrer"
|
|
94
|
+
className="flex h-8 items-center rounded-full px-2 text-step-12 text-text-2 hover:bg-hover"
|
|
95
|
+
>
|
|
96
|
+
Open shared page
|
|
97
|
+
</a>
|
|
98
|
+
) : null}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type { LocalShareSnapshot } from "@hyperframes/studio-server";
|
|
2
|
+
import { Button } from "../ui";
|
|
3
|
+
import { ShareAudience } from "./ShareAudience";
|
|
4
|
+
import { Link, ArrowUpRight } from "@phosphor-icons/react";
|
|
5
|
+
import type { QuickShareModel } from "./useQuickShare";
|
|
6
|
+
|
|
7
|
+
type Props = { model: QuickShareModel; snapshot: LocalShareSnapshot };
|
|
8
|
+
export function ShareSettings({ model, snapshot }: Props) {
|
|
9
|
+
return <ShareAudience model={model} snapshot={snapshot} />;
|
|
10
|
+
}
|
|
11
|
+
export function ShareNotices({ model, snapshot }: Props) {
|
|
12
|
+
const { share } = snapshot;
|
|
13
|
+
const messages = [
|
|
14
|
+
model.audience === "invite" ? "Add people from Manage sharing after creating the link." : null,
|
|
15
|
+
share.changed
|
|
16
|
+
? "Local changes aren’t shared yet. Update the shared version when you’re ready."
|
|
17
|
+
: share.changed === null
|
|
18
|
+
? "Changes after your last upload aren’t shared automatically. Update to share the current project."
|
|
19
|
+
: null,
|
|
20
|
+
share.state === "link_off" ? "The link is off. Updating the video keeps it off." : null,
|
|
21
|
+
share.state === "processing" && !model.busy && snapshot.job?.state !== "failed"
|
|
22
|
+
? "The shared video is still being prepared. Reopen sharing to check its status."
|
|
23
|
+
: null,
|
|
24
|
+
share.state === "unavailable" ? "Sharing is paused. Open Manage sharing for details." : null,
|
|
25
|
+
!snapshot.versionSharing && share.state === "not_shared"
|
|
26
|
+
? "Sharing isn’t available for this account yet."
|
|
27
|
+
: null,
|
|
28
|
+
];
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
{share.state === "failed" && share.failure ? (
|
|
32
|
+
<p role="alert" className="text-step-11 text-text-3">
|
|
33
|
+
{share.failure}
|
|
34
|
+
</p>
|
|
35
|
+
) : null}
|
|
36
|
+
{messages.filter(Boolean).map((message) => (
|
|
37
|
+
<p key={message} className="text-step-11 text-text-3">
|
|
38
|
+
{message}
|
|
39
|
+
</p>
|
|
40
|
+
))}
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
export function ShareActions({ model, snapshot, url }: Props & { url: string | null }) {
|
|
45
|
+
if (snapshot.share.state === "not_shared")
|
|
46
|
+
return <CreateShare model={model} snapshot={snapshot} />;
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
{url ? <CopyShare model={model} snapshot={snapshot} url={url} /> : null}
|
|
50
|
+
{snapshot.versionSharing && snapshot.share.state !== "unavailable" ? (
|
|
51
|
+
<Button
|
|
52
|
+
className="h-9 rounded-lg"
|
|
53
|
+
variant={snapshot.share.changed !== false ? "primary" : "secondary"}
|
|
54
|
+
disabled={model.busy}
|
|
55
|
+
onClick={() => void model.run({ action: "update" })}
|
|
56
|
+
>
|
|
57
|
+
{(snapshot.job?.state === "failed" || snapshot.share.state === "failed") &&
|
|
58
|
+
snapshot.share.hasReadyVersion === false
|
|
59
|
+
? "Create share link"
|
|
60
|
+
: "Update shared version"}
|
|
61
|
+
</Button>
|
|
62
|
+
) : null}
|
|
63
|
+
<ManageShare model={model} snapshot={snapshot} url={url} />
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
function CreateShare({ model, snapshot }: Props) {
|
|
68
|
+
const space = snapshot.spaces.find((item) => item.id === model.spaceId);
|
|
69
|
+
const canCreate = snapshot.versionSharing && space?.canCreate && model.audience !== "";
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
{!space || !space.canCreate ? (
|
|
73
|
+
<p className="text-step-11 text-text-3">
|
|
74
|
+
Sharing isn’t available in the workspace selected at sign-in. Sign in with an accessible
|
|
75
|
+
workspace to continue.
|
|
76
|
+
</p>
|
|
77
|
+
) : null}
|
|
78
|
+
<Button
|
|
79
|
+
variant="primary"
|
|
80
|
+
className="h-9 self-end rounded-lg px-3 text-step-13"
|
|
81
|
+
disabled={model.busy || !canCreate}
|
|
82
|
+
onClick={() => {
|
|
83
|
+
if (model.audience)
|
|
84
|
+
void model.run({ action: "share", audience: model.audience, space: model.spaceId });
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
Create share link
|
|
88
|
+
</Button>
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function CopyShare({ model, snapshot, url }: Props & { url: string }) {
|
|
93
|
+
const label = model.copied
|
|
94
|
+
? "Copied"
|
|
95
|
+
: snapshot.share.changed !== false
|
|
96
|
+
? "Copy current shared link"
|
|
97
|
+
: "Copy link";
|
|
98
|
+
return (
|
|
99
|
+
<div className="flex min-w-0 items-center gap-2 rounded-xl border border-border p-2.5">
|
|
100
|
+
<span
|
|
101
|
+
className="min-w-0 flex-1 truncate rounded-lg bg-press px-2.5 py-2 font-mono text-step-11 text-text-3"
|
|
102
|
+
title={url}
|
|
103
|
+
>
|
|
104
|
+
{url.replace(/^https:\/\//, "")}
|
|
105
|
+
</span>
|
|
106
|
+
<Button
|
|
107
|
+
className="h-9 shrink-0 rounded-lg px-3 text-step-12"
|
|
108
|
+
variant={snapshot.share.changed !== false ? "secondary" : "primary"}
|
|
109
|
+
disabled={model.busy}
|
|
110
|
+
onClick={() => void model.copy(url)}
|
|
111
|
+
>
|
|
112
|
+
<Link size={15} aria-hidden="true" />
|
|
113
|
+
{label}
|
|
114
|
+
</Button>
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
function ManageShare({ model, snapshot, url }: Props & { url: string | null }) {
|
|
119
|
+
return (
|
|
120
|
+
<div className="flex flex-wrap items-center justify-end gap-1">
|
|
121
|
+
{model.audience && model.audience !== snapshot.share.audience ? (
|
|
122
|
+
<Button
|
|
123
|
+
variant="ghost"
|
|
124
|
+
className="h-8 rounded-full text-step-13"
|
|
125
|
+
disabled={model.busy}
|
|
126
|
+
onClick={() => {
|
|
127
|
+
if (model.audience) void model.run({ action: "access", audience: model.audience });
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
Save access
|
|
131
|
+
</Button>
|
|
132
|
+
) : null}
|
|
133
|
+
{snapshot.share.state === "link_off" ? (
|
|
134
|
+
<Button disabled={model.busy} onClick={() => void model.run({ action: "on" })}>
|
|
135
|
+
Turn link on
|
|
136
|
+
</Button>
|
|
137
|
+
) : null}
|
|
138
|
+
{url ? (
|
|
139
|
+
<Button
|
|
140
|
+
variant="ghost"
|
|
141
|
+
className="h-8 rounded-full text-step-13"
|
|
142
|
+
disabled={model.busy}
|
|
143
|
+
onClick={() => {
|
|
144
|
+
if (
|
|
145
|
+
window.confirm(
|
|
146
|
+
"Turn off this link? Everyone using the link loses access. Comments are kept.",
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
void model.run({ action: "off" });
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
Turn link off
|
|
153
|
+
</Button>
|
|
154
|
+
) : null}
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function ShareSourceStatus({ model, snapshot }: Props) {
|
|
160
|
+
const last = snapshot.job?.result;
|
|
161
|
+
const recover = snapshot.job?.error?.code === "source_unavailable";
|
|
162
|
+
let message = "Project files are checked when you share.";
|
|
163
|
+
if (last?.source === "video_only")
|
|
164
|
+
message = "Last Studio upload: video only. Project files weren’t included.";
|
|
165
|
+
if (last?.source === "ready")
|
|
166
|
+
message =
|
|
167
|
+
last.state === "ready"
|
|
168
|
+
? "Last Studio upload: project files included."
|
|
169
|
+
: "Project files are ready; sharing is still processing.";
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<p className="text-step-11 text-text-3">{message}</p>
|
|
173
|
+
{recover ? (
|
|
174
|
+
<Button
|
|
175
|
+
variant="ghost"
|
|
176
|
+
className="h-8 rounded-full text-step-13"
|
|
177
|
+
disabled={model.busy}
|
|
178
|
+
onClick={() => void model.run({ action: "update", videoOnly: true })}
|
|
179
|
+
>
|
|
180
|
+
Retry with video only
|
|
181
|
+
</Button>
|
|
182
|
+
) : null}
|
|
183
|
+
</>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function ShareLogin({ model }: { model: QuickShareModel }) {
|
|
188
|
+
if (
|
|
189
|
+
!model.errorCode ||
|
|
190
|
+
![
|
|
191
|
+
"not_configured",
|
|
192
|
+
"unauthenticated",
|
|
193
|
+
"login_expired",
|
|
194
|
+
"login_changed",
|
|
195
|
+
"refresh_failed",
|
|
196
|
+
"device_auth_failed",
|
|
197
|
+
].includes(model.errorCode)
|
|
198
|
+
)
|
|
199
|
+
return null;
|
|
200
|
+
return (
|
|
201
|
+
<>
|
|
202
|
+
<Button
|
|
203
|
+
variant="primary"
|
|
204
|
+
disabled={model.busy}
|
|
205
|
+
onClick={() => void model.run({ action: "login" })}
|
|
206
|
+
>
|
|
207
|
+
Sign in
|
|
208
|
+
</Button>
|
|
209
|
+
<p className="text-step-11 text-text-3">
|
|
210
|
+
Or run <code>hyperframes auth login</code> in your terminal, then return to Studio. Sharing
|
|
211
|
+
reconnects automatically.
|
|
212
|
+
</p>
|
|
213
|
+
</>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function SharePlan({ model, snapshot }: Props) {
|
|
218
|
+
const space = snapshot.spaces.find((item) => item.id === model.spaceId);
|
|
219
|
+
const upgrade = space?.upgradeUrl;
|
|
220
|
+
const allowed =
|
|
221
|
+
upgrade &&
|
|
222
|
+
["https://hyperframes.dev/pricing", "https://dev.hyperframes.dev/pricing"].includes(upgrade);
|
|
223
|
+
return (
|
|
224
|
+
<div className="flex flex-wrap items-center justify-between gap-2 text-step-12">
|
|
225
|
+
{space && space.limit !== null && space.used !== null ? (
|
|
226
|
+
<span className="text-text-3 tabular-nums">
|
|
227
|
+
{space.used} of {space.limit} free share links used
|
|
228
|
+
</span>
|
|
229
|
+
) : null}
|
|
230
|
+
{space?.plan === "free" && allowed ? (
|
|
231
|
+
<a
|
|
232
|
+
href={upgrade}
|
|
233
|
+
target="_blank"
|
|
234
|
+
rel="noreferrer"
|
|
235
|
+
className="inline-flex h-8 items-center gap-1 rounded-full px-2 font-semibold text-accent hover:bg-hover"
|
|
236
|
+
>
|
|
237
|
+
Upgrade to Pro
|
|
238
|
+
<ArrowUpRight size={13} aria-hidden="true" />
|
|
239
|
+
</a>
|
|
240
|
+
) : null}
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CaretDown, Globe, Lock, Users, UserPlus } from "@phosphor-icons/react";
|
|
2
|
+
import type { LocalShareAudience, LocalShareSnapshot } from "@hyperframes/studio-server";
|
|
3
|
+
import { Menu, MenuRadioGroup, MenuRadioItem } from "../ui";
|
|
4
|
+
import { isAudience } from "./localShareClient";
|
|
5
|
+
import type { QuickShareModel } from "./useQuickShare";
|
|
6
|
+
|
|
7
|
+
const AUDIENCES = {
|
|
8
|
+
public: { label: "Anyone with the link", detail: "Anyone you send the link to", icon: Globe },
|
|
9
|
+
team: {
|
|
10
|
+
label: "Anyone in this workspace",
|
|
11
|
+
detail: "People in your signed-in workspace",
|
|
12
|
+
icon: Users,
|
|
13
|
+
},
|
|
14
|
+
invite: {
|
|
15
|
+
label: "Only invited people",
|
|
16
|
+
detail: "People you add in Manage sharing",
|
|
17
|
+
icon: UserPlus,
|
|
18
|
+
},
|
|
19
|
+
private: { label: "Only you", detail: "This existing share is private", icon: Lock },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function ShareAudience({
|
|
23
|
+
model,
|
|
24
|
+
snapshot,
|
|
25
|
+
}: {
|
|
26
|
+
model: QuickShareModel;
|
|
27
|
+
snapshot: LocalShareSnapshot;
|
|
28
|
+
}) {
|
|
29
|
+
const selected = model.audience ? AUDIENCES[model.audience] : null;
|
|
30
|
+
const Icon = selected?.icon ?? Lock;
|
|
31
|
+
const space = snapshot.spaces.find((item) => item.id === model.spaceId);
|
|
32
|
+
const choices: LocalShareAudience[] = ["public", "team", "invite"];
|
|
33
|
+
if (snapshot.share.audience === "private") choices.push("private");
|
|
34
|
+
return (
|
|
35
|
+
<Menu
|
|
36
|
+
aria-label="Who can access"
|
|
37
|
+
className="w-80 max-w-[calc(100vw-2rem)] rounded-xl p-1.5"
|
|
38
|
+
trigger={
|
|
39
|
+
<button
|
|
40
|
+
type="button"
|
|
41
|
+
aria-label="Who can access"
|
|
42
|
+
disabled={model.busy || snapshot.share.state === "unavailable"}
|
|
43
|
+
className="flex min-h-11 w-full items-center gap-2.5 rounded-xl px-1.5 py-1.5 text-left text-step-13 hover:bg-hover disabled:opacity-40"
|
|
44
|
+
>
|
|
45
|
+
<span className="grid size-8 shrink-0 place-items-center rounded-full bg-press text-text-2">
|
|
46
|
+
<Icon size={16} aria-hidden="true" />
|
|
47
|
+
</span>
|
|
48
|
+
<span className="min-w-0 flex-1 font-semibold">
|
|
49
|
+
{selected?.label ?? "Choose who can access"}
|
|
50
|
+
</span>
|
|
51
|
+
<CaretDown size={14} aria-hidden="true" />
|
|
52
|
+
</button>
|
|
53
|
+
}
|
|
54
|
+
>
|
|
55
|
+
<MenuRadioGroup
|
|
56
|
+
value={model.audience}
|
|
57
|
+
onValueChange={(value) => {
|
|
58
|
+
if (isAudience(value)) model.setAudience(value);
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{choices.map((value) => {
|
|
62
|
+
const option = AUDIENCES[value];
|
|
63
|
+
const OptionIcon = option.icon;
|
|
64
|
+
return (
|
|
65
|
+
<MenuRadioItem
|
|
66
|
+
key={value}
|
|
67
|
+
value={value}
|
|
68
|
+
closeOnClick
|
|
69
|
+
disabled={
|
|
70
|
+
model.busy ||
|
|
71
|
+
(!space?.audiences.includes(value) && value !== snapshot.share.audience)
|
|
72
|
+
}
|
|
73
|
+
className="h-auto min-h-12 rounded-lg px-2 py-2 text-step-13"
|
|
74
|
+
>
|
|
75
|
+
<span className="flex items-center gap-2.5">
|
|
76
|
+
<span className="grid size-7 shrink-0 place-items-center rounded-full bg-press text-text-2">
|
|
77
|
+
<OptionIcon size={15} aria-hidden="true" />
|
|
78
|
+
</span>
|
|
79
|
+
<span className="min-w-0 leading-snug">
|
|
80
|
+
<span className="block font-semibold">{option.label}</span>
|
|
81
|
+
<span className="block whitespace-normal text-step-11 text-text-3">
|
|
82
|
+
{option.detail}
|
|
83
|
+
</span>
|
|
84
|
+
</span>
|
|
85
|
+
</span>
|
|
86
|
+
</MenuRadioItem>
|
|
87
|
+
);
|
|
88
|
+
})}
|
|
89
|
+
</MenuRadioGroup>
|
|
90
|
+
</Menu>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LocalShareAction,
|
|
3
|
+
LocalShareAudience,
|
|
4
|
+
LocalShareJob,
|
|
5
|
+
LocalShareSnapshot,
|
|
6
|
+
LocalShareState,
|
|
7
|
+
LocalShareSpace,
|
|
8
|
+
} from "@hyperframes/studio-server";
|
|
9
|
+
import { studioApiFetch } from "../../utils/studioApiFetch";
|
|
10
|
+
|
|
11
|
+
const audiences: readonly LocalShareAudience[] = ["public", "team", "invite", "private"];
|
|
12
|
+
const record = (value: unknown): value is Record<string, unknown> =>
|
|
13
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
const text = (value: unknown): value is string => typeof value === "string";
|
|
15
|
+
const nullableText = (value: unknown): value is string | null => value === null || text(value);
|
|
16
|
+
const nullableBoolean = (value: unknown): value is boolean | null =>
|
|
17
|
+
value === null || typeof value === "boolean";
|
|
18
|
+
const nullableNumber = (value: unknown): value is number | null =>
|
|
19
|
+
value === null || (typeof value === "number" && Number.isFinite(value));
|
|
20
|
+
export const isAudience = (value: unknown): value is LocalShareAudience =>
|
|
21
|
+
audiences.some((mode) => mode === value);
|
|
22
|
+
function isState(value: unknown): value is LocalShareState {
|
|
23
|
+
return (
|
|
24
|
+
record(value) &&
|
|
25
|
+
["not_shared", "link_off", "ready", "processing", "failed", "unavailable"].includes(
|
|
26
|
+
String(value.state),
|
|
27
|
+
) &&
|
|
28
|
+
optionalFailure(value.failure) &&
|
|
29
|
+
nullableText(value.url) &&
|
|
30
|
+
text(value.manageUrl) &&
|
|
31
|
+
nullableBoolean(value.changed) &&
|
|
32
|
+
nullableAudience(value.audience) &&
|
|
33
|
+
nullableText(value.spaceId) &&
|
|
34
|
+
["not_checked", "ready", "video_only"].includes(String(value.source))
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
function isSpace(value: unknown): value is LocalShareSpace {
|
|
38
|
+
return (
|
|
39
|
+
record(value) &&
|
|
40
|
+
text(value.id) &&
|
|
41
|
+
text(value.name) &&
|
|
42
|
+
typeof value.bound === "boolean" &&
|
|
43
|
+
typeof value.canCreate === "boolean" &&
|
|
44
|
+
Array.isArray(value.audiences) &&
|
|
45
|
+
value.audiences.every(isAudience) &&
|
|
46
|
+
nullableNumber(value.used) &&
|
|
47
|
+
nullableNumber(value.limit)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function isError(value: unknown): boolean {
|
|
51
|
+
return value === null || (record(value) && text(value.code) && text(value.message));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isJob(value: unknown): value is LocalShareJob {
|
|
55
|
+
return (
|
|
56
|
+
record(value) &&
|
|
57
|
+
text(value.id) &&
|
|
58
|
+
["running", "done", "failed"].includes(String(value.state)) &&
|
|
59
|
+
text(value.step) &&
|
|
60
|
+
(value.result === null || isState(value.result)) &&
|
|
61
|
+
isError(value.error)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function isSnapshot(value: unknown): value is LocalShareSnapshot {
|
|
65
|
+
return (
|
|
66
|
+
record(value) &&
|
|
67
|
+
typeof value.versionSharing === "boolean" &&
|
|
68
|
+
isState(value.share) &&
|
|
69
|
+
Array.isArray(value.spaces) &&
|
|
70
|
+
value.spaces.every(isSpace) &&
|
|
71
|
+
(value.job === null || isJob(value.job))
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
export class LocalShareError extends Error {
|
|
75
|
+
constructor(
|
|
76
|
+
public readonly code: string,
|
|
77
|
+
message: string,
|
|
78
|
+
public readonly job: LocalShareJob | null = null,
|
|
79
|
+
) {
|
|
80
|
+
super(message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function json(
|
|
84
|
+
path: string,
|
|
85
|
+
token: string | null,
|
|
86
|
+
signal: AbortSignal,
|
|
87
|
+
action?: LocalShareAction,
|
|
88
|
+
): Promise<unknown> {
|
|
89
|
+
const response = await studioApiFetch(`/api/share/${path}`, {
|
|
90
|
+
method: action ? "POST" : "GET",
|
|
91
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(30_000)]),
|
|
92
|
+
headers: {
|
|
93
|
+
...(token ? { "X-Hyperframes-Share-CSRF": token } : {}),
|
|
94
|
+
...(action ? { "Content-Type": "application/json" } : {}),
|
|
95
|
+
},
|
|
96
|
+
...(action ? { body: JSON.stringify(action) } : {}),
|
|
97
|
+
});
|
|
98
|
+
const body: unknown = await response.json().catch(() => null);
|
|
99
|
+
if (!response.ok) throw responseError(body);
|
|
100
|
+
return body;
|
|
101
|
+
}
|
|
102
|
+
function responseError(body: unknown): LocalShareError {
|
|
103
|
+
const code = record(body) && text(body.code) ? body.code : "unavailable";
|
|
104
|
+
const message =
|
|
105
|
+
record(body) && text(body.message)
|
|
106
|
+
? body.message
|
|
107
|
+
: "Sharing is unavailable. Try again from a local Studio preview.";
|
|
108
|
+
const job = record(body) && isJob(body.job) ? body.job : null;
|
|
109
|
+
return new LocalShareError(code, message, job);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function shareBootstrap(signal: AbortSignal): Promise<string> {
|
|
113
|
+
const value = await json("bootstrap", null, signal);
|
|
114
|
+
if (!record(value) || !text(value.csrf) || !/^[A-Za-z0-9_-]{43}$/.test(value.csrf))
|
|
115
|
+
throw new LocalShareError("unavailable", "Sharing is not available in this Studio host.");
|
|
116
|
+
return value.csrf;
|
|
117
|
+
}
|
|
118
|
+
export async function shareSnapshot(
|
|
119
|
+
token: string,
|
|
120
|
+
signal: AbortSignal,
|
|
121
|
+
): Promise<LocalShareSnapshot> {
|
|
122
|
+
const value = await json("snapshot", token, signal);
|
|
123
|
+
if (!isSnapshot(value))
|
|
124
|
+
throw new LocalShareError(
|
|
125
|
+
"unavailable",
|
|
126
|
+
"Sharing returned an unreadable response. Refresh Studio.",
|
|
127
|
+
);
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
export async function shareAction(
|
|
131
|
+
token: string,
|
|
132
|
+
action: LocalShareAction,
|
|
133
|
+
signal: AbortSignal,
|
|
134
|
+
): Promise<LocalShareJob> {
|
|
135
|
+
const value = await json("actions", token, signal, action);
|
|
136
|
+
if (!isJob(value))
|
|
137
|
+
throw new LocalShareError(
|
|
138
|
+
"unavailable",
|
|
139
|
+
"Could not start sharing. Refresh to check its status.",
|
|
140
|
+
);
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
export async function shareJob(
|
|
144
|
+
token: string,
|
|
145
|
+
id: string,
|
|
146
|
+
signal: AbortSignal,
|
|
147
|
+
): Promise<LocalShareJob> {
|
|
148
|
+
const value = await json(`jobs/${encodeURIComponent(id)}`, token, signal);
|
|
149
|
+
if (!isJob(value))
|
|
150
|
+
throw new LocalShareError(
|
|
151
|
+
"unavailable",
|
|
152
|
+
"Could not read sharing progress. Refresh to check its status.",
|
|
153
|
+
);
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
export function safeShareUrl(value: string): string | null {
|
|
157
|
+
try {
|
|
158
|
+
const url = new URL(value);
|
|
159
|
+
return url.protocol === "https:" && !url.username && !url.password ? url.href : null;
|
|
160
|
+
} catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function optionalFailure(value: unknown): boolean {
|
|
166
|
+
return value === undefined || nullableText(value);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function nullableAudience(value: unknown): boolean {
|
|
170
|
+
return value === null || isAudience(value);
|
|
171
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
const policy = vi.hoisted(() => vi.fn());
|
|
3
|
+
vi.mock("../../telemetry/policy", () => ({ browserTelemetryAllowed: policy }));
|
|
4
|
+
import { shareInteraction } from "./localShareTelemetry";
|
|
5
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
6
|
+
it("obeys browser opt-out before calling the guarded local bridge", async () => {
|
|
7
|
+
const fetch = vi.fn(async () => new Response(null, { status: 204 }));
|
|
8
|
+
vi.stubGlobal("fetch", fetch);
|
|
9
|
+
policy.mockReturnValue(false);
|
|
10
|
+
shareInteraction("token", { event: "share_opened", link: "none" });
|
|
11
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
12
|
+
policy.mockReturnValue(true);
|
|
13
|
+
shareInteraction("token", { event: "share_link_copied", via: "copy" });
|
|
14
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
15
|
+
"/api/share/events",
|
|
16
|
+
expect.objectContaining({
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: { "Content-Type": "application/json", "X-Hyperframes-Share-CSRF": "token" },
|
|
19
|
+
body: JSON.stringify({ event: "share_link_copied", via: "copy" }),
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LocalShareInteraction } from "@hyperframes/studio-server";
|
|
2
|
+
import { browserTelemetryAllowed } from "../../telemetry/policy";
|
|
3
|
+
import { studioApiFetch } from "../../utils/studioApiFetch";
|
|
4
|
+
|
|
5
|
+
export function shareInteraction(token: string, event: LocalShareInteraction): void {
|
|
6
|
+
if (!browserTelemetryAllowed()) return;
|
|
7
|
+
void studioApiFetch("/api/share/events", {
|
|
8
|
+
method: "POST",
|
|
9
|
+
signal: AbortSignal.timeout(5000),
|
|
10
|
+
headers: { "Content-Type": "application/json", "X-Hyperframes-Share-CSRF": token },
|
|
11
|
+
body: JSON.stringify(event),
|
|
12
|
+
}).catch(() => {});
|
|
13
|
+
}
|