Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 5c45338

Browse files
committed
Consumers and Dynamic Endpoints WIP
1 parent 5d4773b commit 5c45338

25 files changed

Lines changed: 3657 additions & 18 deletions

File tree

‎src/lib/components/Navigation.svelte‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,42 @@
6060
},
6161
],
6262
},
63+
{
64+
label: "Dynamic Endpoints",
65+
icon: "🔌",
66+
available: true,
67+
subItems: [
68+
{
69+
href: "/dynamic-endpoints/system",
70+
label: "System Dynamic Endpoints",
71+
icon: "⚙️",
72+
},
73+
{
74+
href: "/dynamic-endpoints/bank",
75+
label: "Bank Dynamic Endpoints",
76+
icon: "🏦",
77+
},
78+
],
79+
},
6380
].filter((item) => item.available)
6481
: [],
6582
);
6683
6784
// Reactive check for active route
68-
function isActiveRoute(href: string): boolean {
85+
function isActiveRoute(href: string | undefined): boolean {
86+
if (!href) return false;
6987
if (href === "/") {
7088
return $page.url.pathname === "/";
7189
}
7290
return $page.url.pathname.startsWith(href);
7391
}
7492
93+
// Check if any sub-item of a dropdown is active
94+
function isDropdownActive(subItems: Array<{ href: string }> | undefined): boolean {
95+
if (!subItems) return false;
96+
return subItems.some((subItem) => isActiveRoute(subItem.href));
97+
}
98+
7599
// Event handlers with better encapsulation
76100
const handlers = {
77101
toggleMobileMenu: () => {
@@ -135,7 +159,7 @@
135159
<div class="nav-dropdown">
136160
<button
137161
class="nav-link dropdown-toggle"
138-
class:active={isActiveRoute(item.href)}
162+
class:active={isDropdownActive(item.subItems)}
139163
onclick={() => handlers.toggleDropdown(item.label)}
140164
onblur={() => setTimeout(handlers.closeDropdown, 200)}
141165
>
@@ -239,7 +263,7 @@
239263
<div class="mobile-nav-dropdown">
240264
<button
241265
class="mobile-nav-link"
242-
class:active={isActiveRoute(item.href)}
266+
class:active={isDropdownActive(item.subItems)}
243267
onclick={() => handlers.toggleDropdown(item.label)}
244268
>
245269
<span class="nav-icon">{item.icon}</span>

‎src/lib/components/PageRoleCheck.svelte‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import MissingRoleAlert from "$lib/components/MissingRoleAlert.svelte";
33
import type { RoleRequirement } from "$lib/utils/roleChecker";
4-
import { checkRoles, groupMissingRolesByBank } from "$lib/utils/roleChecker";
4+
import { checkRoles } from "$lib/utils/roleChecker";
55
import type { Snippet } from "svelte";
66
77
interface Props {
@@ -17,26 +17,20 @@
1717
return checkRoles(userEntitlements || [], requiredRoles);
1818
});
1919
20-
// Group missing roles by bank for display
21-
let groupedMissingRoles = $derived.by(() => {
22-
return groupMissingRolesByBank(roleCheck.missingRoles);
23-
});
20+
// Get just the first missing role (so request entitlement button can request a single role)
21+
let firstMissingRole = $derived(roleCheck.missingRoles[0] || null);
2422
2523
// Determine if we should show content or only alerts
2624
let showContent = $derived(roleCheck.hasAllRoles);
2725
</script>
2826

29-
{#if roleCheck.missingRoles.length > 0}
27+
{#if firstMissingRole}
3028
<div class="role-alerts">
31-
{#each Array.from(groupedMissingRoles.entries()) as [bankKey, roles]}
32-
<MissingRoleAlert
33-
roles={roles.map((r) => r.role)}
34-
bankId={bankKey === "system-wide" ? undefined : bankKey}
35-
message={roles.length === 1
36-
? `You need the following role to ${roles[0].action || "perform this action"}: ${roles[0].role}`
37-
: `You need the following roles for this page: ${roles.map((r) => r.role).join(", ")}`}
38-
/>
39-
{/each}
29+
<MissingRoleAlert
30+
roles={[firstMissingRole.role]}
31+
bankId={firstMissingRole.bankId || undefined}
32+
message={`You need the following role to ${firstMissingRole.action || "access this page"}: ${firstMissingRole.role}`}
33+
/>
4034
</div>
4135
{/if}
4236

‎src/lib/config/navigation.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
Waves,
2525
FolderOpen,
2626
Star,
27+
Plug,
2728
} from "@lucide/svelte";
2829
import { env } from "$env/dynamic/public";
2930

@@ -312,6 +313,38 @@ export function getActiveDynamicEntitiesMenuItem(pathname: string) {
312313
return found || dynamicEntitiesItems[0]; // fallback to first item
313314
}
314315

316+
// Dynamic Endpoints navigation items
317+
function buildDynamicEndpointsItems(): NavigationItem[] {
318+
const items: NavigationItem[] = [
319+
{
320+
href: "/dynamic-endpoints/system",
321+
label: "System Dynamic Endpoints",
322+
iconComponent: Plug,
323+
},
324+
{
325+
href: "/dynamic-endpoints/bank",
326+
label: "Bank Dynamic Endpoints",
327+
iconComponent: Building2,
328+
},
329+
];
330+
331+
return items;
332+
}
333+
334+
export const dynamicEndpointsItems = buildDynamicEndpointsItems();
335+
336+
export function getActiveDynamicEndpointsMenuItem(pathname: string) {
337+
const found = dynamicEndpointsItems.find((item) => {
338+
// Skip external links for active menu detection
339+
if (item.external) {
340+
return false;
341+
}
342+
return pathname.startsWith(item.href);
343+
});
344+
345+
return found || dynamicEndpointsItems[0]; // fallback to first item
346+
}
347+
315348
// ABAC navigation items
316349
function buildAbacItems(): NavigationItem[] {
317350
const items: NavigationItem[] = [

‎src/routes/(protected)/consumers/[consumer_id]/edit/+page.server.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ export async function load(event: RequestEvent) {
6161
throw error(400, "Consumer ID is required.");
6262
}
6363

64+
// Get user entitlements from session for role checking
65+
const userEntitlements = (session.data.user as any)?.entitlements?.list || [];
66+
67+
// Required roles for this page - checked one at a time by PageRoleCheck
68+
const requiredRoles = [
69+
{ role: "CanGetConsumers", action: "view consumer details" },
70+
{ role: "CanEnableConsumers", action: "enable or disable consumers" },
71+
{ role: "CanCreateScopeAtOneBank", action: "add scopes to consumers" },
72+
{ role: "CanDeleteScopeAtAnyBank", action: "delete scopes from consumers" },
73+
{ role: "CanUpdateConsumerRedirectUrl", action: "update consumer redirect URL" },
74+
];
75+
6476
let consumer: Consumer | undefined = undefined;
6577
let scopes: Scope[] = [];
6678
let availableRoles: Role[] = [];
@@ -129,6 +141,8 @@ export async function load(event: RequestEvent) {
129141
scopes,
130142
availableRoles,
131143
banks,
144+
userEntitlements,
145+
requiredRoles,
132146
};
133147
}
134148

‎src/routes/(protected)/consumers/[consumer_id]/edit/+page.svelte‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<script lang="ts">
22
import { enhance } from "$app/forms";
33
import { invalidateAll } from "$app/navigation";
4+
import PageRoleCheck from "$lib/components/PageRoleCheck.svelte";
45
56
let { data, form } = $props();
67
78
let consumer = $derived(data.consumer);
89
let scopes = $derived(data.scopes || []);
910
let availableRoles = $derived(data.availableRoles || []);
1011
let banks = $derived(data.banks || []);
12+
const userEntitlements = data.userEntitlements || [];
13+
const requiredRoles = data.requiredRoles || [];
1114
1215
let isSubmitting = $state(false);
1316
let selectedRole = $state("");
@@ -57,6 +60,7 @@
5760
<title>Edit Consumer - {consumer.app_name}</title>
5861
</svelte:head>
5962

63+
<PageRoleCheck {userEntitlements} {requiredRoles}>
6064
<div class="mb-6">
6165
<a
6266
href="/consumers"
@@ -616,3 +620,4 @@
616620
Manage Rate Limits
617621
</a>
618622
</div>
623+
</PageRoleCheck>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { PageServerLoad } from "./$types";
2+
import { error } from "@sveltejs/kit";
3+
import { createLogger } from "$lib/utils/logger";
4+
import { SessionOAuthHelper } from "$lib/oauth/sessionHelper";
5+
6+
const logger = createLogger("BankDynamicEndpointsPageServer");
7+
8+
export const load: PageServerLoad = async ({ locals }) => {
9+
logger.info("=== Bank Dynamic Endpoints Page Load Started ===");
10+
11+
const session = locals.session;
12+
13+
if (!session?.data?.user) {
14+
logger.error("No user in session");
15+
throw error(401, "Unauthorized");
16+
}
17+
18+
const sessionOAuth = SessionOAuthHelper.getSessionOAuth(session);
19+
const accessToken = sessionOAuth?.accessToken;
20+
21+
if (!accessToken) {
22+
logger.error("No access token available");
23+
throw error(401, "No API access token available");
24+
}
25+
26+
// Bank selection will be handled client-side
27+
return {
28+
endpoints: [],
29+
};
30+
};

0 commit comments

Comments
 (0)