@hazem3500/palette 0.9.108 → 0.9.110
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 +32 -30
- package/README.md +58 -46
- package/cli/agent.mjs +93 -69
- package/cli/config.mjs +17 -1
- package/cli/design-edit.mjs +9 -7
- package/cli/index.mjs +26 -24
- package/cli/snapshots.mjs +3 -3
- package/cli/workflow.mjs +15 -7
- package/dist/{accent-picker-TTIZ65XF.js → accent-picker-PPVPURA7.js} +1 -1
- package/dist/account-tokens-LBRVZAEJ.js +1 -0
- package/dist/adapters/css-variables.js +1 -1
- package/dist/adapters/tailwind.js +1 -1
- package/dist/chunk-2FX2JEMO.js +1 -0
- package/dist/chunk-4HBBEVFK.js +1 -0
- package/dist/chunk-5HZI7HRR.js +1 -0
- package/dist/chunk-DU7H4TEX.js +1 -0
- package/dist/chunk-FGZXQUAD.js +1 -0
- package/dist/{chunk-AYGLN3MI.js → chunk-HLXSRXTK.js} +1 -1
- package/dist/{chunk-DZRM3YUQ.js → chunk-J47R52WX.js} +1 -1
- package/dist/chunk-KELFDOEC.js +1 -0
- package/dist/{chunk-2J3IID4N.js → chunk-KLPQTFVH.js} +1 -1
- package/dist/chunk-ONUORDYE.js +1 -0
- package/dist/chunk-PF4NYFZK.js +1 -0
- package/dist/chunk-S6NEYT36.js +1 -0
- package/dist/chunk-U55ASP2Y.js +1 -0
- package/dist/chunk-VX6XCU4E.js +1 -0
- package/dist/color-editor-QPJQD36F.js +1 -0
- package/dist/config.d.ts +1 -1
- package/dist/design-comment-BF2KGPWU.js +1 -0
- package/dist/{design-export-BNNHI4JP.js → design-export-Y2GU3KER.js} +1 -1
- package/dist/design-geometry-HJLEXLPO.js +1 -0
- package/dist/design-mode-styles.d.ts +1 -1
- package/dist/design-mode.js +1 -1
- package/dist/design-panel-ZQS4WQCI.js +1 -0
- package/dist/design-panel-styles.d.ts +1 -1
- package/dist/design-popup.d.ts +1 -1
- package/dist/design-system.d.ts +5 -4
- package/dist/{field-controls-4ROTPXMO.js → field-controls-4AIIXPNQ.js} +1 -1
- package/dist/{frame-iframe-WBEP3R6S.js → frame-iframe-PYLYMCOK.js} +1 -1
- package/dist/frame-size-TF6SIUFO.js +1 -0
- package/dist/frame-target.d.ts +5 -2
- package/dist/host-motion.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/inline-text-editor-MK6FHDAM.js +1 -0
- package/dist/live-colors-D426RBEC.js +1 -0
- package/dist/live-colors.d.ts +1 -1
- package/dist/node.mjs +102 -75
- package/dist/onboarding-6OSADOWE.js +1 -0
- package/dist/{pin-groups-YAYFPJYA.js → pin-groups-GF53RTHP.js} +1 -1
- package/dist/{pin-move-PG54WWPU.js → pin-move-G6EWHLDO.js} +1 -1
- package/dist/public-env.d.ts +49 -11
- package/dist/react-props-panel-ZSKQ44GS.js +1 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +1 -1
- package/dist/select-menu-OZVNHZ73.js +1 -0
- package/dist/server.js +80 -57
- package/dist/setup.js +1 -1
- package/dist/shell-mode-PLV6F474.js +1 -0
- package/dist/shell-session.d.ts +5 -3
- package/dist/shell.d.ts +1 -1
- package/dist/shell.js +1 -1
- package/dist/shortcut-help-DIMOT2ZK.js +1 -0
- package/dist/snapshot-3PSQKXUV.js +1 -0
- package/dist/snapshot.d.ts +1 -1
- package/dist/source-info.d.ts +1 -1
- package/dist/storage-keys.d.ts +5 -0
- package/dist/tag-editor-B3I7WD4N.js +1 -0
- package/dist/thread-snapshot-ML2RZVID.js +1 -0
- package/dist/token-custom-CASAQWYW.js +1 -0
- package/dist/token-page-NIB5HAVS.js +1 -0
- package/dist/token-picker-AJ5E5IN5.js +1 -0
- package/dist/{toolbar-runtime-QCZONSWE.js → toolbar-runtime-TZWY2KH3.js} +1 -1
- package/dist/typed-custom.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/server/account-page.ts +6 -6
- package/server/iap.ts +2 -2
- package/server/index.ts +30 -24
- package/server/project-management.ts +5 -5
- package/server/proxy-auth.ts +17 -16
- package/server/public-env.ts +67 -11
- package/server/setup-client.txt +173 -173
- package/server/setup-page.ts +1 -1
- package/server/tokens.ts +9 -6
- package/server/webhooks.ts +9 -5
- package/src/types.ts +1 -1
- package/dist/account-tokens-PINQNSNE.js +0 -1
- package/dist/chunk-4KEVPMJJ.js +0 -1
- package/dist/chunk-4XQD75A2.js +0 -1
- package/dist/chunk-57MG3M5P.js +0 -1
- package/dist/chunk-5OVDW2RU.js +0 -1
- package/dist/chunk-6HM4JQLV.js +0 -1
- package/dist/chunk-DLC3CRFV.js +0 -1
- package/dist/chunk-DVYSFT6O.js +0 -1
- package/dist/chunk-FD4GACV2.js +0 -1
- package/dist/chunk-IQOPM3JF.js +0 -1
- package/dist/chunk-UEZCLURX.js +0 -1
- package/dist/color-editor-ATWWSENS.js +0 -1
- package/dist/design-comment-RXUCDTYA.js +0 -1
- package/dist/design-geometry-DPMHGQEK.js +0 -1
- package/dist/design-panel-HTN6LR3V.js +0 -1
- package/dist/frame-size-MRCN6XYD.js +0 -1
- package/dist/inline-text-editor-AMFRKW5Z.js +0 -1
- package/dist/live-colors-GWOVVQSO.js +0 -1
- package/dist/onboarding-BVTCFEHL.js +0 -1
- package/dist/react-props-panel-4XO3NSX3.js +0 -1
- package/dist/select-menu-QAYV7NKJ.js +0 -1
- package/dist/shell-mode-SUYLWDWW.js +0 -1
- package/dist/shortcut-help-XRDNX7MZ.js +0 -1
- package/dist/snapshot-V264ZMQG.js +0 -1
- package/dist/tag-editor-MMAMOEI4.js +0 -1
- package/dist/thread-snapshot-HLTNHS4N.js +0 -1
- package/dist/token-custom-UCA6CBOV.js +0 -1
- package/dist/token-page-PGPWPUKU.js +0 -1
- package/dist/token-picker-WMWUKLKJ.js +0 -1
package/server/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type PatAccess,
|
|
18
18
|
} from "./tokens";
|
|
19
19
|
import { authOptions, type ProxyAuthProvider, type ProxyIdentity } from "./proxy-auth";
|
|
20
|
+
import { paletteEnv } from "./public-env";
|
|
20
21
|
import setupClient from "./setup-client.txt";
|
|
21
22
|
import {
|
|
22
23
|
dispatchWebhook,
|
|
@@ -135,7 +136,7 @@ function webhookEvent(
|
|
|
135
136
|
const json = (data: unknown, status = 200) => Response.json(data, { status });
|
|
136
137
|
const token = () => crypto.randomUUID() + crypto.randomUUID();
|
|
137
138
|
// Sessions should not force reviewers back through sign-in: unless
|
|
138
|
-
//
|
|
139
|
+
// PALETTE_SESSION_MAX_AGE_DAYS caps them, keep them valid for a century and only
|
|
139
140
|
// revoke on logout.
|
|
140
141
|
const SESSION_LIFETIME = 100 * 365 * 86400000;
|
|
141
142
|
async function hash(value: string) {
|
|
@@ -319,7 +320,7 @@ async function authenticate(
|
|
|
319
320
|
} catch (error) {
|
|
320
321
|
if (missingSessionColumns(error))
|
|
321
322
|
throw new ConfigError(
|
|
322
|
-
"
|
|
323
|
+
"PALETTE_PROXY_AUTH and PALETTE_SESSION_MAX_AGE_DAYS need D1 migration 0021_session_origin. Apply the migrations."
|
|
323
324
|
);
|
|
324
325
|
throw error;
|
|
325
326
|
}
|
|
@@ -430,7 +431,7 @@ async function oauthAuthorize(
|
|
|
430
431
|
authorize.search = new URLSearchParams({
|
|
431
432
|
client_id:
|
|
432
433
|
provider === "google" ? env.GOOGLE_CLIENT_ID : env.GITHUB_CLIENT_ID,
|
|
433
|
-
redirect_uri: `${url.origin}${env.
|
|
434
|
+
redirect_uri: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/auth/${provider}/callback`,
|
|
434
435
|
...(provider === "google"
|
|
435
436
|
? { response_type: "code", scope: "openid profile email" }
|
|
436
437
|
: {}),
|
|
@@ -505,7 +506,7 @@ async function oauthCallback(
|
|
|
505
506
|
: env.GITHUB_CLIENT_SECRET,
|
|
506
507
|
grant_type: "authorization_code",
|
|
507
508
|
code,
|
|
508
|
-
redirect_uri: `${url.origin}${env.
|
|
509
|
+
redirect_uri: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/auth/${provider}/callback`,
|
|
509
510
|
code_verifier: saved.verifier,
|
|
510
511
|
}),
|
|
511
512
|
}
|
|
@@ -594,7 +595,7 @@ async function finishSignIn(
|
|
|
594
595
|
via: SessionVia = provider
|
|
595
596
|
) {
|
|
596
597
|
const setupCode =
|
|
597
|
-
env.
|
|
598
|
+
env.PALETTE_HOSTED === "true" &&
|
|
598
599
|
saved.approved_origins &&
|
|
599
600
|
saved.project.startsWith("setup:")
|
|
600
601
|
? saved.project.slice(6)
|
|
@@ -726,12 +727,12 @@ async function route(
|
|
|
726
727
|
const url = new URL(request.url);
|
|
727
728
|
// Invalid sign-in options fail every request, health checks included.
|
|
728
729
|
const auth = authOptions(env);
|
|
729
|
-
if (url.pathname === "/health") return json({ ok: true, version: env.
|
|
730
|
+
if (url.pathname === "/health") return json({ ok: true, version: env.PALETTE_VERSION?.id });
|
|
730
731
|
if (url.pathname === "/setup-client.js" && request.method === "GET")
|
|
731
732
|
return new Response(setupClient, {
|
|
732
733
|
headers: { "Content-Type": "text/javascript; charset=utf-8" },
|
|
733
734
|
});
|
|
734
|
-
if (env.
|
|
735
|
+
if (env.PALETTE_PAUSED === "true")
|
|
735
736
|
throw new HttpError(503, "Inline feedback is temporarily paused.");
|
|
736
737
|
if (env.EDGE_LIMIT) {
|
|
737
738
|
const allowed = await env.EDGE_LIMIT.limit({
|
|
@@ -741,12 +742,12 @@ async function route(
|
|
|
741
742
|
}
|
|
742
743
|
// Keep exact shared quotas: the per-location edge limiter cannot enforce a
|
|
743
744
|
// service-wide daily budget. Unchanged polls still consume these counters.
|
|
744
|
-
if (env.
|
|
745
|
+
if (env.PALETTE_HOSTED === "true")
|
|
745
746
|
await limit(env, "service:requests", 100000, 86400);
|
|
746
747
|
if (
|
|
747
748
|
url.pathname === "/setup/connect" &&
|
|
748
749
|
request.method === "GET" &&
|
|
749
|
-
env.
|
|
750
|
+
env.PALETTE_HOSTED === "true"
|
|
750
751
|
) {
|
|
751
752
|
check(
|
|
752
753
|
env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET,
|
|
@@ -819,13 +820,13 @@ async function route(
|
|
|
819
820
|
authorize.searchParams.set("state", state);
|
|
820
821
|
return oauthAuthorize(new Request(authorize), env, "google");
|
|
821
822
|
}
|
|
822
|
-
if (url.pathname === "/setup") return setupPage(env.
|
|
823
|
+
if (url.pathname === "/setup") return setupPage(env.PALETTE_PUBLIC_PATH ?? "");
|
|
823
824
|
if (url.pathname === "/account" && request.method === "GET")
|
|
824
825
|
return accountPage(env, url);
|
|
825
826
|
if (
|
|
826
827
|
url.pathname === "/setup/start" &&
|
|
827
828
|
request.method === "POST" &&
|
|
828
|
-
env.
|
|
829
|
+
env.PALETTE_HOSTED === "true"
|
|
829
830
|
) {
|
|
830
831
|
await limit(
|
|
831
832
|
env,
|
|
@@ -846,12 +847,12 @@ async function route(
|
|
|
846
847
|
)
|
|
847
848
|
.bind(id, await hash(secret), JSON.stringify(config), Date.now() + 600000)
|
|
848
849
|
.run();
|
|
849
|
-
return json({ id, secret, url: `${url.origin}${env.
|
|
850
|
+
return json({ id, secret, url: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/setup?code=${id}` });
|
|
850
851
|
}
|
|
851
852
|
if (
|
|
852
853
|
url.pathname === "/setup/poll" &&
|
|
853
854
|
request.method === "POST" &&
|
|
854
|
-
env.
|
|
855
|
+
env.PALETTE_HOSTED === "true"
|
|
855
856
|
) {
|
|
856
857
|
await limit(
|
|
857
858
|
env,
|
|
@@ -874,7 +875,7 @@ async function route(
|
|
|
874
875
|
? {
|
|
875
876
|
project: row.project,
|
|
876
877
|
repo: JSON.parse(row.config).repo,
|
|
877
|
-
endpoint: `${url.origin}${env.
|
|
878
|
+
endpoint: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}`,
|
|
878
879
|
}
|
|
879
880
|
: { pending: true }
|
|
880
881
|
);
|
|
@@ -884,7 +885,7 @@ async function route(
|
|
|
884
885
|
);
|
|
885
886
|
if (auth.proxy) {
|
|
886
887
|
// Proxy sign-in replaces OAuth. Its handlers live only under
|
|
887
|
-
//
|
|
888
|
+
// PALETTE_AUTH_PATH_PREFIX when set, the path the proxy protects.
|
|
888
889
|
const prefix = auth.signInPrefix;
|
|
889
890
|
const signInPath =
|
|
890
891
|
!prefix || url.pathname.startsWith(`${prefix}/auth/`)
|
|
@@ -913,7 +914,7 @@ async function route(
|
|
|
913
914
|
: oauthCallback(request, env, oauthPath[1] as "github" | "google");
|
|
914
915
|
const project = string(url.searchParams.get("project"), 100, "project");
|
|
915
916
|
const config: Project | undefined =
|
|
916
|
-
project === "_komo" && env.
|
|
917
|
+
project === "_komo" && env.PALETTE_HOSTED === "true"
|
|
917
918
|
? { repo: "_komo", origins: [url.origin], allowGuests: false }
|
|
918
919
|
: await projectConfig(env, project);
|
|
919
920
|
check(config, 404, "Unknown comments project.");
|
|
@@ -991,7 +992,7 @@ async function route(
|
|
|
991
992
|
url.pathname === "/setup/complete" &&
|
|
992
993
|
request.method === "POST" &&
|
|
993
994
|
project === "_komo" &&
|
|
994
|
-
env.
|
|
995
|
+
env.PALETTE_HOSTED === "true"
|
|
995
996
|
) {
|
|
996
997
|
const user = await authenticate(request, env, project);
|
|
997
998
|
check(
|
|
@@ -1122,7 +1123,7 @@ async function route(
|
|
|
1122
1123
|
403,
|
|
1123
1124
|
"A Google-authenticated owner must finish workspace setup first."
|
|
1124
1125
|
);
|
|
1125
|
-
if (env.
|
|
1126
|
+
if (env.PALETTE_HOSTED !== "true") ctx.waitUntil(maintain(env.DB));
|
|
1126
1127
|
if (url.pathname === "/config" && request.method === "GET")
|
|
1127
1128
|
return json({
|
|
1128
1129
|
// The repository is feedback metadata: keep it from anonymous callers
|
|
@@ -1274,8 +1275,8 @@ async function route(
|
|
|
1274
1275
|
)
|
|
1275
1276
|
.run();
|
|
1276
1277
|
return json({
|
|
1277
|
-
//
|
|
1278
|
-
url: `${url.origin}${env.
|
|
1278
|
+
// PALETTE_PUBLIC_PATH covers apps served under a path behind a proxy that strips it.
|
|
1279
|
+
url: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}${auth.signInPrefix}/auth/${provider}/authorize?state=${encodeURIComponent(state)}`,
|
|
1279
1280
|
});
|
|
1280
1281
|
}
|
|
1281
1282
|
if (url.pathname === "/me") {
|
|
@@ -1447,7 +1448,7 @@ async function route(
|
|
|
1447
1448
|
const group = snapshotsByThread.get(item.thread_id) ?? {};
|
|
1448
1449
|
scope.set("v", String(item.created_at));
|
|
1449
1450
|
group[item.kind] =
|
|
1450
|
-
`${url.origin}${env.
|
|
1451
|
+
`${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/threads/${item.thread_id}/snapshot/${item.kind}?${scope}`;
|
|
1451
1452
|
snapshotsByThread.set(item.thread_id, group);
|
|
1452
1453
|
}
|
|
1453
1454
|
const commentsByThread = new Map<string, CommentRow[]>();
|
|
@@ -1675,7 +1676,7 @@ async function route(
|
|
|
1675
1676
|
ok: true,
|
|
1676
1677
|
kind: snapshot.kind,
|
|
1677
1678
|
size: snapshot.bytes.length,
|
|
1678
|
-
url: `${url.origin}${env.
|
|
1679
|
+
url: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/threads/${threadId}/snapshot/${snapshot.kind}?${scope}`,
|
|
1679
1680
|
},
|
|
1680
1681
|
201
|
|
1681
1682
|
);
|
|
@@ -1952,11 +1953,16 @@ function parseTags(value: string | null | undefined): string[] {
|
|
|
1952
1953
|
return [];
|
|
1953
1954
|
}
|
|
1954
1955
|
}
|
|
1956
|
+
const settingsFor = new WeakMap<Env, Env>();
|
|
1955
1957
|
export default {
|
|
1956
1958
|
async scheduled(_event, env, ctx) {
|
|
1957
1959
|
ctx.waitUntil(maintain(env.DB, true));
|
|
1958
1960
|
},
|
|
1959
|
-
async fetch(request,
|
|
1961
|
+
async fetch(request, settings, ctx) {
|
|
1962
|
+
// Deployments configured before the rename set KOMO_ names. One copy per
|
|
1963
|
+
// bindings object keeps the per-env caches (sign-in options) warm.
|
|
1964
|
+
let env = settingsFor.get(settings);
|
|
1965
|
+
if (!env) settingsFor.set(settings, (env = paletteEnv(settings)));
|
|
1960
1966
|
let response: Response;
|
|
1961
1967
|
// An unapproved site may read why /config refused it, and nothing else.
|
|
1962
1968
|
let refusedSite = false;
|
|
@@ -2003,7 +2009,7 @@ export default {
|
|
|
2003
2009
|
let config: { origins: string[] } | undefined;
|
|
2004
2010
|
try {
|
|
2005
2011
|
config = project
|
|
2006
|
-
? project === "_komo" && env.
|
|
2012
|
+
? project === "_komo" && env.PALETTE_HOSTED === "true"
|
|
2007
2013
|
? { origins: [new URL(request.url).origin] }
|
|
2008
2014
|
: await projectConfig(env, project)
|
|
2009
2015
|
: undefined;
|
|
@@ -103,7 +103,7 @@ export async function manageProject(
|
|
|
103
103
|
enabled: !!row?.webhook_enabled,
|
|
104
104
|
secretConfigured: !!row?.webhook_secret,
|
|
105
105
|
deliveryAvailable:
|
|
106
|
-
typeof env.
|
|
106
|
+
typeof env.PALETTE_WEBHOOK_SEND === "function" && !!env.PALETTE_WEBHOOK_KEYS,
|
|
107
107
|
supportedEvents: WEBHOOK_EVENTS,
|
|
108
108
|
});
|
|
109
109
|
}
|
|
@@ -136,9 +136,9 @@ export async function manageProject(
|
|
|
136
136
|
let secret = current?.webhook_secret ?? null;
|
|
137
137
|
if (data.secret !== undefined && data.secret !== "") {
|
|
138
138
|
check(typeof data.secret === "string", 400, "Invalid signing secret.");
|
|
139
|
-
check(env.
|
|
139
|
+
check(env.PALETTE_WEBHOOK_KEYS, 503, "Webhook encryption is not configured on this server.");
|
|
140
140
|
try {
|
|
141
|
-
secret = await encryptWebhookSecret(env.
|
|
141
|
+
secret = await encryptWebhookSecret(env.PALETTE_WEBHOOK_KEYS, project, data.secret);
|
|
142
142
|
} catch (error) {
|
|
143
143
|
check(false, 400, error instanceof Error ? error.message : "Invalid signing secret.");
|
|
144
144
|
}
|
|
@@ -147,7 +147,7 @@ export async function manageProject(
|
|
|
147
147
|
}
|
|
148
148
|
if (data.enabled) {
|
|
149
149
|
check(
|
|
150
|
-
typeof env.
|
|
150
|
+
typeof env.PALETTE_WEBHOOK_SEND === "function" && !!env.PALETTE_WEBHOOK_KEYS,
|
|
151
151
|
503,
|
|
152
152
|
"Secure webhook delivery is unavailable on this server."
|
|
153
153
|
);
|
|
@@ -245,7 +245,7 @@ export async function manageProject(
|
|
|
245
245
|
return Response.json(
|
|
246
246
|
{
|
|
247
247
|
invite,
|
|
248
|
-
url: `${url.origin}${env.
|
|
248
|
+
url: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/setup?project=${encodeURIComponent(project)}#invite=${encodeURIComponent(invite)}`,
|
|
249
249
|
expiresInDays: 7,
|
|
250
250
|
},
|
|
251
251
|
{ status: 201 }
|
package/server/proxy-auth.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Sign-in and session options shared by the Worker and Node runtimes. Each one
|
|
2
|
-
// is off by default. A trusted identity proxy (
|
|
2
|
+
// is off by default. A trusted identity proxy (PALETTE_PROXY_AUTH) forces the
|
|
3
3
|
// strict settings: reads need a session and guests are refused.
|
|
4
4
|
import { gcpIap } from "./iap";
|
|
5
5
|
import { ConfigError } from "./validation";
|
|
6
|
+
import { paletteEnv } from "./public-env";
|
|
6
7
|
|
|
7
8
|
/** The account a sign-in proxy vouches for. */
|
|
8
9
|
export type ProxyIdentity = { id: string; email: string };
|
|
@@ -63,35 +64,35 @@ export function authPrefix(value: string | undefined): string {
|
|
|
63
64
|
!/^(\/[A-Za-z0-9._~-]+)+$/.test(prefix) ||
|
|
64
65
|
prefix.split("/").some((segment) => segment === "." || segment === "..")
|
|
65
66
|
)
|
|
66
|
-
throw new ConfigError("
|
|
67
|
+
throw new ConfigError("PALETTE_AUTH_PATH_PREFIX must be a path such as /backoffice.");
|
|
67
68
|
return prefix;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
function resolve(env: OptionEnv): AuthOptions {
|
|
71
|
-
const name = option(env, ["
|
|
72
|
-
const audience = option(env, ["
|
|
73
|
-
if (!name && option(env, ["
|
|
74
|
-
throw new ConfigError("
|
|
72
|
+
const name = option(env, ["PALETTE_PROXY_AUTH"]);
|
|
73
|
+
const audience = option(env, ["PALETTE_PROXY_AUDIENCE", "PALETTE_IAP_AUDIENCE"]);
|
|
74
|
+
if (!name && option(env, ["PALETTE_PROXY_AUDIENCE"]))
|
|
75
|
+
throw new ConfigError("PALETTE_PROXY_AUDIENCE needs PALETTE_PROXY_AUTH, such as gcp-iap.");
|
|
75
76
|
const provider = name ?? (audience ? "gcp-iap" : undefined);
|
|
76
77
|
if (provider && !Object.hasOwn(PROVIDERS, provider))
|
|
77
78
|
throw new ConfigError(
|
|
78
|
-
`
|
|
79
|
+
`PALETTE_PROXY_AUTH "${provider}" is not supported. Use one of: ${Object.keys(PROVIDERS).join(", ")}.`,
|
|
79
80
|
);
|
|
80
81
|
if (provider && !audience)
|
|
81
|
-
throw new ConfigError(`
|
|
82
|
+
throw new ConfigError(`PALETTE_PROXY_AUTH=${provider} needs PALETTE_PROXY_AUDIENCE.`);
|
|
82
83
|
const proxy = provider ? PROVIDERS[provider](audience!) : undefined;
|
|
83
84
|
|
|
84
|
-
const signInPrefix = authPrefix(option(env, ["
|
|
85
|
+
const signInPrefix = authPrefix(option(env, ["PALETTE_AUTH_PATH_PREFIX", "PALETTE_AUTH_PREFIX"]));
|
|
85
86
|
if (signInPrefix && !proxy)
|
|
86
|
-
throw new ConfigError("
|
|
87
|
+
throw new ConfigError("PALETTE_AUTH_PATH_PREFIX only applies with PALETTE_PROXY_AUTH.");
|
|
87
88
|
|
|
88
|
-
const days = option(env, ["
|
|
89
|
+
const days = option(env, ["PALETTE_SESSION_MAX_AGE_DAYS"]);
|
|
89
90
|
if (days !== undefined && !(/^\d{1,5}$/.test(days) && +days >= 1 && +days <= 36500))
|
|
90
|
-
throw new ConfigError("
|
|
91
|
+
throw new ConfigError("PALETTE_SESSION_MAX_AGE_DAYS must be a whole number of days from 1 to 36500.");
|
|
91
92
|
|
|
92
93
|
// Parse both flags even when a proxy overrides them, so typos still fail.
|
|
93
|
-
const requireSessionForReads = flag(env, "
|
|
94
|
-
const allowGuests = flag(env, "
|
|
94
|
+
const requireSessionForReads = flag(env, "PALETTE_REQUIRE_SESSION_FOR_READS", false);
|
|
95
|
+
const allowGuests = flag(env, "PALETTE_ALLOW_GUESTS", true);
|
|
95
96
|
return {
|
|
96
97
|
proxy,
|
|
97
98
|
signInPrefix,
|
|
@@ -105,7 +106,7 @@ const resolved = new WeakMap<object, AuthOptions>();
|
|
|
105
106
|
/** The server's sign-in options. Throws ConfigError on an invalid value. */
|
|
106
107
|
export function authOptions(env: object): AuthOptions {
|
|
107
108
|
let options = resolved.get(env);
|
|
108
|
-
if (!options) resolved.set(env, (options = resolve(env as OptionEnv)));
|
|
109
|
+
if (!options) resolved.set(env, (options = resolve(paletteEnv(env) as OptionEnv)));
|
|
109
110
|
return options;
|
|
110
111
|
}
|
|
111
112
|
|
|
@@ -124,7 +125,7 @@ export function publicLocation(value: string): { origin: string; path: string }
|
|
|
124
125
|
!["localhost", "127.0.0.1"].includes(url.hostname))
|
|
125
126
|
)
|
|
126
127
|
throw new ConfigError(
|
|
127
|
-
"PUBLIC_URL must be an HTTPS origin, optionally with a path such as https://example.com/
|
|
128
|
+
"PUBLIC_URL must be an HTTPS origin, optionally with a path such as https://example.com/palette (localhost allowed for development)",
|
|
128
129
|
);
|
|
129
130
|
return { origin: url.origin, path };
|
|
130
131
|
}
|
package/server/public-env.ts
CHANGED
|
@@ -7,34 +7,90 @@ export interface ServerEnv {
|
|
|
7
7
|
GITHUB_CLIENT_ID: string;
|
|
8
8
|
GITHUB_CLIENT_SECRET: string;
|
|
9
9
|
GOOGLE_CLIENT_SECRET: string;
|
|
10
|
+
EDGE_LIMIT?: RateLimit;
|
|
11
|
+
PALETTE_WEBHOOK_KEYS?: string;
|
|
12
|
+
PALETTE_WEBHOOK_SEND?: (
|
|
13
|
+
url: string,
|
|
14
|
+
body: string,
|
|
15
|
+
headers: Record<string, string>
|
|
16
|
+
) => Promise<void>;
|
|
17
|
+
/** Optional server secret mixed into access token hashes. Changing it revokes every token. */
|
|
18
|
+
PALETTE_TOKEN_PEPPER?: string;
|
|
19
|
+
PALETTE_HOSTED?: string;
|
|
20
|
+
PALETTE_PAUSED?: string;
|
|
21
|
+
/** Trusted identity proxy that signs reviewers in, e.g. "gcp-iap". Off unless set. */
|
|
22
|
+
PALETTE_PROXY_AUTH?: string;
|
|
23
|
+
/** The audience the proxy signs its assertions for. */
|
|
24
|
+
PALETTE_PROXY_AUDIENCE?: string;
|
|
25
|
+
/** Older name: setting it alone turns on "gcp-iap" with this audience. */
|
|
26
|
+
PALETTE_IAP_AUDIENCE?: string;
|
|
27
|
+
/** Path the proxy protects for the sign-in handlers, e.g. "/backoffice". */
|
|
28
|
+
PALETTE_AUTH_PATH_PREFIX?: string;
|
|
29
|
+
/** Older name for PALETTE_AUTH_PATH_PREFIX. */
|
|
30
|
+
PALETTE_AUTH_PREFIX?: string;
|
|
31
|
+
/** "true" makes reading comments need a session. Always on with a proxy. */
|
|
32
|
+
PALETTE_REQUIRE_SESSION_FOR_READS?: string;
|
|
33
|
+
/** "false" refuses guest sign-in on every project. Always off with a proxy. */
|
|
34
|
+
PALETTE_ALLOW_GUESTS?: string;
|
|
35
|
+
/** Caps session age in days. Unset keeps sessions until sign-out. */
|
|
36
|
+
PALETTE_SESSION_MAX_AGE_DAYS?: string;
|
|
37
|
+
/** Path the app is served under behind a proxy that strips it, e.g. "/palette". */
|
|
38
|
+
PALETTE_PUBLIC_PATH?: string;
|
|
39
|
+
PALETTE_VERSION?: { id: string };
|
|
40
|
+
/** @deprecated Read when PALETTE_WEBHOOK_KEYS is unset. */
|
|
10
41
|
KOMO_WEBHOOK_KEYS?: string;
|
|
42
|
+
/** @deprecated Read when PALETTE_WEBHOOK_SEND is unset. */
|
|
11
43
|
KOMO_WEBHOOK_SEND?: (
|
|
12
44
|
url: string,
|
|
13
45
|
body: string,
|
|
14
46
|
headers: Record<string, string>
|
|
15
47
|
) => Promise<void>;
|
|
16
|
-
/**
|
|
48
|
+
/** @deprecated Read when PALETTE_TOKEN_PEPPER is unset. */
|
|
17
49
|
KOMO_TOKEN_PEPPER?: string;
|
|
50
|
+
/** @deprecated Read when PALETTE_HOSTED is unset. */
|
|
18
51
|
KOMO_HOSTED?: string;
|
|
52
|
+
/** @deprecated Read when PALETTE_PAUSED is unset. */
|
|
19
53
|
KOMO_PAUSED?: string;
|
|
20
|
-
/**
|
|
54
|
+
/** @deprecated Read when PALETTE_PROXY_AUTH is unset. */
|
|
21
55
|
KOMO_PROXY_AUTH?: string;
|
|
22
|
-
/**
|
|
56
|
+
/** @deprecated Read when PALETTE_PROXY_AUDIENCE is unset. */
|
|
23
57
|
KOMO_PROXY_AUDIENCE?: string;
|
|
24
|
-
/**
|
|
58
|
+
/** @deprecated Read when PALETTE_IAP_AUDIENCE is unset. */
|
|
25
59
|
KOMO_IAP_AUDIENCE?: string;
|
|
26
|
-
/**
|
|
60
|
+
/** @deprecated Read when PALETTE_AUTH_PATH_PREFIX is unset. */
|
|
27
61
|
KOMO_AUTH_PATH_PREFIX?: string;
|
|
28
|
-
/**
|
|
62
|
+
/** @deprecated Read when PALETTE_AUTH_PREFIX is unset. */
|
|
29
63
|
KOMO_AUTH_PREFIX?: string;
|
|
30
|
-
/**
|
|
64
|
+
/** @deprecated Read when PALETTE_REQUIRE_SESSION_FOR_READS is unset. */
|
|
31
65
|
KOMO_REQUIRE_SESSION_FOR_READS?: string;
|
|
32
|
-
/**
|
|
66
|
+
/** @deprecated Read when PALETTE_ALLOW_GUESTS is unset. */
|
|
33
67
|
KOMO_ALLOW_GUESTS?: string;
|
|
34
|
-
/**
|
|
68
|
+
/** @deprecated Read when PALETTE_SESSION_MAX_AGE_DAYS is unset. */
|
|
35
69
|
KOMO_SESSION_MAX_AGE_DAYS?: string;
|
|
36
|
-
/**
|
|
70
|
+
/** @deprecated Read when PALETTE_PUBLIC_PATH is unset. */
|
|
37
71
|
KOMO_PUBLIC_PATH?: string;
|
|
38
|
-
|
|
72
|
+
/** @deprecated Read when PALETTE_VERSION is unset. */
|
|
39
73
|
KOMO_VERSION?: { id: string };
|
|
40
74
|
}
|
|
75
|
+
|
|
76
|
+
const unset = (value: unknown) => value === undefined || value === null || value === "";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* `env` with each PALETTE_ setting filled from its older KOMO_ name when unset
|
|
80
|
+
* (missing, null or ""), so deployments configured before the rename keep working
|
|
81
|
+
* unchanged and an empty PALETTE_ value never hides a KOMO_ one.
|
|
82
|
+
*/
|
|
83
|
+
export function paletteEnv<T extends object>(env: T): T {
|
|
84
|
+
const values = env as Record<PropertyKey, unknown>;
|
|
85
|
+
const legacy: Record<string, unknown> = {};
|
|
86
|
+
for (const key in values)
|
|
87
|
+
if (key.startsWith("KOMO_") && unset(values[`PALETTE_${key.slice(5)}`]) && !unset(values[key]))
|
|
88
|
+
legacy[`PALETTE_${key.slice(5)}`] = values[key];
|
|
89
|
+
if (!Object.keys(legacy).length) return env;
|
|
90
|
+
// A plain copy of every binding (enumerable or not, by reference), so a spread,
|
|
91
|
+
// Object.keys or JSON.stringify of the result still sees all of them.
|
|
92
|
+
const copy: Record<PropertyKey, unknown> = {};
|
|
93
|
+
for (const key of Reflect.ownKeys(env)) copy[key] = values[key];
|
|
94
|
+
for (const key in values) copy[key] = values[key];
|
|
95
|
+
return Object.assign(copy, legacy) as T;
|
|
96
|
+
}
|