@hyperframes/share 0.9.71 → 0.9.74
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/reviewClient.d.mts +6 -3
- package/dist/reviewShare.d.mts +3 -1
- package/package.json +1 -1
- package/src/reviewClient.mjs +13 -4
- package/src/reviewShare.mjs +52 -6
package/dist/reviewClient.d.mts
CHANGED
|
@@ -63,10 +63,13 @@ export function reviewClient({ access, fetchImpl, signedInEmail }: {
|
|
|
63
63
|
versionSharing: boolean;
|
|
64
64
|
shareFiles: boolean;
|
|
65
65
|
}>;
|
|
66
|
-
/** Registers into `spaceId`; without one the server uses the caller's default space.
|
|
66
|
+
/** Registers into `spaceId`; without one the server uses the caller's default space. `created` is true only for
|
|
67
|
+
* a 201: a 200 answers a project that was already bound to this `studio_project_id`.
|
|
67
68
|
* @param {import("./types/reviewWire.js").RegisterProjectRequest} body @param {string | null} [spaceId]
|
|
68
|
-
* @returns {Promise<ProjectDTO>} */
|
|
69
|
-
register: (body: import("./types/reviewWire.js").RegisterProjectRequest, spaceId?: string | null) => Promise<ProjectDTO
|
|
69
|
+
* @returns {Promise<ProjectDTO & { created: boolean }>} */
|
|
70
|
+
register: (body: import("./types/reviewWire.js").RegisterProjectRequest, spaceId?: string | null) => Promise<ProjectDTO & {
|
|
71
|
+
created: boolean;
|
|
72
|
+
}>;
|
|
70
73
|
/** @param {string} id @returns {Promise<ShareDTO>} */
|
|
71
74
|
share: (id: string) => Promise<ShareDTO>;
|
|
72
75
|
/** @param {string} id @param {import("./types/reviewWire.js").UpdateProjectShareRequest} body
|
package/dist/reviewShare.d.mts
CHANGED
|
@@ -64,13 +64,14 @@ export function reviewSwitchPath(projectPath: string): string;
|
|
|
64
64
|
export function onRebound(listener: (projectPath: string) => void): undefined;
|
|
65
65
|
export function setAsideReview(projectPath: string): Promise<void>;
|
|
66
66
|
export function readShare(client: ReviewClient, id: string, projectPath?: string): Promise<import("./types/reviewWire.js").ShareDTO>;
|
|
67
|
-
export function shareForReview({ projectPath, title, client, spaceId, audience, beforeOpen, }: {
|
|
67
|
+
export function shareForReview({ projectPath, title, client, spaceId, audience, beforeOpen, confirmed, }: {
|
|
68
68
|
projectPath: string;
|
|
69
69
|
title: string;
|
|
70
70
|
client: ReviewClient;
|
|
71
71
|
spaceId?: string | null;
|
|
72
72
|
audience?: import("./types/share.js").AccessMode | undefined;
|
|
73
73
|
beforeOpen?: (projectId: string) => Promise<void>;
|
|
74
|
+
confirmed?: string | null;
|
|
74
75
|
}): Promise<import("./types/share.js").ReviewShare>;
|
|
75
76
|
export function setReviewAccess({ projectPath, client, change }: {
|
|
76
77
|
projectPath: string;
|
|
@@ -85,6 +86,7 @@ export function markReviewRemoved(projectPath: string, projectId: string): Promi
|
|
|
85
86
|
export function removeLocalReview(projectPath: string, projectId: string, client: ReviewClient): Promise<void>;
|
|
86
87
|
export type ReviewClient = import("./reviewClient.mjs").ReviewClient;
|
|
87
88
|
export type ShareDTO = import("./types/reviewWire.js").ShareDTO;
|
|
89
|
+
export type ProjectDTO = import("./types/reviewWire.js").ProjectDTO;
|
|
88
90
|
export type ReviewShare = import("./types/share.js").ReviewShare;
|
|
89
91
|
export type ReviewSpace = import("./types/share.js").ReviewSpace;
|
|
90
92
|
export type ReviewAccessChange = import("./types/share.js").ReviewAccessChange;
|
package/package.json
CHANGED
package/src/reviewClient.mjs
CHANGED
|
@@ -99,11 +99,20 @@ export function reviewClient({ access, fetchImpl = fetch, signedInEmail = async
|
|
|
99
99
|
shareFiles: data?.share_files === true,
|
|
100
100
|
};
|
|
101
101
|
},
|
|
102
|
-
/** Registers into `spaceId`; without one the server uses the caller's default space.
|
|
102
|
+
/** Registers into `spaceId`; without one the server uses the caller's default space. `created` is true only for
|
|
103
|
+
* a 201: a 200 answers a project that was already bound to this `studio_project_id`.
|
|
103
104
|
* @param {import("./types/reviewWire.js").RegisterProjectRequest} body @param {string | null} [spaceId]
|
|
104
|
-
* @returns {Promise<ProjectDTO>} */
|
|
105
|
-
register: (body, spaceId) =>
|
|
106
|
-
|
|
105
|
+
* @returns {Promise<ProjectDTO & { created: boolean }>} */
|
|
106
|
+
register: async (body, spaceId) => {
|
|
107
|
+
const { reply } = await request(
|
|
108
|
+
"POST",
|
|
109
|
+
PROJECTS,
|
|
110
|
+
body,
|
|
111
|
+
spaceId ? { "x-space-id": spaceId } : {},
|
|
112
|
+
null,
|
|
113
|
+
);
|
|
114
|
+
return { ...(await dataOf(reply, `POST ${PROJECTS}`)), created: reply.status === 201 };
|
|
115
|
+
},
|
|
107
116
|
/** @param {string} id @returns {Promise<ShareDTO>} */
|
|
108
117
|
share: (id) => call("GET", `${project(id)}/share`),
|
|
109
118
|
/** @param {string} id @param {import("./types/reviewWire.js").UpdateProjectShareRequest} body
|
package/src/reviewShare.mjs
CHANGED
|
@@ -21,7 +21,8 @@ import { ReviewFailed } from "./reviewClient.mjs";
|
|
|
21
21
|
import { rename } from "./storage.mjs";
|
|
22
22
|
|
|
23
23
|
/** @typedef {import("./reviewClient.mjs").ReviewClient} ReviewClient
|
|
24
|
-
* @typedef {import("./types/reviewWire.js").ShareDTO} ShareDTO
|
|
24
|
+
* @typedef {import("./types/reviewWire.js").ShareDTO} ShareDTO
|
|
25
|
+
* @typedef {import("./types/reviewWire.js").ProjectDTO} ProjectDTO */
|
|
25
26
|
|
|
26
27
|
/** @typedef {import("./types/share.js").ReviewShare} ReviewShare
|
|
27
28
|
* @typedef {import("./types/share.js").ReviewSpace} ReviewSpace
|
|
@@ -426,13 +427,45 @@ async function registerOnce(client, projectPath, record, title) {
|
|
|
426
427
|
client_operation_id: randomUUID(),
|
|
427
428
|
};
|
|
428
429
|
await writeJsonAtomic(recordPath(projectPath), { ...record, registration: body });
|
|
430
|
+
let project;
|
|
429
431
|
try {
|
|
430
|
-
|
|
432
|
+
project = await client.register(body, record.spaceId);
|
|
431
433
|
} catch (error) {
|
|
432
434
|
if (!(error instanceof ReviewFailed) || error.reason !== "space_forbidden") throw error;
|
|
433
435
|
await writeJsonAtomic(recordPath(projectPath), { ...record, spaceId: null });
|
|
434
436
|
throw await spaceRefusal(client, record.spaceId, error);
|
|
435
437
|
}
|
|
438
|
+
if (project.created || (record.registration && (await unused(client, project))))
|
|
439
|
+
return project.project_id;
|
|
440
|
+
await writeJsonAtomic(recordPath(projectPath), record);
|
|
441
|
+
throw new ReviewFailed(409, "review_project_changed");
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** A first share may only land on a project it made. A server answer of an existing project is a retry after a lost
|
|
445
|
+
* reply only when the record already held this registration and the project is as registration left it: private,
|
|
446
|
+
* link never turned off, no ready version. Anything else is a review nobody confirmed, so nothing is changed.
|
|
447
|
+
* @param {ReviewClient} client @param {ProjectDTO} project */
|
|
448
|
+
async function unused(client, project) {
|
|
449
|
+
if (project.latest_ready_version_id) return false;
|
|
450
|
+
return untouched(project, await readShare(client, project.project_id));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** A project as an unfinished first share leaves it: no ready version, its link never turned off, and private, or set
|
|
454
|
+
* to this share's audience already when only the reply to that change was lost.
|
|
455
|
+
* @param {ProjectDTO} project @param {ShareDTO} share @param {import("./types/share.js").AccessMode} [audience] */
|
|
456
|
+
const untouched = (project, share, audience) =>
|
|
457
|
+
!project.latest_ready_version_id &&
|
|
458
|
+
!share.revoked &&
|
|
459
|
+
(share.access_mode === "private" || share.access_mode === audience);
|
|
460
|
+
|
|
461
|
+
/** With no review a host confirmed, a record's project that no share finished names nothing the person agreed to: only
|
|
462
|
+
* a first share that stopped before it finished goes on. Anything else is refused, and the record stays as it is.
|
|
463
|
+
* @param {ReviewClient} client @param {ReviewRecord} read @param {ShareDTO} share
|
|
464
|
+
* @param {import("./types/share.js").AccessMode} [audience] */
|
|
465
|
+
async function assertUnfinished(client, read, share, audience) {
|
|
466
|
+
if (!read.projectId || read.opened) return;
|
|
467
|
+
if (!untouched(await client.project(read.projectId), share, audience))
|
|
468
|
+
throw new ReviewFailed(409, "review_project_changed");
|
|
436
469
|
}
|
|
437
470
|
|
|
438
471
|
/** A space refused at registration. Only one picked before the workspace changed is replaced by the next press;
|
|
@@ -447,8 +480,10 @@ async function spaceRefusal(client, refused, error) {
|
|
|
447
480
|
/** Share's press: the first registers the project into the space given (none: the signed-in one) and opens its link
|
|
448
481
|
* to that space; a later one reads the link, turning it back on when it was off. A registered project keeps its space.
|
|
449
482
|
* A host can prepare review content after registration is saved and before the link or its audience changes.
|
|
483
|
+
* `confirmed` is the review the person was shown, null for a new one; a record that names another is refused unchanged.
|
|
450
484
|
* @param {{ projectPath: string, title: string, client: ReviewClient, spaceId?: string | null, audience?:
|
|
451
|
-
* import("./types/share.js").AccessMode | undefined, beforeOpen?: (projectId: string) => Promise<void
|
|
485
|
+
* import("./types/share.js").AccessMode | undefined, beforeOpen?: (projectId: string) => Promise<void>,
|
|
486
|
+
* confirmed?: string | null }} request */
|
|
452
487
|
export const shareForReview = ({
|
|
453
488
|
projectPath,
|
|
454
489
|
title,
|
|
@@ -456,9 +491,10 @@ export const shareForReview = ({
|
|
|
456
491
|
spaceId = null,
|
|
457
492
|
audience,
|
|
458
493
|
beforeOpen,
|
|
494
|
+
confirmed,
|
|
459
495
|
}) =>
|
|
460
496
|
oneAtATime(projectPath, async () => {
|
|
461
|
-
const read = await recordToShare(client, projectPath, spaceId);
|
|
497
|
+
const read = assertConfirmed(await recordToShare(client, projectPath, spaceId), confirmed);
|
|
462
498
|
const id = read.projectId ?? (await registerOnce(client, projectPath, read, title));
|
|
463
499
|
const record = read.projectId
|
|
464
500
|
? read
|
|
@@ -466,6 +502,7 @@ export const shareForReview = ({
|
|
|
466
502
|
if (!read.projectId) await writeJsonAtomic(recordPath(projectPath), record);
|
|
467
503
|
const share = await readShare(client, id, projectPath);
|
|
468
504
|
if (takenDown(share)) return shown(client, share);
|
|
505
|
+
if (confirmed === undefined) await assertUnfinished(client, read, share, audience);
|
|
469
506
|
if (!record.opened || share.revoked) await beforeOpen?.(id);
|
|
470
507
|
return openLink(client, projectPath, record, id, share, audience).then(
|
|
471
508
|
(opened) => shown(client, opened),
|
|
@@ -473,6 +510,13 @@ export const shareForReview = ({
|
|
|
473
510
|
);
|
|
474
511
|
});
|
|
475
512
|
|
|
513
|
+
/** @param {ReviewRecord} record @param {string | null | undefined} confirmed */
|
|
514
|
+
function assertConfirmed(record, confirmed) {
|
|
515
|
+
if (confirmed !== undefined && record.projectId !== confirmed)
|
|
516
|
+
throw new ReviewFailed(409, "review_project_changed");
|
|
517
|
+
return record;
|
|
518
|
+
}
|
|
519
|
+
|
|
476
520
|
/** Turns a link that was off back on, and opens a first share to the workspace.
|
|
477
521
|
* @param {ReviewClient} client @param {string} projectPath @param {ReviewRecord} record @param {string} id
|
|
478
522
|
* @param {ShareDTO} share @param {import("./types/share.js").AccessMode} [audience] */
|
|
@@ -483,7 +527,8 @@ async function openLink(client, projectPath, record, id, share, audience) {
|
|
|
483
527
|
expected_link_generation: share.link_generation,
|
|
484
528
|
client_operation_id: randomUUID(),
|
|
485
529
|
});
|
|
486
|
-
//
|
|
530
|
+
// Opens a first share. Unless the host confirmed this review, a retry after a lost reply reaches here only while
|
|
531
|
+
// the review is private or already has this audience (assertUnfinished).
|
|
487
532
|
if (!record.opened) {
|
|
488
533
|
share = await applyFirstAudience(client, id, share, audience);
|
|
489
534
|
await writeJsonAtomic(recordPath(projectPath), { ...record, projectId: id, opened: true });
|
|
@@ -539,7 +584,8 @@ const SENTENCES = {
|
|
|
539
584
|
review_subscription_required: "Restricted sharing requires a HyperFrames subscription.",
|
|
540
585
|
review_public_consent_required: "Choose Share with anyone who has the link to continue.",
|
|
541
586
|
review_entitlement_unavailable: "Couldn't confirm sharing availability. Try again.",
|
|
542
|
-
review_project_changed:
|
|
587
|
+
review_project_changed:
|
|
588
|
+
"This project’s review changed. Reopen sharing and try again. If it keeps failing, remove .hyperframes/review.json to share this folder as a new review.",
|
|
543
589
|
review_project_removed:
|
|
544
590
|
"This review project was removed. Share again to create a new link and discussion.",
|
|
545
591
|
moderation_hold: "This review was taken down for a policy violation, so it can't be shared.",
|