@vite-hub/comments 0.1.0 → 0.3.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 +79 -31
- package/dist/anchor.d.ts +7 -4
- package/dist/anchor.js +10 -5
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +78 -3
- package/dist/client.js +198 -13
- package/dist/{console-BIz9t2cO.d.ts → console-h4KlhIik.d.ts} +97 -8
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +738 -347
- package/dist/database/postgres.js +28 -7
- package/dist/{database-Cb2xjC1V.d.ts → database-CA1aHKN7.d.ts} +675 -276
- package/dist/database.d.ts +6 -98
- package/dist/database.js +2 -3
- package/dist/define-43mMR39K.js +89 -0
- package/dist/define-B3TF9zzn.d.ts +204 -0
- package/dist/errors-4gelGVmK.js +57 -0
- package/dist/errors-C6qptPoG.js +135 -0
- package/dist/errors-CyQyKAvy.d.ts +185 -0
- package/dist/fold-name-B7Zb3-MF.js +7 -0
- package/dist/{identity-3qtVC4rF.js → identity-CBOzgxSf.js} +7 -2
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +196 -5
- package/dist/install-BcMPgPk_.js +1154 -0
- package/dist/install-W9ghhGoh.d.ts +36 -0
- package/dist/installed-B-PfERBU.js +30 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/migrate-B0k_0swk.d.ts +54 -0
- package/dist/migrate-BDQ8xqUs.js +289 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/{operations-0B0QTVWX.d.ts → operations-D4A1Fcgf.d.ts} +37 -15
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -7
- package/dist/operations.js +3 -2
- package/dist/overlay/client-DmsSMOzi.js +4 -0
- package/dist/overlay/dist-BoHMOFax.js +14 -0
- package/dist/overlay/dist-yIZmvSaU.js +1 -0
- package/dist/overlay/overlay.js +183 -177
- package/dist/page/loader.js +138 -18
- package/dist/{page-BuroSMXO.js → page-B41ozN63.js} +8 -6
- package/dist/{page-BtXADR6d.d.ts → page-DtbMOEMd.d.ts} +6 -5
- package/dist/page-tools-shared-NHUjKI8E.js +117 -0
- package/dist/path--zk6PEMz.js +18 -0
- package/dist/plugin-PS8PMYus.js +74 -0
- package/dist/realtime.d.ts +6 -12
- package/dist/realtime.js +23 -24
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -29
- package/dist/rpc.js +2 -75
- package/dist/runtime/auth.d.ts +5 -3
- package/dist/runtime/auth.js +8 -5
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +26 -21
- package/dist/runtime/index.d.ts +108 -60
- package/dist/runtime/index.js +684 -236
- package/dist/{server-BomGg3Gb.js → server-D8k-0GXe.js} +16 -7
- package/dist/server.d.ts +14 -88
- package/dist/server.js +7 -326
- package/dist/service-CFVm23k7.d.ts +158 -0
- package/dist/service-GHhhyQj4.js +609 -0
- package/dist/session-DVx-1Tym.d.ts +14 -0
- package/dist/session-EkudzUmm.js +503 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +14 -2
- package/dist/tokens-DSbwkVSy.js +58 -0
- package/dist/types-BIS0hCEl.d.ts +124 -0
- package/dist/types-CZujrMFd.d.ts +322 -0
- package/dist/vite.d.ts +91 -87
- package/dist/vite.js +535 -796
- package/package.json +24 -27
- package/dist/database-BSnVrwHn.js +0 -60
- package/dist/database-C-ktS9Do.js +0 -95
- package/dist/define-BzW2Ychn.d.ts +0 -46
- package/dist/define-Cbhl6QVJ.js +0 -32
- package/dist/errors-BAQYcy3_.d.ts +0 -89
- package/dist/errors-DeD6wTCl.js +0 -77
- package/dist/h3-v1-request-DDGXJ9E7.js +0 -166
- package/dist/index-DklG2Etf.d.ts +0 -111
- package/dist/operations-NZG5dB8y.js +0 -732
- package/dist/page-tools-shared-D-amu6sx.js +0 -53
- package/dist/plugin-QElKQYkA.js +0 -725
- package/dist/request-DVc3M_AG.js +0 -14
- package/dist/src-CRTwnaEG.js +0 -1362
- package/dist/types-Cj8K7Vx7.d.ts +0 -176
- package/dist/types-Un2dcJWD.d.ts +0 -288
package/dist/realtime.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as normalizeCommentPage, t as commentRoom } from "./page-B41ozN63.js";
|
|
2
|
+
import { i as text } from "./identity-CBOzgxSf.js";
|
|
3
|
+
import { n as resolveCommentsPage, t as resolveCommentsIdentity } from "./session-EkudzUmm.js";
|
|
2
4
|
//#region src/realtime.ts
|
|
3
5
|
function toRealtimeUser(user) {
|
|
4
6
|
const result = { id: user.id };
|
|
@@ -12,36 +14,33 @@ function toRealtimeUser(user) {
|
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* The Realtime Definition of the page presence rooms: who is on a page and where their cursor is. Rooms hold no
|
|
15
|
-
* document; threads stay in the Database.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* document; threads stay in the Database. The server binds account presence to the user that Comments resolves.
|
|
18
|
+
* Guests name themselves in the browser. ViteHub adds it as the `comments` definition when the host has a room
|
|
19
|
+
* authority.
|
|
18
20
|
*/
|
|
19
21
|
function commentsRealtime(comments, options = {}) {
|
|
20
22
|
const readers = /* @__PURE__ */ new WeakMap();
|
|
21
23
|
return {
|
|
22
24
|
async identify({ event }) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const user = comments.options.identify ? await comments.options.identify({ event }) : options.consoleSession ? consoleUser : await options.session?.(event).catch(() => null);
|
|
29
|
-
readers.set(event, await comments.can({
|
|
30
|
-
user: user ?? null,
|
|
31
|
-
action: "read"
|
|
32
|
-
}));
|
|
33
|
-
return user && (comments.options.identify || user.guest !== true) ? toRealtimeUser(user) : null;
|
|
25
|
+
const identity = await resolveCommentsIdentity(comments, event, options);
|
|
26
|
+
readers.set(event, identity);
|
|
27
|
+
if (!identity.user) return null;
|
|
28
|
+
return comments.options.identify || identity.user.guest !== true ? toRealtimeUser(identity.user) : null;
|
|
34
29
|
},
|
|
35
|
-
authorize
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
-
|
|
30
|
+
async authorize({ event, mode, documentId, request }) {
|
|
31
|
+
const identity = readers.get(event);
|
|
32
|
+
if (mode !== "read" || identity === void 0) return false;
|
|
33
|
+
const page = new URL(request.url).searchParams.get("page");
|
|
34
|
+
if (!page) return false;
|
|
35
|
+
if (documentId !== commentRoom(normalizeCommentPage(page))) return false;
|
|
36
|
+
const { subject } = await resolveCommentsPage(comments, event, request, page);
|
|
37
|
+
return await comments.can({
|
|
38
|
+
user: identity.user,
|
|
39
|
+
action: "read",
|
|
40
|
+
subject
|
|
41
|
+
}, identity.gate);
|
|
43
42
|
},
|
|
44
|
-
|
|
43
|
+
document: false
|
|
45
44
|
};
|
|
46
45
|
}
|
|
47
46
|
//#endregion
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { E as CommentsTransport } from "./types-CZujrMFd.js";
|
|
2
|
+
//#region src/operations-core/rpc.d.ts
|
|
3
|
+
interface RpcTransportOptions {
|
|
4
|
+
/** The app origin and mount, such as `https://app.example.com` or `/portal`. Defaults to the page origin. */
|
|
5
|
+
base?: string;
|
|
6
|
+
/** Replaces `fetch`, for tests. */
|
|
7
|
+
fetch?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A transport over the operations RPC at `POST /_vitehub/rpc`, one birpc call for each request, for development only.
|
|
11
|
+
* A browser cannot sign Console calls, so it works on a development server with `console: { auth: false }` or without
|
|
12
|
+
* the `console` option. Pages of a production app use `createRestTransport()` from `@vite-hub/comments/client`. It has
|
|
13
|
+
* no `subscribe`: the client refreshes when the window gets focus.
|
|
14
|
+
*/
|
|
15
|
+
declare function createRpcTransport(options?: RpcTransportOptions): CommentsTransport;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createRpcTransport as n, RpcTransportOptions as t };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { i as commentsUnansweredError, t as commentsAnswerError } from "./client-diagnostics-CcFpkbAk.js";
|
|
2
|
+
import { n as isRecordOrFunction, t as isRecord } from "./object-Da1zyPCR.js";
|
|
3
|
+
import { createBirpc } from "birpc";
|
|
4
|
+
//#region ../internal/src/operation-rpc.ts
|
|
5
|
+
/** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
|
|
6
|
+
const operationRpcPath = "/_vitehub/rpc";
|
|
7
|
+
function text(value) {
|
|
8
|
+
return String(value) === value && value ? value : void 0;
|
|
9
|
+
}
|
|
10
|
+
/** Read an untrusted failure body. It keeps only the diagnostic fields, so a stack never passes through. */
|
|
11
|
+
function readOperationRpcError(value) {
|
|
12
|
+
if (!isRecord(value)) return void 0;
|
|
13
|
+
const code = text(value.code);
|
|
14
|
+
const message = text(value.message);
|
|
15
|
+
const status = value.status;
|
|
16
|
+
if (!code || !message || !Number.isInteger(status)) return void 0;
|
|
17
|
+
const failure = {
|
|
18
|
+
code,
|
|
19
|
+
message,
|
|
20
|
+
status: Number(status)
|
|
21
|
+
};
|
|
22
|
+
if (text(value.fix)) failure.fix = text(value.fix);
|
|
23
|
+
if (text(value.docs)) failure.docs = text(value.docs);
|
|
24
|
+
if (isRecord(value.details)) failure.details = value.details;
|
|
25
|
+
return failure;
|
|
26
|
+
}
|
|
27
|
+
/** Read one response message. */
|
|
28
|
+
function readOperationRpcReply(value) {
|
|
29
|
+
if (!isRecord(value) || value.t !== "s") return void 0;
|
|
30
|
+
const id = text(value.i);
|
|
31
|
+
if (Object.hasOwn(value, "e")) {
|
|
32
|
+
const error = readOperationRpcError(value.e);
|
|
33
|
+
return error ? {
|
|
34
|
+
t: "s",
|
|
35
|
+
...id ? { i: id } : {},
|
|
36
|
+
e: error
|
|
37
|
+
} : void 0;
|
|
38
|
+
}
|
|
39
|
+
return id ? {
|
|
40
|
+
t: "s",
|
|
41
|
+
i: id,
|
|
42
|
+
r: value.r
|
|
43
|
+
} : void 0;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Call one operation with birpc over a request and answer transport, such as one HTTP POST per call. `send` posts the
|
|
47
|
+
* JSON message and returns the parsed answer; its own failures, such as a network error or an abort, reject.
|
|
48
|
+
*/
|
|
49
|
+
async function callOperationRpc(name, input, send) {
|
|
50
|
+
let receive;
|
|
51
|
+
let answer;
|
|
52
|
+
const notReply = /* @__PURE__ */ new Error("The answer is not a reply to the operation call.");
|
|
53
|
+
const rpc = createBirpc({}, {
|
|
54
|
+
on: (listener) => {
|
|
55
|
+
receive = listener;
|
|
56
|
+
},
|
|
57
|
+
post: async (message) => {
|
|
58
|
+
answer = await send(JSON.stringify(message));
|
|
59
|
+
const reply = readOperationRpcReply(answer.body);
|
|
60
|
+
if (!reply || reply.i !== void 0 && reply.i !== message.i) throw notReply;
|
|
61
|
+
await receive({
|
|
62
|
+
...reply,
|
|
63
|
+
i: message.i
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
proxify: false,
|
|
67
|
+
timeout: -1
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
return {
|
|
71
|
+
ok: true,
|
|
72
|
+
value: await rpc.$call(name, ...input === void 0 ? [] : [input]),
|
|
73
|
+
answer
|
|
74
|
+
};
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (!answer) throw error;
|
|
77
|
+
if (error === notReply) return {
|
|
78
|
+
ok: false,
|
|
79
|
+
error: void 0,
|
|
80
|
+
answer
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
ok: false,
|
|
84
|
+
error: readOperationRpcError(error),
|
|
85
|
+
answer
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/operations-core/rpc.ts
|
|
91
|
+
/**
|
|
92
|
+
* A transport over the operations RPC at `POST /_vitehub/rpc`, one birpc call for each request, for development only.
|
|
93
|
+
* A browser cannot sign Console calls, so it works on a development server with `console: { auth: false }` or without
|
|
94
|
+
* the `console` option. Pages of a production app use `createRestTransport()` from `@vite-hub/comments/client`. It has
|
|
95
|
+
* no `subscribe`: the client refreshes when the window gets focus.
|
|
96
|
+
*/
|
|
97
|
+
function createRpcTransport(options = {}) {
|
|
98
|
+
const base = (options.base ?? "").replace(/\/+$/, "");
|
|
99
|
+
async function call(operation, input) {
|
|
100
|
+
const send = options.fetch ?? globalThis.fetch;
|
|
101
|
+
let outcome;
|
|
102
|
+
try {
|
|
103
|
+
outcome = await callOperationRpc(operation, input, async (body) => {
|
|
104
|
+
const response = await send(`${base}${operationRpcPath}`, {
|
|
105
|
+
body,
|
|
106
|
+
cache: "no-store",
|
|
107
|
+
credentials: "same-origin",
|
|
108
|
+
headers: {
|
|
109
|
+
"content-type": "application/json",
|
|
110
|
+
"x-vitehub-console": "1"
|
|
111
|
+
},
|
|
112
|
+
method: "POST"
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
body: await response.json().catch(() => void 0),
|
|
116
|
+
response
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
} catch (cause) {
|
|
120
|
+
throw commentsUnansweredError(0, cause);
|
|
121
|
+
}
|
|
122
|
+
if (outcome.ok) return outcome.value;
|
|
123
|
+
if (outcome.error) {
|
|
124
|
+
const { message, ...failure } = outcome.error;
|
|
125
|
+
throw commentsAnswerError({
|
|
126
|
+
...failure,
|
|
127
|
+
why: message
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const { body, response } = outcome.answer;
|
|
131
|
+
if (!isRecordOrFunction(body) || typeof body.code !== "string" || typeof body.message !== "string") throw commentsUnansweredError(response.status);
|
|
132
|
+
throw commentsAnswerError({
|
|
133
|
+
code: body.code,
|
|
134
|
+
status: typeof body.status === "number" ? body.status : response.status,
|
|
135
|
+
why: body.message,
|
|
136
|
+
...typeof body.fix === "string" ? { fix: body.fix } : {},
|
|
137
|
+
...isRecordOrFunction(body.details) ? { details: body.details } : {}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
create: (input) => call("comments.create", input),
|
|
142
|
+
delete: (input) => call("comments.delete", input),
|
|
143
|
+
edit: (input) => call("comments.edit", input),
|
|
144
|
+
get: (input) => call("comments.get", input),
|
|
145
|
+
list: (query) => call("comments.list", query),
|
|
146
|
+
reopen: (input) => call("comments.reopen", input),
|
|
147
|
+
reply: (input) => call("comments.reply", input),
|
|
148
|
+
resolve: (input) => call("comments.resolve", input),
|
|
149
|
+
users: (input) => call("comments.users", input)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
export { createRpcTransport as t };
|
package/dist/rpc.d.ts
CHANGED
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export interface RpcTransportOptions {
|
|
4
|
-
/** The app origin and mount, such as `https://app.example.com` or `/portal`. Defaults to the page origin. */
|
|
5
|
-
base?: string;
|
|
6
|
-
/** Replaces `fetch`, for tests. */
|
|
7
|
-
fetch?: typeof fetch;
|
|
8
|
-
}
|
|
9
|
-
/** A failed operation, with the fields that every ViteHub surface reports. */
|
|
10
|
-
export declare class CommentsRpcError extends Error {
|
|
11
|
-
readonly code: string;
|
|
12
|
-
readonly fix?: string;
|
|
13
|
-
readonly status: number;
|
|
14
|
-
readonly details?: Record<string, unknown>;
|
|
15
|
-
constructor(failure: {
|
|
16
|
-
code: string;
|
|
17
|
-
details?: Record<string, unknown>;
|
|
18
|
-
fix?: string;
|
|
19
|
-
message: string;
|
|
20
|
-
status: number;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A transport over the operations RPC at `/_vitehub/rpc/__call`. The browser sends its session cookie, and the server
|
|
25
|
-
* runs `console.authorize` and the `authorize` of `server/comments.ts`. It has no `subscribe`: the client refreshes
|
|
26
|
-
* when the window gets focus.
|
|
27
|
-
*/
|
|
28
|
-
export declare function createRpcTransport(options?: RpcTransportOptions): CommentsTransport;
|
|
29
|
-
//#endregion
|
|
1
|
+
import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-HBcWtg0T.js";
|
|
2
|
+
export { RpcTransportOptions, createRpcTransport };
|
package/dist/rpc.js
CHANGED
|
@@ -1,75 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var CommentsRpcError = class extends Error {
|
|
4
|
-
code;
|
|
5
|
-
fix;
|
|
6
|
-
status;
|
|
7
|
-
details;
|
|
8
|
-
constructor(failure) {
|
|
9
|
-
super(failure.message);
|
|
10
|
-
this.name = "CommentsRpcError";
|
|
11
|
-
this.code = failure.code;
|
|
12
|
-
this.status = failure.status;
|
|
13
|
-
if (failure.fix) this.fix = failure.fix;
|
|
14
|
-
if (failure.details) this.details = failure.details;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
function isRecord(value) {
|
|
18
|
-
return value !== null && Object(value) === value && !Array.isArray(value);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* A transport over the operations RPC at `/_vitehub/rpc/__call`. The browser sends its session cookie, and the server
|
|
22
|
-
* runs `console.authorize` and the `authorize` of `server/comments.ts`. It has no `subscribe`: the client refreshes
|
|
23
|
-
* when the window gets focus.
|
|
24
|
-
*/
|
|
25
|
-
function createRpcTransport(options = {}) {
|
|
26
|
-
const base = (options.base ?? "").replace(/\/+$/, "");
|
|
27
|
-
async function call(operation, input) {
|
|
28
|
-
const send = options.fetch ?? globalThis.fetch;
|
|
29
|
-
let response;
|
|
30
|
-
try {
|
|
31
|
-
response = await send(`${base}/_vitehub/rpc/__call`, {
|
|
32
|
-
body: JSON.stringify({
|
|
33
|
-
operation,
|
|
34
|
-
input
|
|
35
|
-
}),
|
|
36
|
-
cache: "no-store",
|
|
37
|
-
credentials: "same-origin",
|
|
38
|
-
headers: {
|
|
39
|
-
"content-type": "application/json",
|
|
40
|
-
"x-vitehub-console": "1"
|
|
41
|
-
},
|
|
42
|
-
method: "POST"
|
|
43
|
-
});
|
|
44
|
-
} catch (cause) {
|
|
45
|
-
throw new CommentsRpcError({
|
|
46
|
-
code: "COMMENTS_R0013",
|
|
47
|
-
fix: "Check the connection and try again.",
|
|
48
|
-
message: `The request failed: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
49
|
-
status: 0
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
const body = await response.json().catch(() => void 0);
|
|
53
|
-
if (isRecord(body) && body.ok === true) return body.value;
|
|
54
|
-
throw new CommentsRpcError({
|
|
55
|
-
code: isRecord(body) && typeof body.code === "string" ? body.code : "COMMENTS_R0013",
|
|
56
|
-
message: isRecord(body) && typeof body.message === "string" ? body.message : `The server answered with HTTP ${response.status}.`,
|
|
57
|
-
status: isRecord(body) && typeof body.status === "number" ? body.status : response.status,
|
|
58
|
-
...isRecord(body) && typeof body.fix === "string" ? { fix: body.fix } : {},
|
|
59
|
-
...isRecord(body) && isRecord(body.details) ? { details: body.details } : {}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
create: (input) => call("comments.create", input),
|
|
64
|
-
delete: (input) => call("comments.delete", input),
|
|
65
|
-
edit: (input) => call("comments.edit", input),
|
|
66
|
-
get: (input) => call("comments.get", input),
|
|
67
|
-
list: (query) => call("comments.list", query),
|
|
68
|
-
reopen: (input) => call("comments.reopen", input),
|
|
69
|
-
reply: (input) => call("comments.reply", input),
|
|
70
|
-
resolve: (input) => call("comments.resolve", input),
|
|
71
|
-
users: (input) => call("comments.users", input)
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
export { CommentsRpcError, createRpcTransport };
|
|
1
|
+
import { t as createRpcTransport } from "./rpc-RKPAusHp.js";
|
|
2
|
+
export { createRpcTransport };
|
package/dist/runtime/auth.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { d as CommentsPeople, g as CommentsUser } from "../define-B3TF9zzn.js";
|
|
2
|
+
import { s as CommentsRequestEvent } from "../types-BIS0hCEl.js";
|
|
3
3
|
//#region src/runtime/auth.d.ts
|
|
4
4
|
/** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
|
|
5
|
-
export declare function commentsAuthSession(event:
|
|
5
|
+
export declare function commentsAuthSession(event: CommentsRequestEvent): Promise<CommentsUser | null>;
|
|
6
|
+
/** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
|
|
7
|
+
export declare const commentsAuthUsers: CommentsPeople;
|
|
6
8
|
//#endregion
|
package/dist/runtime/auth.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as createAuthUsers } from "../server-D8k-0GXe.js";
|
|
2
|
+
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
3
3
|
//#region src/runtime/auth.ts
|
|
4
|
+
const authServer = () => import("@vite-hub/auth/server");
|
|
4
5
|
/** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
|
|
5
6
|
async function commentsAuthSession(event) {
|
|
6
|
-
const request =
|
|
7
|
-
const user = (await
|
|
7
|
+
const request = getStandardContext(event).req;
|
|
8
|
+
const user = (await (await authServer()).useAuth(event).api.getSession({ headers: request.headers }))?.user;
|
|
8
9
|
if (!user || typeof user !== "object" || !("id" in user) || typeof user.id !== "string") return null;
|
|
9
10
|
return {
|
|
10
11
|
...user,
|
|
11
12
|
id: user.id
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
/** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
|
|
16
|
+
const commentsAuthUsers = createAuthUsers(async () => (await authServer()).getAuth());
|
|
14
17
|
//#endregion
|
|
15
|
-
export { commentsAuthSession };
|
|
18
|
+
export { commentsAuthSession, commentsAuthUsers };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ViteHubConsoleRecord } from "../console-
|
|
1
|
+
import { n as ViteHubConsoleRecord } from "../console-h4KlhIik.js";
|
|
2
2
|
//#region src/runtime/console.d.ts
|
|
3
3
|
/** The threads of the app as Console records: open threads first, each group newest activity first. It runs on each Console request. */
|
|
4
4
|
export declare function readCommentsConsoleRecords(): Promise<ViteHubConsoleRecord[]>;
|
package/dist/runtime/console.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as installedComments } from "../plugin-
|
|
1
|
+
import { n as commentsPageScope } from "../page-B41ozN63.js";
|
|
2
|
+
import { t as describeCommentContext } from "../context-BqIsmYP1.js";
|
|
3
|
+
import { n as installedComments } from "../plugin-PS8PMYus.js";
|
|
4
4
|
//#region src/runtime/console.ts
|
|
5
5
|
function excerpt(text) {
|
|
6
6
|
const line = text.replace(/\s+/g, " ").trim();
|
|
@@ -10,46 +10,51 @@ function excerpt(text) {
|
|
|
10
10
|
async function readCommentsConsoleRecords() {
|
|
11
11
|
const comments = installedComments();
|
|
12
12
|
if (!comments) return [];
|
|
13
|
-
const [error,
|
|
13
|
+
const [error, listed] = await comments.list({
|
|
14
14
|
scope: commentsPageScope,
|
|
15
|
+
subjectKind: "page",
|
|
15
16
|
limit: 500
|
|
16
17
|
});
|
|
17
18
|
if (error) return [];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const threads = listed.filter((thread) => thread.subject.kind === "page");
|
|
20
|
+
const ordered = [...threads.filter((thread) => thread.status === "open"), ...threads.filter((thread) => thread.status !== "open")];
|
|
21
|
+
const author = (person) => `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
|
|
22
|
+
return ordered.map((thread) => {
|
|
23
|
+
const first = thread.messages[0];
|
|
24
|
+
const page = thread.subject.id;
|
|
25
|
+
const { anchor } = thread;
|
|
21
26
|
return {
|
|
22
27
|
id: thread.id,
|
|
23
28
|
cells: {
|
|
24
29
|
comment: first ? excerpt(first.body) : "",
|
|
25
|
-
page: `\`${
|
|
26
|
-
author: author(thread.
|
|
27
|
-
replies: String(Math.max(0, thread.
|
|
30
|
+
page: `\`${page}\``,
|
|
31
|
+
author: author(thread.author),
|
|
32
|
+
replies: String(Math.max(0, thread.messages.length - 1)),
|
|
28
33
|
status: thread.status === "open" ? "Open" : "Resolved",
|
|
29
|
-
updated: thread.updatedAt
|
|
34
|
+
updated: new Date(thread.updatedAt).toISOString()
|
|
30
35
|
},
|
|
31
36
|
link: {
|
|
32
|
-
href: `${
|
|
37
|
+
href: `${page}?comment=${thread.n}`,
|
|
33
38
|
label: "Open on page"
|
|
34
39
|
},
|
|
35
|
-
activity: thread.
|
|
36
|
-
author: author(
|
|
37
|
-
at:
|
|
38
|
-
text:
|
|
40
|
+
activity: thread.messages.map((message) => ({
|
|
41
|
+
author: author(message.author),
|
|
42
|
+
at: new Date(message.createdAt).toISOString(),
|
|
43
|
+
text: message.body
|
|
39
44
|
})),
|
|
40
45
|
fields: [
|
|
41
46
|
{
|
|
42
47
|
label: "Page",
|
|
43
|
-
value:
|
|
48
|
+
value: page
|
|
44
49
|
},
|
|
45
|
-
...
|
|
50
|
+
...anchor.kind === "element" ? [{
|
|
46
51
|
label: "Anchor",
|
|
47
|
-
value:
|
|
52
|
+
value: anchor.field ? `Content field ${anchor.field}` : anchor.label ?? anchor.selector
|
|
48
53
|
}] : [],
|
|
49
|
-
...describeCommentContext(thread.context),
|
|
54
|
+
...describeCommentContext(thread.context ?? null),
|
|
50
55
|
...thread.resolvedBy ? [{
|
|
51
56
|
label: "Resolved by",
|
|
52
|
-
value: thread.resolvedBy
|
|
57
|
+
value: author(thread.resolvedBy)
|
|
53
58
|
}] : []
|
|
54
59
|
]
|
|
55
60
|
};
|