@hazem3500/palette 0.9.113 → 0.9.115
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 +6 -4
- package/README.md +8 -6
- package/dist/{account-tokens-YO6MIZFF.js → account-tokens-ZXA2HQS4.js} +1 -1
- package/dist/chunk-PI5FFV5P.js +1 -0
- package/dist/index.js +1 -1
- package/dist/node.mjs +17 -11
- package/dist/public-env.d.ts +5 -1
- package/dist/react.js +1 -1
- package/dist/server.js +15 -11
- package/dist/setup.js +1 -1
- package/dist/shell-mode-RPV7AVA4.js +1 -0
- package/dist/shell-mode.d.ts +2 -2
- package/dist/shell-session.d.ts +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/server/index.ts +1 -1
- package/server/proxy-auth.ts +5 -1
- package/server/public-env.ts +5 -1
- package/server/setup-client.txt +57 -57
- package/server/tokens.ts +13 -11
- package/src/types.ts +1 -0
- package/dist/chunk-CF4GJN3B.js +0 -1
- package/dist/shell-mode-PLV6F474.js +0 -1
package/server/tokens.ts
CHANGED
|
@@ -99,9 +99,9 @@ export const pruneAudit = (db: D1Database, now: number) =>
|
|
|
99
99
|
db.prepare("DELETE FROM audit_log WHERE at<?").bind(now - AUDIT_RETENTION);
|
|
100
100
|
|
|
101
101
|
/** Projects an account holder may limit a token to: owned or joined. */
|
|
102
|
-
export async function accountProjects(env: Env, userId: string) {
|
|
102
|
+
export async function accountProjects(env: Env, userId: string, activeMembership = false) {
|
|
103
103
|
const rows = await env.DB.prepare(
|
|
104
|
-
|
|
104
|
+
`SELECT id AS project FROM workspaces WHERE owner_id=? UNION SELECT project FROM ${activeMembership ? "project_access" : "project_members"} WHERE user_id=? UNION SELECT project FROM project_owners WHERE user_id=?`
|
|
105
105
|
)
|
|
106
106
|
.bind(userId, userId, userId)
|
|
107
107
|
.all<{ project: string }>();
|
|
@@ -137,9 +137,10 @@ export async function createToken(
|
|
|
137
137
|
userId: string,
|
|
138
138
|
data: Record<string, unknown>
|
|
139
139
|
) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
check(
|
|
140
|
+
const auth = authOptions(env);
|
|
141
|
+
if (auth.proxy) {
|
|
142
|
+
check(auth.proxyTokenNoExpiry || (data.expiresInDays !== undefined && data.expiresInDays !== null), 400, "Choose an expiry between 1 and 365 days.");
|
|
143
|
+
check(auth.proxyTokenAllProjects || (Array.isArray(data.projects) && data.projects.length > 0), 400, "Choose explicit projects for this token.");
|
|
143
144
|
}
|
|
144
145
|
const name = string(data.name, 60, "token name").trim();
|
|
145
146
|
check(name.length > 0, 400, "Name your token.");
|
|
@@ -290,13 +291,14 @@ export async function authenticateToken(
|
|
|
290
291
|
row.revoked_at === null &&
|
|
291
292
|
(row.expires_at === null || row.expires_at > now);
|
|
292
293
|
check(valid, 401, "This access token is invalid, expired, or revoked.");
|
|
293
|
-
|
|
294
|
+
const auth = authOptions(env);
|
|
295
|
+
if (auth.proxy) {
|
|
294
296
|
check(
|
|
295
|
-
row.expires_at
|
|
296
|
-
row.expires_at - row.created_at <= MAX_LIFETIME_DAYS * 86400000 &&
|
|
297
|
-
(list(row.projects)?.length ?? 0) > 0,
|
|
297
|
+
(row.expires_at === null ? auth.proxyTokenNoExpiry :
|
|
298
|
+
row.expires_at > row.created_at && row.expires_at - row.created_at <= MAX_LIFETIME_DAYS * 86400000) &&
|
|
299
|
+
(list(row.projects) === null ? auth.proxyTokenAllProjects : (list(row.projects)?.length ?? 0) > 0),
|
|
298
300
|
403,
|
|
299
|
-
"
|
|
301
|
+
"This access token exceeds the proxy token policy."
|
|
300
302
|
);
|
|
301
303
|
}
|
|
302
304
|
const user = await env.DB.prepare("SELECT * FROM users WHERE id=?")
|
|
@@ -321,7 +323,7 @@ export async function authenticateToken(
|
|
|
321
323
|
);
|
|
322
324
|
const projects = list(row.projects);
|
|
323
325
|
check(
|
|
324
|
-
|
|
326
|
+
projects ? projects.includes(project) : !auth.proxy || (await accountProjects(env, row.user_id, true)).includes(project),
|
|
325
327
|
403,
|
|
326
328
|
"This token is not allowed for this project."
|
|
327
329
|
);
|
package/src/types.ts
CHANGED
|
@@ -285,6 +285,7 @@ export interface CommentsOptions {
|
|
|
285
285
|
* Single-copy simulated viewport (with mode "iframe"): turning it on reloads this page as a
|
|
286
286
|
* shell for Palette, so the app runs once, in the frame. Requires the app's entry
|
|
287
287
|
* to skip mounting when `isShell(project)` from `@hazem3500/palette/shell` is true.
|
|
288
|
+
* Cancellation or failure keeps the normal page; a second app is never loaded as fallback.
|
|
288
289
|
*/
|
|
289
290
|
shell?: boolean;
|
|
290
291
|
};
|