@vite-hub/comments 0.0.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/LICENSE +201 -0
- package/README.md +291 -0
- package/dist/anchor.d.ts +43 -0
- package/dist/anchor.js +133 -0
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +176 -0
- package/dist/client.js +738 -0
- package/dist/console-h4KlhIik.d.ts +332 -0
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +1402 -0
- package/dist/database/postgres.js +81 -0
- package/dist/database-CA1aHKN7.d.ts +1495 -0
- package/dist/database.d.ts +12 -0
- package/dist/database.js +2 -0
- 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-CBOzgxSf.js +39 -0
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +196 -0
- 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-D4A1Fcgf.d.ts +160 -0
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -0
- package/dist/operations.js +3 -0
- 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 +201 -0
- package/dist/page/loader.js +142 -0
- package/dist/page-B41ozN63.js +40 -0
- package/dist/page-DtbMOEMd.d.ts +22 -0
- 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 +12 -0
- package/dist/realtime.js +47 -0
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.js +2 -0
- package/dist/runtime/auth.d.ts +8 -0
- package/dist/runtime/auth.js +18 -0
- package/dist/runtime/connect/node.d.ts +1 -0
- package/dist/runtime/connect/node.js +2 -0
- package/dist/runtime/connect.d.ts +1 -0
- package/dist/runtime/connect.js +2 -0
- package/dist/runtime/console.d.ts +5 -0
- package/dist/runtime/console.js +64 -0
- package/dist/runtime/index.d.ts +270 -0
- package/dist/runtime/index.js +1113 -0
- package/dist/server-D8k-0GXe.js +72 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.js +7 -0
- 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 +30 -0
- package/dist/testing.js +187 -0
- 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 +308 -0
- package/dist/vite.js +1660 -0
- package/package.json +153 -4
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
//#region src/operations-core/errors.d.ts
|
|
2
|
+
declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
|
|
3
|
+
readonly COMMENTS_R0002: {
|
|
4
|
+
readonly why: ({ id }: {
|
|
5
|
+
id: string;
|
|
6
|
+
}) => string;
|
|
7
|
+
readonly fix: "List the threads again, because someone may have deleted this one.";
|
|
8
|
+
};
|
|
9
|
+
readonly COMMENTS_R0003: {
|
|
10
|
+
readonly why: ({ messageId }: {
|
|
11
|
+
messageId: string;
|
|
12
|
+
}) => string;
|
|
13
|
+
readonly fix: "Read the thread again, because someone may have deleted the message.";
|
|
14
|
+
};
|
|
15
|
+
readonly COMMENTS_R0004: {
|
|
16
|
+
readonly why: "Only the author of a message can edit or delete it.";
|
|
17
|
+
readonly fix: "Sign in as the author, or ask them to change the message.";
|
|
18
|
+
};
|
|
19
|
+
readonly COMMENTS_R0005: {
|
|
20
|
+
readonly why: "A comment needs some text.";
|
|
21
|
+
readonly fix: "Write at least one character before you send.";
|
|
22
|
+
};
|
|
23
|
+
readonly COMMENTS_R0006: {
|
|
24
|
+
readonly why: "server/comments.ts defines no authorize policy, so a production build lets in only people signed in with GitHub who can push to the repository, and people that the Console admits to its Comments section. Other signed-in people, such as users of ViteHub Auth or identify, get nothing.";
|
|
25
|
+
readonly fix: "Pass authorize to defineComments({ authorize }) and return true for the people and Agents that may take the action. See https://vitehub.dev/docs/comments/configure#decide-who-can-comment";
|
|
26
|
+
};
|
|
27
|
+
readonly COMMENTS_R0007: {
|
|
28
|
+
readonly why: ({ message }: {
|
|
29
|
+
message: string;
|
|
30
|
+
}) => string;
|
|
31
|
+
readonly fix: "Mention only people that users() finds, and write @ and their name in the text.";
|
|
32
|
+
};
|
|
33
|
+
readonly COMMENTS_R0008: {
|
|
34
|
+
readonly why: ({ kind }: {
|
|
35
|
+
kind: string;
|
|
36
|
+
}) => string;
|
|
37
|
+
readonly fix: "Use page or content, or add defineCommentSubject({ kind, scope }) to defineComments({ subjects }).";
|
|
38
|
+
};
|
|
39
|
+
readonly COMMENTS_R0009: {
|
|
40
|
+
readonly why: ({ action }: {
|
|
41
|
+
action: string;
|
|
42
|
+
}) => string;
|
|
43
|
+
readonly fix: "Ask for access, or allow the action in defineComments({ authorize }).";
|
|
44
|
+
};
|
|
45
|
+
readonly COMMENTS_R0010: {
|
|
46
|
+
readonly why: "The comments runtime is not installed.";
|
|
47
|
+
readonly fix: "Add server/comments.ts and enable the Database with vitehub({ database: true }). `vite dev` and builds install the runtime for you.";
|
|
48
|
+
};
|
|
49
|
+
readonly COMMENTS_R0011: {
|
|
50
|
+
readonly why: "The comment numbers of this scope are busy.";
|
|
51
|
+
readonly fix: "Try again. Several people created a comment at the same moment.";
|
|
52
|
+
};
|
|
53
|
+
readonly COMMENTS_R0012: {
|
|
54
|
+
readonly why: "Writing a comment needs a signed-in user.";
|
|
55
|
+
readonly fix: "Sign in, then try again. Without ViteHub Auth or `identify`, sign in with GitHub so comments know who writes.";
|
|
56
|
+
};
|
|
57
|
+
readonly COMMENTS_R0014: {
|
|
58
|
+
readonly why: "Comments has no place to store attachments: the app has no Blob store and no storeAttachment hook.";
|
|
59
|
+
readonly fix: "Turn on Blob with vitehub({ blob: true }), or pass storeAttachment to defineComments().";
|
|
60
|
+
};
|
|
61
|
+
readonly COMMENTS_R0016: {
|
|
62
|
+
readonly why: "The thread is resolved, so it takes no new replies.";
|
|
63
|
+
readonly fix: "Reopen the thread first, or pass { allowResolved: true } to comments.reply() when your UI allows replies to resolved threads.";
|
|
64
|
+
};
|
|
65
|
+
readonly COMMENTS_R0017: {
|
|
66
|
+
readonly why: ({ message }: {
|
|
67
|
+
message: string;
|
|
68
|
+
}) => string;
|
|
69
|
+
readonly fix: "Attach an image, a PDF, or a text file of at most 5 MB.";
|
|
70
|
+
};
|
|
71
|
+
readonly COMMENTS_R0018: {
|
|
72
|
+
readonly why: ({ message }: {
|
|
73
|
+
message: string;
|
|
74
|
+
}) => string;
|
|
75
|
+
readonly fix: "Check the input against the limits of comments: https://vitehub.dev/docs/comments/limits-and-errors";
|
|
76
|
+
};
|
|
77
|
+
readonly COMMENTS_R0019: {
|
|
78
|
+
readonly why: ({ state, missing }: {
|
|
79
|
+
state: "empty" | "live" | "outdated";
|
|
80
|
+
missing: readonly string[];
|
|
81
|
+
}) => string;
|
|
82
|
+
readonly fix: ({ state }: {
|
|
83
|
+
state: "empty" | "live" | "outdated";
|
|
84
|
+
}) => "Move the tables once in a custom migration: run vitehub database generate --custom --schema-snapshot --name comments_one_model, put the SQL of commentsMigrationSql({ from: \"live\" }) from vite-hub/comments/database in it, then run vitehub database migrate. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model" | "Run vitehub database generate and vitehub database migrate, so the Database gets the comment tables of this version. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model";
|
|
85
|
+
};
|
|
86
|
+
readonly COMMENTS_R0020: {
|
|
87
|
+
readonly why: ({ key }: {
|
|
88
|
+
key: string;
|
|
89
|
+
}) => string;
|
|
90
|
+
readonly fix: "Read the attachment through a message that lists its key, as a person who may read that thread.";
|
|
91
|
+
};
|
|
92
|
+
readonly COMMENTS_R0021: {
|
|
93
|
+
readonly why: "Comments stores attachments with storeAttachment, but has no readAttachment to read them back.";
|
|
94
|
+
readonly fix: "Pass readAttachment to defineComments(), next to storeAttachment, and return the file of the key as a Blob.";
|
|
95
|
+
};
|
|
96
|
+
readonly COMMENTS_R0022: {
|
|
97
|
+
readonly why: "Another comment thread of this scope already uses this requestId: it has another author or another subject, or you may not read it.";
|
|
98
|
+
readonly fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment. Send the same requestId again only to retry the same comment.";
|
|
99
|
+
};
|
|
100
|
+
readonly COMMENTS_B0001: {
|
|
101
|
+
readonly why: ({ file }: {
|
|
102
|
+
file: string;
|
|
103
|
+
}) => string;
|
|
104
|
+
readonly fix: "Remove `database: false` from vitehub(), or set `database: true`. vitehub() turns the Database on for comments when the option is unset.";
|
|
105
|
+
};
|
|
106
|
+
readonly COMMENTS_B0002: {
|
|
107
|
+
readonly why: ({ file }: {
|
|
108
|
+
file: string;
|
|
109
|
+
}) => string;
|
|
110
|
+
readonly fix: "Write `export default defineComments({ authorize })` in server/comments.ts.";
|
|
111
|
+
};
|
|
112
|
+
readonly COMMENTS_B0003: {
|
|
113
|
+
readonly why: "comments() from @vite-hub/comments/vite is for apps without vitehub(). In this app vitehub() owns the Comments configuration.";
|
|
114
|
+
readonly fix: "Remove comments() from the plugins and set vitehub({ comments: true }), or add server/comments.ts. See https://vitehub.dev/docs/comments/configure#turn-comments-on-in-a-vitehub-app";
|
|
115
|
+
};
|
|
116
|
+
readonly COMMENTS_B0004: {
|
|
117
|
+
readonly why: ({ file }: {
|
|
118
|
+
file: string;
|
|
119
|
+
}) => string;
|
|
120
|
+
readonly fix: "Write the Database name as a string literal, such as `defineComments({ database: \"content\" })`, and put no spread after it. Remove the option to use the default or only Database.";
|
|
121
|
+
};
|
|
122
|
+
readonly COMMENTS_GITHUB_CREDENTIALS_MISSING: {
|
|
123
|
+
readonly why: "Comments needs GitHub credentials to post to pull requests: VITEHUB_GITHUB_APP_ID with VITEHUB_GITHUB_PRIVATE_KEY, or VITEHUB_GITHUB_TOKEN.";
|
|
124
|
+
readonly fix: "Set `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY` of a GitHub App that is installed on the repository, or set `VITEHUB_GITHUB_TOKEN`.";
|
|
125
|
+
};
|
|
126
|
+
readonly COMMENTS_GITHUB_REQUEST_FAILED: {
|
|
127
|
+
readonly why: ({ path, status }: {
|
|
128
|
+
path: string;
|
|
129
|
+
status: number;
|
|
130
|
+
}) => string;
|
|
131
|
+
readonly fix: "Sign in with GitHub again, because a status of 401 means that the token expired. For other statuses, check that the GitHub OAuth app of the Comments login is active and that GitHub is reachable.";
|
|
132
|
+
};
|
|
133
|
+
readonly COMMENTS_GITHUB_SYNC_FAILED: {
|
|
134
|
+
readonly why: ({ reason, request, status }: {
|
|
135
|
+
reason: string;
|
|
136
|
+
request: string;
|
|
137
|
+
status: number;
|
|
138
|
+
}) => string;
|
|
139
|
+
readonly fix: "Check that the GitHub App or `VITEHUB_GITHUB_TOKEN` can write pull request comments in the repository. A retry helps for a 5xx status.";
|
|
140
|
+
};
|
|
141
|
+
readonly COMMENTS_GUEST_RATE_LIMITED: {
|
|
142
|
+
readonly why: ({ retryAfter }: {
|
|
143
|
+
retryAfter: number | undefined;
|
|
144
|
+
}) => string;
|
|
145
|
+
readonly fix: "Wait, then try again. Sign in to write without the guest limit of defineComments({ rateLimit }).";
|
|
146
|
+
};
|
|
147
|
+
readonly COMMENTS_MIGRATION_DATABASE_UNSUPPORTED: {
|
|
148
|
+
readonly why: ({ dialect }: {
|
|
149
|
+
dialect: "postgresql" | "sqlite";
|
|
150
|
+
}) => "[vitehub] migrateComments() needs a Postgres Drizzle database with transaction()." | "[vitehub] migrateComments() needs a Drizzle database with batch() or transaction(), so a failure changes nothing.";
|
|
151
|
+
readonly fix: "Pass `migrateComments()` the Drizzle database of `useDatabase()`, or of another driver with `transaction()` on Postgres, or `batch()` or `transaction()` on SQLite.";
|
|
152
|
+
};
|
|
153
|
+
readonly COMMENTS_MIGRATION_LIVE_POSTGRES: {
|
|
154
|
+
readonly why: "[vitehub] The live-site comments model had no Postgres tables, so there is nothing to move.";
|
|
155
|
+
readonly fix: "Use `from: \"outdated\"` for a Postgres Database. Only SQLite, libSQL, and D1 have tables of the live-site model.";
|
|
156
|
+
};
|
|
157
|
+
readonly COMMENTS_RATE_LIMIT_INVALID: {
|
|
158
|
+
readonly why: ({ issue }: {
|
|
159
|
+
issue: string;
|
|
160
|
+
}) => string;
|
|
161
|
+
readonly fix: "Pass rateLimit as { limit, window }, such as { limit: 5, window: \"1m\" }, or remove it to let guests write without a limit.";
|
|
162
|
+
};
|
|
163
|
+
readonly COMMENTS_SECRET_TOO_SHORT: {
|
|
164
|
+
readonly why: ({ minimum }: {
|
|
165
|
+
minimum: number;
|
|
166
|
+
}) => string;
|
|
167
|
+
readonly fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters.";
|
|
168
|
+
};
|
|
169
|
+
readonly COMMENTS_R0001: {
|
|
170
|
+
why: ({ target }: {
|
|
171
|
+
target: string;
|
|
172
|
+
}) => string;
|
|
173
|
+
fix: string;
|
|
174
|
+
};
|
|
175
|
+
readonly COMMENTS_R0013: {
|
|
176
|
+
why: string;
|
|
177
|
+
fix: string;
|
|
178
|
+
};
|
|
179
|
+
readonly COMMENTS_R0015: {
|
|
180
|
+
why: string;
|
|
181
|
+
fix: string;
|
|
182
|
+
};
|
|
183
|
+
}, readonly import("nostics").AnyDiagnosticReporter[], import("nostics").InferCodesData>;
|
|
184
|
+
//#endregion
|
|
185
|
+
export { commentsErrorDiagnostics as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/fold-name.ts
|
|
2
|
+
/** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
|
|
3
|
+
function foldName(text) {
|
|
4
|
+
return text.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { foldName as t };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/identity.ts
|
|
2
|
+
/**
|
|
3
|
+
* Guests name themselves in the browser. Their ids start with this, so a stored guest stays a guest. It lives here,
|
|
4
|
+
* not in the store, so the comment operations load without drizzle-orm.
|
|
5
|
+
*/
|
|
6
|
+
const guestIdPrefix = "guest:";
|
|
7
|
+
/** A non-empty string, or undefined. User records come from apps and Auth, so their fields are untrusted. */
|
|
8
|
+
function text(value) {
|
|
9
|
+
return typeof value === "string" && value ? value : void 0;
|
|
10
|
+
}
|
|
11
|
+
/** The author that a comment keeps for a user: the name, else the email, else "Someone", and the image. */
|
|
12
|
+
function authorOf(user) {
|
|
13
|
+
const author = {
|
|
14
|
+
id: user.id,
|
|
15
|
+
name: (text(user.name) ?? text(user.email) ?? "Someone").slice(0, 256)
|
|
16
|
+
};
|
|
17
|
+
const image = text(user.image);
|
|
18
|
+
if (image) author.image = image;
|
|
19
|
+
if (user.guest === true) author.guest = true;
|
|
20
|
+
return author;
|
|
21
|
+
}
|
|
22
|
+
/** The guest that the overlay names in its request headers after a person without an account types a name. */
|
|
23
|
+
function guestFromHeaders(headers) {
|
|
24
|
+
const id = headers.get("x-vitehub-comments-guest-id");
|
|
25
|
+
const name = headers.get("x-vitehub-comments-guest-name");
|
|
26
|
+
if (!id || !name || id.length > 64) return;
|
|
27
|
+
try {
|
|
28
|
+
const decoded = decodeURIComponent(name).trim().slice(0, 64);
|
|
29
|
+
return decoded ? {
|
|
30
|
+
id: `${guestIdPrefix}${id}`,
|
|
31
|
+
name: decoded,
|
|
32
|
+
guest: true
|
|
33
|
+
} : void 0;
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { text as i, guestFromHeaders as n, guestIdPrefix as r, authorOf as t };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { S as CommentThread, g as CommentMessage, s as CommentContext, w as CommentUser, x as CommentSubject } from "./types-CZujrMFd.js";
|
|
2
|
+
import { f as CommentsPolicyGate, g as CommentsUser, t as CommentAction } from "./define-B3TF9zzn.js";
|
|
3
|
+
import { c as CreateCommentThreadInput, d as ListCommentThreadsOptions, f as ReplyInput, l as DefineCommentsOptions, p as ReplyOptions, t as CommentsErrorCode, u as EditCommentInput } from "./types-BIS0hCEl.js";
|
|
4
|
+
import { i as CommentsRuntime } from "./service-CFVm23k7.js";
|
|
5
|
+
import { Result } from "@vite-hub/runtime";
|
|
6
|
+
//#region src/context.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The context of a thread as label and value pairs, in the order a person reads them: page, element, components,
|
|
9
|
+
* browser, build. The Console and Agent tools show these.
|
|
10
|
+
*/
|
|
11
|
+
declare function describeCommentContext(context: CommentContext | null): Array<{
|
|
12
|
+
label: string;
|
|
13
|
+
value: string;
|
|
14
|
+
}>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/installed.d.ts
|
|
17
|
+
/** The runtime that `installComments()` connected, for the overlay API and the MCP tools. */
|
|
18
|
+
declare function commentsRuntimeOf(comments: Comments): CommentsRuntime | undefined;
|
|
19
|
+
/** The runtime of a definition, or the one that the generated Nitro plugin builds on first use, for the overlay API. */
|
|
20
|
+
declare function resolveCommentsRuntime(comments: Comments): Promise<CommentsRuntime | undefined>;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/index.d.ts
|
|
23
|
+
type Codes<T extends CommentsErrorCode> = T;
|
|
24
|
+
/** The Comments runtime of an app: the export of `server/comments.ts`. */
|
|
25
|
+
interface Comments {
|
|
26
|
+
readonly options: DefineCommentsOptions;
|
|
27
|
+
/** Threads with their messages, newest activity first. */
|
|
28
|
+
list(options?: ListCommentThreadsOptions): Promise<Result<CommentThread[], Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_INVALID_INPUT">>>;
|
|
29
|
+
get(id: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
30
|
+
/** The thread that holds a message, for a route that has only the message id. */
|
|
31
|
+
getByMessage(messageId: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
32
|
+
/** Thread `#n` of a numbering scope, such as `site`. */
|
|
33
|
+
getByNumber(scope: string, n: number): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
34
|
+
/** Starts a thread with its first message, numbered next in the scope of its subject. Runs `onComment`. */
|
|
35
|
+
create(input: CreateCommentThreadInput): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_INVALID_INPUT">>>;
|
|
36
|
+
/** Adds a message to an open thread. Runs `onComment`. */
|
|
37
|
+
reply(threadId: string, input: ReplyInput, options?: ReplyOptions): Promise<Result<CommentMessage, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT" | "COMMENTS_RESOLVED">>>;
|
|
38
|
+
resolve(threadId: string, options: {
|
|
39
|
+
by: CommentUser;
|
|
40
|
+
}): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
41
|
+
reopen(threadId: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
42
|
+
/** Deletes a thread and all its messages. */
|
|
43
|
+
remove(threadId: string): Promise<Result<void, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
44
|
+
/** Deletes one message. Deleting the first message deletes the thread. */
|
|
45
|
+
removeMessage(messageId: string): Promise<Result<void, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
|
|
46
|
+
/** Changes the text of a message and sets `editedAt`. */
|
|
47
|
+
edit(messageId: string, input: EditCommentInput): Promise<Result<CommentMessage, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT">>>;
|
|
48
|
+
/** Deletes every thread of a numbering scope, such as when app code deletes the document that the scope names. */
|
|
49
|
+
removeScope(scope: string): Promise<Result<{
|
|
50
|
+
removed: number;
|
|
51
|
+
}, Codes<"COMMENTS_NOT_INSTALLED">>>;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the `authorize` policy allows an action. Without a policy, see `defaultPolicy()`. `gate` says what your
|
|
54
|
+
* server checked before, such as Console section access; a route of your own usually passes nothing.
|
|
55
|
+
*/
|
|
56
|
+
can(context: {
|
|
57
|
+
user: CommentsUser | null;
|
|
58
|
+
action: CommentAction;
|
|
59
|
+
thread?: CommentThread;
|
|
60
|
+
subject?: CommentSubject;
|
|
61
|
+
console?: boolean;
|
|
62
|
+
}, gate?: CommentsPolicyGate): Promise<boolean>;
|
|
63
|
+
/** People that `@` suggests to `user`, at most 20: `people`, else Auth, else the authors of threads that `user` may read. */
|
|
64
|
+
people(context: {
|
|
65
|
+
query: string;
|
|
66
|
+
user: CommentsUser | null;
|
|
67
|
+
thread?: CommentThread;
|
|
68
|
+
subject?: CommentSubject;
|
|
69
|
+
limit?: number;
|
|
70
|
+
gate?: CommentsPolicyGate;
|
|
71
|
+
}): Promise<Result<CommentUser[], Codes<"COMMENTS_NOT_INSTALLED">>>;
|
|
72
|
+
/**
|
|
73
|
+
* With `forge`: brings the thread's pull request comments in line with the thread now, and posts what failed
|
|
74
|
+
* before. Every change starts this on its own; `flush()` waits for it.
|
|
75
|
+
*/
|
|
76
|
+
sync(threadId: string): Promise<void>;
|
|
77
|
+
/** Waits for the pull request syncs and `onMention` calls that earlier changes started. On Cloudflare, pass it to `waitUntil`. */
|
|
78
|
+
flush(): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
/** Defines Comments for the app: the access policy, the people, the hooks, and the trusted server API. */
|
|
81
|
+
declare function defineComments(options?: DefineCommentsOptions): Comments;
|
|
82
|
+
//#endregion
|
|
83
|
+
export { describeCommentContext as a, resolveCommentsRuntime as i, defineComments as n, commentsRuntimeOf as r, Comments as t };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { A as TextAnchor, C as CommentUploadInput, D as ElementAnchor, E as CommentsTransport, O as ImageAnchor, S as CommentThread, T as CommentUsersInput, _ as CommentMetadata, a as CommentBuild, b as CommentStatusInput, c as CommentCreateInput, d as CommentEvent, f as CommentForgeLink, g as CommentMessage, h as CommentListQuery, i as CommentAttachment, k as PageAnchor, l as CommentDeleteInput, m as CommentListCursor, n as CommentActor, o as CommentComponent, p as CommentGetInput, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentEditInput, v as CommentReplyInput, w as CommentUser, x as CommentSubject, y as CommentStatus } from "./types-CZujrMFd.js";
|
|
2
|
+
import { _ as builtinCommentSubjects, a as CommentsAttachmentFile, b as defineCommentSubject, c as CommentsCanMentionContext, d as CommentsPeople, f as CommentsPolicyGate, g as CommentsUser, h as CommentsStoreAttachmentContext, i as CommentSubjectDefinition, l as CommentsDefinition, m as CommentsReadAttachmentContext, n as CommentMentionEvent, o as CommentsAuthorize, p as CommentsRateLimit, r as CommentMessageEvent, s as CommentsAuthorizeContext, t as CommentAction, u as CommentsGitHubAccess, v as commentsRoleAllows, y as defaultPolicy } from "./define-B3TF9zzn.js";
|
|
3
|
+
import { a as CommentsPageContext, c as CreateCommentThreadInput, d as ListCommentThreadsOptions, f as ReplyInput, i as CommentsIdentifyContext, l as DefineCommentsOptions, n as CommentsForgeOptions, o as CommentsPageSubject, p as ReplyOptions, r as CommentsForgeTarget, s as CommentsRequestEvent, t as CommentsErrorCode, u as EditCommentInput } from "./types-BIS0hCEl.js";
|
|
4
|
+
import { t as commentsErrorDiagnostics } from "./errors-CyQyKAvy.js";
|
|
5
|
+
import { a as describeCommentContext, i as resolveCommentsRuntime, n as defineComments, r as commentsRuntimeOf, t as Comments } from "./index-DNhy69Wt.js";
|
|
6
|
+
import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage, r as commentsRealtimeDefinition, t as commentRoom } from "./page-DtbMOEMd.js";
|
|
7
|
+
export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentEditInput, type CommentEvent, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, builtinCommentSubjects, commentRoom, commentsErrorDiagnostics, commentsPageScope, commentsRealtimeDefinition, commentsRoleAllows, commentsRoute, commentsRuntimeOf, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage, resolveCommentsRuntime };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
|
|
2
|
+
import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage, r as commentsRealtimeDefinition, t as commentRoom } from "./page-B41ozN63.js";
|
|
3
|
+
import { _ as scopeOf, i as createThread, m as replyToThread, n as can, s as editMessage, x as clientRateLimitIssue, y as suggest } from "./service-GHhhyQj4.js";
|
|
4
|
+
import { t as describeCommentContext } from "./context-BqIsmYP1.js";
|
|
5
|
+
import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition, t as builtinCommentSubjects } from "./define-43mMR39K.js";
|
|
6
|
+
import { a as runtimeOf, n as pendingKey, o as runtimes, r as resolveCommentsRuntime, t as commentsRuntimeOf } from "./installed-B-PfERBU.js";
|
|
7
|
+
import { t as commentsErrors } from "./errors-4gelGVmK.js";
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
/** A thread that someone deleted during the change: the store reads it again and finds nothing. */
|
|
10
|
+
function gone(error) {
|
|
11
|
+
if (error instanceof Error && Reflect.get(error, "code") === "COMMENTS_R0002") return void 0;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
/** Diagnostics of the shared core, as the `[error, data]` codes of the server API. */
|
|
15
|
+
function resultError(error, id) {
|
|
16
|
+
const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
17
|
+
if (code === "COMMENTS_R0002" || code === "COMMENTS_R0003") return commentsErrors.COMMENTS_NOT_FOUND({ id });
|
|
18
|
+
if (code === "COMMENTS_R0016") return commentsErrors.COMMENTS_RESOLVED();
|
|
19
|
+
if (typeof code === "string" && [
|
|
20
|
+
"COMMENTS_R0005",
|
|
21
|
+
"COMMENTS_R0007",
|
|
22
|
+
"COMMENTS_R0008",
|
|
23
|
+
"COMMENTS_R0017",
|
|
24
|
+
"COMMENTS_R0018",
|
|
25
|
+
"COMMENTS_R0022"
|
|
26
|
+
].includes(code)) return commentsErrors.COMMENTS_INVALID_INPUT({ issue: error instanceof Error ? error.message : String(error) });
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
/** Defines Comments for the app: the access policy, the people, the hooks, and the trusted server API. */
|
|
30
|
+
function defineComments(options = {}) {
|
|
31
|
+
const rateLimitIssue = options.rateLimit && clientRateLimitIssue(options.rateLimit);
|
|
32
|
+
if (rateLimitIssue) throw commentsErrorDiagnostics.COMMENTS_RATE_LIMIT_INVALID({ issue: rateLimitIssue });
|
|
33
|
+
const pending = /* @__PURE__ */ new Set();
|
|
34
|
+
const runtime = () => runtimeOf(comments);
|
|
35
|
+
const notInstalled = () => [commentsErrors.COMMENTS_NOT_INSTALLED(), void 0];
|
|
36
|
+
const notFound = (id) => [commentsErrors.COMMENTS_NOT_FOUND({ id }), void 0];
|
|
37
|
+
async function withForge(current, threads) {
|
|
38
|
+
return current.forge ? await current.forge.attach(threads) : threads;
|
|
39
|
+
}
|
|
40
|
+
async function one(current, found, id) {
|
|
41
|
+
return found ? [void 0, (await withForge(current, [found]))[0]] : notFound(id);
|
|
42
|
+
}
|
|
43
|
+
const comments = {
|
|
44
|
+
options,
|
|
45
|
+
async list(query = {}) {
|
|
46
|
+
const current = await runtime();
|
|
47
|
+
if (!current) return notInstalled();
|
|
48
|
+
const limit = Math.min(Math.max(Math.trunc(query.limit ?? 200), 1), 500);
|
|
49
|
+
const { page, ...rest } = query;
|
|
50
|
+
const subject = query.subject ?? (page === void 0 ? void 0 : {
|
|
51
|
+
id: normalizeCommentPage(page),
|
|
52
|
+
kind: "page"
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
return [void 0, await withForge(current, await current.store.list({
|
|
56
|
+
...rest,
|
|
57
|
+
...subject ? { subject } : {},
|
|
58
|
+
limit
|
|
59
|
+
}))];
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (Reflect.get(Object(error), "code") === "COMMENTS_R0019") throw error;
|
|
62
|
+
return [commentsErrors.COMMENTS_INVALID_INPUT({ issue: error instanceof Error ? error.message : String(error) }), void 0];
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
async get(id) {
|
|
66
|
+
const current = await runtime();
|
|
67
|
+
if (!current) return notInstalled();
|
|
68
|
+
return one(current, await current.store.getById(id), id);
|
|
69
|
+
},
|
|
70
|
+
async getByMessage(messageId) {
|
|
71
|
+
const current = await runtime();
|
|
72
|
+
if (!current) return notInstalled();
|
|
73
|
+
return one(current, await current.store.getByMessage(messageId), messageId);
|
|
74
|
+
},
|
|
75
|
+
async getByNumber(scope, n) {
|
|
76
|
+
const current = await runtime();
|
|
77
|
+
if (!current) return notInstalled();
|
|
78
|
+
return one(current, await current.store.getByNumber(scope, n), `${scope}#${n}`);
|
|
79
|
+
},
|
|
80
|
+
async create({ page, subject, ...input }) {
|
|
81
|
+
const current = await runtime();
|
|
82
|
+
if (!current) return notInstalled();
|
|
83
|
+
const target = subject ?? (page === void 0 ? void 0 : {
|
|
84
|
+
id: normalizeCommentPage(page),
|
|
85
|
+
kind: "page"
|
|
86
|
+
});
|
|
87
|
+
if (!target) return [commentsErrors.COMMENTS_INVALID_INPUT({ issue: "subject: Give a subject, or a page." }), void 0];
|
|
88
|
+
try {
|
|
89
|
+
return [void 0, await createThread(current, {
|
|
90
|
+
...input,
|
|
91
|
+
subject: target
|
|
92
|
+
})];
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const failure = resultError(error, target.id);
|
|
95
|
+
return [failure.code === "COMMENTS_NOT_FOUND" ? commentsErrors.COMMENTS_INVALID_INPUT({ issue: failure.why }) : failure, void 0];
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
async reply(threadId, input, replyOptions = {}) {
|
|
99
|
+
const current = await runtime();
|
|
100
|
+
if (!current) return notInstalled();
|
|
101
|
+
const found = await current.store.getById(threadId);
|
|
102
|
+
if (!found) return notFound(threadId);
|
|
103
|
+
try {
|
|
104
|
+
const { message } = await replyToThread(current, found, input, { allowResolved: replyOptions.allowResolved === true });
|
|
105
|
+
return [void 0, message];
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return [resultError(error, threadId), void 0];
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
async resolve(threadId, { by }) {
|
|
111
|
+
const current = await runtime();
|
|
112
|
+
if (!current) return notInstalled();
|
|
113
|
+
if (!await current.store.getById(threadId)) return notFound(threadId);
|
|
114
|
+
const thread = await current.store.setStatus(threadId, "resolved", by, Date.now()).catch(gone);
|
|
115
|
+
if (!thread) return notFound(threadId);
|
|
116
|
+
current.forge?.changed(threadId);
|
|
117
|
+
return [void 0, thread];
|
|
118
|
+
},
|
|
119
|
+
async reopen(threadId) {
|
|
120
|
+
const current = await runtime();
|
|
121
|
+
if (!current) return notInstalled();
|
|
122
|
+
if (!await current.store.getById(threadId)) return notFound(threadId);
|
|
123
|
+
const thread = await current.store.setStatus(threadId, "open", { id: "" }, Date.now()).catch(gone);
|
|
124
|
+
if (!thread) return notFound(threadId);
|
|
125
|
+
current.forge?.changed(threadId);
|
|
126
|
+
return [void 0, thread];
|
|
127
|
+
},
|
|
128
|
+
async remove(threadId) {
|
|
129
|
+
const current = await runtime();
|
|
130
|
+
if (!current) return notInstalled();
|
|
131
|
+
if (!await current.store.getById(threadId)) return notFound(threadId);
|
|
132
|
+
await current.store.deleteThread(threadId);
|
|
133
|
+
current.forge?.changed(threadId);
|
|
134
|
+
return [void 0, void 0];
|
|
135
|
+
},
|
|
136
|
+
async removeMessage(messageId) {
|
|
137
|
+
const current = await runtime();
|
|
138
|
+
if (!current) return notInstalled();
|
|
139
|
+
const thread = await current.store.getByMessage(messageId);
|
|
140
|
+
if (!thread) return notFound(messageId);
|
|
141
|
+
if (thread.messages[0]?.id === messageId) await current.store.deleteThread(thread.id);
|
|
142
|
+
else await current.store.deleteMessage(thread.id, messageId, Date.now()).catch(gone);
|
|
143
|
+
current.forge?.changed(thread.id);
|
|
144
|
+
return [void 0, void 0];
|
|
145
|
+
},
|
|
146
|
+
async edit(messageId, input) {
|
|
147
|
+
const current = await runtime();
|
|
148
|
+
if (!current) return notInstalled();
|
|
149
|
+
const thread = await current.store.getByMessage(messageId);
|
|
150
|
+
if (!thread) return notFound(messageId);
|
|
151
|
+
const author = thread.messages.find((message) => message.id === messageId).author;
|
|
152
|
+
try {
|
|
153
|
+
return [void 0, (await editMessage(current, thread, messageId, input, { user: author.guest ? null : { ...author } })).messages.find((message) => message.id === messageId)];
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const failure = resultError(error, messageId);
|
|
156
|
+
return [failure.code === "COMMENTS_RESOLVED" ? commentsErrors.COMMENTS_INVALID_INPUT({ issue: failure.why }) : failure, void 0];
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
async removeScope(scope) {
|
|
160
|
+
const current = await runtime();
|
|
161
|
+
if (!current) return notInstalled();
|
|
162
|
+
if (!scope || scope.length > 256) return [void 0, { removed: 0 }];
|
|
163
|
+
const removed = await current.store.deleteScope(scope);
|
|
164
|
+
for (const threadId of removed) current.forge?.changed(threadId);
|
|
165
|
+
return [void 0, { removed: removed.length }];
|
|
166
|
+
},
|
|
167
|
+
async can(context, gate) {
|
|
168
|
+
const current = await runtime();
|
|
169
|
+
return can(current ?? { definition: options }, context, gate);
|
|
170
|
+
},
|
|
171
|
+
async people({ query, user, thread, subject, limit = 20, gate }) {
|
|
172
|
+
const current = await runtime();
|
|
173
|
+
if (!current) return notInstalled();
|
|
174
|
+
if (subject) scopeOf(current, subject);
|
|
175
|
+
return [void 0, await suggest(current, {
|
|
176
|
+
limit: Math.min(Math.max(limit, 1), 20),
|
|
177
|
+
query,
|
|
178
|
+
user,
|
|
179
|
+
...gate ? { gate } : {},
|
|
180
|
+
...thread ? { thread } : {},
|
|
181
|
+
...subject ? { subject } : {}
|
|
182
|
+
})];
|
|
183
|
+
},
|
|
184
|
+
async sync(threadId) {
|
|
185
|
+
await runtime();
|
|
186
|
+
await runtimes.get(comments)?.sync?.(threadId);
|
|
187
|
+
},
|
|
188
|
+
async flush() {
|
|
189
|
+
while (pending.size) await Promise.all(pending);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
Reflect.set(comments, pendingKey, pending);
|
|
193
|
+
return Object.freeze(markCommentsDefinition(comments));
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
export { builtinCommentSubjects, commentRoom, commentsErrorDiagnostics, commentsPageScope, commentsRealtimeDefinition, commentsRoleAllows, commentsRoute, commentsRuntimeOf, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage, resolveCommentsRuntime };
|