@schemavaults/auth-server-sdk 0.21.4 → 0.21.5
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/cli.cjs +2 -2
- package/dist/route_guards/withAdminRouteGuard/index.d.ts +4 -0
- package/dist/route_guards/withAdminRouteGuard/index.js +3 -0
- package/dist/route_guards/withAdminRouteGuard/index.js.map +1 -0
- package/dist/route_guards/withAdminRouteGuard/withAdminApiRouteGuard.d.ts +8 -0
- package/dist/route_guards/withAdminRouteGuard/withAdminApiRouteGuard.js +7 -0
- package/dist/route_guards/withAdminRouteGuard/withAdminApiRouteGuard.js.map +1 -0
- package/dist/route_guards/withAdminRouteGuard/withAdminServerComponentRouteGuard.d.ts +7 -0
- package/dist/route_guards/withAdminRouteGuard/withAdminServerComponentRouteGuard.js +6 -0
- package/dist/route_guards/withAdminRouteGuard/withAdminServerComponentRouteGuard.js.map +1 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedApiRouteInputs.d.ts +5 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedApiRouteInputs.js +2 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedApiRouteInputs.js.map +1 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedServerComponentPageProps.d.ts +7 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedServerComponentPageProps.js +2 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedServerComponentPageProps.js.map +1 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/index.d.ts +7 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/index.js +4 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/index.js.map +1 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/initDefaultJwtKeyManagerForAuthenticatedRouteGuard.d.ts +3 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/initDefaultJwtKeyManagerForAuthenticatedRouteGuard.js +11 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/initDefaultJwtKeyManagerForAuthenticatedRouteGuard.js.map +1 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/withAuthenticatedApiRouteGuard.d.ts +8 -0
- package/dist/route_guards/{withAuthenticatedRouteGuard.js → withAuthenticatedRouteGuard/withAuthenticatedApiRouteGuard.js} +20 -124
- package/dist/route_guards/withAuthenticatedRouteGuard/withAuthenticatedApiRouteGuard.js.map +1 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/withAuthenticatedServerComponentRouteGuard.d.ts +8 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/withAuthenticatedServerComponentRouteGuard.js +112 -0
- package/dist/route_guards/withAuthenticatedRouteGuard/withAuthenticatedServerComponentRouteGuard.js.map +1 -0
- package/package.json +1 -1
- package/dist/route_guards/withAdminRouteGuard.d.ts +0 -8
- package/dist/route_guards/withAdminRouteGuard.js +0 -9
- package/dist/route_guards/withAdminRouteGuard.js.map +0 -1
- package/dist/route_guards/withAuthenticatedRouteGuard.d.ts +0 -18
- package/dist/route_guards/withAuthenticatedRouteGuard.js.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -66,7 +66,7 @@ var init_resolve_codegen_templates_directory = __esm({
|
|
|
66
66
|
|
|
67
67
|
// src/NextjsAppDirectoryPlugin/codegen-marker.ts
|
|
68
68
|
function getCodegenMarkerComment() {
|
|
69
|
-
const version = true ? "0.21.
|
|
69
|
+
const version = true ? "0.21.5" : "unknown";
|
|
70
70
|
return `${CODEGEN_MARKER_PREFIX}${version}`;
|
|
71
71
|
}
|
|
72
72
|
function hasCodegenMarker(firstLine) {
|
|
@@ -248,7 +248,7 @@ async function main() {
|
|
|
248
248
|
return;
|
|
249
249
|
}
|
|
250
250
|
if (args.includes("--version") || args.includes("-v")) {
|
|
251
|
-
console.log(`${PACKAGE_NAME}@${"0.21.
|
|
251
|
+
console.log(`${PACKAGE_NAME}@${"0.21.5"}`);
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
254
|
const command = args.find((arg) => !arg.startsWith("-")) ?? "codegen";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { withAdminApiRouteGuard } from "./withAdminApiRouteGuard";
|
|
2
|
+
export type { TProtectedAdminApiRoute, IBaseProtectedAdminApiRouteInputs, } from "./withAdminApiRouteGuard";
|
|
3
|
+
export { withAdminServerComponentRouteGuard } from "./withAdminServerComponentRouteGuard";
|
|
4
|
+
export type { TProtectedAdminPageServerComponent, IBaseProtectedAdminServerComponentPageProps, } from "./withAdminServerComponentRouteGuard";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/route_guards/withAdminRouteGuard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAMlE,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiServerId } from "@schemavaults/app-definitions";
|
|
2
|
+
import { type TProtectedAuthenticatedApiRoute, type IBaseProtectedAuthenticatedApiRouteInputs } from "../../route_guards/withAuthenticatedRouteGuard";
|
|
3
|
+
import type { NextRequest, NextResponse } from "next/server";
|
|
4
|
+
import type { IJwtKeyManager } from "../../JwtKeyManager";
|
|
5
|
+
type TAdditionalRouteInputs<TRouteInputs extends IBaseProtectedAuthenticatedApiRouteInputs> = Omit<TRouteInputs, keyof IBaseProtectedAuthenticatedApiRouteInputs>;
|
|
6
|
+
export declare function withAdminApiRouteGuard<TRouteInputs extends IBaseProtectedAuthenticatedApiRouteInputs>(api_route_handler: TProtectedAuthenticatedApiRoute<TRouteInputs>, additional_custom_api_route_inputs?: TAdditionalRouteInputs<TRouteInputs> | undefined, custom_is_authorized_check?: ((route_inputs: TRouteInputs) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): (req: NextRequest) => Promise<NextResponse>;
|
|
7
|
+
export default withAdminApiRouteGuard;
|
|
8
|
+
export type { TProtectedAuthenticatedApiRoute as TProtectedAdminApiRoute, IBaseProtectedAuthenticatedApiRouteInputs as IBaseProtectedAdminApiRouteInputs, } from "../../route_guards/withAuthenticatedRouteGuard";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { initDefaultJwtKeyManagerForAuthenticatedRouteGuard, withAuthenticatedApiRouteGuard, } from "../../route_guards/withAuthenticatedRouteGuard";
|
|
2
|
+
import getSchemavaultsApiServerId from "../../get-schemavaults-api-server-id";
|
|
3
|
+
export function withAdminApiRouteGuard(api_route_handler, additional_custom_api_route_inputs = undefined, custom_is_authorized_check = async (inputs) => inputs.user.admin === true, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
4
|
+
return withAuthenticatedApiRouteGuard(api_route_handler, additional_custom_api_route_inputs, "admin", custom_is_authorized_check, jwt_keys_manager, getApiServerId);
|
|
5
|
+
}
|
|
6
|
+
export default withAdminApiRouteGuard;
|
|
7
|
+
//# sourceMappingURL=withAdminApiRouteGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAdminApiRouteGuard.js","sourceRoot":"","sources":["../../../src/route_guards/withAdminRouteGuard/withAdminApiRouteGuard.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kDAAkD,EAElD,8BAA8B,GAE/B,MAAM,4CAA4C,CAAC;AAEpD,OAAO,0BAA0B,MAAM,kCAAkC,CAAC;AAO1E,MAAM,UAAU,sBAAsB,CAGpC,iBAAgE,EAChE,qCAEgB,SAAS,EACzB,6BAEgB,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAC5D,mBAAmC,kDAAkD,EAAE,EACvF,iBAAoC,0BAA0B;IAE9D,OAAO,8BAA8B,CACnC,iBAAiB,EACjB,kCAAkC,EAClC,OAAO,EACP,0BAA0B,EAC1B,gBAAgB,EAChB,cAAc,CACf,CAAC;AACJ,CAAC;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ApiServerId } from "@schemavaults/app-definitions";
|
|
2
|
+
import { type IBaseProtectedAuthenticatedServerComponentPageProps, type TProtectedAuthenticatedPageServerComponent } from "../../route_guards/withAuthenticatedRouteGuard";
|
|
3
|
+
import type { ReactElement } from "react";
|
|
4
|
+
import type { IJwtKeyManager } from "../../JwtKeyManager";
|
|
5
|
+
type TAdditionalProps<TProps extends IBaseProtectedAuthenticatedServerComponentPageProps> = Omit<TProps, keyof IBaseProtectedAuthenticatedServerComponentPageProps>;
|
|
6
|
+
export declare function withAdminServerComponentRouteGuard<TProps extends IBaseProtectedAuthenticatedServerComponentPageProps>(server_component: TProtectedAuthenticatedPageServerComponent<TProps>, additional_custom_server_component_props?: TAdditionalProps<TProps> | undefined, custom_is_authorized_check?: ((props: TProps) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): Promise<ReactElement>;
|
|
7
|
+
export type { TProtectedAuthenticatedPageServerComponent as TProtectedAdminPageServerComponent, IBaseProtectedAuthenticatedServerComponentPageProps as IBaseProtectedAdminServerComponentPageProps, } from "../../route_guards/withAuthenticatedRouteGuard";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { initDefaultJwtKeyManagerForAuthenticatedRouteGuard, withAuthenticatedServerComponentRouteGuard, } from "../../route_guards/withAuthenticatedRouteGuard";
|
|
2
|
+
import getSchemavaultsApiServerId from "../../get-schemavaults-api-server-id";
|
|
3
|
+
export async function withAdminServerComponentRouteGuard(server_component, additional_custom_server_component_props = undefined, custom_is_authorized_check = async (props) => props.user.admin === true, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
4
|
+
return await withAuthenticatedServerComponentRouteGuard(server_component, additional_custom_server_component_props, "admin", custom_is_authorized_check, jwt_keys_manager, getApiServerId);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=withAdminServerComponentRouteGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAdminServerComponentRouteGuard.js","sourceRoot":"","sources":["../../../src/route_guards/withAdminRouteGuard/withAdminServerComponentRouteGuard.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kDAAkD,EAClD,0CAA0C,GAG3C,MAAM,4CAA4C,CAAC;AAEpD,OAAO,0BAA0B,MAAM,kCAAkC,CAAC;AAO1E,MAAM,CAAC,KAAK,UAAU,kCAAkC,CAGtD,gBAAoE,EACpE,2CAEgB,SAAS,EACzB,6BAEgB,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAC1D,mBAAmC,kDAAkD,EAAE,EACvF,iBAAoC,0BAA0B;IAE9D,OAAO,MAAM,0CAA0C,CACrD,gBAAgB,EAChB,wCAAwC,EACxC,OAAO,EACP,0BAA0B,EAC1B,gBAAgB,EAChB,cAAc,CACf,CAAC;AACJ,CAAC"}
|
package/dist/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedApiRouteInputs.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
import type { IBaseProtectedAuthenticatedServerComponentPageProps } from "./IBaseProtectedAuthenticatedServerComponentPageProps";
|
|
3
|
+
export interface IBaseProtectedAuthenticatedApiRouteInputs extends IBaseProtectedAuthenticatedServerComponentPageProps {
|
|
4
|
+
req: NextRequest;
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBaseProtectedAuthenticatedApiRouteInputs.js","sourceRoot":"","sources":["../../../src/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedApiRouteInputs.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SchemaVaultsAppEnvironment } from "@schemavaults/app-definitions";
|
|
2
|
+
import type { OrganizationID, UserData } from "@schemavaults/auth-common";
|
|
3
|
+
export interface IBaseProtectedAuthenticatedServerComponentPageProps {
|
|
4
|
+
user: UserData;
|
|
5
|
+
user_organizations: readonly OrganizationID[];
|
|
6
|
+
environment: SchemaVaultsAppEnvironment;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBaseProtectedAuthenticatedServerComponentPageProps.js","sourceRoot":"","sources":["../../../src/route_guards/withAuthenticatedRouteGuard/IBaseProtectedAuthenticatedServerComponentPageProps.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { withAuthenticatedApiRouteGuard } from "./withAuthenticatedApiRouteGuard";
|
|
2
|
+
export type { TProtectedAuthenticatedApiRoute } from "./withAuthenticatedApiRouteGuard";
|
|
3
|
+
export type { IBaseProtectedAuthenticatedApiRouteInputs } from "./IBaseProtectedAuthenticatedApiRouteInputs";
|
|
4
|
+
export { withAuthenticatedServerComponentRouteGuard } from "./withAuthenticatedServerComponentRouteGuard";
|
|
5
|
+
export type { TProtectedAuthenticatedPageServerComponent } from "./withAuthenticatedServerComponentRouteGuard";
|
|
6
|
+
export type { IBaseProtectedAuthenticatedServerComponentPageProps } from "./IBaseProtectedAuthenticatedServerComponentPageProps";
|
|
7
|
+
export { initDefaultJwtKeyManagerForAuthenticatedRouteGuard } from "./initDefaultJwtKeyManagerForAuthenticatedRouteGuard";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { withAuthenticatedApiRouteGuard } from "./withAuthenticatedApiRouteGuard";
|
|
2
|
+
export { withAuthenticatedServerComponentRouteGuard } from "./withAuthenticatedServerComponentRouteGuard";
|
|
3
|
+
export { initDefaultJwtKeyManagerForAuthenticatedRouteGuard } from "./initDefaultJwtKeyManagerForAuthenticatedRouteGuard";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/route_guards/withAuthenticatedRouteGuard/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAIlF,OAAO,EAAE,0CAA0C,EAAE,MAAM,8CAA8C,CAAC;AAI1G,OAAO,EAAE,kDAAkD,EAAE,MAAM,sDAAsD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import getSchemaVaultsAuthServerUri from "../../get-schemavaults-auth-server-uri";
|
|
2
|
+
import RemoteJwtKeyManager from "../../JwtKeyManager/RemoteJwtKeyManager";
|
|
3
|
+
// default key manager is RemoteJwtKeyManager-- makes it easier for external apps, we can overwrite this once for the auth server
|
|
4
|
+
export function initDefaultJwtKeyManagerForAuthenticatedRouteGuard(debug = process.env.NODE_ENV === "development") {
|
|
5
|
+
return new RemoteJwtKeyManager({
|
|
6
|
+
auth_server_uri: getSchemaVaultsAuthServerUri(),
|
|
7
|
+
debug,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export default initDefaultJwtKeyManagerForAuthenticatedRouteGuard;
|
|
11
|
+
//# sourceMappingURL=initDefaultJwtKeyManagerForAuthenticatedRouteGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initDefaultJwtKeyManagerForAuthenticatedRouteGuard.js","sourceRoot":"","sources":["../../../src/route_guards/withAuthenticatedRouteGuard/initDefaultJwtKeyManagerForAuthenticatedRouteGuard.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,MAAM,oCAAoC,CAAC;AAE9E,OAAO,mBAAmB,MAAM,qCAAqC,CAAC;AAEtE,iIAAiI;AACjI,MAAM,UAAU,kDAAkD,CAChE,QAAiB,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;IAEvD,OAAO,IAAI,mBAAmB,CAAC;QAC7B,eAAe,EAAE,4BAA4B,EAAE;QAC/C,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED,eAAe,kDAAkD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ApiServerId } from "@schemavaults/app-definitions";
|
|
2
|
+
import type { NextRequest, NextResponse } from "next/server";
|
|
3
|
+
import type { IJwtKeyManager } from "../../JwtKeyManager";
|
|
4
|
+
import type { IBaseProtectedAuthenticatedApiRouteInputs } from "./IBaseProtectedAuthenticatedApiRouteInputs";
|
|
5
|
+
export type TProtectedAuthenticatedApiRoute<TRouteInputs extends IBaseProtectedAuthenticatedApiRouteInputs> = (route_inputs: TRouteInputs) => Promise<NextResponse>;
|
|
6
|
+
type TAdditionalRouteInputs<TRouteInputs extends IBaseProtectedAuthenticatedApiRouteInputs> = Omit<TRouteInputs, keyof IBaseProtectedAuthenticatedApiRouteInputs>;
|
|
7
|
+
export declare function withAuthenticatedApiRouteGuard<TRouteInputs extends IBaseProtectedAuthenticatedApiRouteInputs>(api_route_handler: TProtectedAuthenticatedApiRoute<TRouteInputs>, additional_custom_api_route_inputs?: TAdditionalRouteInputs<TRouteInputs> | undefined, route_guard_type?: "authenticated" | "admin", custom_is_authorized_check?: ((route_inputs: TRouteInputs) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): (req: NextRequest) => Promise<NextResponse>;
|
|
8
|
+
export default withAuthenticatedApiRouteGuard;
|
|
@@ -1,122 +1,14 @@
|
|
|
1
1
|
import { SCHEMAVAULTS_AUTH_APP_ID, getAppEnvironment, } from "@schemavaults/app-definitions";
|
|
2
2
|
import { accessTokenDataSchema, } from "@schemavaults/auth-common";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import assertValidRouteGuardType from "./assertValidRouteGuardType";
|
|
13
|
-
import getSchemaVaultsAuthServerUri from "../get-schemavaults-auth-server-uri";
|
|
14
|
-
// default key manager is RemoteJwtKeyManager-- makes it easier for external apps, we can overwrite this once for the auth server
|
|
15
|
-
export function initDefaultJwtKeyManagerForAuthenticatedRouteGuard(debug = process.env.NODE_ENV === "development") {
|
|
16
|
-
return new RemoteJwtKeyManager({
|
|
17
|
-
auth_server_uri: getSchemaVaultsAuthServerUri(),
|
|
18
|
-
debug,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export async function withAuthenticatedServerComponentRouteGuard(server_component, additional_custom_server_component_props, route_guard_type = "authenticated", custom_is_authorized_check = undefined, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
22
|
-
assertValidRouteGuardType(route_guard_type);
|
|
23
|
-
const environment = getAppEnvironment();
|
|
24
|
-
const api_server_id = getApiServerId();
|
|
25
|
-
const [loadCookies, redirect] = await Promise.all([
|
|
26
|
-
import("next/headers").then((mod) => mod.cookies),
|
|
27
|
-
import("next/navigation").then((mod) => mod.redirect),
|
|
28
|
-
]);
|
|
29
|
-
if (typeof loadCookies !== "function") {
|
|
30
|
-
throw new TypeError("Expected 'loadCookies' to be a function");
|
|
31
|
-
}
|
|
32
|
-
else if (typeof redirect !== "function") {
|
|
33
|
-
throw new TypeError("Expected 'redirect' to be a function");
|
|
34
|
-
}
|
|
35
|
-
const cookies = await loadCookies();
|
|
36
|
-
if (!("get" in cookies) || typeof cookies.get !== "function") {
|
|
37
|
-
throw new TypeError("Expected 'cookies' to be a RequestCookies object with a 'get' method!");
|
|
38
|
-
}
|
|
39
|
-
const token_sources = [];
|
|
40
|
-
// Load Refresh Token for Auth Server
|
|
41
|
-
if (api_server_id === SCHEMAVAULTS_AUTH_APP_ID) {
|
|
42
|
-
const refresh_token_cookie = cookies.get(RefreshTokenCookieName(SCHEMAVAULTS_AUTH_APP_ID));
|
|
43
|
-
if (typeof refresh_token_cookie?.value === "string") {
|
|
44
|
-
token_sources.push({
|
|
45
|
-
sourceHint: "Auth Server Refresh Token",
|
|
46
|
-
type: "refresh",
|
|
47
|
-
token: refresh_token_cookie.value,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Load Access Token from designated cookie for current server
|
|
52
|
-
const access_token_cookie_name = AccessTokenCookieName(api_server_id);
|
|
53
|
-
const access_token_cookie = cookies.get(access_token_cookie_name);
|
|
54
|
-
if (typeof access_token_cookie?.value === "string" &&
|
|
55
|
-
access_token_cookie.value.length > 64) {
|
|
56
|
-
let jwt_string = null;
|
|
57
|
-
try {
|
|
58
|
-
const parsed = JSON.parse(access_token_cookie.value);
|
|
59
|
-
if (parsed && typeof parsed.token === "string") {
|
|
60
|
-
jwt_string = parsed.token;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// Raw JWT string fallback
|
|
65
|
-
jwt_string = access_token_cookie.value;
|
|
66
|
-
}
|
|
67
|
-
if (jwt_string) {
|
|
68
|
-
token_sources.push({
|
|
69
|
-
sourceHint: `Access Token from cookie '${access_token_cookie_name}'`,
|
|
70
|
-
type: "access",
|
|
71
|
-
token: jwt_string,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (token_sources.length === 0) {
|
|
76
|
-
redirectToLogin(redirect);
|
|
77
|
-
}
|
|
78
|
-
const route_guard_factory = new RouteGuardFactory({
|
|
79
|
-
environment,
|
|
80
|
-
is_auth_server: api_server_id === SCHEMAVAULTS_AUTH_APP_ID,
|
|
81
|
-
jwt_keys_manager,
|
|
82
|
-
});
|
|
83
|
-
const route_guard = await route_guard_factory.createGuardFromTokenSources(route_guard_type, token_sources, api_server_id);
|
|
84
|
-
if (!route_guard.user) {
|
|
85
|
-
redirectToLogin(redirect);
|
|
86
|
-
}
|
|
87
|
-
const user = route_guard.user;
|
|
88
|
-
if (!route_guard.isAccessAllowed()) {
|
|
89
|
-
redirectWithError(redirect, 403, "forbidden");
|
|
90
|
-
}
|
|
91
|
-
if (typeof server_component !== "function") {
|
|
92
|
-
throw new TypeError("Expected 'server_component' passed to withAuthenticatedServerComponentRouteGuard to be a function");
|
|
93
|
-
}
|
|
94
|
-
const ProtectedAuthenticatedPageServerComponent = server_component;
|
|
95
|
-
const base_server_component_props = {
|
|
96
|
-
user,
|
|
97
|
-
environment,
|
|
98
|
-
user_organizations: route_guard.user_organizations,
|
|
99
|
-
};
|
|
100
|
-
const server_component_props = {
|
|
101
|
-
...base_server_component_props,
|
|
102
|
-
...additional_custom_server_component_props,
|
|
103
|
-
};
|
|
104
|
-
if (typeof custom_is_authorized_check === "function") {
|
|
105
|
-
let is_authorized = false;
|
|
106
|
-
try {
|
|
107
|
-
is_authorized = await custom_is_authorized_check(server_component_props);
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
console.error("Error in 'custom_is_authorized_check' handler: ", e);
|
|
111
|
-
redirectWithError(redirect, 500, "internal_server_error");
|
|
112
|
-
}
|
|
113
|
-
if (!is_authorized) {
|
|
114
|
-
redirectWithError(redirect, 403, "forbidden");
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return (await ProtectedAuthenticatedPageServerComponent(server_component_props));
|
|
118
|
-
}
|
|
119
|
-
export function withAuthenticatedApiRouteGuard(api_route_handler, additional_custom_api_route_inputs, route_guard_type = "authenticated", custom_is_authorized_check = undefined, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
3
|
+
import RouteGuardFactory from "../../route_guards/route-guard-factory";
|
|
4
|
+
import getStringByteSize from "../../getStringByteSize";
|
|
5
|
+
import MaximumBrowserCookieSize from "../../MaximumBrowserCookieSize";
|
|
6
|
+
import { AccessTokenCookieName } from "../../AccessTokenCookieNames";
|
|
7
|
+
import { RefreshTokenCookieName } from "../../RefreshTokenCookieNames";
|
|
8
|
+
import getSchemavaultsApiServerId from "../../get-schemavaults-api-server-id";
|
|
9
|
+
import assertValidRouteGuardType from "../../route_guards/assertValidRouteGuardType";
|
|
10
|
+
import initDefaultJwtKeyManagerForAuthenticatedRouteGuard from "./initDefaultJwtKeyManagerForAuthenticatedRouteGuard";
|
|
11
|
+
export function withAuthenticatedApiRouteGuard(api_route_handler, additional_custom_api_route_inputs = undefined, route_guard_type = "authenticated", custom_is_authorized_check = undefined, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
120
12
|
assertValidRouteGuardType(route_guard_type);
|
|
121
13
|
const AuthenticatedApiRoute = api_route_handler;
|
|
122
14
|
return async function ProtectedAuthenticatedApiRoute(req) {
|
|
@@ -244,14 +136,17 @@ export function withAuthenticatedApiRouteGuard(api_route_handler, additional_cus
|
|
|
244
136
|
environment,
|
|
245
137
|
user_organizations,
|
|
246
138
|
};
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
139
|
+
const final_route_inputs = typeof additional_custom_api_route_inputs === "object" &&
|
|
140
|
+
additional_custom_api_route_inputs
|
|
141
|
+
? {
|
|
142
|
+
...base_api_route_inputs,
|
|
143
|
+
...additional_custom_api_route_inputs,
|
|
144
|
+
}
|
|
145
|
+
: base_api_route_inputs;
|
|
251
146
|
if (typeof custom_is_authorized_check === "function") {
|
|
252
147
|
let is_authorized = false;
|
|
253
148
|
try {
|
|
254
|
-
is_authorized = await custom_is_authorized_check(
|
|
149
|
+
is_authorized = await custom_is_authorized_check(final_route_inputs);
|
|
255
150
|
}
|
|
256
151
|
catch (e) {
|
|
257
152
|
console.error("Error in 'custom_is_authorized_check' handler: ", e);
|
|
@@ -269,7 +164,8 @@ export function withAuthenticatedApiRouteGuard(api_route_handler, additional_cus
|
|
|
269
164
|
}, { status: 403 });
|
|
270
165
|
}
|
|
271
166
|
}
|
|
272
|
-
return (await AuthenticatedApiRoute(
|
|
167
|
+
return (await AuthenticatedApiRoute(final_route_inputs));
|
|
273
168
|
};
|
|
274
169
|
}
|
|
275
|
-
|
|
170
|
+
export default withAuthenticatedApiRouteGuard;
|
|
171
|
+
//# sourceMappingURL=withAuthenticatedApiRouteGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAuthenticatedApiRouteGuard.js","sourceRoot":"","sources":["../../../src/route_guards/withAuthenticatedRouteGuard/withAuthenticatedApiRouteGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EAExB,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,qBAAqB,GAItB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,iBAAiB,MAAM,oCAAoC,CAAC;AAEnE,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,0BAA0B,MAAM,kCAAkC,CAAC;AAE1E,OAAO,yBAAyB,MAAM,0CAA0C,CAAC;AAEjF,OAAO,kDAAkD,MAAM,sDAAsD,CAAC;AAUtH,MAAM,UAAU,8BAA8B,CAG5C,iBAAgE,EAChE,qCAEgB,SAAS,EACzB,mBAA8C,eAAe,EAC7D,6BAEgB,SAAS,EACzB,mBAAmC,kDAAkD,EAAE,EACvF,iBAAoC,0BAA0B;IAE9D,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;IAE5C,MAAM,qBAAqB,GACzB,iBAAiB,CAAC;IACpB,OAAO,KAAK,UAAU,8BAA8B,CAClD,GAAgB;QAEhB,MAAM,WAAW,GAA+B,iBAAiB,EAAE,CAAC;QACpE,MAAM,aAAa,GAAgB,cAAc,EAAE,CAAC;QACpD,MAAM,IAAI,GAA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,OAAO,IAAI,CACT;oBACE,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,IAAI;oBACX,OAAO,EAAE,2CAA2C;iBACrD,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,OAAO,IAAI,CACT;oBACE,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,IAAI;oBACX,OAAO,EAAE,uBAAuB;iBACjC,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,CAAC,MAAM,qBAAqB,CACjC,kBAAkB,CACnB,CAAwB,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,eAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ApiServerId } from "@schemavaults/app-definitions";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import type { IJwtKeyManager } from "../../JwtKeyManager";
|
|
4
|
+
import type { IBaseProtectedAuthenticatedServerComponentPageProps } from "./IBaseProtectedAuthenticatedServerComponentPageProps";
|
|
5
|
+
export type TProtectedAuthenticatedPageServerComponent<TProps extends IBaseProtectedAuthenticatedServerComponentPageProps> = (props: TProps) => Promise<ReactElement>;
|
|
6
|
+
type TAdditionalProps<TProps extends IBaseProtectedAuthenticatedServerComponentPageProps> = Omit<TProps, keyof IBaseProtectedAuthenticatedServerComponentPageProps>;
|
|
7
|
+
export declare function withAuthenticatedServerComponentRouteGuard<TProps extends IBaseProtectedAuthenticatedServerComponentPageProps>(server_component: TProtectedAuthenticatedPageServerComponent<TProps>, additional_custom_server_component_props?: TAdditionalProps<TProps> | undefined, route_guard_type?: "authenticated" | "admin", custom_is_authorized_check?: ((props: TProps) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): Promise<ReactElement>;
|
|
8
|
+
export default withAuthenticatedServerComponentRouteGuard;
|
package/dist/route_guards/withAuthenticatedRouteGuard/withAuthenticatedServerComponentRouteGuard.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { SCHEMAVAULTS_AUTH_APP_ID, getAppEnvironment, } from "@schemavaults/app-definitions";
|
|
2
|
+
import { redirectWithError } from "../../redirect-with-error";
|
|
3
|
+
import RouteGuardFactory from "../../route_guards/route-guard-factory";
|
|
4
|
+
import { AccessTokenCookieName } from "../../AccessTokenCookieNames";
|
|
5
|
+
import { RefreshTokenCookieName } from "../../RefreshTokenCookieNames";
|
|
6
|
+
import getSchemavaultsApiServerId from "../../get-schemavaults-api-server-id";
|
|
7
|
+
import redirectToLogin from "../../redirect-to-login";
|
|
8
|
+
import assertValidRouteGuardType from "../../route_guards/assertValidRouteGuardType";
|
|
9
|
+
import initDefaultJwtKeyManagerForAuthenticatedRouteGuard from "./initDefaultJwtKeyManagerForAuthenticatedRouteGuard";
|
|
10
|
+
export async function withAuthenticatedServerComponentRouteGuard(server_component, additional_custom_server_component_props = undefined, route_guard_type = "authenticated", custom_is_authorized_check = undefined, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
11
|
+
assertValidRouteGuardType(route_guard_type);
|
|
12
|
+
const environment = getAppEnvironment();
|
|
13
|
+
const api_server_id = getApiServerId();
|
|
14
|
+
const [loadCookies, redirect] = await Promise.all([
|
|
15
|
+
import("next/headers").then((mod) => mod.cookies),
|
|
16
|
+
import("next/navigation").then((mod) => mod.redirect),
|
|
17
|
+
]);
|
|
18
|
+
if (typeof loadCookies !== "function") {
|
|
19
|
+
throw new TypeError("Expected 'loadCookies' to be a function");
|
|
20
|
+
}
|
|
21
|
+
else if (typeof redirect !== "function") {
|
|
22
|
+
throw new TypeError("Expected 'redirect' to be a function");
|
|
23
|
+
}
|
|
24
|
+
const cookies = await loadCookies();
|
|
25
|
+
if (!("get" in cookies) || typeof cookies.get !== "function") {
|
|
26
|
+
throw new TypeError("Expected 'cookies' to be a RequestCookies object with a 'get' method!");
|
|
27
|
+
}
|
|
28
|
+
const token_sources = [];
|
|
29
|
+
// Load Refresh Token for Auth Server
|
|
30
|
+
if (api_server_id === SCHEMAVAULTS_AUTH_APP_ID) {
|
|
31
|
+
const refresh_token_cookie = cookies.get(RefreshTokenCookieName(SCHEMAVAULTS_AUTH_APP_ID));
|
|
32
|
+
if (typeof refresh_token_cookie?.value === "string") {
|
|
33
|
+
token_sources.push({
|
|
34
|
+
sourceHint: "Auth Server Refresh Token",
|
|
35
|
+
type: "refresh",
|
|
36
|
+
token: refresh_token_cookie.value,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Load Access Token from designated cookie for current server
|
|
41
|
+
const access_token_cookie_name = AccessTokenCookieName(api_server_id);
|
|
42
|
+
const access_token_cookie = cookies.get(access_token_cookie_name);
|
|
43
|
+
if (typeof access_token_cookie?.value === "string" &&
|
|
44
|
+
access_token_cookie.value.length > 64) {
|
|
45
|
+
let jwt_string = null;
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(access_token_cookie.value);
|
|
48
|
+
if (parsed && typeof parsed.token === "string") {
|
|
49
|
+
jwt_string = parsed.token;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Raw JWT string fallback
|
|
54
|
+
jwt_string = access_token_cookie.value;
|
|
55
|
+
}
|
|
56
|
+
if (jwt_string) {
|
|
57
|
+
token_sources.push({
|
|
58
|
+
sourceHint: `Access Token from cookie '${access_token_cookie_name}'`,
|
|
59
|
+
type: "access",
|
|
60
|
+
token: jwt_string,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (token_sources.length === 0) {
|
|
65
|
+
redirectToLogin(redirect);
|
|
66
|
+
}
|
|
67
|
+
const route_guard_factory = new RouteGuardFactory({
|
|
68
|
+
environment,
|
|
69
|
+
is_auth_server: api_server_id === SCHEMAVAULTS_AUTH_APP_ID,
|
|
70
|
+
jwt_keys_manager,
|
|
71
|
+
});
|
|
72
|
+
const route_guard = await route_guard_factory.createGuardFromTokenSources(route_guard_type, token_sources, api_server_id);
|
|
73
|
+
if (!route_guard.user) {
|
|
74
|
+
redirectToLogin(redirect);
|
|
75
|
+
}
|
|
76
|
+
const user = route_guard.user;
|
|
77
|
+
if (!route_guard.isAccessAllowed()) {
|
|
78
|
+
redirectWithError(redirect, 403, "forbidden");
|
|
79
|
+
}
|
|
80
|
+
if (typeof server_component !== "function") {
|
|
81
|
+
throw new TypeError("Expected 'server_component' passed to withAuthenticatedServerComponentRouteGuard to be a function");
|
|
82
|
+
}
|
|
83
|
+
const ProtectedAuthenticatedPageServerComponent = server_component;
|
|
84
|
+
const base_server_component_props = {
|
|
85
|
+
user,
|
|
86
|
+
environment,
|
|
87
|
+
user_organizations: route_guard.user_organizations,
|
|
88
|
+
};
|
|
89
|
+
const final_server_component_props = typeof additional_custom_server_component_props === "object" &&
|
|
90
|
+
additional_custom_server_component_props
|
|
91
|
+
? {
|
|
92
|
+
...base_server_component_props,
|
|
93
|
+
...additional_custom_server_component_props,
|
|
94
|
+
}
|
|
95
|
+
: base_server_component_props;
|
|
96
|
+
if (typeof custom_is_authorized_check === "function") {
|
|
97
|
+
let is_authorized = false;
|
|
98
|
+
try {
|
|
99
|
+
is_authorized = await custom_is_authorized_check(final_server_component_props);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.error("Error in 'custom_is_authorized_check' handler: ", e);
|
|
103
|
+
redirectWithError(redirect, 500, "internal_server_error");
|
|
104
|
+
}
|
|
105
|
+
if (!is_authorized) {
|
|
106
|
+
redirectWithError(redirect, 403, "forbidden");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return (await ProtectedAuthenticatedPageServerComponent(final_server_component_props));
|
|
110
|
+
}
|
|
111
|
+
export default withAuthenticatedServerComponentRouteGuard;
|
|
112
|
+
//# sourceMappingURL=withAuthenticatedServerComponentRouteGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAuthenticatedServerComponentRouteGuard.js","sourceRoot":"","sources":["../../../src/route_guards/withAuthenticatedRouteGuard/withAuthenticatedServerComponentRouteGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EAExB,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AAOvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,iBAAiB,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,0BAA0B,MAAM,kCAAkC,CAAC;AAE1E,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAClD,OAAO,yBAAyB,MAAM,0CAA0C,CAAC;AAEjF,OAAO,kDAAkD,MAAM,sDAAsD,CAAC;AActH,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAG9D,gBAAoE,EACpE,2CAEgB,SAAS,EACzB,mBAA8C,eAAe,EAC7D,6BAEgB,SAAS,EACzB,mBAAmC,kDAAkD,EAAE,EACvF,iBAAoC,0BAA0B;IAE9D,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;IAE5C,MAAM,WAAW,GAA+B,iBAAiB,EAAE,CAAC;IACpE,MAAM,aAAa,GAAgB,cAAc,EAAE,CAAC;IACpD,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;QACjD,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC;KACtD,CAAC,CAAC;IAC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ACJ,WAAW;QACX,kBAAkB,EAAE,WAAW,CAAC,kBAAkB;KACnD,CAAC;IAEJ,MAAM,4BAA4B,GAChC,OAAO,wCAAwC,KAAK,QAAQ;QAC5D,wCAAwC;QACtC,CAAC,CAAE;YACC,GAAG,2BAA2B;YAC9B,GAAG,wCAAwC;SACtB;QACzB,CAAC,CAAE,2BAAiD,CAAC;IAEzD,IAAI,OAAO,0BAA0B,KAAK,UAAU,EAAE,CAAC;QACrD,IAAI,aAAa,GAAY,KAAK,CAAC;QACnC,IAAI,CAAC;YACH,aAAa,GAAG,MAAM,0BAA0B,CAC9C,4BAA4B,CAC7B,CAAC;QACJ,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,iDAAiD,EAAE,CAAC,CAAC,CAAC;YACpE,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,uBAAuB,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO,CAAC,MAAM,yCAAyC,CACrD,4BAA4B,CAC7B,CAAwB,CAAC;AAC5B,CAAC;AAED,eAAe,0CAA0C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/auth-server-sdk",
|
|
3
3
|
"description": "TypeScript SDK for building authenticated endpoints/middlewares for the Auth Server and Resource Servers",
|
|
4
|
-
"version": "0.21.
|
|
4
|
+
"version": "0.21.5",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type ApiServerId } from "@schemavaults/app-definitions";
|
|
2
|
-
import { type TProtectedAuthenticatedApiRoute, type IBaseProtectedAuthenticatedServerComponentPageProps, type TProtectedAuthenticatedPageServerComponent } from "./withAuthenticatedRouteGuard";
|
|
3
|
-
import type { ReactElement } from "react";
|
|
4
|
-
import type { NextRequest, NextResponse } from "next/server";
|
|
5
|
-
import type { IJwtKeyManager } from "../JwtKeyManager";
|
|
6
|
-
export declare function withAdminServerComponentRouteGuard<TAdditionalCustomProps extends object>(server_component: TProtectedAuthenticatedPageServerComponent<TAdditionalCustomProps>, additional_custom_server_component_props: TAdditionalCustomProps, custom_is_authorized_check?: ((props: IBaseProtectedAuthenticatedServerComponentPageProps & TAdditionalCustomProps) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): Promise<ReactElement>;
|
|
7
|
-
export declare function withAdminApiRouteGuard<TAdditionalCustomRouteInputs extends object>(api_route_handler: TProtectedAuthenticatedApiRoute<TAdditionalCustomRouteInputs>, additional_custom_api_route_inputs: TAdditionalCustomRouteInputs, custom_is_authorized_check?: ((route_inputs: IBaseProtectedAuthenticatedServerComponentPageProps & TAdditionalCustomRouteInputs) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): (req: NextRequest) => Promise<NextResponse>;
|
|
8
|
-
export type { TProtectedAuthenticatedPageServerComponent as TProtectedAdminPageServerComponent, TProtectedAuthenticatedApiRoute as TProtectedAdminApiRoute, IBaseProtectedAuthenticatedServerComponentPageProps as IBaseProtectedAdminServerComponentPageProps, IBaseProtectedAuthenticatedApiRouteInputs as IBaseProtectedAdminApiRouteInputs, } from "./withAuthenticatedRouteGuard";
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { initDefaultJwtKeyManagerForAuthenticatedRouteGuard, withAuthenticatedServerComponentRouteGuard, withAuthenticatedApiRouteGuard, } from "./withAuthenticatedRouteGuard";
|
|
2
|
-
import getSchemavaultsApiServerId from "../get-schemavaults-api-server-id";
|
|
3
|
-
export async function withAdminServerComponentRouteGuard(server_component, additional_custom_server_component_props, custom_is_authorized_check = async (props) => props.user.admin === true, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
4
|
-
return await withAuthenticatedServerComponentRouteGuard(server_component, additional_custom_server_component_props, "admin", custom_is_authorized_check, jwt_keys_manager, getApiServerId);
|
|
5
|
-
}
|
|
6
|
-
export function withAdminApiRouteGuard(api_route_handler, additional_custom_api_route_inputs, custom_is_authorized_check = async (inputs) => inputs.user.admin === true, jwt_keys_manager = initDefaultJwtKeyManagerForAuthenticatedRouteGuard(), getApiServerId = getSchemavaultsApiServerId) {
|
|
7
|
-
return withAuthenticatedApiRouteGuard(api_route_handler, additional_custom_api_route_inputs, "admin", custom_is_authorized_check, jwt_keys_manager, getApiServerId);
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=withAdminRouteGuard.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withAdminRouteGuard.js","sourceRoot":"","sources":["../../src/route_guards/withAdminRouteGuard.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kDAAkD,EAElD,0CAA0C,EAC1C,8BAA8B,GAG/B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,0BAA0B,MAAM,kCAAkC,CAAC;AAG1E,MAAM,CAAC,KAAK,UAAU,kCAAkC,CAGtD,gBAAoF,EACpF,wCAAgE,EAChE,6BAKgB,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAC1D,mBAAmC,kDAAkD,EAAE,EACvF,iBAAoC,0BAA0B;IAE9D,OAAO,MAAM,0CAA0C,CACrD,gBAAgB,EAChB,wCAAwC,EACxC,OAAO,EACP,0BAA0B,EAC1B,gBAAgB,EAChB,cAAc,CACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAGpC,iBAAgF,EAChF,kCAAgE,EAChE,6BAKgB,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAC5D,mBAAmC,kDAAkD,EAAE,EACvF,iBAAoC,0BAA0B;IAE9D,OAAO,8BAA8B,CACnC,iBAAiB,EACjB,kCAAkC,EAClC,OAAO,EACP,0BAA0B,EAC1B,gBAAgB,EAChB,cAAc,CACf,CAAC;AACJ,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type ApiServerId, type SchemaVaultsAppEnvironment } from "@schemavaults/app-definitions";
|
|
2
|
-
import { type OrganizationID, type UserData } from "@schemavaults/auth-common";
|
|
3
|
-
import type { ReactElement } from "react";
|
|
4
|
-
import type { NextRequest, NextResponse } from "next/server";
|
|
5
|
-
import { type IJwtKeyManager } from "../JwtKeyManager";
|
|
6
|
-
export interface IBaseProtectedAuthenticatedServerComponentPageProps {
|
|
7
|
-
user: UserData;
|
|
8
|
-
user_organizations: readonly OrganizationID[];
|
|
9
|
-
environment: SchemaVaultsAppEnvironment;
|
|
10
|
-
}
|
|
11
|
-
export type TProtectedAuthenticatedPageServerComponent<TAdditionalCustomProps extends object> = (props: IBaseProtectedAuthenticatedServerComponentPageProps & TAdditionalCustomProps) => Promise<ReactElement>;
|
|
12
|
-
export interface IBaseProtectedAuthenticatedApiRouteInputs extends IBaseProtectedAuthenticatedServerComponentPageProps {
|
|
13
|
-
req: NextRequest;
|
|
14
|
-
}
|
|
15
|
-
export type TProtectedAuthenticatedApiRoute<TAdditionalCustomRouteInputs extends object> = (route_inputs: TAdditionalCustomRouteInputs & IBaseProtectedAuthenticatedApiRouteInputs) => Promise<NextResponse>;
|
|
16
|
-
export declare function initDefaultJwtKeyManagerForAuthenticatedRouteGuard(debug?: boolean): IJwtKeyManager;
|
|
17
|
-
export declare function withAuthenticatedServerComponentRouteGuard<TAdditionalCustomProps extends object>(server_component: TProtectedAuthenticatedPageServerComponent<TAdditionalCustomProps>, additional_custom_server_component_props: TAdditionalCustomProps, route_guard_type?: "authenticated" | "admin", custom_is_authorized_check?: ((props: IBaseProtectedAuthenticatedServerComponentPageProps & TAdditionalCustomProps) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): Promise<ReactElement>;
|
|
18
|
-
export declare function withAuthenticatedApiRouteGuard<TAdditionalCustomRouteInputs extends object>(api_route_handler: TProtectedAuthenticatedApiRoute<TAdditionalCustomRouteInputs>, additional_custom_api_route_inputs: TAdditionalCustomRouteInputs, route_guard_type?: "authenticated" | "admin", custom_is_authorized_check?: ((route_inputs: IBaseProtectedAuthenticatedApiRouteInputs & TAdditionalCustomRouteInputs) => Promise<boolean>) | undefined, jwt_keys_manager?: IJwtKeyManager, getApiServerId?: () => ApiServerId): (req: NextRequest) => Promise<NextResponse>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withAuthenticatedRouteGuard.js","sourceRoot":"","sources":["../../src/route_guards/withAuthenticatedRouteGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EAExB,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,qBAAqB,GAItB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAEtD,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,0BAA0B,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAuB,MAAM,iBAAiB,CAAC;AAC3E,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAClD,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AACpE,OAAO,4BAA4B,MAAM,oCAAoC,CAAC;AA+B9E,iIAAiI;AACjI,MAAM,UAAU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