@krak-stack/auth 0.1.45 → 0.1.47

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.
@@ -82,6 +82,7 @@ const messages = {
82
82
  user_button_admin_users_description: "Review and manage users.",
83
83
  user_button_api_keys: "API keys",
84
84
  user_button_aria_label: "Open user menu",
85
+ user_button_impersonating: "Impersonating",
85
86
  user_button_logout: "Log out",
86
87
  user_button_security: "Security",
87
88
  user_button_stop_impersonating: "Stop impersonating",
@@ -169,6 +170,7 @@ const messages = {
169
170
  user_button_admin_users_description: "Consultez et gérez les utilisateurs.",
170
171
  user_button_api_keys: "Clés API",
171
172
  user_button_aria_label: "Ouvrir le menu utilisateur",
173
+ user_button_impersonating: "Imitation",
172
174
  user_button_logout: "Se déconnecter",
173
175
  user_button_security: "Sécurité",
174
176
  user_button_stop_impersonating: "Arrêter l'imitation",
@@ -317,6 +319,9 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
317
319
  const displayEmail = session.user.email.trim();
318
320
  const displayImage = assetUrl(session.user.image, baseUrl);
319
321
  const isImpersonating = Boolean(session.session.impersonatedBy);
322
+ const isOrganizationImpersonating = Boolean(session.session.impersonatedByOrganizationId);
323
+ const canManageUserSettings = !isOrganizationImpersonating;
324
+ const canUseAdminSettings = !isOrganizationImpersonating;
320
325
  const isAdmin = hasAdminRole(session.user);
321
326
  const signOut = async () => {
322
327
  const redirectUrl = signOutRedirect.startsWith("http")
@@ -357,7 +362,7 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
357
362
  await refetch();
358
363
  setSettingsDialog(null);
359
364
  };
360
- return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full rounded-md object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {}), isAdmin || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: stopImpersonating, children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: settingsDialog === "account", onOpenChange: (open) => {
365
+ return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full rounded-md object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [isImpersonating ? (_jsx("div", { className: "px-1 py-0.5", children: _jsx(Badge, { variant: "secondary", className: "text-xs font-normal", children: m.user_button_impersonating() }) })) : null, _jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(DropdownMenuSeparator, {}), canManageUserSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {})] })) : null, (isAdmin && canUseAdminSettings) || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin && canUseAdminSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: stopImpersonating, children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "account", onOpenChange: (open) => {
361
366
  setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
362
367
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsx(Separator, {}), isPending ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(UserForm, { defaultValues: {
363
368
  name: displayName ?? "",
@@ -371,9 +376,9 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
371
376
  ? error.message
372
377
  : m.user_form_update_error());
373
378
  }
374
- } }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache, googleEnabled: projectConfig?.authOptions.google ?? true, currentSiteHref: currentSiteHref, navigate: navigate })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
379
+ } }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache, googleEnabled: projectConfig?.authOptions.google ?? true, currentSiteHref: currentSiteHref, navigate: navigate })] }))] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "security", onOpenChange: (open) => {
375
380
  setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
376
- }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: settingsDialog === "apiKeys", onOpenChange: (open) => {
381
+ }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "apiKeys", onOpenChange: (open) => {
377
382
  setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
378
383
  }, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} })] }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
379
384
  setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
@@ -10,7 +10,7 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
10
10
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
11
11
  readonly id: import("effect/Schema").String;
12
12
  readonly key: import("effect/Schema").String;
13
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
13
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
14
14
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
15
15
  readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
16
16
  readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
@@ -33,11 +33,11 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
33
33
  readonly newPassword: import("effect/Schema").NonEmptyString;
34
34
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
35
35
  readonly ok: import("effect/Schema").Boolean;
36
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadUserImage", "POST", "/auth/image/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
36
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadUserImage", "POST", "/auth/image/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
37
37
  readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
38
38
  }>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
39
39
  readonly url: import("effect/Schema").String;
40
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
40
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
41
41
  readonly key: import("effect/Schema").NonEmptyString;
42
42
  readonly configId: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>>;
43
43
  readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
@@ -65,4 +65,4 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
65
65
  readonly password: import("effect/Schema").NonEmptyString;
