@hazem3500/palette 0.9.120 → 0.9.122
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/NODE.md +12 -0
- package/README.md +1 -0
- package/dist/{account-tokens-ZXA2HQS4.js → account-tokens-W2SBGBUW.js} +1 -1
- package/dist/api.d.ts +2 -0
- package/dist/chunk-7DRZRQU4.js +1 -0
- package/dist/chunk-HHUTDVTM.js +1 -0
- package/dist/index.js +1 -1
- package/dist/node.mjs +35 -5
- package/dist/{onboarding-6OSADOWE.js → onboarding-WNFR5RLQ.js} +1 -1
- package/dist/postgres/009_user_share_comments.sql +2 -0
- package/dist/react.js +1 -1
- package/dist/server.js +33 -4
- package/dist/setup.js +1 -1
- package/dist/types.d.ts +10 -0
- package/package.json +1 -1
- package/server/index.ts +42 -3
- package/server/migrations/0023_user_share_comments.sql +3 -0
- package/server/setup-client.txt +73 -68
- package/server/webhooks.ts +2 -0
- package/src/types.ts +8 -0
- package/dist/chunk-AAFGCZLH.js +0 -1
- package/dist/chunk-DU7H4TEX.js +0 -1
package/dist/setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as n,d as o}from"./chunk-
|
|
1
|
+
import{a as n,d as o}from"./chunk-7DRZRQU4.js";import"./chunk-KLPQTFVH.js";import"./chunk-RBHY7UDS.js";import"./chunk-LMXFSXO6.js";import"./chunk-HHUTDVTM.js";import"./chunk-5HZI7HRR.js";import"./chunk-2BS2OWWH.js";import"./chunk-J47R52WX.js";import"./chunk-VX6XCU4E.js";import"./chunk-4HBBEVFK.js";function r(r){return(t={})=>o(n({...r,...t}))}var t=r;export{t as defineKomo,r as definePalette};
|
package/dist/types.d.ts
CHANGED
|
@@ -346,6 +346,16 @@ export interface CommentsOptions {
|
|
|
346
346
|
* never captured, nor is anything inside an element with data-palette-no-snapshot (or the older data-komo-no-snapshot).
|
|
347
347
|
*/
|
|
348
348
|
snapshots?: PaletteSnapshots;
|
|
349
|
+
/**
|
|
350
|
+
* Let reviewers keep new comments out of an integration fed by the project's
|
|
351
|
+
* webhooks, e.g. { label: "Post to the GitHub PR" }. Adds a setting to the Account
|
|
352
|
+
* panel that every new comment follows; a comment kept in Palette is delivered
|
|
353
|
+
* with `share: false`.
|
|
354
|
+
* Needs a server that advertises `share` in /config. Off by default.
|
|
355
|
+
*/
|
|
356
|
+
share?: {
|
|
357
|
+
label: string;
|
|
358
|
+
};
|
|
349
359
|
}
|
|
350
360
|
export interface CommentsController {
|
|
351
361
|
/** Open a new comment anchored to an element. */
|
package/package.json
CHANGED
package/server/index.ts
CHANGED
|
@@ -202,8 +202,10 @@ async function body(request: Request): Promise<Record<string, unknown>> {
|
|
|
202
202
|
? ["emoji", "active"]
|
|
203
203
|
: path === "/me"
|
|
204
204
|
? ["name", "avatarUrl", "accentColor"]
|
|
205
|
+
: path === "/me/settings"
|
|
206
|
+
? ["shareComments"]
|
|
205
207
|
: path === "/threads"
|
|
206
|
-
? ["body", "page", "anchor", "tags", "scope", "snapshotIntent"]
|
|
208
|
+
? ["body", "page", "anchor", "tags", "scope", "snapshotIntent", "share"]
|
|
207
209
|
: path.endsWith("/comments")
|
|
208
210
|
? ["body"]
|
|
209
211
|
: path.includes("/comments/")
|
|
@@ -241,6 +243,22 @@ async function limit(env: Env, key: string, max: number, seconds = 60) {
|
|
|
241
243
|
}
|
|
242
244
|
/** How a session was signed in, stored from D1 migration 0021 / PostgreSQL 007. */
|
|
243
245
|
type SessionVia = "proxy" | "google" | "github" | "guest";
|
|
246
|
+
/** Before migration 0023 (Postgres 009) every reviewer shares new comments. */
|
|
247
|
+
async function shareComments(env: Env, userId: string) {
|
|
248
|
+
try {
|
|
249
|
+
const row = await env.DB.prepare("SELECT share_comments FROM users WHERE id=?")
|
|
250
|
+
.bind(userId)
|
|
251
|
+
.first<{ share_comments: number | null }>();
|
|
252
|
+
return row?.share_comments !== 0;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (missingShareColumn(error)) return true;
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const missingShareColumn = (error: unknown) =>
|
|
259
|
+
error instanceof Error &&
|
|
260
|
+
/no such column|has no column named|column .* does not exist/i.test(error.message) &&
|
|
261
|
+
/share_comments/.test(error.message);
|
|
244
262
|
const missingSessionColumns = (error: unknown) =>
|
|
245
263
|
error instanceof Error &&
|
|
246
264
|
/no such column|has no column named|column .* does not exist/i.test(error.message) &&
|
|
@@ -1151,6 +1169,8 @@ async function route(
|
|
|
1151
1169
|
guestResolve: config.allowGuestResolve !== false,
|
|
1152
1170
|
tokens: !auth.proxy || auth.proxyAccessTokens,
|
|
1153
1171
|
// Element snapshots are opt-in on the client; guests need project consent.
|
|
1172
|
+
// Clients may send `share` on new threads and edit `/me/settings`.
|
|
1173
|
+
share: true,
|
|
1154
1174
|
snapshots: {
|
|
1155
1175
|
readiness: true,
|
|
1156
1176
|
guests: auth.allowGuests && config.allowGuestSnapshots === true,
|
|
@@ -1343,7 +1363,25 @@ async function route(
|
|
|
1343
1363
|
});
|
|
1344
1364
|
}
|
|
1345
1365
|
check(request.method === "GET", 405, "Method not allowed.");
|
|
1346
|
-
return json({ user });
|
|
1366
|
+
return json({ user, settings: { shareComments: await shareComments(env, user.id) } });
|
|
1367
|
+
}
|
|
1368
|
+
if (url.pathname === "/me/settings") {
|
|
1369
|
+
check(request.method === "PATCH", 405, "Method not allowed.");
|
|
1370
|
+
const user = await authenticate(request, env, project);
|
|
1371
|
+
const data = await body(request);
|
|
1372
|
+
check(typeof data.shareComments === "boolean", 400, "Invalid sharing setting.");
|
|
1373
|
+
try {
|
|
1374
|
+
await env.DB.prepare("UPDATE users SET share_comments=? WHERE id=?")
|
|
1375
|
+
.bind(data.shareComments ? 1 : 0, user.id)
|
|
1376
|
+
.run();
|
|
1377
|
+
} catch (error) {
|
|
1378
|
+
if (missingShareColumn(error))
|
|
1379
|
+
throw new ConfigError(
|
|
1380
|
+
"Saving the sharing setting needs D1 migration 0023_user_share_comments (Postgres 009). Apply the migrations."
|
|
1381
|
+
);
|
|
1382
|
+
throw error;
|
|
1383
|
+
}
|
|
1384
|
+
return json({ settings: { shareComments: data.shareComments } });
|
|
1347
1385
|
}
|
|
1348
1386
|
const access: PatAccess = request.method === "GET" ? "read" : "write";
|
|
1349
1387
|
// No anonymous reads. Behind a proxy, authenticate() accepts only sessions
|
|
@@ -1543,6 +1581,7 @@ async function route(
|
|
|
1543
1581
|
const firstCommentId = crypto.randomUUID();
|
|
1544
1582
|
check(data.snapshotIntent === undefined || typeof data.snapshotIntent === "boolean", 400, "Invalid snapshot intent.");
|
|
1545
1583
|
const snapshotStatus = data.snapshotIntent === undefined ? null : data.snapshotIntent ? "pending" : "skipped";
|
|
1584
|
+
check(data.share === undefined || typeof data.share === "boolean", 400, "Invalid sharing choice.");
|
|
1546
1585
|
await env.DB.batch([
|
|
1547
1586
|
// Page-only threads rely on the column default, as before the scope column existed.
|
|
1548
1587
|
scope === "all"
|
|
@@ -1567,7 +1606,7 @@ async function route(
|
|
|
1567
1606
|
user.name,
|
|
1568
1607
|
text,
|
|
1569
1608
|
origin || url.origin
|
|
1570
|
-
), ...(snapshotStatus ? { snapshotStatus } : {}) }, firstCommentId),
|
|
1609
|
+
), ...(snapshotStatus ? { snapshotStatus } : {}), ...(data.share === false ? { share: false } : {}) }, firstCommentId),
|
|
1571
1610
|
...retainReviewerComments(
|
|
1572
1611
|
env.DB,
|
|
1573
1612
|
project,
|