critiqs-react 0.0.0-stage → 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/AGENT_SETUP.md +190 -0
- package/LICENSE +21 -0
- package/README.md +341 -2
- package/bin/cli.d.mts +21 -0
- package/bin/cli.mjs +293 -0
- package/bin/critiqs.mjs +4 -0
- package/bin/env.d.mts +41 -0
- package/bin/env.mjs +384 -0
- package/bin/init.d.mts +126 -0
- package/bin/init.mjs +965 -0
- package/bin/mcp.d.mts +20 -0
- package/bin/mcp.mjs +314 -0
- package/bin/setup.d.mts +183 -0
- package/bin/setup.mjs +1054 -0
- package/dist/Critiqs.d.ts +9 -0
- package/dist/backend/convex/_generated/api.d.ts +95 -0
- package/dist/backend/convex/_generated/api.js +23 -0
- package/dist/backend/convex/_generated/dataModel.d.ts +60 -0
- package/dist/backend/convex/_generated/server.d.ts +162 -0
- package/dist/backend/convex/_generated/server.js +101 -0
- package/dist/backend/convex/ai.ts +93 -0
- package/dist/backend/convex/aiSettings.ts +43 -0
- package/dist/backend/convex/auth.config.ts +18 -0
- package/dist/backend/convex/captureHttp.ts +96 -0
- package/dist/backend/convex/captures.ts +167 -0
- package/dist/backend/convex/crons.ts +14 -0
- package/dist/backend/convex/deviceSignIn.ts +151 -0
- package/dist/backend/convex/grouping.ts +41 -0
- package/dist/backend/convex/http.ts +724 -0
- package/dist/backend/convex/lib/ai.ts +6 -0
- package/dist/backend/convex/lib/links.ts +12 -0
- package/dist/backend/convex/lib/pages.ts +207 -0
- package/dist/backend/convex/lib/r2.ts +75 -0
- package/dist/backend/convex/lib/store.ts +509 -0
- package/dist/backend/convex/lib/tokens.ts +101 -0
- package/dist/backend/convex/lib/validators.ts +73 -0
- package/dist/backend/convex/lib/vendor/aws4fetch.js +289 -0
- package/dist/backend/convex/lib/vendor/critiqs_ai.js +49081 -0
- package/dist/backend/convex/lib/vendor/critiqs_core.js +385 -0
- package/dist/backend/convex/lib/vendor/critiqs_server.js +3108 -0
- package/dist/backend/convex/notificationEmails.ts +61 -0
- package/dist/backend/convex/notifications.ts +182 -0
- package/dist/backend/convex/plans.ts +67 -0
- package/dist/backend/convex/projects.ts +46 -0
- package/dist/backend/convex/schema.ts +343 -0
- package/dist/backend/convex/search.ts +26 -0
- package/dist/backend/convex/signIn.ts +368 -0
- package/dist/backend/convex/tags.ts +68 -0
- package/dist/backend/convex/threads.ts +146 -0
- package/dist/backend/convex/users.ts +13 -0
- package/dist/constants.d.ts +4 -0
- package/dist/core/types.d.ts +72 -0
- package/dist/host.d.ts +66 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8076 -0
- package/dist/server/chunks/driver-n9zpr0k3.js +21 -0
- package/dist/server/chunks/index-9bg7tmnq.js +522 -0
- package/dist/server/chunks/index-askcfn7t.js +148 -0
- package/dist/server/chunks/providers-rv184xvj.js +48444 -0
- package/dist/server/chunks/token-kzddms7r.js +63 -0
- package/dist/server/chunks/token-util-k8bee1wc.js +4 -0
- package/dist/server/index.d.ts +87 -0
- package/dist/server/index.js +4889 -0
- package/package.json +77 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use node";
|
|
2
|
+
|
|
3
|
+
import { deliverOne, resendMailer } from "./lib/vendor/critiqs_server.js";
|
|
4
|
+
import { internal } from "./_generated/api";
|
|
5
|
+
import type { Id } from "./_generated/dataModel";
|
|
6
|
+
import { internalAction } from "./_generated/server";
|
|
7
|
+
import { linkSecret } from "./lib/links";
|
|
8
|
+
import { r2Config, r2Storage } from "./lib/r2";
|
|
9
|
+
|
|
10
|
+
// The mention email worker. It runs in Convex's Node runtime, whose actions
|
|
11
|
+
// have 512 MiB of memory: an email may carry a whole long discussion and a
|
|
12
|
+
// 10 MiB capture, up to the mail service's 40 MB, which the default runtime's
|
|
13
|
+
// 64 MiB could not hold alongside its copies.
|
|
14
|
+
|
|
15
|
+
/** Notifications one worker run takes on. */
|
|
16
|
+
const BATCH = 25;
|
|
17
|
+
|
|
18
|
+
/** Sends due mention emails, then runs again while more are waiting. */
|
|
19
|
+
export const deliver = internalAction({
|
|
20
|
+
args: {},
|
|
21
|
+
handler: async (ctx) => {
|
|
22
|
+
// Each run holds what it claims under its own token, so a run that outlives its lease can't overwrite another's work.
|
|
23
|
+
const claimToken = crypto.randomUUID();
|
|
24
|
+
const ids = await ctx.runMutation(internal.notifications.claim, { claimToken, limit: BATCH });
|
|
25
|
+
if (ids.length === 0) return;
|
|
26
|
+
const secret = await linkSecret(ctx);
|
|
27
|
+
type Outcome = { deliveryId: Id<"deliveries">; result: "sent" | "skipped" | "failed"; reason?: string };
|
|
28
|
+
const outcomes: Outcome[] = [];
|
|
29
|
+
const apiKey = process.env.RESEND_API_KEY;
|
|
30
|
+
const from = process.env.CRITIQS_EMAIL_FROM;
|
|
31
|
+
for (const id of ids) {
|
|
32
|
+
if (!apiKey || !from) {
|
|
33
|
+
outcomes.push({ deliveryId: id, result: "skipped", reason: "Email isn't set up for this deployment." });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const mailer = resendMailer({ apiKey, from });
|
|
37
|
+
// Prepared emails are private files: captures are attached, never linked, since Convex storage links open for anyone who has them.
|
|
38
|
+
const outcome = await deliverOne({
|
|
39
|
+
begin: () => ctx.runQuery(internal.notifications.begin, { id, claimToken, secret }),
|
|
40
|
+
page: ({ version, cursor }) => ctx.runQuery(internal.notifications.page, { id, claimToken, version, cursor }),
|
|
41
|
+
stillMentions: (messageId) => ctx.runQuery(internal.notifications.mentioned, { id, claimToken, messageId: messageId as Id<"messages"> }),
|
|
42
|
+
freeze: ({ version, fileId, to }) =>
|
|
43
|
+
ctx.runMutation(internal.notifications.freeze, { id, claimToken, version, fileId: fileId as Id<"_storage">, to }),
|
|
44
|
+
readFile: async (fileId) => {
|
|
45
|
+
const location = await ctx.runQuery(internal.captures.fileLocation, { fileId: fileId as Id<"_storage"> | Id<"captureFiles"> });
|
|
46
|
+
if (location === null) return await ctx.storage.get(fileId as Id<"_storage">);
|
|
47
|
+
if (location.status !== "attached") return null;
|
|
48
|
+
const response = await r2Storage(r2Config()).get(location);
|
|
49
|
+
return response === null ? null : await response.blob();
|
|
50
|
+
},
|
|
51
|
+
saveFile: (body) => ctx.storage.store(body),
|
|
52
|
+
deleteFile: async (fileId) => void (await ctx.runMutation(internal.notifications.removeFile, { fileId: fileId as Id<"_storage"> })),
|
|
53
|
+
sendPrepared: (body, idempotencyKey) => mailer.sendPrepared!(body, idempotencyKey),
|
|
54
|
+
sendMessage: (message) => mailer.send(message),
|
|
55
|
+
});
|
|
56
|
+
if (outcome !== null) outcomes.push({ deliveryId: id, ...outcome });
|
|
57
|
+
}
|
|
58
|
+
await ctx.runMutation(internal.notifications.complete, { claimToken, outcomes });
|
|
59
|
+
if (ids.length === BATCH) await ctx.scheduler.runAfter(0, internal.notificationEmails.deliver, {});
|
|
60
|
+
},
|
|
61
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyPreferenceLink,
|
|
3
|
+
beginDelivery,
|
|
4
|
+
claimDue,
|
|
5
|
+
cleanUpDeliveries,
|
|
6
|
+
completeDeliveries,
|
|
7
|
+
discussionPage,
|
|
8
|
+
freezeDelivery,
|
|
9
|
+
isLocalReviewAddress,
|
|
10
|
+
operations,
|
|
11
|
+
preferenceToken,
|
|
12
|
+
stillMentions,
|
|
13
|
+
touchParticipant,
|
|
14
|
+
} from "./lib/vendor/critiqs_server.js";
|
|
15
|
+
import { v } from "convex/values";
|
|
16
|
+
import { internal } from "./_generated/api";
|
|
17
|
+
import type { Id } from "./_generated/dataModel";
|
|
18
|
+
import { internalMutation, internalQuery, mutation, query } from "./_generated/server";
|
|
19
|
+
import { convexStore, identityOf, run } from "./lib/store";
|
|
20
|
+
|
|
21
|
+
// Mention emails. Messages save the emails they owe; the worker in
|
|
22
|
+
// `notificationEmails.ts` sends them a minute later through the steps here,
|
|
23
|
+
// retries failures, and gives up after several attempts.
|
|
24
|
+
|
|
25
|
+
export const settings = query({
|
|
26
|
+
args: { projectId: v.id("projects") },
|
|
27
|
+
handler: async (ctx, args) => run(async () => operations.getNotificationSettings(convexStore(ctx), await identityOf(ctx), args)),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const setSettings = mutation({
|
|
31
|
+
args: { projectId: v.id("projects"), mentionEmails: v.optional(v.boolean()), projectMuted: v.optional(v.boolean()) },
|
|
32
|
+
handler: async (ctx, args) => run(async () => operations.setNotificationSettings(convexStore(ctx), await identityOf(ctx), args)),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const claim = internalMutation({
|
|
36
|
+
args: { claimToken: v.string(), limit: v.number() },
|
|
37
|
+
handler: async (ctx, { claimToken, limit }) =>
|
|
38
|
+
(await claimDue(convexStore(ctx), Date.now(), limit, claimToken)) as Id<"deliveries">[],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// The steps of sending one delivery, each its own transaction (see `deliverOne`).
|
|
42
|
+
|
|
43
|
+
/** Checks a claimed delivery; the link key comes from the action, which may generate it. */
|
|
44
|
+
export const begin = internalQuery({
|
|
45
|
+
args: { id: v.id("deliveries"), claimToken: v.string(), secret: v.string() },
|
|
46
|
+
handler: async (ctx, { id, claimToken, secret }) =>
|
|
47
|
+
await beginDelivery(convexStore(ctx), { id, claimToken, preferenceUrl: (scope) => preferenceLink(secret, scope) }),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const page = internalQuery({
|
|
51
|
+
args: { id: v.id("deliveries"), claimToken: v.string(), version: v.string(), cursor: v.union(v.string(), v.null()) },
|
|
52
|
+
handler: async (ctx, args) => await discussionPage(convexStore(ctx), args),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const mentioned = internalQuery({
|
|
56
|
+
args: { id: v.id("deliveries"), claimToken: v.string(), messageId: v.id("messages") },
|
|
57
|
+
handler: async (ctx, args) => await stillMentions(convexStore(ctx), args),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const freeze = internalMutation({
|
|
61
|
+
args: { id: v.id("deliveries"), claimToken: v.string(), version: v.string(), fileId: v.id("_storage"), to: v.string() },
|
|
62
|
+
handler: async (ctx, args) => await freezeDelivery(convexStore(ctx), args),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const removeFile = internalMutation({
|
|
66
|
+
args: { fileId: v.id("_storage") },
|
|
67
|
+
handler: async (ctx, { fileId }) => await convexStore(ctx).files.delete(fileId),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const complete = internalMutation({
|
|
71
|
+
args: {
|
|
72
|
+
claimToken: v.string(),
|
|
73
|
+
outcomes: v.array(
|
|
74
|
+
v.object({
|
|
75
|
+
deliveryId: v.id("deliveries"),
|
|
76
|
+
result: v.union(v.literal("sent"), v.literal("skipped"), v.literal("failed")),
|
|
77
|
+
reason: v.optional(v.string()),
|
|
78
|
+
}),
|
|
79
|
+
),
|
|
80
|
+
},
|
|
81
|
+
handler: async (ctx, { claimToken, outcomes }) =>
|
|
82
|
+
await completeDeliveries(
|
|
83
|
+
convexStore(ctx),
|
|
84
|
+
outcomes.map((outcome) => ({ ...outcome, claimToken })),
|
|
85
|
+
Date.now(),
|
|
86
|
+
),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/** Removes deliveries finished more than a month ago, in batches. */
|
|
90
|
+
export const cleanUp = internalMutation({
|
|
91
|
+
args: {},
|
|
92
|
+
handler: async (ctx) => {
|
|
93
|
+
const removed = await cleanUpDeliveries(convexStore(ctx), Date.now(), 100);
|
|
94
|
+
if (removed === 100) await ctx.scheduler.runAfter(0, internal.notifications.cleanUp, {});
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Lets everyone who commented before mentions existed be mentioned: records
|
|
100
|
+
* each message author as a participant of its project, a page at a time.
|
|
101
|
+
* Run once with `npx convex run notifications:backfillParticipants`.
|
|
102
|
+
*/
|
|
103
|
+
export const backfillParticipants = internalMutation({
|
|
104
|
+
args: { cursor: v.optional(v.union(v.string(), v.null())) },
|
|
105
|
+
handler: async (ctx, { cursor }) => {
|
|
106
|
+
const store = convexStore(ctx);
|
|
107
|
+
const result = await ctx.db.query("messages").paginate({ numItems: 200, cursor: cursor ?? null });
|
|
108
|
+
for (const message of result.page) {
|
|
109
|
+
const thread = await ctx.db.get(message.threadId);
|
|
110
|
+
if (thread !== null) await touchParticipant(store, thread.projectId, message.authorId, message.createdAt);
|
|
111
|
+
}
|
|
112
|
+
if (!result.isDone) await ctx.scheduler.runAfter(0, internal.notifications.backfillParticipants, { cursor: result.continueCursor });
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/** Mention emails waiting longer than this mean scheduled sending isn't running. */
|
|
117
|
+
const OVERDUE_MS = 10 * 60_000;
|
|
118
|
+
|
|
119
|
+
/** Whether mention emails are going out, and whether a project exists, for `critiqs doctor`. */
|
|
120
|
+
export const health = internalQuery({
|
|
121
|
+
args: { projectId: v.optional(v.string()) },
|
|
122
|
+
handler: async (ctx, { projectId }) => {
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
const oldest = await ctx.db
|
|
125
|
+
.query("deliveries")
|
|
126
|
+
.withIndex("by_status_due", (q) => q.eq("status", "pending"))
|
|
127
|
+
.first();
|
|
128
|
+
// A worker that stopped mid-send leaves its claim behind; retries pick it up once the lease ends.
|
|
129
|
+
const stranded = await ctx.db
|
|
130
|
+
.query("deliveries")
|
|
131
|
+
.withIndex("by_status_lease", (q) => q.eq("status", "sending").lt("leaseUntil", now - OVERDUE_MS))
|
|
132
|
+
.first();
|
|
133
|
+
const last = await ctx.db
|
|
134
|
+
.query("deliveries")
|
|
135
|
+
.withIndex("by_finished", (q) => q.gt("finishedAt", 0))
|
|
136
|
+
.order("desc")
|
|
137
|
+
.first();
|
|
138
|
+
const id = projectId === undefined ? null : ctx.db.normalizeId("projects", projectId);
|
|
139
|
+
const project = id === null ? null : await ctx.db.get(id);
|
|
140
|
+
const waitingSince = Math.min(oldest?.dueAt ?? Infinity, stranded?.leaseUntil ?? Infinity);
|
|
141
|
+
return {
|
|
142
|
+
mentionEmails: {
|
|
143
|
+
overdue: waitingSince < now - OVERDUE_MS,
|
|
144
|
+
waitingSince: Number.isFinite(waitingSince) ? waitingSince : null,
|
|
145
|
+
last: last === null ? null : { status: last.status, at: last.finishedAt ?? null },
|
|
146
|
+
},
|
|
147
|
+
...(projectId === undefined
|
|
148
|
+
? {}
|
|
149
|
+
: { project: project === null ? "missing" : "found", ...(project === null ? {} : { reviewAddress: project.reviewUrl !== undefined, reviewAddressLocal: isLocalReviewAddress(project.reviewUrl) }) }),
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// Mute and unsubscribe links
|
|
156
|
+
|
|
157
|
+
export const secretValue = internalQuery({
|
|
158
|
+
args: {},
|
|
159
|
+
handler: async (ctx) => (await ctx.db.query("settings").withIndex("by_key", (q) => q.eq("key", "preference-links")).unique())?.value ?? null,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/** Stores the generated key unless another run stored one first; returns the key in use. */
|
|
163
|
+
export const saveSecret = internalMutation({
|
|
164
|
+
args: { value: v.string() },
|
|
165
|
+
handler: async (ctx, { value }) => {
|
|
166
|
+
const existing = await ctx.db.query("settings").withIndex("by_key", (q) => q.eq("key", "preference-links")).unique();
|
|
167
|
+
if (existing !== null) return existing.value;
|
|
168
|
+
await ctx.db.insert("settings", { key: "preference-links", value });
|
|
169
|
+
return value;
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
async function preferenceLink(secret: string, scope: { userId: string; projectId: string | null }): Promise<string> {
|
|
174
|
+
const site = (process.env.CONVEX_SITE_URL ?? "").replace(/\/$/, "");
|
|
175
|
+
return `${site}/notifications/preferences?token=${encodeURIComponent(await preferenceToken(secret, scope))}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Applies a mute or unsubscribe link after the reviewer confirms it. */
|
|
179
|
+
export const applyLink = internalMutation({
|
|
180
|
+
args: { userId: v.string(), projectId: v.union(v.string(), v.null()) },
|
|
181
|
+
handler: async (ctx, scope) => await applyPreferenceLink(convexStore(ctx), scope),
|
|
182
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DEFAULT_PLANS } from "./lib/vendor/critiqs_server.js";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import type { Id } from "./_generated/dataModel";
|
|
4
|
+
import { internalMutation, internalQuery } from "./_generated/server";
|
|
5
|
+
|
|
6
|
+
// Critiqs Cloud's plans are configuration. Change one without a deploy:
|
|
7
|
+
// npx convex run plans:set '{"name":"free","label":"Free","limits":[...]}'
|
|
8
|
+
// A configured plan replaces the built-in plan of the same name. A plan
|
|
9
|
+
// belongs to an account and covers every project it owns; move an account,
|
|
10
|
+
// found by one of its projects, to another plan with:
|
|
11
|
+
// npx convex run plans:assign '{"projectId":"...","plan":"team"}'
|
|
12
|
+
|
|
13
|
+
const limitValidator = v.object({
|
|
14
|
+
metric: v.union(
|
|
15
|
+
v.literal("projects"),
|
|
16
|
+
v.literal("threads"),
|
|
17
|
+
v.literal("messages"),
|
|
18
|
+
v.literal("reviewers"),
|
|
19
|
+
v.literal("captureBytes"),
|
|
20
|
+
v.literal("mentionEmails"),
|
|
21
|
+
),
|
|
22
|
+
period: v.union(v.literal("total"), v.literal("month"), v.literal("day")),
|
|
23
|
+
max: v.number(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const set = internalMutation({
|
|
27
|
+
args: { name: v.string(), label: v.string(), limits: v.array(limitValidator) },
|
|
28
|
+
handler: async (ctx, plan) => {
|
|
29
|
+
const existing = await ctx.db.query("plans").withIndex("by_name", (q) => q.eq("name", plan.name)).unique();
|
|
30
|
+
if (existing === null) await ctx.db.insert("plans", plan);
|
|
31
|
+
else await ctx.db.replace(existing._id, plan);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** Every plan in effect: configured ones, and built-in ones not replaced. */
|
|
36
|
+
export const list = internalQuery({
|
|
37
|
+
args: {},
|
|
38
|
+
handler: async (ctx) => {
|
|
39
|
+
const configured = await ctx.db.query("plans").collect();
|
|
40
|
+
const names = new Set(configured.map((plan) => plan.name));
|
|
41
|
+
return [
|
|
42
|
+
...configured.map(({ name, label, limits }) => ({ name, label, limits, source: "configured" as const })),
|
|
43
|
+
...Object.values(DEFAULT_PLANS)
|
|
44
|
+
.filter((plan) => !names.has(plan.name))
|
|
45
|
+
.map((plan) => ({ ...plan, source: "built-in" as const })),
|
|
46
|
+
];
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/** Moves an account to another plan, such as after an upgrade: given directly, or as the owner of a project. */
|
|
51
|
+
export const assign = internalMutation({
|
|
52
|
+
args: { userId: v.optional(v.id("users")), projectId: v.optional(v.id("projects")), plan: v.string() },
|
|
53
|
+
handler: async (ctx, { userId, projectId, plan }) => {
|
|
54
|
+
const configured = await ctx.db.query("plans").withIndex("by_name", (q) => q.eq("name", plan)).unique();
|
|
55
|
+
if (configured === null && DEFAULT_PLANS[plan] === undefined) throw new Error(`There is no plan named "${plan}".`);
|
|
56
|
+
let owner: Id<"users"> | undefined = userId;
|
|
57
|
+
if (projectId !== undefined) {
|
|
58
|
+
const project = await ctx.db.get(projectId);
|
|
59
|
+
if (project === null) throw new Error("There is no such project.");
|
|
60
|
+
if (owner !== undefined && owner !== project.createdBy) throw new Error("That project belongs to another account.");
|
|
61
|
+
owner = project.createdBy;
|
|
62
|
+
}
|
|
63
|
+
if (owner === undefined) throw new Error("Name the account by userId or by one of its projects (projectId).");
|
|
64
|
+
if ((await ctx.db.get(owner)) === null) throw new Error("There is no such account.");
|
|
65
|
+
await ctx.db.patch(owner, { plan });
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { operations } from "./lib/vendor/critiqs_server.js";
|
|
2
|
+
import { paginationOptsValidator } from "convex/server";
|
|
3
|
+
import { v } from "convex/values";
|
|
4
|
+
import type { Id } from "./_generated/dataModel";
|
|
5
|
+
import { mutation, query } from "./_generated/server";
|
|
6
|
+
import { convexStore, identityOf, run } from "./lib/store";
|
|
7
|
+
|
|
8
|
+
export { DEFAULT_TAGS } from "./lib/vendor/critiqs_server.js";
|
|
9
|
+
|
|
10
|
+
/** Project setup: any signed-in reviewer can create a project, noting where its prototype is reviewed. */
|
|
11
|
+
export const create = mutation({
|
|
12
|
+
args: { name: v.string(), reviewUrl: v.optional(v.union(v.string(), v.null())) },
|
|
13
|
+
handler: async (ctx, args) =>
|
|
14
|
+
run(async () => (await operations.createProject(convexStore(ctx), await identityOf(ctx), args)) as Id<"projects">),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/** Projects the reviewer created, so setup can reconnect an existing project. */
|
|
18
|
+
export const listMine = query({
|
|
19
|
+
args: { paginationOpts: paginationOptsValidator },
|
|
20
|
+
handler: async (ctx, { paginationOpts }) =>
|
|
21
|
+
run(async () => operations.listMyProjects(convexStore(ctx), await identityOf(ctx), paginationOpts)),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const get = query({
|
|
25
|
+
args: { projectId: v.id("projects") },
|
|
26
|
+
handler: async (ctx, args) => run(async () => operations.getProject(convexStore(ctx), await identityOf(ctx), args)),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/** The prototype address mention emails link to. Only the project's creator may change it. */
|
|
30
|
+
export const setReviewUrl = mutation({
|
|
31
|
+
args: { projectId: v.id("projects"), reviewUrl: v.string() },
|
|
32
|
+
handler: async (ctx, args) => run(async () => operations.setReviewUrl(convexStore(ctx), await identityOf(ctx), args)),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** Mention suggestions: people who have commented in the project, by name. */
|
|
36
|
+
export const participants = query({
|
|
37
|
+
args: { projectId: v.id("projects"), query: v.string() },
|
|
38
|
+
handler: async (ctx, args) => run(async () => operations.listParticipants(convexStore(ctx), await identityOf(ctx), args)),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** The project's usage against its Critiqs Cloud plan, for its owner; null without plans. */
|
|
42
|
+
export const usage = query({
|
|
43
|
+
// The UTC day comes from the client, so the result changes when the day does.
|
|
44
|
+
args: { projectId: v.id("projects"), day: v.string() },
|
|
45
|
+
handler: async (ctx, args) => run(async () => operations.getUsage(convexStore(ctx), await identityOf(ctx), args)),
|
|
46
|
+
});
|