@01.works/visual-review 0.12.0 → 0.13.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.
@@ -1 +0,0 @@
1
- import{c as e,o as t,s as n}from"./src-CjYM9---.js";const r=Symbol.for(`functionName`),i=Symbol.for(`toReferencePath`);function a(e){return e[i]??null}function o(e){return e.startsWith(`function://`)}function s(e){let t;if(typeof e==`string`)t=o(e)?{functionHandle:e}:{name:e};else if(e[r])t={name:e[r]};else{let n=a(e);if(!n)throw Error(`${e} is not a functionReference`);t={reference:n}}return t}function c(e){let t=s(e);if(t.name===void 0)throw t.functionHandle===void 0?t.reference===void 0?Error(`Expected function reference like "api.file.func" or "internal.file.func", but received ${JSON.stringify(t)}`):Error(`Expected function reference in the current component like "api.file.func" or "internal.file.func", but received reference ${t.reference}`):Error(`Expected function reference like "api.file.func" or "internal.file.func", but received function handle ${t.functionHandle}`);if(typeof e==`string`)return e;let n=e[r];if(!n)throw Error(`${e} is not a functionReference`);return n}function l(e){return{[r]:e}}function u(e=[]){return new Proxy({},{get(t,n){if(typeof n==`string`)return u([...e,n]);if(n===r){if(e.length<2){let t=[`api`,...e].join(`.`);throw Error(`API path is expected to be of the form \`api.moduleName.functionName\`. Found: \`${t}\``)}let t=e.slice(0,-1).join(`/`),n=e[e.length-1];return n==="default"?t:t+`:`+n}else if(n===Symbol.toStringTag)return`FunctionReference`;else return}})}u();const d=Object.freeze({resolveSession:l(`reviews:resolveSession`),pageSnapshot:l(`reviews:pageSnapshot`),projectSnapshot:l(`reviews:projectSnapshot`),createComment:l(`reviews:createComment`),createReply:l(`reviews:createReply`),presenceList:l(`presence:list`),presenceUpdate:l(`presence:update`),presenceDisconnect:l(`presence:disconnect`),screenshotUploadUrl:l(`screenshots:generateUploadUrl`),screenshotCommit:l(`screenshots:commitUpload`),screenshotDiscard:l(`screenshots:discardUpload`)});Object.freeze({catalog:l(`owners:catalog`),listProjects:l(`owners:listProjects`),projectOverview:l(`owners:projectOverview`),feedbackPage:l(`owners:feedbackPage`),createProject:l(`owners:createProject`),createProjectWithOrigins:l(`owners:createProjectWithOrigins`),configureProjectLinkAccess:l(`owners:configureProjectLinkAccess`),deleteProject:l(`owners:deleteProject`),addOrigin:l(`owners:addOrigin`),removeOrigin:l(`owners:removeOrigin`),replaceOrigins:l(`owners:replaceOrigins`),createPage:l(`owners:createPage`),deletePage:l(`owners:deletePage`),upsertPageBuild:l(`owners:upsertPageBuild`),createInvitation:l(`owners:createInvitation`),revokeInvitation:l(`owners:revokeInvitation`),revokeReviewerAccess:l(`owners:revokeReviewerAccess`),setCommentStatus:l(`owners:setCommentStatus`),createReply:l(`owners:createReply`),deleteComment:l(`owners:deleteComment`),deleteReply:l(`owners:deleteReply`),screenshotDownload:l(`screenshots:ownerDownload`)});var f=class{client;session;#e;#t;#n;constructor(e,t,n){this.client=e,this.session=t,this.#e=_(n.invitationId??t.invitationId,`invitationId`),this.#t=v(n.origin),this.#n=n.fetch??globalThis.fetch.bind(globalThis)}async attachScreenshot(e,t,n){_(e,`pageId`);let r=_(t,`commentId`);if(n.bytes.byteLength===0||n.bytes.byteLength>15e5)throw Error(`Screenshot size is invalid`);let i=await this.client.mutation(d.screenshotUploadUrl,{...this.#r(),commentId:r}),a=await this.#n(i.uploadUrl,{method:`POST`,headers:{"content-type":n.contentType},body:p(n.bytes)});if(!a.ok)throw Error(`Screenshot upload failed`);let o=await a.json();if(typeof o.storageId!=`string`||!o.storageId)throw Error(`Screenshot upload returned an invalid storage ID`);try{await this.client.mutation(d.screenshotCommit,{...this.#r(),commentId:r,grantId:i.grantId,storageId:o.storageId,contentType:n.contentType,width:n.width,height:n.height})}catch(e){throw await this.client.mutation(d.screenshotDiscard,{...this.#r(),commentId:r,grantId:i.grantId,storageId:o.storageId}).catch(()=>void 0),e}}async getSnapshot(e){return g(await this.client.query(d.pageSnapshot,{...this.#r(),pageId:_(e,`pageId`)}))}async getProjectSnapshot(e){return this.#i(e),structuredClone(await this.client.query(d.projectSnapshot,{...this.#r(),projectId:e}))}subscribe(e,t,n){return this.client.onUpdate(d.pageSnapshot,{...this.#r(),pageId:_(e,`pageId`)},e=>t(g(e)),e=>n?.(m(e)))}subscribeProject(e,t,n){return this.#i(e),this.client.onUpdate(d.projectSnapshot,{...this.#r(),projectId:e},e=>t(structuredClone(e)),e=>n?.(m(e)))}async mutate(r,i){switch(i.type){case`comment.upsert`:{let a=i.comment;if(a.pageId!==r)throw Error(`Comment page mismatch`);if(a.authorId!==this.session.reviewerId)throw Error(`Comment author mismatch`);if(a.status!==`open`||a.resolvedAt!==void 0||a.resolvedById!==void 0||a.createdAt!==a.updatedAt)throw Error(`Only new open comments can be created by a reviewer`);let o=n(a.body).trim(),s=t(a.target),c=a.scope===void 0?void 0:e(a.scope);await this.client.mutation(d.createComment,{...this.#r(),pageId:r,commentId:a.id,body:o,targetJson:JSON.stringify(s.publicTarget),sourceContextJson:s.sourceContextJson,...c===void 0?{}:{scopeJson:JSON.stringify(c)}});return}case`reply.upsert`:{let e=i.reply;if(e.authorId!==this.session.reviewerId)throw Error(`Reply author mismatch`);if(e.createdAt!==e.updatedAt)throw Error(`Reply edits require an owner command`);await this.client.mutation(d.createReply,{...this.#r(),commentId:e.commentId,replyId:e.id,body:n(e.body,`Reply body`).trim()});return}case`comment.delete`:throw Error(`Comment deletion requires an owner command`);case`reply.delete`:throw Error(`Reply deletion requires an owner command`)}}#r(){return{invitationId:this.#e,origin:this.#t}}#i(e){if(!e.trim()||e!==this.session.projectId)throw Error(`Project does not belong to the reviewer session`)}};function p(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}function m(e){let t=h(e);return t===`UNAUTHENTICATED`||t===`INVITATION_EXPIRED`?{type:`access-lost`,code:`session-expired`,recovery:`reauthenticate`,clearSnapshot:!0}:t===`INVITATION_REVOKED`||t===`MEMBERSHIP_REVOKED`?{type:`access-lost`,code:`membership-revoked`,recovery:`reauthenticate`,clearSnapshot:!0}:t===`ORIGIN_MISMATCH`||t===`ORIGIN_NOT_ALLOWED`||t===`INVITATION_REQUIRED`?{type:`access-lost`,code:`permission-denied`,recovery:`reauthenticate`,clearSnapshot:!0}:{type:`error`,code:e instanceof Error?`transport`:`unknown`,recovery:`retry`,clearSnapshot:!0}}function h(e){if(!e||typeof e!=`object`)return;let t=e.data;if(typeof t==`string`)return t;if(t&&typeof t==`object`){let e=t.code;if(typeof e==`string`)return e}}function g(e){return structuredClone(e)}function _(e,t){let n=e.trim();if(!n)throw Error(`${t} is required`);return n}function v(e){let t=_(e,`origin`);try{let e=new URL(t);if(e.origin!==t)throw Error();return e.origin}catch{throw Error(`A valid browser origin is required`)}}export{c as i,m as n,d as r,f as t};