@vite-hub/comments 0.6.0 → 0.7.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/README.md +23 -6
- package/dist/{client-diagnostics-CvfTW5d4.js → client-diagnostics-DoXqdnBd.js} +12 -0
- package/dist/client.d.ts +119 -23
- package/dist/client.js +708 -209
- package/dist/{database-BkPoOdZr.js → database-BuSNVwTx.js} +1 -1
- package/dist/database.js +1 -1
- package/dist/{define-BCxNaSZv.js → define-BqPcuDhf.js} +1 -1
- package/dist/{errors-DFNiJg67.js → errors-CBvIpwbo.js} +1 -1
- package/dist/hosted/hosted-comments/frame.js +1 -1
- package/dist/hosted/hosted-comments/tools.js +371 -0
- package/dist/hosted/hosted-comments.js +1 -9
- package/dist/index.js +11 -10
- package/dist/{install-NehuMNhG.d.ts → install-9L4ASzUC.d.ts} +10 -1
- package/dist/{install-w6CCgGFV.js → install-CqBWFmU7.js} +23 -15
- package/dist/{installed-C9SkldMi.js → installed-wUYjqk_k.js} +1 -1
- package/dist/{operations-8hqTi0DH.d.ts → operations-DFLer1fR.d.ts} +1 -0
- package/dist/{operations-Cic9A9e_.d.ts → operations-Qt8ASQqW.d.ts} +2 -2
- package/dist/{operations-B8IMhRmY.js → operations-kMPw-Cyb.js} +10 -11
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/client-CrnKCZXc.js +4 -0
- package/dist/overlay/overlay.js +70 -29
- package/dist/page/loader.js +25 -23
- package/dist/{page-xzgZ6DGm.js → page-2NzFladc.js} +5 -1
- package/dist/{page-tools-shared-fvmJQCrP.js → page-tools-shared-BNw-aWEH.js} +2 -5
- package/dist/{plugin-DbCYT7Ac.js → plugin-ChOHe7vq.js} +9 -8
- package/dist/realtime.d.ts +12 -1
- package/dist/realtime.js +14 -6
- package/dist/{request-origin-YPzfE2eh.js → request-origin-B-CPVAVk.js} +6 -1
- package/dist/{rpc-BKY7XRlR.js → rpc-kkxzQ3Qy.js} +1 -1
- package/dist/rpc.js +1 -1
- package/dist/runtime/auth.js +1 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/index.d.ts +4 -1
- package/dist/runtime/index.js +16 -14
- package/dist/{server-BGbD7H5s.js → server-8o9u8leM.js} +1 -1
- package/dist/server.d.ts +3 -3
- package/dist/server.js +6 -6
- package/dist/{service-CPiWPoiY.d.ts → service-IvgrI4XM.d.ts} +2 -0
- package/dist/{service-DUh2uGd2.js → service-XT2A8YEF.js} +11 -6
- package/dist/{session-_1GY5gaG.js → session-DGdFKWDB.js} +8 -7
- package/dist/testing.js +1 -1
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +31 -11
- package/package.json +9 -8
- package/dist/hosted/hosted-comments/client-B3dlmmQd.js +0 -4
- package/dist/hosted/hosted-comments/dist-DyVmH21U.js +0 -14
- package/dist/hosted/hosted-comments/overlay-CFuq5QAH.js +0 -182
- package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +0 -1
- package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +0 -1
- package/dist/hosted/hosted-comments/tools-Bz--joZw.js +0 -126
- package/dist/overlay/client-CerbVjTz.js +0 -4
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import{a as e,n as t,r as n,s as r,t as i}from"./hosted-comments/protocol-BHvtQKte.js";var a=`vitehub`,o=[`comment`];function s(e,t){let n=new URLSearchParams(e);if(n.has(`vitehub`)||o.some(e=>n.has(e)))return!0;let r=t.split(`;`).map(e=>e.trim());return r.includes(`vitehub-tools=1`)?!0:r.includes(`vitehub_session=1`)&&!r.some(e=>e.startsWith(`vitehub-tools=`))}var c=`/_vitehub/page/assets`,l=`/_vitehub/page/tools`,u=`button{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:var(--vitehub-pill-justify,center);gap:4px;min-width:28px;height:28px;padding:0 8px;border-radius:8px;font:inherit;white-space:nowrap;color:var(--vitehub-pill-text);cursor:pointer;touch-action:manipulation;-webkit-tap-highlight-color:transparent;transition-property:background-color,color;transition-duration:150ms;transition-timing-function:cubic-bezier(.23,1,.32,1)}
|
|
3
|
-
@media(hover:hover){button:where(:not(:disabled):hover){background:var(--vitehub-pill-hover);color:var(--vitehub-pill-strong)}}
|
|
4
|
-
button[aria-pressed=true],button[aria-expanded=true]{background:var(--vitehub-pill-on);color:var(--vitehub-pill-on-text)}
|
|
5
|
-
:host([aria-busy=true]) button,button[aria-busy=true]{background:var(--vitehub-pill-on);color:var(--vitehub-pill-on-text);cursor:progress}
|
|
6
|
-
button:focus-visible{outline:2px solid var(--vitehub-pill-on);outline-offset:1px}
|
|
7
|
-
button svg{width:14px;height:14px;flex:none}
|
|
8
|
-
@media(any-pointer:coarse){button{min-width:44px;height:44px}}
|
|
9
|
-
@media(prefers-reduced-motion:reduce){button{transition:none}}`,d=`data-vitehub-pill`;function f(e){let t=new URL(e,`http://localhost`).pathname,n=t.lastIndexOf(`${c}/`);return n===-1?l:`${t.slice(0,n)}${l}`}function p(e){return typeof e==`string`&&e?e:void 0}function m(e){if(typeof e!=`object`||!e)return;let t=p(Reflect.get(e,`id`)),n=p(Reflect.get(e,`script`));if(!t||!n)return;let r={id:t,label:p(Reflect.get(e,`label`))??t,icon:p(Reflect.get(e,`icon`))??``,script:n};Reflect.get(e,`lazy`)===!0&&(r.lazy=!0);let i=p(Reflect.get(e,`hotkey`));i&&(r.hotkey=i);let a=p(Reflect.get(e,`param`));return a&&(r.param=a),r}function h(e){if(typeof e!=`object`||!e)return;let t=p(Reflect.get(e,`name`)),n=p(Reflect.get(e,`signOut`));if(!t||!n?.startsWith(`/`)||n.startsWith(`//`)||n.includes(`\\`))return;let r={name:t,signOut:n},i=p(Reflect.get(e,`email`));i&&(r.email=i);let a=p(Reflect.get(e,`image`));return a&&/^https?:\/\//i.test(a)&&(r.image=a),Reflect.get(e,`via`)===`console`&&(r.via=`console`),Reflect.get(e,`guest`)===!0&&(r.guest=!0),r}function g(e){let t=typeof e==`object`&&e?Reflect.get(e,`tools`):void 0,n={tools:Array.isArray(t)?t.map(m).filter(e=>!!e):[]},r=typeof e==`object`&&e?h(Reflect.get(e,`account`)):void 0;return r&&(n.account=r),n}var _=`modulepreload`,v=function(e,t){return new URL(e,t).href},y={},b=function(e){return e.pathname.endsWith(`.css`)},x=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},S=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=v(t,n);let r=s(t),i=b(r);return x(y,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:_,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},C=15e3,w=3e4,T=5e3,E=RegExp(`^#(/?)vhc=([\\w-]+)$`);function D(){let e=E.exec(location.hash);if(!e)return;let[,t,n]=e;return history.replaceState(history.state,``,`${location.pathname}${location.search}${t?`#/`:``}`),n}function O(e){try{return sessionStorage.getItem(e)===`1`}catch{return!1}}function k(e){try{sessionStorage.setItem(e,`1`)}catch{}}function A(i,a){let o=document.createElement(`iframe`);o.src=`${i}${n(a)}`,o.hidden=!0,o.tabIndex=-1,o.title=`ViteHub Comments`,o.setAttribute(`aria-hidden`,`true`),o.setAttribute(`data-comments-ui`,``);let s=new MessageChannel,c=new Map,l=0,u={call:(t,n)=>new Promise((i,a)=>{let o=++l,u=setTimeout(()=>{c.delete(o),a(r(0))},w);c.set(o,t=>{clearTimeout(u),t.ok?i(t):a(e(t.error))}),s.port1.postMessage({id:o,method:t,input:n})})};return new Promise((e,n)=>{let a=setTimeout(()=>n(r(0)),C);s.port1.addEventListener(`message`,({data:t})=>{if(typeof t==`object`&&t){if(Reflect.get(t,`event`)===`ready`)clearTimeout(a),e(u);else{let e=Reflect.get(t,`id`),n=typeof e==`number`?c.get(e):void 0;if(!n||typeof e!=`number`)return;c.delete(e),n(t)}}}),s.port1.start(),o.addEventListener(`load`,()=>o.contentWindow?.postMessage({type:t},i,[s.port2]),{once:!0}),o.addEventListener(`error`,()=>n(r(0)),{once:!0}),document.documentElement.append(o)})}async function j(e,t){return await new Promise(n=>{let r=setTimeout(()=>i(!1),T);function i(t){clearTimeout(r),e.removeEventListener(`message`,a),n(t)}function a({data:e}){e.type===`redeemed`&&e.code===t&&i(!0)}e.addEventListener(`message`,a),e.postMessage({type:`code`,code:t})})}async function M(e,t){let n=D(),r=`vitehub-comments:${e}`;if(!n&&!O(r)&&!s(location.search,document.cookie))return;k(r);let a=new BroadcastChannel(i(e)),o=A(t,e),c=async e=>(await(await o).call(`redeem`,e)).value===!0,l=S(()=>import(`./hosted-comments/tools-Bz--joZw.js`).then(e=>e.t),__vite__mapDeps([0,1,2]),import.meta.url);a.addEventListener(`message`,({data:e})=>{e.type===`code`&&c(e.code).then(t=>{t&&(a.postMessage({type:`redeemed`,code:e.code}),l.then(({mountHostedComments:e})=>e(o)))},()=>void 0)});let u=n?await c(n).catch(()=>!1):!1;if(n&&!u&&await j(a,n)){window.close();return}let{mountHostedComments:d}=await l;await d(o)}var N=document.querySelector(`script[data-vitehub-comments]`)?.dataset.vitehubComments;N&&M(N,new URL(import.meta.url).origin);export{a,u as c,o as i,g as n,s as o,f as r,d as s,S as t};
|
|
1
|
+
var e=`vitehub`,t=[`comment`];function n(e,n){let r=new URLSearchParams(e);if(r.has(`vitehub`)||t.some(e=>r.has(e)))return!0;let i=n.split(`;`).map(e=>e.trim());return i.includes(`vitehub-tools=1`)?!0:i.includes(`vitehub_session=1`)&&!i.some(e=>e.startsWith(`vitehub-tools=`))}`${JSON.stringify([e,...t])}`;var r=/^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/(?!\.+$)[A-Za-z0-9._-]{1,100}$/;function i(e){return e&&r.test(e)?e:void 0}function a(e,...t){return typeof e==`function`?e(...t):e}var o=Error.captureStackTrace,s=class e extends Error{get why(){return this.message}constructor(t,n=e){super(t.why,{cause:t.cause}),this.code=this.name=t.code,this.docs=t.docs,this.fix=t.fix,this.sources=t.sources,this.data=t.data,o?.(this,n)}toJSON(){return{name:this.name,why:this.why,fix:this.fix,docs:this.docs,sources:this.sources,cause:this.cause,data:this.data,stack:this.stack}}};function c(e,t){return typeof e==`string`?`${e}/${t.toLowerCase()}`:e?.(t)}var l=e=>t=>t instanceof s&&e in t;function u(e){let t=e.reporters??[],n=Symbol(),r=Object.defineProperty({},"is",{value:l(n)}),{docsBase:i}=e;for(let o of Object.keys(e.codes)){let l=e.codes[o],u=l.docs===!1?void 0:l.docs||c(i,o),d=(e={},r={})=>{let i=new s({code:o,why:a(l.why,e),fix:a(l.fix,e),docs:u,cause:e.cause,sources:e.sources,data:a(l.data,e)},d);i[n]=1;for(let e of t)e(i,r);return i};d.is=e=>r.is(e)&&e.code===o,r[o]=d}return r}var d=u({docsBase:`https://vitehub.dev/docs/comments/diagnostics`,codes:{COMMENTS_HOSTED_CONFLICT:{why:`This page runs the app's own Comments, so the Hosted Comments script does not start its overlay.`,fix:"Remove the Hosted Comments script, or keep it and set `comments: { overlay: false }` to turn off the app's overlay. See https://vitehub.dev/docs/comments/configure#add-hosted-comments"},COMMENTS_OUTBOX_ACCOUNT_CHANGED:{why:`The current author is not the author of this queued comment.`,fix:`Sign in as the original author and retry the outbox.`},COMMENTS_OUTBOX_RESOLVE_BLOCKED:{why:`Queued delivery must resume before the thread can close.`,fix:`Go online, then retry or dismiss any blocked comments and resolve the thread again.`},COMMENTS_OUTBOX_SENDING:{why:`The server may already have this comment, so the draft cannot change.`,fix:`Wait for delivery to finish, then edit or delete the server copy.`},COMMENTS_OVERLAY_ELEMENT_TAKEN:{why:({name:e})=>`Another script defined the <${e}> element, so this Comments overlay cannot start.`,fix:`Load one Comments overlay script on the page. Remove the other script that defines the element.`},COMMENTS_R0001:{why:({target:e})=>`createAnchor() found nothing to anchor to for ${e}.`,fix:`Pass an element, a non-empty selection, or a point that is over an element of the page.`},COMMENTS_R0013:{why:`The comments request did not get an answer from the server.`,fix:`Check the connection and the app URL, then try again.`},COMMENTS_R0015:{why:`The comment list kept changing while its pages were loading.`,fix:`Refresh again. The previous cache is kept until two complete scans agree.`}}});function f(e){let{code:t,details:n,fix:r,retryAfter:i,status:a,why:o}=e,c=t.startsWith(`COMMENTS_`)?`https://vitehub.dev/docs/comments/diagnostics/${t.toLowerCase()}`:void 0;return Object.assign(new s({code:t,why:o,...r?{fix:r}:{},...c?{docs:c}:{}}),{status:a,...n?{details:n}:{},...i===void 0?{}:{retryAfter:i}})}function p(e,t,n){return Object.assign(d.COMMENTS_R0013(t===void 0?{}:{cause:t}),{status:e,...n===void 0?{}:{retryAfter:n}})}var m=`vitehub-comments:connect`;function h(e){return`vitehub-comments:${e}`}function g(e){return`/comments/${encodeURIComponent(e)}/embed`}var _=15e3,v=3e4,y=5e3,b=`vitehub-comments:`,x=RegExp(`^#(/?)vhc=([\\w-]+)$`);function S(e=!1){let t=x.exec(location.hash);if(!t)return;let[,n,r]=t,i=new URL(location.href);return e&&i.searchParams.delete(`vhp`),i.hash=n?`#/`:``,history.replaceState(history.state,``,i),r}function C(e){try{return sessionStorage.getItem(e)===`1`}catch{return!1}}function w(){try{for(let e=0;e<sessionStorage.length;e++)if(sessionStorage.key(e)?.startsWith(b))return!0}catch{}return!1}function T(e){try{sessionStorage.setItem(e,`1`)}catch{}}function E(e,t){let n=document.createElement(`iframe`);n.src=`${e}${g(t)}`,n.hidden=!0,n.tabIndex=-1,n.title=`ViteHub Comments`,n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`data-comments-ui`,``);let r=new MessageChannel,i=new Map,a=0,o={call:(e,t)=>new Promise((n,o)=>{let s=++a,c=setTimeout(()=>{i.delete(s),o(p(0))},v);i.set(s,e=>{clearTimeout(c),e.ok?n(e):o(f(e.error))}),r.port1.postMessage({id:s,method:e,input:t})})};return new Promise((t,a)=>{let s=setTimeout(()=>a(p(0)),_);r.port1.addEventListener(`message`,({data:e})=>{if(typeof e==`object`&&e){if(Reflect.get(e,`event`)===`ready`)clearTimeout(s),t(o);else{let t=Reflect.get(e,`id`),n=typeof t==`number`?i.get(t):void 0;if(!n||typeof t!=`number`)return;i.delete(t),n(e)}}}),r.port1.start(),n.addEventListener(`load`,()=>n.contentWindow?.postMessage({type:m},e,[r.port2]),{once:!0}),n.addEventListener(`error`,()=>a(p(0)),{once:!0}),document.documentElement.append(n)})}async function D(e,t){return await new Promise(n=>{let r=setTimeout(()=>i(!1),y);function i(t){clearTimeout(r),e.removeEventListener(`message`,a),n(t)}function a({data:e}){e.type===`redeemed`&&e.code===t&&i(!0)}e.addEventListener(`message`,a),e.postMessage({type:`code`,code:t})})}function O(){return import(new URL(`hosted-comments/tools.js`,``+import.meta.url).href)}async function k(e,t,r,i=n(location.search,document.cookie),a){let o=S(a!==void 0),s=`${b}${e}`;if(!o&&!C(s)&&!i)return;T(s);let c=new BroadcastChannel(h(e)),l=E(t,e),u=async e=>(await(await l).call(`redeem`,e)).value===!0,d=O(),f={id:e,console:t,...r?{repository:r}:{},...a?{consoleUrl:a}:{}};c.addEventListener(`message`,({data:e})=>{e.type===`code`&&u(e.code).then(t=>{t&&(c.postMessage({type:`redeemed`,code:e.code}),d.then(({mountHostedComments:e})=>e(l,f)))},()=>void 0)});let p=o?await u(o).catch(()=>!1):!1;if(o&&!p&&await D(c,o)){window.close();return}let{mountHostedComments:m}=await d;await m(l,f)}function A(e){return typeof e==`object`&&!!e&&typeof Reflect.get(e,`id`)==`string`&&typeof Reflect.get(e,`team`)==`string`}async function j(e,t,r){let i=n(location.search,``)||w(),a=x.test(location.hash);if(!i&&!a)return;let o=new URL(`/comments/project`,t);for(let t of e)o.searchParams.append(`key`,t);o.searchParams.set(`base`,r);let s=await fetch(o,{credentials:`omit`}).then(e=>e.ok?e.json():void 0).catch(()=>void 0),c=typeof s==`object`&&s?Reflect.get(s,`projects`):void 0,l=Array.isArray(c)?c.filter(A):[],u=e=>{let n=new URL(`/open`,t);return n.searchParams.set(`project`,`${location.origin}${r}`),n.searchParams.set(`path`,`/`),e&&n.searchParams.set(`app`,e),n.href},d=e=>k(e,t,void 0,!0,u(e)),f=a?new URLSearchParams(location.search).get(`vhp`):null,p=l.filter(e=>C(`${b}${e.id}`)),m=f?l.find(e=>e.id===f):l.length===1?l[0]:p.length===1?p[0]:void 0;if(m)return await d(m.id);a&&S(!0);let{mountHostedProjectChoice:h}=await O();await h(u(),l.map(e=>({team:e.team,choose:()=>void d(e.id)})))}var M=document.querySelector(`script[data-vitehub-comments], script[data-vitehub-console-key]`),N=new URL(import.meta.url).origin,P=M?.dataset.vitehubComments,F=M?.dataset.vitehubConsoleKey?.split(/\s+/).filter(Boolean)??[];P?k(P,N,i(M?.dataset.vitehubRepo)):F.length&&j(F,N,M?.dataset.vitehubBase??``);
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { S as suggest, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply
|
|
2
|
-
import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition } from "./define-
|
|
3
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
1
|
+
import { C as threadChanged, S as suggest, T as clientRateLimitIssue, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply } from "./service-XT2A8YEF.js";
|
|
2
|
+
import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition } from "./define-BqPcuDhf.js";
|
|
3
|
+
import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
|
|
4
4
|
import { t as commentsErrors } from "./errors-C0VwRHiy.js";
|
|
5
|
-
import { a as runtimeOf, n as pendingKey, o as runtimes, t as commentSendOf } from "./installed-
|
|
6
|
-
import {
|
|
5
|
+
import { a as runtimeOf, n as pendingKey, o as runtimes, t as commentSendOf } from "./installed-wUYjqk_k.js";
|
|
6
|
+
import { c as normalizeCommentPage, n as commentRoom } from "./page-2NzFladc.js";
|
|
7
7
|
import { t as describeCommentContext } from "./context-DbkBjITZ.js";
|
|
8
8
|
// src/index.ts
|
|
9
9
|
/** A thread that someone deleted during the change: the store reads it again and finds nothing. */
|
|
@@ -147,7 +147,7 @@ function defineComments(options = {}) {
|
|
|
147
147
|
if (!await current.store.getById(threadId)) return notFound(threadId);
|
|
148
148
|
const thread = await current.store.setStatus(threadId, "resolved", by, Date.now(), actor).catch(gone);
|
|
149
149
|
if (!thread) return notFound(threadId);
|
|
150
|
-
current
|
|
150
|
+
await threadChanged(current, thread);
|
|
151
151
|
return [void 0, thread];
|
|
152
152
|
},
|
|
153
153
|
async reopen(threadId) {
|
|
@@ -156,16 +156,17 @@ function defineComments(options = {}) {
|
|
|
156
156
|
if (!await current.store.getById(threadId)) return notFound(threadId);
|
|
157
157
|
const thread = await current.store.setStatus(threadId, "open", { id: "" }, Date.now()).catch(gone);
|
|
158
158
|
if (!thread) return notFound(threadId);
|
|
159
|
-
current
|
|
159
|
+
await threadChanged(current, thread);
|
|
160
160
|
await current.reopened?.(thread);
|
|
161
161
|
return [void 0, thread];
|
|
162
162
|
},
|
|
163
163
|
async remove(threadId) {
|
|
164
164
|
const current = await runtime();
|
|
165
165
|
if (!current) return notInstalled();
|
|
166
|
-
|
|
166
|
+
const found = await current.store.getById(threadId);
|
|
167
|
+
if (!found) return notFound(threadId);
|
|
167
168
|
await current.store.deleteThread(threadId);
|
|
168
|
-
current
|
|
169
|
+
await threadChanged(current, found);
|
|
169
170
|
return [void 0, void 0];
|
|
170
171
|
},
|
|
171
172
|
async removeMessage(messageId) {
|
|
@@ -175,7 +176,7 @@ function defineComments(options = {}) {
|
|
|
175
176
|
if (!thread) return notFound(messageId);
|
|
176
177
|
if (thread.messages[0]?.id === messageId) await current.store.deleteThread(thread.id);
|
|
177
178
|
else await current.store.deleteMessage(thread.id, messageId, Date.now()).catch(gone);
|
|
178
|
-
current
|
|
179
|
+
await threadChanged(current, thread);
|
|
179
180
|
return [void 0, void 0];
|
|
180
181
|
},
|
|
181
182
|
async edit(messageId, input) {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { T as CommentThread } from "./types-BX3vH18p.js";
|
|
1
2
|
import { o as commentsSchema } from "./database-DUs3c2al.js";
|
|
2
|
-
import { i as CommentsRuntime, n as CommentsAttachmentStore, o as SharedRateLimit } from "./service-
|
|
3
|
+
import { i as CommentsRuntime, n as CommentsAttachmentStore, o as SharedRateLimit } from "./service-IvgrI4XM.js";
|
|
3
4
|
import { c as CommentSendWebhooks, t as Comments } from "./index-D1T7RJ4R.js";
|
|
4
5
|
import { d as CommentsPeople } from "./define-B1jLSPe9.js";
|
|
5
6
|
import { r as CommentsTables, t as CommentsDatabase } from "./store-DvNTDNgn.js";
|
|
6
7
|
import { r as CommentsSchemaOwner } from "./migrate-XjFeQppf.js";
|
|
8
|
+
import "./types-l6GOb_yc.js";
|
|
7
9
|
/** Options of `tenantCommentsStore()`. */
|
|
8
10
|
interface TenantCommentsStoreOptions {
|
|
9
11
|
/** The stored scope of every thread of the tenant, such as a project id. */
|
|
@@ -38,6 +40,13 @@ interface InstallCommentsOptions {
|
|
|
38
40
|
* Without it, the Send routes answer `COMMENTS_SEND_OFF`.
|
|
39
41
|
*/
|
|
40
42
|
webhooks?: () => Promise<CommentSendWebhooks>;
|
|
43
|
+
/**
|
|
44
|
+
* Loads `@vite-hub/comments/realtime`, when the app has the page presence rooms. After each change of a thread, it
|
|
45
|
+
* tells the open pages of the thread to load their threads again. The generated plugin passes it.
|
|
46
|
+
*/
|
|
47
|
+
realtime?: () => Promise<{
|
|
48
|
+
notifyCommentsChange: (thread: CommentThread) => Promise<void>;
|
|
49
|
+
}>;
|
|
41
50
|
/**
|
|
42
51
|
* Keeps the threads of one tenant in `tables` that several tenants share, such as one project of a hosted Console.
|
|
43
52
|
* See `tenantCommentsStore()`. The runtime serves only this definition: the comment operations of the app keep
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { i as installCommentsRuntime } from "./server-
|
|
1
|
+
import { i as installCommentsRuntime } from "./server-8o9u8leM.js";
|
|
2
2
|
import { r as guestIdPrefix } from "./identity-CT7-UGmS.js";
|
|
3
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
4
|
-
import { a as commentsSchemaGate, d as commentForge, f as commentMessages, m as commentsSchema, p as commentThreads, r as commentSendsTables, t as commentSends, u as commentCounters } from "./database-
|
|
3
|
+
import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
|
|
4
|
+
import { a as commentsSchemaGate, d as commentForge, f as commentMessages, m as commentsSchema, p as commentThreads, r as commentSendsTables, t as commentSends, u as commentCounters } from "./database-BuSNVwTx.js";
|
|
5
5
|
import { t as logFailure } from "./request-log-DllKQXj7.js";
|
|
6
6
|
import { i as getActiveCloudflareBinding, n as recentGitHubToken } from "./tokens-Bx4lZ0yt.js";
|
|
7
7
|
import { t as describeCommentContext } from "./context-DbkBjITZ.js";
|
|
8
8
|
import { t as invariant } from "./invariant-CmdvZ3vp.js";
|
|
9
|
-
import { n as isSecureOrigin } from "./request-origin-
|
|
9
|
+
import { n as isSecureOrigin } from "./request-origin-B-CPVAVk.js";
|
|
10
10
|
import { t as commentsErrors } from "./errors-C0VwRHiy.js";
|
|
11
|
-
import { n as pendingKey, o as runtimes } from "./installed-
|
|
11
|
+
import { n as pendingKey, o as runtimes } from "./installed-wUYjqk_k.js";
|
|
12
|
+
import { PgTable } from "drizzle-orm/pg-core";
|
|
12
13
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
13
14
|
import * as v from "valibot";
|
|
14
|
-
import { and, asc, desc, eq, getTableName, gt, gte, inArray, isNotNull, isNull, like, lt, lte, or, sql } from "drizzle-orm";
|
|
15
|
+
import { and, asc, desc, eq, getTableName, gt, gte, inArray, is, isNotNull, isNull, like, lt, lte, or, sql } from "drizzle-orm";
|
|
15
16
|
import { forgeEnv, githubAppCredentials, githubInstallationFor, githubInstallationRouting, readForgeEnv, readGitHubAppPrivateKey } from "@vite-hub/forge";
|
|
16
17
|
// \0rolldown/runtime.js
|
|
17
18
|
var __defProp = Object.defineProperty;
|
|
@@ -129,9 +130,6 @@ function isUniqueViolation(error) {
|
|
|
129
130
|
}
|
|
130
131
|
return false;
|
|
131
132
|
}
|
|
132
|
-
function escapeLike(value) {
|
|
133
|
-
return value.replaceAll(/[%_\\]/g, "\\$&");
|
|
134
|
-
}
|
|
135
133
|
function createCommentsStore(database, tables = {
|
|
136
134
|
commentCounters,
|
|
137
135
|
commentMessages,
|
|
@@ -139,6 +137,16 @@ function createCommentsStore(database, tables = {
|
|
|
139
137
|
}) {
|
|
140
138
|
const { commentCounters: counters, commentMessages: messages, commentThreads: threads } = tables;
|
|
141
139
|
const db = database;
|
|
140
|
+
const postgres = is(messages, PgTable);
|
|
141
|
+
function contains(text, value) {
|
|
142
|
+
return postgres ? sql`strpos(${text}, ${value}) > 0` : sql`instr(${text}, ${value}) > 0`;
|
|
143
|
+
}
|
|
144
|
+
function containsQuotedString(column, value) {
|
|
145
|
+
return contains(column, JSON.stringify(value));
|
|
146
|
+
}
|
|
147
|
+
function listIncludes(column, value) {
|
|
148
|
+
return postgres ? sql`${column}::jsonb @> jsonb_build_array(${value}::text)` : sql`exists (select 1 from json_each(${column}) where json_each.value = ${value})`;
|
|
149
|
+
}
|
|
142
150
|
async function attach(rows) {
|
|
143
151
|
const ids = rows.map((row) => row.id);
|
|
144
152
|
const byThread = /* @__PURE__ */ new Map();
|
|
@@ -295,7 +303,7 @@ function createCommentsStore(database, tables = {
|
|
|
295
303
|
...query.status ? [eq(threads.status, query.status)] : [],
|
|
296
304
|
...query.revision ? [lte(threads.revision, query.revision.lte)] : [],
|
|
297
305
|
...query.mine ? [query.userId ? eq(threads.authorId, query.userId) : sql`1 = 0`] : [],
|
|
298
|
-
...query.mentions ? [query.userId ? sql`exists (select 1 from ${messages} where ${messages.threadId} = ${threads.id} and ${messages.mentions
|
|
306
|
+
...query.mentions ? [query.userId ? sql`exists (select 1 from ${messages} where ${messages.threadId} = ${threads.id} and ${listIncludes(messages.mentions, query.userId)})` : sql`1 = 0`] : [],
|
|
299
307
|
...before ? [or(lt(threads.updatedAt, before.updatedAt), and(eq(threads.updatedAt, before.updatedAt), lt(threads.id, before.id)))] : []
|
|
300
308
|
];
|
|
301
309
|
const limit = Math.min(Math.max(Math.trunc(query.limit ?? 200), 1), 500);
|
|
@@ -313,12 +321,11 @@ function createCommentsStore(database, tables = {
|
|
|
313
321
|
return row ? find(row.threadId) : null;
|
|
314
322
|
},
|
|
315
323
|
async getByAttachment(key, cursor) {
|
|
316
|
-
const pattern = `%${JSON.stringify(key).replaceAll(/[\\%_]/g, (character) => `\\${character}`)}%`;
|
|
317
324
|
const rows = await db.select({
|
|
318
325
|
id: messages.id,
|
|
319
326
|
threadId: messages.threadId,
|
|
320
327
|
attachments: messages.attachments
|
|
321
|
-
}).from(messages).where(and(
|
|
328
|
+
}).from(messages).where(and(containsQuotedString(messages.attachments, key), cursor === void 0 ? void 0 : gt(messages.id, cursor))).orderBy(asc(messages.id)).limit(candidateLimit);
|
|
322
329
|
const ids = [...new Set(rows.filter((row) => parseJson(row.attachments, []).includes(key)).map((row) => row.threadId))];
|
|
323
330
|
return {
|
|
324
331
|
threads: (await Promise.all(ids.map((id) => find(id)))).filter((thread) => thread !== null),
|
|
@@ -439,7 +446,7 @@ function createCommentsStore(database, tables = {
|
|
|
439
446
|
const resolved = (await db.select({
|
|
440
447
|
id: threads.id,
|
|
441
448
|
resolvedBy: threads.resolvedBy
|
|
442
|
-
}).from(threads).where(
|
|
449
|
+
}).from(threads).where(containsQuotedString(threads.resolvedBy, userId))).flatMap(({ id, resolvedBy }) => resolvedBy !== null && parseJson(resolvedBy, void 0)?.id === userId ? [{
|
|
443
450
|
id,
|
|
444
451
|
resolvedBy
|
|
445
452
|
}] : []);
|
|
@@ -477,8 +484,7 @@ function createCommentsStore(database, tables = {
|
|
|
477
484
|
return [...seen.values()];
|
|
478
485
|
},
|
|
479
486
|
async knownUsers(query, limit, canRead) {
|
|
480
|
-
const
|
|
481
|
-
const matching = sql`lower(coalesce(${messages.authorName}, ${messages.authorId})) like ${pattern} escape '\\'`;
|
|
487
|
+
const matching = contains(sql`lower(coalesce(${messages.authorName}, ${messages.authorId}))`, query.toLowerCase());
|
|
482
488
|
const seen = /* @__PURE__ */ new Map();
|
|
483
489
|
const readable = candidateThreadAccess(canRead);
|
|
484
490
|
let before;
|
|
@@ -2080,6 +2086,8 @@ function installComments(comments, install) {
|
|
|
2080
2086
|
...install.attachments ? { attachments: install.attachments } : {},
|
|
2081
2087
|
...install.rateLimit ? { rateLimit: install.rateLimit } : {}
|
|
2082
2088
|
};
|
|
2089
|
+
const realtime = install.realtime;
|
|
2090
|
+
if (realtime && !install.tenant) runtime.changed = async (thread) => (await realtime()).notifyCommentsChange(thread);
|
|
2083
2091
|
let sync;
|
|
2084
2092
|
if (comments.options.forge) {
|
|
2085
2093
|
const forge = createForgeSync(comments.options.forge, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-
|
|
1
|
+
import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-8o9u8leM.js";
|
|
2
2
|
// src/installed.ts
|
|
3
3
|
/** The runtime that `installComments()` connected to each definition. */
|
|
4
4
|
const runtimes = /* @__PURE__ */ new WeakMap();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-
|
|
2
|
-
import { t as AnyOperation } from "./operations-
|
|
1
|
+
import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-IvgrI4XM.js";
|
|
2
|
+
import { t as AnyOperation } from "./operations-DFLer1fR.js";
|
|
3
3
|
import { f as CommentsPolicyGate, g as CommentsUser } from "./define-B1jLSPe9.js";
|
|
4
4
|
import { C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, O as CommentUsersInput, T as CommentThread, c as CommentCreateInput, f as CommentEditInput, g as CommentGetInput, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, s as CommentContext, v as CommentListQuery, x as CommentReplyInput, y as CommentMessage } from "./types-BX3vH18p.js";
|
|
5
5
|
import * as v from "valibot";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { n as outboxAccountHeader } from "./client-files-lC6X7XyS.js";
|
|
2
|
-
import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
|
|
3
2
|
import { n as pagePathOf, t as isPagePath } from "./path-8yqMd8zR.js";
|
|
4
3
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
5
|
-
import {
|
|
4
|
+
import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
|
|
5
|
+
import { C as threadChanged, E as createClientRateLimit, S as suggest, _ as requestIdSchema, a as createThread, c as earlierThread, d as maximumAttachmentBytes, f as maximumCommentBodyLength, g as replyToThread, h as readAttachment, l as editMessage, m as personOf, n as base64, o as deniedError, r as can, s as earlierReply, t as attachmentThread, u as fail, v as retried, w as clientAddressKey, x as storeAttachment, y as retriedReply } from "./service-XT2A8YEF.js";
|
|
6
6
|
import { n as guestFromHeaders, t as authorOf } from "./identity-CT7-UGmS.js";
|
|
7
7
|
import { t as describeCommentContext } from "./context-DbkBjITZ.js";
|
|
8
|
-
import { t as commentsRuntime } from "./server-
|
|
8
|
+
import { t as commentsRuntime } from "./server-8o9u8leM.js";
|
|
9
9
|
import { defineDiagnostics } from "nostics";
|
|
10
10
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
11
11
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
@@ -40,7 +40,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
40
40
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
41
41
|
},
|
|
42
42
|
INTERNAL_R0024: {
|
|
43
|
-
fix: "Start the dev server
|
|
43
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`), or pass `--url <origin>` of a deployed app and set VITEHUB_CONSOLE_PRIVATE_KEY_<NAME> to a private key whose public key the app has in VITEHUB_CONSOLE_KEY_<NAME>.",
|
|
44
44
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
45
45
|
},
|
|
46
46
|
INTERNAL_R0023: {
|
|
@@ -156,7 +156,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
156
156
|
fix: "Give a switch column `format: \"switch\"` and `switch: { operation, input }` with a registered operation name, or remove both."
|
|
157
157
|
},
|
|
158
158
|
INTERNAL_R0025: {
|
|
159
|
-
fix: "Start `vite dev` in the project that you run the command from, or pass `--url` of that server.",
|
|
159
|
+
fix: "Start the dev server (`nuxt dev` or `vite dev`) in the project that you run the command from, or pass `--url` of that server.",
|
|
160
160
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
161
161
|
},
|
|
162
162
|
INTERNAL_R0026: {
|
|
@@ -177,7 +177,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
177
177
|
},
|
|
178
178
|
INTERNAL_R0002: {
|
|
179
179
|
...dynamicError,
|
|
180
|
-
fix:
|
|
180
|
+
fix: ({ fix }) => fix ?? "Build for a host that provides this capability, or set the option named in the message to `false`."
|
|
181
181
|
},
|
|
182
182
|
INTERNAL_R0004: {
|
|
183
183
|
...dynamicError,
|
|
@@ -415,7 +415,6 @@ function isSectionId(section) {
|
|
|
415
415
|
function operationInputJsonSchema(operation) {
|
|
416
416
|
return standardJsonSchema(operation.input, "input") ?? { type: "object" };
|
|
417
417
|
}
|
|
418
|
-
/** `"blob:media"` → `["blob:media", "blob"]`: a grant of the section covers each of its scopes. */
|
|
419
418
|
function grantsFor(section) {
|
|
420
419
|
const separator = section.indexOf(":");
|
|
421
420
|
return separator === -1 ? [section] : [section, section.slice(0, separator)];
|
|
@@ -905,18 +904,18 @@ const commentActions = {
|
|
|
905
904
|
}
|
|
906
905
|
if (deletesThread) {
|
|
907
906
|
if (await who.runtime.store.deleteThread(found.id, owns ? ownerId : void 0) === false) throw fail(commentsErrorDiagnostics.COMMENTS_R0009({ action: "delete" }), 403);
|
|
908
|
-
who.runtime
|
|
907
|
+
await threadChanged(who.runtime, found);
|
|
909
908
|
return null;
|
|
910
909
|
}
|
|
911
910
|
const next = await who.runtime.store.deleteMessage(found.id, target.id, Date.now());
|
|
912
|
-
who.runtime
|
|
911
|
+
await threadChanged(who.runtime, next);
|
|
913
912
|
return next;
|
|
914
913
|
},
|
|
915
914
|
async setStatus(input, who, status) {
|
|
916
915
|
const found = await load(who, input.threadId);
|
|
917
916
|
await allow(who, "resolve", { thread: found });
|
|
918
917
|
const next = await who.runtime.store.setStatus(found.id, status, author(who), Date.now(), status === "resolved" ? who.actor : void 0);
|
|
919
|
-
who.runtime
|
|
918
|
+
await threadChanged(who.runtime, next);
|
|
920
919
|
if (status === "open") await who.runtime.reopened?.(next);
|
|
921
920
|
return next;
|
|
922
921
|
},
|
|
@@ -964,7 +963,7 @@ const commentActions = {
|
|
|
964
963
|
}
|
|
965
964
|
if (thread.status !== "resolved" || thread.messages.some((message) => message.createdAt > (thread.resolvedAt ?? 0))) {
|
|
966
965
|
thread = await who.runtime.store.setStatus(thread.id, "resolved", by, Date.now(), who.actor);
|
|
967
|
-
who.runtime
|
|
966
|
+
await threadChanged(who.runtime, thread);
|
|
968
967
|
}
|
|
969
968
|
resolved.push(thread);
|
|
970
969
|
} catch (cause) {
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as maximumCommentBodyLength } from "./service-
|
|
2
|
-
import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-
|
|
1
|
+
import { a as maximumCommentBodyLength } from "./service-IvgrI4XM.js";
|
|
2
|
+
import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-Qt8ASQqW.js";
|
|
3
3
|
export { CommentsCaller, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
|
package/dist/operations.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-
|
|
2
|
-
import { f as maximumCommentBodyLength } from "./service-
|
|
1
|
+
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-kMPw-Cyb.js";
|
|
2
|
+
import { f as maximumCommentBodyLength } from "./service-XT2A8YEF.js";
|
|
3
3
|
export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
|