qarpeo 0.3.5 → 0.4.1
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/dist/chunks/{tools.mjs → manifest.get.mjs} +229 -3
- package/dist/cli/index.mjs +74 -5
- package/dist/features/console.d.ts +4 -0
- package/dist/module.mjs +299 -57
- package/dist/runtime/app/components/{BlobImage.vue → QImg.vue} +5 -4
- package/dist/runtime/app/composables/console.d.ts +60 -0
- package/dist/runtime/app/composables/console.mjs +169 -0
- package/dist/runtime/app/composables/pwa.d.ts +34 -0
- package/dist/runtime/app/composables/pwa.mjs +86 -0
- package/dist/runtime/app/composables/rbac.d.ts +33 -0
- package/dist/runtime/app/composables/rbac.mjs +60 -0
- package/dist/runtime/app/composables/site.d.ts +73 -0
- package/dist/runtime/app/composables/site.mjs +174 -1
- package/dist/runtime/app/middleware/console.global.d.ts +2 -0
- package/dist/runtime/app/middleware/console.global.mjs +37 -0
- package/dist/runtime/app/plugins/pwa.client.d.ts +2 -0
- package/dist/runtime/app/plugins/pwa.client.mjs +28 -0
- package/dist/runtime/app/plugins/pwa.d.ts +2 -0
- package/dist/runtime/app/plugins/pwa.mjs +42 -0
- package/dist/runtime/app/plugins/seo.mjs +39 -10
- package/dist/runtime/schema.d.ts +32 -12
- package/dist/runtime/schema.mjs +47 -125
- package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.d.ts +13 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.mjs +46 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.mjs +40 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.d.ts +20 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.mjs +52 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.d.ts +26 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.mjs +80 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.d.ts +16 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.mjs +30 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.d.ts +21 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.mjs +49 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.mjs +65 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.d.ts +12 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.mjs +17 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.mjs +87 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.d.ts +25 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.mjs +119 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/users.post.d.ts +19 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/users.post.mjs +86 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.d.ts +21 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.mjs +91 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.d.ts +13 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.mjs +49 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.d.ts +43 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.mjs +111 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/overview.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/overview.get.mjs +44 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.mjs +27 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.d.ts +23 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.mjs +56 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.d.ts +21 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.mjs +50 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.d.ts +12 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.mjs +24 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.d.ts +26 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.mjs +40 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.d.ts +39 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.mjs +69 -0
- package/dist/runtime/server/routes/__qarpeo/manifest.get.d.ts +39 -0
- package/dist/runtime/server/routes/__qarpeo/manifest.get.mjs +226 -0
- package/dist/runtime/server/routes/__qarpeo/og.get.d.ts +15 -0
- package/dist/runtime/server/routes/__qarpeo/og.get.mjs +109 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/me.get.d.ts +26 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/me.get.mjs +23 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.d.ts +12 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.mjs +12 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.d.ts +16 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.mjs +15 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.mjs +16 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/users.post.d.ts +14 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/users.post.mjs +19 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.d.ts +2 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.mjs +31 -0
- package/dist/runtime/server/routes/robots.txt.get.mjs +20 -4
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +47 -6
- package/dist/runtime/server/routes/sw.js.get.d.ts +8 -0
- package/dist/runtime/server/routes/sw.js.get.mjs +141 -0
- package/dist/runtime/server/utils/auth.d.ts +2 -14
- package/dist/runtime/server/utils/auth.mjs +32 -36
- package/dist/runtime/server/utils/cloud-auth.d.ts +8 -0
- package/dist/runtime/server/utils/cloud-auth.mjs +23 -0
- package/dist/runtime/server/utils/console.d.ts +19 -0
- package/dist/runtime/server/utils/console.mjs +34 -0
- package/dist/runtime/server/utils/legacy-hash.d.ts +76 -0
- package/dist/runtime/server/utils/legacy-hash.mjs +96 -0
- package/dist/runtime/server/utils/rbac.d.ts +89 -0
- package/dist/runtime/server/utils/rbac.mjs +427 -0
- package/dist/runtime/server/utils/role-env.d.ts +19 -0
- package/dist/runtime/server/utils/role-env.mjs +34 -0
- package/dist/runtime/server.d.ts +2 -0
- package/dist/runtime/server.mjs +2 -0
- package/dist/types/console.d.ts +67 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/options.d.ts +9 -0
- package/dist/types/site.d.ts +102 -0
- package/dist/types/storage.d.ts +5 -11
- package/package.json +1 -1
- package/dist/runtime/providers/qarpeo.d.ts +0 -23
- package/dist/runtime/providers/qarpeo.mjs +0 -46
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createError } from "nuxt/server";
|
|
2
|
+
import { timingSafeEqualString } from "./crypto.mjs";
|
|
3
|
+
export function verifyCloudSecret(event) {
|
|
4
|
+
const cfEnv = event.context?.cloudflare?.env;
|
|
5
|
+
const expected = typeof cfEnv?.QARPEO_CLOUD_SECRET === "string" && cfEnv.QARPEO_CLOUD_SECRET || typeof process !== "undefined" && process.env?.QARPEO_CLOUD_SECRET || "";
|
|
6
|
+
if (!expected) {
|
|
7
|
+
throw createError({
|
|
8
|
+
statusCode: 401,
|
|
9
|
+
statusMessage: "Unauthorized",
|
|
10
|
+
message: "[qarpeo] QARPEO_CLOUD_SECRET is not configured on this Worker."
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
const ev = event;
|
|
14
|
+
const authHeader = ev.req?.headers?.get?.("authorization") || ev.headers?.get?.("authorization") || ev.node?.req?.headers?.authorization || "";
|
|
15
|
+
const token = typeof authHeader === "string" && authHeader.startsWith("Bearer ") ? authHeader.slice(7).trim() : "";
|
|
16
|
+
if (!token || !timingSafeEqualString(token, expected)) {
|
|
17
|
+
throw createError({
|
|
18
|
+
statusCode: 401,
|
|
19
|
+
statusMessage: "Unauthorized",
|
|
20
|
+
message: "[qarpeo] Invalid QARPEO_CLOUD_SECRET token."
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RequestEvent } from "nuxt/server";
|
|
2
|
+
import { type ResolvedPermissions } from "./rbac";
|
|
3
|
+
/**
|
|
4
|
+
* Enforces that the current request has `console:access`.
|
|
5
|
+
* Throws 401 if unauthenticated, 403 if denied.
|
|
6
|
+
*/
|
|
7
|
+
export declare function requireConsoleAccess(event: RequestEvent): Promise<ResolvedPermissions>;
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether the current request has `console:access` without throwing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasConsoleAccess(event: RequestEvent): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Enforces `console:access` AND the specified module/action permission(s).
|
|
14
|
+
*
|
|
15
|
+
* @param event - Nitro/H3 request event
|
|
16
|
+
* @param permission - Required permission key or list of keys
|
|
17
|
+
* @param match - `"all"` (default) requires every permission; `"any"` requires at least one
|
|
18
|
+
*/
|
|
19
|
+
export declare function requireConsolePermission(event: RequestEvent, permission: string | string[], match?: "all" | "any"): Promise<ResolvedPermissions>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createError } from "nuxt/server";
|
|
2
|
+
import { getAuthContext } from "./context.mjs";
|
|
3
|
+
import {
|
|
4
|
+
evaluatePermission,
|
|
5
|
+
hasPermission,
|
|
6
|
+
requirePermission
|
|
7
|
+
} from "./rbac.mjs";
|
|
8
|
+
export async function requireConsoleAccess(event) {
|
|
9
|
+
return requirePermission(event, "console:access");
|
|
10
|
+
}
|
|
11
|
+
export async function hasConsoleAccess(event) {
|
|
12
|
+
return hasPermission(event, "console:access");
|
|
13
|
+
}
|
|
14
|
+
export async function requireConsolePermission(event, permission, match = "all") {
|
|
15
|
+
const resolved = await requireConsoleAccess(event);
|
|
16
|
+
const requiredList = (Array.isArray(permission) ? permission : [permission]).filter(Boolean);
|
|
17
|
+
if (requiredList.length === 0) {
|
|
18
|
+
return resolved;
|
|
19
|
+
}
|
|
20
|
+
const auth = await getAuthContext(event);
|
|
21
|
+
const checkOne = (perm) => {
|
|
22
|
+
if (auth && !auth.hasScope(perm)) return false;
|
|
23
|
+
return evaluatePermission(resolved, perm);
|
|
24
|
+
};
|
|
25
|
+
const allowed = match === "any" ? requiredList.some(checkOne) : requiredList.every(checkOne);
|
|
26
|
+
if (!allowed) {
|
|
27
|
+
throw createError({
|
|
28
|
+
statusCode: 403,
|
|
29
|
+
statusMessage: "Forbidden",
|
|
30
|
+
message: `Missing console permission: ${requiredList.join(match === "any" ? " | " : ", ")}`
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return resolved;
|
|
34
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy password hash verification helpers for migrating users from other auth systems.
|
|
3
|
+
*
|
|
4
|
+
* Better Auth uses `scrypt` (via `@noble/hashes/scrypt`) for all new hashes. This module
|
|
5
|
+
* provides pure-Web-Crypto / pure-JS fallbacks to verify passwords stored in older formats so
|
|
6
|
+
* that users can log in with their existing password, which is then transparently re-hashed to
|
|
7
|
+
* scrypt on successful verification.
|
|
8
|
+
*
|
|
9
|
+
* Supported legacy formats:
|
|
10
|
+
* - bcrypt — `$2a$`, `$2b$`, `$2x$`, `$2y$` prefix (requires `bcryptjs` dev dep)
|
|
11
|
+
* - Django PBKDF2-SHA256 — `pbkdf2_sha256$<iterations>$<salt>$<hash>` format (pure Web Crypto)
|
|
12
|
+
* - SHA-1 — 40-char hex (plain SHA-1, common in very old Rails / PHP apps)
|
|
13
|
+
* - MD5 — 32-char hex (plain MD5 — not supported, Web Crypto lacks MD5)
|
|
14
|
+
*
|
|
15
|
+
* Usage in `defineQarpeoAuth`:
|
|
16
|
+
* ```ts
|
|
17
|
+
* emailAndPassword: {
|
|
18
|
+
* verifyLegacyPassword: async (password, hash) => {
|
|
19
|
+
* return verifyLegacyPassword(password, hash)
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Returns true if `hash` looks like a bcrypt hash (`$2a$`, `$2b$`, `$2x$`, `$2y$`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function isBcryptHash(hash: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Verifies a password against a bcrypt hash using `bcryptjs` (pure JS, works on CF Workers).
|
|
30
|
+
* Returns `false` if `bcryptjs` is not installed — install it as a dev dependency and add it
|
|
31
|
+
* to `optimizeDeps.include` / `noExternal` if needed.
|
|
32
|
+
*/
|
|
33
|
+
export declare function verifyBcrypt(password: string, hash: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns true if `hash` is a Django-style PBKDF2-SHA256 hash.
|
|
36
|
+
* Format: `pbkdf2_sha256$<iterations>$<salt>$<hash_base64>`
|
|
37
|
+
*/
|
|
38
|
+
export declare function isDjangoPbkdf2Hash(hash: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Verifies a password against a Django PBKDF2-SHA256 hash using the Web Crypto API.
|
|
41
|
+
* This works without any external library on Cloudflare Workers.
|
|
42
|
+
*/
|
|
43
|
+
export declare function verifyDjangoPbkdf2(password: string, hash: string): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if `hash` looks like a plain 40-char hex SHA-1 digest.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isSha1Hash(hash: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Verifies a password against a plain SHA-1 hex hash using Web Crypto.
|
|
50
|
+
* Note: SHA-1 is cryptographically broken — this is provided only for migration.
|
|
51
|
+
*/
|
|
52
|
+
export declare function verifySha1(password: string, hash: string): Promise<boolean>;
|
|
53
|
+
export type LegacyHashType = "bcrypt" | "pbkdf2_sha256" | "sha1" | "unknown";
|
|
54
|
+
/**
|
|
55
|
+
* Detects the hash type from the hash string.
|
|
56
|
+
*/
|
|
57
|
+
export declare function detectHashType(hash: string): LegacyHashType;
|
|
58
|
+
/**
|
|
59
|
+
* Verifies a password against any supported legacy hash format.
|
|
60
|
+
* Returns `{ valid: boolean; type: LegacyHashType }`.
|
|
61
|
+
*
|
|
62
|
+
* Use this inside `verifyLegacyPassword` callback in `defineQarpeoAuth` options:
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* emailAndPassword: {
|
|
66
|
+
* verifyLegacyPassword: async (password, hash) => {
|
|
67
|
+
* const { valid } = await verifyLegacyPassword(password, hash)
|
|
68
|
+
* return valid
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function verifyLegacyPassword(password: string, hash: string): Promise<{
|
|
74
|
+
valid: boolean;
|
|
75
|
+
type: LegacyHashType;
|
|
76
|
+
}>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export function isBcryptHash(hash) {
|
|
2
|
+
return /^\$2[abxy]\$\d{2}\$/.test(hash);
|
|
3
|
+
}
|
|
4
|
+
export async function verifyBcrypt(password, hash) {
|
|
5
|
+
if (!isBcryptHash(hash)) return false;
|
|
6
|
+
try {
|
|
7
|
+
const bcrypt = await import("bcryptjs").catch(() => null);
|
|
8
|
+
if (!bcrypt) return false;
|
|
9
|
+
return bcrypt.compare(password, hash);
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function isDjangoPbkdf2Hash(hash) {
|
|
15
|
+
return hash.startsWith("pbkdf2_sha256$");
|
|
16
|
+
}
|
|
17
|
+
export async function verifyDjangoPbkdf2(password, hash) {
|
|
18
|
+
if (!isDjangoPbkdf2Hash(hash)) return false;
|
|
19
|
+
try {
|
|
20
|
+
const parts = hash.split("$");
|
|
21
|
+
if (parts.length < 4) return false;
|
|
22
|
+
const iterations = parseInt(parts[1], 10);
|
|
23
|
+
const salt = parts[2];
|
|
24
|
+
const expectedBase64 = parts.slice(3).join("$");
|
|
25
|
+
const encoder = new TextEncoder();
|
|
26
|
+
const keyMaterial = await crypto.subtle.importKey(
|
|
27
|
+
"raw",
|
|
28
|
+
encoder.encode(password),
|
|
29
|
+
{ name: "PBKDF2" },
|
|
30
|
+
false,
|
|
31
|
+
["deriveBits"]
|
|
32
|
+
);
|
|
33
|
+
const derivedBits = await crypto.subtle.deriveBits(
|
|
34
|
+
{
|
|
35
|
+
name: "PBKDF2",
|
|
36
|
+
hash: "SHA-256",
|
|
37
|
+
salt: encoder.encode(salt),
|
|
38
|
+
iterations
|
|
39
|
+
},
|
|
40
|
+
keyMaterial,
|
|
41
|
+
256
|
|
42
|
+
);
|
|
43
|
+
const derivedBase64 = btoa(String.fromCharCode(...new Uint8Array(derivedBits)));
|
|
44
|
+
const a = encoder.encode(derivedBase64);
|
|
45
|
+
const b = encoder.encode(expectedBase64);
|
|
46
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
47
|
+
let diff = 0;
|
|
48
|
+
for (let i = 0; i < a.byteLength; i++) diff |= a[i] ^ b[i];
|
|
49
|
+
return diff === 0;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function isSha1Hash(hash) {
|
|
55
|
+
return /^[0-9a-f]{40}$/i.test(hash);
|
|
56
|
+
}
|
|
57
|
+
export async function verifySha1(password, hash) {
|
|
58
|
+
if (!isSha1Hash(hash)) return false;
|
|
59
|
+
try {
|
|
60
|
+
const encoder = new TextEncoder();
|
|
61
|
+
const digest = await crypto.subtle.digest("SHA-1", encoder.encode(password));
|
|
62
|
+
const hex = Array.from(new Uint8Array(digest)).map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
63
|
+
const a = encoder.encode(hex.toLowerCase());
|
|
64
|
+
const b = encoder.encode(hash.toLowerCase());
|
|
65
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
66
|
+
let diff = 0;
|
|
67
|
+
for (let i = 0; i < a.byteLength; i++) diff |= a[i] ^ b[i];
|
|
68
|
+
return diff === 0;
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function detectHashType(hash) {
|
|
74
|
+
if (isBcryptHash(hash)) return "bcrypt";
|
|
75
|
+
if (isDjangoPbkdf2Hash(hash)) return "pbkdf2_sha256";
|
|
76
|
+
if (isSha1Hash(hash)) return "sha1";
|
|
77
|
+
return "unknown";
|
|
78
|
+
}
|
|
79
|
+
export async function verifyLegacyPassword(password, hash) {
|
|
80
|
+
const type = detectHashType(hash);
|
|
81
|
+
let valid = false;
|
|
82
|
+
switch (type) {
|
|
83
|
+
case "bcrypt":
|
|
84
|
+
valid = await verifyBcrypt(password, hash);
|
|
85
|
+
break;
|
|
86
|
+
case "pbkdf2_sha256":
|
|
87
|
+
valid = await verifyDjangoPbkdf2(password, hash);
|
|
88
|
+
break;
|
|
89
|
+
case "sha1":
|
|
90
|
+
valid = await verifySha1(password, hash);
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
valid = false;
|
|
94
|
+
}
|
|
95
|
+
return { valid, type };
|
|
96
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type RequestEvent } from "nuxt/server";
|
|
2
|
+
export interface RoleDefinition {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
permissions: string[];
|
|
7
|
+
isSystem: boolean;
|
|
8
|
+
isOverridden?: boolean;
|
|
9
|
+
immutable?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface UserPermissionOverrides {
|
|
12
|
+
userId: string;
|
|
13
|
+
extraRoles: string[];
|
|
14
|
+
allow: string[];
|
|
15
|
+
deny: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface ResolvedPermissions {
|
|
18
|
+
userId: string;
|
|
19
|
+
primaryRole: string;
|
|
20
|
+
roles: string[];
|
|
21
|
+
isSuper: boolean;
|
|
22
|
+
rolePermissions: string[];
|
|
23
|
+
allow: string[];
|
|
24
|
+
deny: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Standard capability catalog across Qarpeo Console & API modules.
|
|
28
|
+
*/
|
|
29
|
+
export declare const PERMISSION_CATALOG: ReadonlyArray<{
|
|
30
|
+
key: string;
|
|
31
|
+
module: "console" | "cms" | "store" | "comments" | "media" | "users" | "roles";
|
|
32
|
+
description: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Built-in default roles. `super` is immutable (`["*"]`).
|
|
36
|
+
* All other roles can be overridden in D1 by `super` (or a delegated `roles:manage` user).
|
|
37
|
+
*/
|
|
38
|
+
export declare const DEFAULT_ROLE_DEFINITIONS: Readonly<Record<string, RoleDefinition>>;
|
|
39
|
+
export declare function invalidateRbacCache(userId?: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if a list of granted permissions (supporting `*` and `module:*` wildcards)
|
|
42
|
+
* satisfies `requiredPermission`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function matchPermission(granted: ReadonlyArray<string>, requiredPermission: string): boolean;
|
|
45
|
+
/** Ensures `role` and `user_permission` tables exist in D1. */
|
|
46
|
+
export declare function ensureRbacTables(d1?: any, event?: RequestEvent): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves a user's effective roles and permission overrides (Deny-first, Fail-closed).
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveUserPermissions(user: {
|
|
51
|
+
id: string;
|
|
52
|
+
email?: string | null;
|
|
53
|
+
role?: string | null;
|
|
54
|
+
}, event?: RequestEvent): Promise<ResolvedPermissions>;
|
|
55
|
+
/** Evaluates a single permission against a resolved permission set (Deny-first). */
|
|
56
|
+
export declare function evaluatePermission(resolved: ResolvedPermissions, permission: string): boolean;
|
|
57
|
+
/** Checks if the current authenticated user has `permission` (returns false if unauthenticated). */
|
|
58
|
+
export declare function hasPermission(event: RequestEvent, permission: string): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Enforces that the current request is authenticated and holds `permission`.
|
|
61
|
+
* Throws 401 if unauthenticated, 403 if denied.
|
|
62
|
+
*/
|
|
63
|
+
export declare function requirePermission(event: RequestEvent, permission: string): Promise<ResolvedPermissions>;
|
|
64
|
+
/** Lists all built-in + D1-overridden + custom roles. */
|
|
65
|
+
export declare function listRoles(event?: RequestEvent): Promise<RoleDefinition[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Creates or updates a role in D1.
|
|
68
|
+
* - `super` is immutable and cannot be modified.
|
|
69
|
+
* - Non-`super` actors with `roles:manage` cannot grant `*`, `roles:manage`, or permissions they do not hold.
|
|
70
|
+
*/
|
|
71
|
+
export declare function upsertRole(event: RequestEvent, input: {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
permissions: string[];
|
|
76
|
+
}): Promise<RoleDefinition>;
|
|
77
|
+
/** Deletes a custom role (or resets a built-in role override back to code defaults). */
|
|
78
|
+
export declare function deleteRole(event: RequestEvent, roleId: string): Promise<{
|
|
79
|
+
reset: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Sets per-user `extraRoles`, `allow`, and `deny` overrides in D1.
|
|
83
|
+
* Non-`super` actors cannot assign `super`, `*`, `roles:manage`, or permissions they do not hold.
|
|
84
|
+
*/
|
|
85
|
+
export declare function setUserPermissions(event: RequestEvent, targetUserId: string, input: {
|
|
86
|
+
extraRoles?: string[];
|
|
87
|
+
allow?: string[];
|
|
88
|
+
deny?: string[];
|
|
89
|
+
}): Promise<UserPermissionOverrides>;
|