66
66
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
67
67
  readonly ok: import("effect/Schema").Boolean;
68
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never>, false>;
68
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never>, false>;
@@ -15,7 +15,12 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
15
15
  .add(HttpApiEndpoint.post("setPassword", "/auth/set-password", {
16
16
  payload: ExtraSetPasswordPayload,
17
17
  success: ExtraOkResponse,
18
- error: ExtraBadRequest,
18
+ error: [
19
+ ExtraBadRequest,
20
+ HttpApiError.Unauthorized,
21
+ HttpApiError.Forbidden,
22
+ HttpApiError.InternalServerError,
23
+ ],
19
24
  }).annotateMerge(OpenApi.annotations({
20
25
  title: "Set password",
21
26
  summary: "Set password for the current user",
@@ -24,7 +29,12 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
24
29
  .add(HttpApiEndpoint.post("verifyPassword", "/auth/verify-password", {
25
30
  payload: ExtraVerifyPasswordPayload,
26
31
  success: ExtraOkResponse,
27
- error: ExtraBadRequest,
32
+ error: [
33
+ ExtraBadRequest,
34
+ HttpApiError.Unauthorized,
35
+ HttpApiError.Forbidden,
36
+ HttpApiError.InternalServerError,
37
+ ],
28
38
  }).annotateMerge(OpenApi.annotations({
29
39
  title: "Verify password",
30
40
  summary: "Verify current user password",
@@ -33,7 +43,12 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
33
43
  .add(HttpApiEndpoint.post("createApiKey", "/auth/create-api-key", {
34
44
  payload: ExtraCreateApiKeyPayload,
35
45
  success: ExtraCreateApiKeyResponse,
36
- error: ExtraBadRequest,
46
+ error: [
47
+ ExtraBadRequest,
48
+ HttpApiError.Unauthorized,
49
+ HttpApiError.Forbidden,
50
+ HttpApiError.InternalServerError,
51
+ ],
37
52
  }).annotateMerge(OpenApi.annotations({
38
53
  title: "Create API key",
39
54
  summary: "Create an API key with optional permissions",
@@ -54,6 +69,7 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
54
69
  error: [
55
70
  ExtraBadRequest,
56
71
  HttpApiError.Unauthorized,
72
+ HttpApiError.Forbidden,
57
73
  HttpApiError.InternalServerError,
58
74
  ],
59
75
  }).annotateMerge(OpenApi.annotations({
@@ -1,11 +1,12 @@
1
1
  import { Layer } from "effect";
2
+ import { HttpServerRequest } from "effect/unstable/http";
2
3
  import { HttpApiError, HttpApiMiddleware, HttpApiSecurity } from "effect/unstable/httpapi";
3
4
  import { AuthService, type AuthServiceLayerOptions } from "../service";
4
5
  export declare const ApiKeySecurity: HttpApiSecurity.ApiKey;
5
6
  declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware, "@krak-stack/auth/AuthMiddleware", {
6
7
  requires: never;
7
8
  provides: AuthService;
8
- error: typeof HttpApiError.Unauthorized;
9
+ error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
9
10
  clientError: never;
10
11
  requiredForClient: false;
11
12
  security: {
@@ -13,11 +14,16 @@ declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware
13
14
  };
14
15
  }, HttpApiMiddleware.HttpApiMiddlewareSecurity<{
15
16
  readonly apiKey: HttpApiSecurity.ApiKey;
16
- }, AuthService, typeof HttpApiError.Unauthorized, never>>;
17
+ }, AuthService, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], never>>;
17
18
  export declare class AuthMiddleware extends AuthMiddleware_base {
19
+ static readonly layer: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
18
20
  }
19
21
  export type AuthenticationLiveOptions = AuthServiceLayerOptions & {
20
- readonly authLayer?: Layer.Layer<AuthService, unknown>;
22
+ readonly allowedOrganizationImpersonationRoutes?: readonly {
23
+ readonly method: string;
24
+ readonly path: string;
25
+ }[];
26
+ readonly authLayer?: Layer.Layer<AuthService, unknown, HttpServerRequest.HttpServerRequest>;
21
27
  };
22
28
  export declare const makeAuthenticationLive: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
23
29
  export {};
@@ -7,17 +7,19 @@ export const ApiKeySecurity = HttpApiSecurity.apiKey({
7
7
  in: "header",
8
8
  });
9
9
  export class AuthMiddleware extends HttpApiMiddleware.Service()("@krak-stack/auth/AuthMiddleware", {
10
- error: HttpApiError.Unauthorized,
10
+ error: [HttpApiError.Unauthorized, HttpApiError.Forbidden],
11
11
  security: {
12
12
  apiKey: ApiKeySecurity,
13
13
  },
14
14
  }) {
15
+ static layer = (options = {}) => makeAuthenticationLive(options);
15
16
  }
16
17
  const isAuthServiceLayer = (value) => Layer.isLayer(value);
17
18
  export const makeAuthenticationLive = (options = {}) => {
18
19
  const legacyLayer = isAuthServiceLayer(options) ? options : undefined;
19
20
  const authOptions = isAuthServiceLayer(options) ? {} : options;
20
21
  const authLayer = legacyLayer ?? authOptions.authLayer;
22
+ const allowedOrganizationImpersonationRoutes = authOptions.allowedOrganizationImpersonationRoutes ?? [];
21
23
  return Layer.effect(AuthMiddleware, Effect.gen(function* () {
22
24
  return {
23
25
  apiKey: (httpEffect, { credential }) => Effect.gen(function* () {
@@ -31,10 +33,31 @@ export const makeAuthenticationLive = (options = {}) => {
31
33
  ...authOptions,
32
34
  headers,
33
35
  })), Effect.tapCause((cause) => Effect.logError("Authentication rejected: auth client initialization failed", Cause.pretty(cause))), Effect.mapError(() => new HttpApiError.Unauthorized({})));
36
+ if (!isAllowedRoute(allowedOrganizationImpersonationRoutes, request)) {
37
+ const session = yield* auth
38
+ .getSession()
39
+ .pipe(Effect.catchTag("Unauthorized", () => Effect.succeed(null)));
40
+ if (session?.session.impersonatedByOrganizationId) {
41
+ return yield* new HttpApiError.Forbidden({});
42
+ }
43
+ }
34
44
  return yield* httpEffect.pipe(Effect.provideService(AuthService, auth));
35
- }).pipe(Effect.mapError((error) => error instanceof HttpApiError.Unauthorized
45
+ }).pipe(Effect.mapError((error) => error instanceof HttpApiError.Unauthorized ||
46
+ error instanceof HttpApiError.Forbidden
36
47
  ? error
37
48
  : new HttpApiError.Unauthorized({}))),
38
49
  };
39
50
  }));
40
51
  };
52
+ const pathnameFromUrl = (url) => new URL(url, "http://localhost").pathname;
53
+ const isAllowedRoute = (routes, request) => routes.some(({ method, path }) => method.toUpperCase() === request.method.toUpperCase() &&
54
+ routePathMatches(path, pathnameFromUrl(request.url)));
55
+ const routePathMatches = (allowedPath, requestPath) => {
56
+ if (allowedPath === requestPath)
57
+ return true;
58
+ const allowedSegments = allowedPath.split("/").filter(Boolean);
59
+ const requestSegments = requestPath.split("/").filter(Boolean);
60
+ if (allowedSegments.length !== requestSegments.length)
61
+ return false;
62
+ return allowedSegments.every((segment, index) => segment.startsWith(":") || segment === requestSegments[index]);
63
+ };
@@ -12,20 +12,8 @@ const blockedRequestHeaders = [
12
12
  "upgrade",
13
13
  "cdn-loop",
14
14
  ];
15
- const parseUrl = (value) => {
16
- if (!value)
17
- return null;
18
- try {
19
- return new URL(value);
20
- }
21
- catch {
22
- return null;
23
- }
24
- };
25
15
  const forwardedUrl = (request) => {
26
- return (parseUrl(request.headers.get("origin")) ??
27
- parseUrl(request.headers.get("referer")) ??
28
- new URL(request.url));
16
+ return new URL(request.url);
29
17
  };
30
18
  const proxyHeaders = (request) => {
31
19
  const headers = new Headers(request.headers);