@foldspace-fe/casdoor-next-auth-kit 0.1.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/billing/index.d.ts +16 -0
- package/dist/billing/index.js +28 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/callback-BTzHQK_r.d.ts +12 -0
- package/dist/casdoor/index.d.ts +28 -0
- package/dist/casdoor/index.js +40 -0
- package/dist/casdoor/index.js.map +1 -0
- package/dist/chunk-6E27SZ7V.js +291 -0
- package/dist/chunk-6E27SZ7V.js.map +1 -0
- package/dist/chunk-DONQHN4U.js +56 -0
- package/dist/chunk-DONQHN4U.js.map +1 -0
- package/dist/chunk-IQEVUR77.js +909 -0
- package/dist/chunk-IQEVUR77.js.map +1 -0
- package/dist/chunk-RGTVPBH7.js +182 -0
- package/dist/chunk-RGTVPBH7.js.map +1 -0
- package/dist/chunk-T2M5MVPE.js +20 -0
- package/dist/chunk-T2M5MVPE.js.map +1 -0
- package/dist/chunk-XMBHIEYL.js +1 -0
- package/dist/chunk-XMBHIEYL.js.map +1 -0
- package/dist/chunk-Y4GJ2AEI.js +192 -0
- package/dist/chunk-Y4GJ2AEI.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +437 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -0
- package/dist/next/index.d.ts +17 -0
- package/dist/next/index.js +24 -0
- package/dist/next/index.js.map +1 -0
- package/dist/options-JUwZSXu2.d.ts +40 -0
- package/dist/react/index.d.ts +242 -0
- package/dist/react/index.js +774 -0
- package/dist/react/index.js.map +1 -0
- package/dist/skills/casdoor-next-auth-kit/SKILL.md +158 -0
- package/dist/skills/casdoor-next-auth-kit/references/casdoor-api-reference.md +2387 -0
- package/dist/skills/casdoor-next-auth-kit/references/swagger.json +3686 -0
- package/dist/types-BPsPs5Rv.d.ts +337 -0
- package/dist/types-DqVXdUge.d.ts +121 -0
- package/package.json +69 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { B as BillingActionPayload, b as BillingRuntimeConfig, m as BillingCreditsState, j as BillingProductState, h as BillingSubscriptionState, n as BillingEntitlementState, c as BillingCatalogConfig, p as BillingPurchaseStatus, k as BillingOrderHistoryItem, l as BillingPaymentHistoryItem, v as BillingInterval, a as BillingItem, q as BillingProductSnapshot } from '../types-BPsPs5Rv.js';
|
|
2
|
+
export { f as BillingActionExecutor, s as BillingActionKind, d as BillingApiClient, t as BillingConversionRule, r as BillingCoreContextValue, u as BillingCreditsContextValue, g as BillingDefaults, w as BillingItemKind, e as BillingLoaders, x as BillingProductContextValue, y as BillingProductPurchaseConfig, o as BillingStatusState, z as BillingSubscriptionContextValue, i as BillingSubscriptionHistoryItem, A as BillingSubscriptionPurchaseConfig } from '../types-BPsPs5Rv.js';
|
|
3
|
+
|
|
4
|
+
declare function normalizeBillingRuntimeConfig(config?: Partial<BillingRuntimeConfig> | null): BillingRuntimeConfig;
|
|
5
|
+
declare function normalizeBillingCatalogConfig(config?: Partial<BillingCatalogConfig> | null): BillingCatalogConfig;
|
|
6
|
+
declare function resolveBillingItem(items: BillingItem[] | undefined, key?: string | null): BillingItem | undefined;
|
|
7
|
+
declare function resolveBillingSubscriptionProduct(subscription: BillingSubscriptionState | undefined, runtimeConfig: BillingRuntimeConfig | undefined): BillingProductSnapshot | undefined;
|
|
8
|
+
declare function resolveBillingProductSnapshot(item?: BillingItem | null): BillingProductSnapshot | undefined;
|
|
9
|
+
declare function deriveBillingCreditsState(credits?: BillingCreditsState | null, products?: BillingProductState[] | null, conversionRules?: BillingRuntimeConfig['conversionRules']): BillingCreditsState;
|
|
10
|
+
declare function deriveBillingEntitlements(subscription: BillingSubscriptionState | undefined, products: BillingProductState[] | undefined, credits: BillingCreditsState | undefined, runtimeConfig: BillingRuntimeConfig | undefined): BillingEntitlementState;
|
|
11
|
+
declare function normalizeBillingPurchaseStatus(status?: Partial<BillingPurchaseStatus> | null, order?: BillingOrderHistoryItem | null, payment?: BillingPaymentHistoryItem | null): BillingPurchaseStatus;
|
|
12
|
+
declare function filterProductsByKind(products: BillingProductState[] | undefined, kind?: 'product' | 'credits'): BillingProductState[];
|
|
13
|
+
declare function resolveBillingInterval(interval?: BillingInterval | null): BillingInterval | undefined;
|
|
14
|
+
declare function buildBillingActionPayload(payload: BillingActionPayload, runtimeConfig?: BillingRuntimeConfig | null): BillingActionPayload;
|
|
15
|
+
|
|
16
|
+
export { BillingActionPayload, BillingCatalogConfig, BillingCreditsState, BillingEntitlementState, BillingInterval, BillingItem, BillingOrderHistoryItem, BillingPaymentHistoryItem, BillingProductSnapshot, BillingProductState, BillingPurchaseStatus, BillingRuntimeConfig, BillingSubscriptionState, buildBillingActionPayload, deriveBillingCreditsState, deriveBillingEntitlements, filterProductsByKind, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingSubscriptionProduct };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "../chunk-XMBHIEYL.js";
|
|
2
|
+
import {
|
|
3
|
+
buildBillingActionPayload,
|
|
4
|
+
deriveBillingCreditsState,
|
|
5
|
+
deriveBillingEntitlements,
|
|
6
|
+
filterProductsByKind,
|
|
7
|
+
normalizeBillingCatalogConfig,
|
|
8
|
+
normalizeBillingPurchaseStatus,
|
|
9
|
+
normalizeBillingRuntimeConfig,
|
|
10
|
+
resolveBillingInterval,
|
|
11
|
+
resolveBillingItem,
|
|
12
|
+
resolveBillingProductSnapshot,
|
|
13
|
+
resolveBillingSubscriptionProduct
|
|
14
|
+
} from "../chunk-RGTVPBH7.js";
|
|
15
|
+
export {
|
|
16
|
+
buildBillingActionPayload,
|
|
17
|
+
deriveBillingCreditsState,
|
|
18
|
+
deriveBillingEntitlements,
|
|
19
|
+
filterProductsByKind,
|
|
20
|
+
normalizeBillingCatalogConfig,
|
|
21
|
+
normalizeBillingPurchaseStatus,
|
|
22
|
+
normalizeBillingRuntimeConfig,
|
|
23
|
+
resolveBillingInterval,
|
|
24
|
+
resolveBillingItem,
|
|
25
|
+
resolveBillingProductSnapshot,
|
|
26
|
+
resolveBillingSubscriptionProduct
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { A as AuthKitConfig, a as AuthBusinessAdapter, b as AuthPersistenceAdapter } from './types-DqVXdUge.js';
|
|
3
|
+
|
|
4
|
+
interface CallbackHandlerOptions {
|
|
5
|
+
config: AuthKitConfig;
|
|
6
|
+
adapter?: AuthBusinessAdapter;
|
|
7
|
+
persistence?: AuthPersistenceAdapter;
|
|
8
|
+
}
|
|
9
|
+
declare function createCallbackResponse(request: NextRequest, options: CallbackHandlerOptions): Promise<NextResponse>;
|
|
10
|
+
declare function createCallbackHandler(options: CallbackHandlerOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
11
|
+
|
|
12
|
+
export { type CallbackHandlerOptions as C, createCallbackResponse as a, createCallbackHandler as c };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { A as AuthKitConfig, O as OAuthTokens, C as CasdoorUserInfo } from '../types-DqVXdUge.js';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
export { C as CallbackHandlerOptions, c as createCallbackHandler, a as createCallbackResponse } from '../callback-BTzHQK_r.js';
|
|
4
|
+
|
|
5
|
+
declare function getCasdoorConfig(config: AuthKitConfig): AuthKitConfig;
|
|
6
|
+
declare function getCasdoorAuthorizeUrl(config: AuthKitConfig, params: {
|
|
7
|
+
state: string;
|
|
8
|
+
codeChallenge: string;
|
|
9
|
+
redirectUri: string;
|
|
10
|
+
kind: 'login' | 'signup';
|
|
11
|
+
}): string;
|
|
12
|
+
declare function getCasdoorTokenUrl(config: AuthKitConfig): string;
|
|
13
|
+
declare function getCasdoorUserInfoUrl(config: AuthKitConfig): string;
|
|
14
|
+
|
|
15
|
+
declare function exchangeCodeForToken(config: AuthKitConfig, code: string, redirectUri: string, codeVerifier: string): Promise<OAuthTokens>;
|
|
16
|
+
declare function fetchCasdoorUserInfo(config: AuthKitConfig, accessToken: string): Promise<CasdoorUserInfo>;
|
|
17
|
+
declare function decodeCasdoorAccessToken(accessToken: string): Record<string, unknown> | null;
|
|
18
|
+
declare const exchangeCasdoorOAuthToken: typeof exchangeCodeForToken;
|
|
19
|
+
|
|
20
|
+
declare function createLoginEntryResponse(request: NextRequest, config: AuthKitConfig): Promise<NextResponse>;
|
|
21
|
+
declare function createSignupEntryResponse(request: NextRequest, config: AuthKitConfig): Promise<NextResponse>;
|
|
22
|
+
declare function createAuthorizeEntryResponse(request: NextRequest, config: AuthKitConfig): Promise<NextResponse>;
|
|
23
|
+
|
|
24
|
+
declare function createCasdoorApiProxyHandler(config: AuthKitConfig, prefix?: string, upstreamPrefix?: string): (request: NextRequest) => Promise<NextResponse>;
|
|
25
|
+
declare function createCasdoorPageProxyHandler(config: AuthKitConfig, prefix?: string, upstreamPrefix?: string): (request: NextRequest) => Promise<NextResponse>;
|
|
26
|
+
declare function createCasdoorCommerceProxyHandler(config: AuthKitConfig, prefix?: string, upstreamPrefix?: string): (request: NextRequest) => Promise<NextResponse>;
|
|
27
|
+
|
|
28
|
+
export { createAuthorizeEntryResponse, createCasdoorApiProxyHandler, createCasdoorCommerceProxyHandler, createCasdoorPageProxyHandler, createLoginEntryResponse, createSignupEntryResponse, decodeCasdoorAccessToken, exchangeCasdoorOAuthToken, exchangeCodeForToken, fetchCasdoorUserInfo, getCasdoorAuthorizeUrl, getCasdoorConfig, getCasdoorTokenUrl, getCasdoorUserInfoUrl };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCasdoorApiProxyHandler,
|
|
3
|
+
createCasdoorCommerceProxyHandler,
|
|
4
|
+
createCasdoorPageProxyHandler
|
|
5
|
+
} from "../chunk-DONQHN4U.js";
|
|
6
|
+
import {
|
|
7
|
+
createAuthorizeEntryResponse,
|
|
8
|
+
createCallbackHandler,
|
|
9
|
+
createCallbackResponse,
|
|
10
|
+
createLoginEntryResponse,
|
|
11
|
+
createSignupEntryResponse,
|
|
12
|
+
decodeCasdoorAccessToken,
|
|
13
|
+
exchangeCasdoorOAuthToken,
|
|
14
|
+
exchangeCodeForToken,
|
|
15
|
+
fetchCasdoorUserInfo,
|
|
16
|
+
getCasdoorAuthorizeUrl,
|
|
17
|
+
getCasdoorConfig,
|
|
18
|
+
getCasdoorTokenUrl,
|
|
19
|
+
getCasdoorUserInfoUrl
|
|
20
|
+
} from "../chunk-IQEVUR77.js";
|
|
21
|
+
import "../chunk-T2M5MVPE.js";
|
|
22
|
+
export {
|
|
23
|
+
createAuthorizeEntryResponse,
|
|
24
|
+
createCallbackHandler,
|
|
25
|
+
createCallbackResponse,
|
|
26
|
+
createCasdoorApiProxyHandler,
|
|
27
|
+
createCasdoorCommerceProxyHandler,
|
|
28
|
+
createCasdoorPageProxyHandler,
|
|
29
|
+
createLoginEntryResponse,
|
|
30
|
+
createSignupEntryResponse,
|
|
31
|
+
decodeCasdoorAccessToken,
|
|
32
|
+
exchangeCasdoorOAuthToken,
|
|
33
|
+
exchangeCodeForToken,
|
|
34
|
+
fetchCasdoorUserInfo,
|
|
35
|
+
getCasdoorAuthorizeUrl,
|
|
36
|
+
getCasdoorConfig,
|
|
37
|
+
getCasdoorTokenUrl,
|
|
38
|
+
getCasdoorUserInfoUrl
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// src/core/env.ts
|
|
2
|
+
var AUTH_KIT_ENV_FILES = [".env", ".env.local", ".env.production", ".env.example"];
|
|
3
|
+
var AUTH_KIT_ENV_VARIABLES = [
|
|
4
|
+
{
|
|
5
|
+
key: "APP_URL",
|
|
6
|
+
description: "\u7AD9\u70B9\u5BF9\u5916\u516C\u5F00\u5730\u5740",
|
|
7
|
+
example: "https://your-domain.com",
|
|
8
|
+
local: "http://localhost:5177",
|
|
9
|
+
production: "https://your-domain.com"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
key: "NEXTAUTH_URL",
|
|
13
|
+
description: "NextAuth \u56DE\u8C03\u5730\u5740",
|
|
14
|
+
example: "http://localhost:5177",
|
|
15
|
+
local: "http://localhost:5177",
|
|
16
|
+
production: "https://your-domain.com"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
key: "NEXTAUTH_SECRET",
|
|
20
|
+
description: "NextAuth JWT secret",
|
|
21
|
+
example: "replace-with-a-random-secret",
|
|
22
|
+
local: "replace-with-a-random-secret",
|
|
23
|
+
production: "replace-with-a-random-secret"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: "GLOBAL_ADMIN_EMAILS",
|
|
27
|
+
description: "\u5168\u5C40\u7BA1\u7406\u5458\u90AE\u7BB1\uFF0C\u9017\u53F7\u5206\u9694",
|
|
28
|
+
example: "admin@example.com",
|
|
29
|
+
local: "admin@example.com",
|
|
30
|
+
production: "admin@example.com"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "AUTH_DEBUG",
|
|
34
|
+
description: "\u662F\u5426\u5F00\u542F\u8BA4\u8BC1\u8C03\u8BD5\u65E5\u5FD7",
|
|
35
|
+
example: "false",
|
|
36
|
+
local: "false",
|
|
37
|
+
production: "false"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "NEXT_PUBLIC_CASDOOR_SERVER_URL",
|
|
41
|
+
description: "Casdoor \u670D\u52A1\u5730\u5740",
|
|
42
|
+
example: "https://auth.example.com",
|
|
43
|
+
local: "https://auth.example.com",
|
|
44
|
+
production: "https://auth.example.com"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
key: "NEXT_PUBLIC_CASDOOR_CLIENT_ID",
|
|
48
|
+
description: "Casdoor client id",
|
|
49
|
+
example: "your-casdoor-client-id",
|
|
50
|
+
local: "your-casdoor-client-id",
|
|
51
|
+
production: "your-casdoor-client-id"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
key: "NEXT_PUBLIC_CASDOOR_APP_NAME",
|
|
55
|
+
description: "Casdoor app name",
|
|
56
|
+
example: "your-app-name",
|
|
57
|
+
local: "your-app-name",
|
|
58
|
+
production: "your-app-name"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: "NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME",
|
|
62
|
+
description: "Casdoor organization name",
|
|
63
|
+
example: "your-org-name",
|
|
64
|
+
local: "your-org-name",
|
|
65
|
+
production: "your-org-name"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: "NEXT_PUBLIC_CASDOOR_REDIRECT_PATH",
|
|
69
|
+
description: "Casdoor OAuth \u56DE\u8C03\u8DEF\u5F84",
|
|
70
|
+
example: "/callback",
|
|
71
|
+
local: "/callback",
|
|
72
|
+
production: "/callback"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: "NEXT_PUBLIC_CASDOOR_SIGNIN_PATH",
|
|
76
|
+
description: "Casdoor authorize \u8DEF\u5F84",
|
|
77
|
+
example: "/login/oauth/authorize",
|
|
78
|
+
local: "/login/oauth/authorize",
|
|
79
|
+
production: "/login/oauth/authorize"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
key: "NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN",
|
|
83
|
+
description: "Casdoor \u9759\u6001\u8D44\u6E90 origin",
|
|
84
|
+
example: "https://casdoor-static.foldspace.cn",
|
|
85
|
+
local: "https://casdoor-static.foldspace.cn",
|
|
86
|
+
production: "https://casdoor-static.foldspace.cn"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "CASDOOR_CLIENT_SECRET",
|
|
90
|
+
description: "Casdoor client secret",
|
|
91
|
+
example: "your-casdoor-client-secret",
|
|
92
|
+
local: "your-casdoor-client-secret",
|
|
93
|
+
production: "your-casdoor-client-secret"
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
function stringifyEnvValue(value) {
|
|
97
|
+
if (value === "") {
|
|
98
|
+
return '""';
|
|
99
|
+
}
|
|
100
|
+
if (/^[A-Za-z0-9_./:-]+$/.test(value)) {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
return JSON.stringify(value);
|
|
104
|
+
}
|
|
105
|
+
function stripQuotes(value) {
|
|
106
|
+
const trimmed = value.trim();
|
|
107
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
108
|
+
return trimmed.slice(1, -1);
|
|
109
|
+
}
|
|
110
|
+
return trimmed;
|
|
111
|
+
}
|
|
112
|
+
function parseEnvKeys(content) {
|
|
113
|
+
const keys = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const line of content.split(/\r?\n/)) {
|
|
115
|
+
const trimmed = line.trim();
|
|
116
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const separatorIndex = trimmed.indexOf("=");
|
|
120
|
+
if (separatorIndex === -1) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const key = trimmed.slice(0, separatorIndex).trim();
|
|
124
|
+
if (key) {
|
|
125
|
+
keys.add(key);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return keys;
|
|
129
|
+
}
|
|
130
|
+
function getManagedEnvValue(definition, file) {
|
|
131
|
+
if (file === ".env.example") {
|
|
132
|
+
return definition.example;
|
|
133
|
+
}
|
|
134
|
+
if (file === ".env.production") {
|
|
135
|
+
return definition.production ?? definition.example;
|
|
136
|
+
}
|
|
137
|
+
if (file === ".env.local") {
|
|
138
|
+
return definition.local ?? definition.example;
|
|
139
|
+
}
|
|
140
|
+
return definition.base ?? definition.local ?? definition.production ?? definition.example;
|
|
141
|
+
}
|
|
142
|
+
function buildManagedEnvTemplate(file, existingContent = "") {
|
|
143
|
+
const existingKeys = parseEnvKeys(existingContent);
|
|
144
|
+
const lines = existingContent.trimEnd() ? existingContent.trimEnd().split(/\r?\n/) : [];
|
|
145
|
+
const missing = AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key));
|
|
146
|
+
if (missing.length === 0 && existingContent) {
|
|
147
|
+
return existingContent;
|
|
148
|
+
}
|
|
149
|
+
if (lines.length > 0) {
|
|
150
|
+
lines.push("");
|
|
151
|
+
}
|
|
152
|
+
lines.push(`# Casdoor Next Auth Kit managed values for ${file}`);
|
|
153
|
+
for (const definition of missing) {
|
|
154
|
+
const value = getManagedEnvValue(definition, file);
|
|
155
|
+
lines.push(`# ${definition.description}`);
|
|
156
|
+
lines.push(`${definition.key}=${stringifyEnvValue(value)}`);
|
|
157
|
+
lines.push("");
|
|
158
|
+
}
|
|
159
|
+
while (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
160
|
+
lines.pop();
|
|
161
|
+
}
|
|
162
|
+
return `${lines.join("\n")}
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
function getMissingManagedEnvKeys(content) {
|
|
166
|
+
const existingKeys = parseEnvKeys(content);
|
|
167
|
+
return AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key)).map(
|
|
168
|
+
(definition) => definition.key
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
function sanitizeExistingEnvContent(content) {
|
|
172
|
+
return stripQuotes(content);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/prisma/schema-template.ts
|
|
176
|
+
var AUTH_PRISMA_SCHEMA_MODELS = [
|
|
177
|
+
{
|
|
178
|
+
name: "AuthUser",
|
|
179
|
+
description: "Shared authentication user record",
|
|
180
|
+
fields: [
|
|
181
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
182
|
+
{ name: "email", type: "String?", attributes: ["@unique"] },
|
|
183
|
+
{ name: "name", type: "String?" },
|
|
184
|
+
{ name: "image", type: "String?" },
|
|
185
|
+
{ name: "isAdmin", type: "Boolean", attributes: ["@default(false)"] },
|
|
186
|
+
{ name: "tokenBalance", type: "Int", attributes: ["@default(0)"] },
|
|
187
|
+
{ name: "isVip", type: "Boolean", attributes: ["@default(false)"] },
|
|
188
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
189
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
190
|
+
],
|
|
191
|
+
blockAttributes: ["@@index([email])"]
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "AuthMembership",
|
|
195
|
+
description: "Subscription membership snapshot",
|
|
196
|
+
fields: [
|
|
197
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
198
|
+
{ name: "userId", type: "String", attributes: ["@unique"] },
|
|
199
|
+
{ name: "plan", type: "String" },
|
|
200
|
+
{ name: "status", type: "String" },
|
|
201
|
+
{ name: "startsAt", type: "DateTime?" },
|
|
202
|
+
{ name: "endsAt", type: "DateTime?" },
|
|
203
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
204
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
205
|
+
],
|
|
206
|
+
blockAttributes: ["@@index([userId])"]
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "AuthOrder",
|
|
210
|
+
description: "Commerce order record",
|
|
211
|
+
fields: [
|
|
212
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
213
|
+
{ name: "userId", type: "String" },
|
|
214
|
+
{ name: "kind", type: "String" },
|
|
215
|
+
{ name: "status", type: "String" },
|
|
216
|
+
{ name: "amount", type: "Int" },
|
|
217
|
+
{ name: "currency", type: "String", attributes: ['@default("CNY")'] },
|
|
218
|
+
{ name: "payload", type: "Json?" },
|
|
219
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
220
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
221
|
+
],
|
|
222
|
+
blockAttributes: ["@@index([userId])"]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "AuthSubscription",
|
|
226
|
+
description: "Commerce subscription record",
|
|
227
|
+
fields: [
|
|
228
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
229
|
+
{ name: "userId", type: "String" },
|
|
230
|
+
{ name: "productId", type: "String" },
|
|
231
|
+
{ name: "status", type: "String" },
|
|
232
|
+
{ name: "interval", type: "String" },
|
|
233
|
+
{ name: "startsAt", type: "DateTime?" },
|
|
234
|
+
{ name: "endsAt", type: "DateTime?" },
|
|
235
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
236
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
237
|
+
],
|
|
238
|
+
blockAttributes: ["@@index([userId])", "@@index([productId])"]
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: "AuthInvoice",
|
|
242
|
+
description: "Commerce invoice record",
|
|
243
|
+
fields: [
|
|
244
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
245
|
+
{ name: "userId", type: "String" },
|
|
246
|
+
{ name: "orderId", type: "String?" },
|
|
247
|
+
{ name: "invoiceNo", type: "String", attributes: ["@unique"] },
|
|
248
|
+
{ name: "status", type: "String" },
|
|
249
|
+
{ name: "amount", type: "Int" },
|
|
250
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
251
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
252
|
+
],
|
|
253
|
+
blockAttributes: ["@@index([userId])", "@@index([orderId])"]
|
|
254
|
+
}
|
|
255
|
+
];
|
|
256
|
+
function renderField(field) {
|
|
257
|
+
const attributes = field.attributes?.length ? ` ${field.attributes.join(" ")}` : "";
|
|
258
|
+
return ` ${field.name} ${field.type}${attributes}`;
|
|
259
|
+
}
|
|
260
|
+
function renderModel(model) {
|
|
261
|
+
const lines = [
|
|
262
|
+
`/// ${model.description}`,
|
|
263
|
+
`model ${model.name} {`,
|
|
264
|
+
...model.fields.map(renderField)
|
|
265
|
+
];
|
|
266
|
+
if (model.blockAttributes?.length) {
|
|
267
|
+
lines.push(...model.blockAttributes.map((attribute) => ` ${attribute}`));
|
|
268
|
+
}
|
|
269
|
+
lines.push("}");
|
|
270
|
+
return lines.join("\n");
|
|
271
|
+
}
|
|
272
|
+
function buildAuthPrismaSchemaTemplate(models = AUTH_PRISMA_SCHEMA_MODELS) {
|
|
273
|
+
return [
|
|
274
|
+
"// generated by @foldspace-fe/casdoor-next-auth-kit",
|
|
275
|
+
"// merge these models into the host Prisma schema if you want a dedicated auth module",
|
|
276
|
+
"",
|
|
277
|
+
...models.map(renderModel)
|
|
278
|
+
].join("\n\n");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export {
|
|
282
|
+
AUTH_KIT_ENV_FILES,
|
|
283
|
+
AUTH_KIT_ENV_VARIABLES,
|
|
284
|
+
getManagedEnvValue,
|
|
285
|
+
buildManagedEnvTemplate,
|
|
286
|
+
getMissingManagedEnvKeys,
|
|
287
|
+
sanitizeExistingEnvContent,
|
|
288
|
+
AUTH_PRISMA_SCHEMA_MODELS,
|
|
289
|
+
buildAuthPrismaSchemaTemplate
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=chunk-6E27SZ7V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/env.ts","../src/prisma/schema-template.ts"],"sourcesContent":["import type { ManagedEnvFile, ManagedEnvVariableDefinition } from '../types';\n\nexport const AUTH_KIT_ENV_FILES: ManagedEnvFile[] = ['.env', '.env.local', '.env.production', '.env.example'];\n\nexport const AUTH_KIT_ENV_VARIABLES: ManagedEnvVariableDefinition[] = [\n {\n key: 'APP_URL',\n description: '站点对外公开地址',\n example: 'https://your-domain.com',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_URL',\n description: 'NextAuth 回调地址',\n example: 'http://localhost:5177',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_SECRET',\n description: 'NextAuth JWT secret',\n example: 'replace-with-a-random-secret',\n local: 'replace-with-a-random-secret',\n production: 'replace-with-a-random-secret',\n },\n {\n key: 'GLOBAL_ADMIN_EMAILS',\n description: '全局管理员邮箱,逗号分隔',\n example: 'admin@example.com',\n local: 'admin@example.com',\n production: 'admin@example.com',\n },\n {\n key: 'AUTH_DEBUG',\n description: '是否开启认证调试日志',\n example: 'false',\n local: 'false',\n production: 'false',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SERVER_URL',\n description: 'Casdoor 服务地址',\n example: 'https://auth.example.com',\n local: 'https://auth.example.com',\n production: 'https://auth.example.com',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_CLIENT_ID',\n description: 'Casdoor client id',\n example: 'your-casdoor-client-id',\n local: 'your-casdoor-client-id',\n production: 'your-casdoor-client-id',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_APP_NAME',\n description: 'Casdoor app name',\n example: 'your-app-name',\n local: 'your-app-name',\n production: 'your-app-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME',\n description: 'Casdoor organization name',\n example: 'your-org-name',\n local: 'your-org-name',\n production: 'your-org-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_REDIRECT_PATH',\n description: 'Casdoor OAuth 回调路径',\n example: '/callback',\n local: '/callback',\n production: '/callback',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SIGNIN_PATH',\n description: 'Casdoor authorize 路径',\n example: '/login/oauth/authorize',\n local: '/login/oauth/authorize',\n production: '/login/oauth/authorize',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN',\n description: 'Casdoor 静态资源 origin',\n example: 'https://casdoor-static.foldspace.cn',\n local: 'https://casdoor-static.foldspace.cn',\n production: 'https://casdoor-static.foldspace.cn',\n },\n {\n key: 'CASDOOR_CLIENT_SECRET',\n description: 'Casdoor client secret',\n example: 'your-casdoor-client-secret',\n local: 'your-casdoor-client-secret',\n production: 'your-casdoor-client-secret',\n },\n];\n\nfunction stringifyEnvValue(value: string): string {\n if (value === '') {\n return '\"\"';\n }\n\n if (/^[A-Za-z0-9_./:-]+$/.test(value)) {\n return value;\n }\n\n return JSON.stringify(value);\n}\n\nfunction stripQuotes(value: string): string {\n const trimmed = value.trim();\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n\n return trimmed;\n}\n\nfunction parseEnvKeys(content: string): Set<string> {\n const keys = new Set<string>();\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) {\n continue;\n }\n\n const separatorIndex = trimmed.indexOf('=');\n if (separatorIndex === -1) {\n continue;\n }\n\n const key = trimmed.slice(0, separatorIndex).trim();\n if (key) {\n keys.add(key);\n }\n }\n return keys;\n}\n\nexport function getManagedEnvValue(definition: ManagedEnvVariableDefinition, file: ManagedEnvFile): string {\n if (file === '.env.example') {\n return definition.example;\n }\n if (file === '.env.production') {\n return definition.production ?? definition.example;\n }\n if (file === '.env.local') {\n return definition.local ?? definition.example;\n }\n return definition.base ?? definition.local ?? definition.production ?? definition.example;\n}\n\nexport function buildManagedEnvTemplate(file: ManagedEnvFile, existingContent = ''): string {\n const existingKeys = parseEnvKeys(existingContent);\n const lines: string[] = existingContent.trimEnd() ? existingContent.trimEnd().split(/\\r?\\n/) : [];\n const missing = AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key));\n\n if (missing.length === 0 && existingContent) {\n return existingContent;\n }\n\n if (lines.length > 0) {\n lines.push('');\n }\n\n lines.push(`# Casdoor Next Auth Kit managed values for ${file}`);\n for (const definition of missing) {\n const value = getManagedEnvValue(definition, file);\n lines.push(`# ${definition.description}`);\n lines.push(`${definition.key}=${stringifyEnvValue(value)}`);\n lines.push('');\n }\n\n while (lines.length > 0 && lines[lines.length - 1] === '') {\n lines.pop();\n }\n\n return `${lines.join('\\n')}\\n`;\n}\n\nexport function getMissingManagedEnvKeys(content: string): string[] {\n const existingKeys = parseEnvKeys(content);\n return AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key)).map(\n (definition) => definition.key,\n );\n}\n\nexport function sanitizeExistingEnvContent(content: string): string {\n return stripQuotes(content);\n}\n","import type { PrismaSchemaFieldDefinition, PrismaSchemaModelDefinition } from '../types';\n\nexport const AUTH_PRISMA_SCHEMA_MODELS: PrismaSchemaModelDefinition[] = [\n {\n name: 'AuthUser',\n description: 'Shared authentication user record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'email', type: 'String?', attributes: ['@unique'] },\n { name: 'name', type: 'String?' },\n { name: 'image', type: 'String?' },\n { name: 'isAdmin', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'tokenBalance', type: 'Int', attributes: ['@default(0)'] },\n { name: 'isVip', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([email])'],\n },\n {\n name: 'AuthMembership',\n description: 'Subscription membership snapshot',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String', attributes: ['@unique'] },\n { name: 'plan', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthOrder',\n description: 'Commerce order record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'kind', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'currency', type: 'String', attributes: ['@default(\"CNY\")'] },\n { name: 'payload', type: 'Json?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthSubscription',\n description: 'Commerce subscription record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'productId', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'interval', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([productId])'],\n },\n {\n name: 'AuthInvoice',\n description: 'Commerce invoice record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'orderId', type: 'String?' },\n { name: 'invoiceNo', type: 'String', attributes: ['@unique'] },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([orderId])'],\n },\n];\n\nfunction renderField(field: PrismaSchemaFieldDefinition): string {\n const attributes = field.attributes?.length ? ` ${field.attributes.join(' ')}` : '';\n return ` ${field.name} ${field.type}${attributes}`;\n}\n\nfunction renderModel(model: PrismaSchemaModelDefinition): string {\n const lines = [\n `/// ${model.description}`,\n `model ${model.name} {`,\n ...model.fields.map(renderField),\n ];\n\n if (model.blockAttributes?.length) {\n lines.push(...model.blockAttributes.map((attribute) => ` ${attribute}`));\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\nexport function buildAuthPrismaSchemaTemplate(models: PrismaSchemaModelDefinition[] = AUTH_PRISMA_SCHEMA_MODELS): string {\n return [\n '// generated by @foldspace-fe/casdoor-next-auth-kit',\n '// merge these models into the host Prisma schema if you want a dedicated auth module',\n '',\n ...models.map(renderModel),\n ].join('\\n\\n');\n}\n"],"mappings":";AAEO,IAAM,qBAAuC,CAAC,QAAQ,cAAc,mBAAmB,cAAc;AAErG,IAAM,yBAAyD;AAAA,EACpE;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAA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AAEA,SAAS,YAAY,OAA4C;AAC/D,QAAM,QAAQ;AAAA,IACZ,OAAO,MAAM,WAAW;AAAA,IACxB,SAAS,MAAM,IAAI;AAAA,IACnB,GAAG,MAAM,OAAO,IAAI,WAAW;AAAA,EACjC;AAEA,MAAI,MAAM,iBAAiB,QAAQ;AACjC,UAAM,KAAK,GAAG,MAAM,gBAAgB,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;AAAA,EAC1E;AAEA,QAAM,KAAK,GAAG;AACd,SAAO,MAAM,KAAK,IAAI;AACxB;AAEO,SAAS,8BAA8B,SAAwC,2BAAmC;AACvH,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,OAAO,IAAI,WAAW;AAAA,EAC3B,EAAE,KAAK,MAAM;AACf;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/casdoor/proxy.ts
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
|
+
function buildUpstreamUrl(request, baseUrl, localPrefix, upstreamPrefix) {
|
|
4
|
+
const url = new URL(request.url);
|
|
5
|
+
const upstreamPath = url.pathname.startsWith(localPrefix) ? upstreamPrefix + url.pathname.slice(localPrefix.length) : url.pathname;
|
|
6
|
+
const rewritten = new URL(upstreamPath, baseUrl);
|
|
7
|
+
rewritten.search = url.search;
|
|
8
|
+
return rewritten.toString();
|
|
9
|
+
}
|
|
10
|
+
async function proxyRequest(request, baseUrl, localPrefix, upstreamPrefix, options = {}) {
|
|
11
|
+
const upstreamUrl = buildUpstreamUrl(request, baseUrl, localPrefix, upstreamPrefix);
|
|
12
|
+
const headers = new Headers(request.headers);
|
|
13
|
+
headers.delete("host");
|
|
14
|
+
const body = request.method === "GET" || request.method === "HEAD" ? void 0 : await request.arrayBuffer();
|
|
15
|
+
const upstream = await fetch(upstreamUrl, {
|
|
16
|
+
method: request.method,
|
|
17
|
+
headers,
|
|
18
|
+
body,
|
|
19
|
+
redirect: options.suppressRedirects ? "manual" : "follow"
|
|
20
|
+
});
|
|
21
|
+
if (options.suppressRedirects && upstream.status >= 300 && upstream.status < 400) {
|
|
22
|
+
return NextResponse.json(
|
|
23
|
+
{
|
|
24
|
+
status: "error",
|
|
25
|
+
msg: "Please login first",
|
|
26
|
+
redirect: upstream.headers.get("location") || null
|
|
27
|
+
},
|
|
28
|
+
{ status: 200 }
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const responseHeaders = new Headers(upstream.headers);
|
|
32
|
+
responseHeaders.delete("content-encoding");
|
|
33
|
+
responseHeaders.delete("content-length");
|
|
34
|
+
responseHeaders.delete("transfer-encoding");
|
|
35
|
+
responseHeaders.delete("connection");
|
|
36
|
+
return new NextResponse(upstream.body, {
|
|
37
|
+
status: upstream.status,
|
|
38
|
+
headers: responseHeaders
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function createCasdoorApiProxyHandler(config, prefix = "/auth/api", upstreamPrefix = "/api") {
|
|
42
|
+
return async (request) => proxyRequest(request, config.casdoor.serverUrl, prefix, upstreamPrefix, { suppressRedirects: true });
|
|
43
|
+
}
|
|
44
|
+
function createCasdoorPageProxyHandler(config, prefix = "/auth", upstreamPrefix = "") {
|
|
45
|
+
return async (request) => proxyRequest(request, config.casdoor.serverUrl, prefix, upstreamPrefix);
|
|
46
|
+
}
|
|
47
|
+
function createCasdoorCommerceProxyHandler(config, prefix = "/auth/api/commerce", upstreamPrefix = "/api/commerce") {
|
|
48
|
+
return async (request) => proxyRequest(request, config.casdoor.serverUrl, prefix, upstreamPrefix, { suppressRedirects: true });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
createCasdoorApiProxyHandler,
|
|
53
|
+
createCasdoorPageProxyHandler,
|
|
54
|
+
createCasdoorCommerceProxyHandler
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=chunk-DONQHN4U.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/casdoor/proxy.ts"],"sourcesContent":["import { NextResponse, type NextRequest } from 'next/server';\nimport type { AuthKitConfig } from '../types';\n\nfunction buildUpstreamUrl(request: NextRequest, baseUrl: string, localPrefix: string, upstreamPrefix: string): string {\n const url = new URL(request.url);\n const upstreamPath = url.pathname.startsWith(localPrefix)\n ? upstreamPrefix + url.pathname.slice(localPrefix.length)\n : url.pathname;\n const rewritten = new URL(upstreamPath, baseUrl);\n rewritten.search = url.search;\n return rewritten.toString();\n}\n\nasync function proxyRequest(\n request: NextRequest,\n baseUrl: string,\n localPrefix: string,\n upstreamPrefix: string,\n options: { suppressRedirects?: boolean } = {},\n): Promise<NextResponse> {\n const upstreamUrl = buildUpstreamUrl(request, baseUrl, localPrefix, upstreamPrefix);\n const headers = new Headers(request.headers);\n headers.delete('host');\n const body = request.method === 'GET' || request.method === 'HEAD' ? undefined : await request.arrayBuffer();\n const upstream = await fetch(upstreamUrl, {\n method: request.method,\n headers,\n body,\n redirect: options.suppressRedirects ? 'manual' : 'follow',\n });\n\n if (options.suppressRedirects && upstream.status >= 300 && upstream.status < 400) {\n return NextResponse.json(\n {\n status: 'error',\n msg: 'Please login first',\n redirect: upstream.headers.get('location') || null,\n },\n { status: 200 },\n );\n }\n\n const responseHeaders = new Headers(upstream.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n responseHeaders.delete('transfer-encoding');\n responseHeaders.delete('connection');\n return new NextResponse(upstream.body, {\n status: upstream.status,\n headers: responseHeaders,\n });\n}\n\nexport function createCasdoorApiProxyHandler(\n config: AuthKitConfig,\n prefix = '/auth/api',\n upstreamPrefix = '/api',\n): (request: NextRequest) => Promise<NextResponse> {\n return async (request) => proxyRequest(request, config.casdoor.serverUrl, prefix, upstreamPrefix, { suppressRedirects: true });\n}\n\nexport function createCasdoorPageProxyHandler(\n config: AuthKitConfig,\n prefix = '/auth',\n upstreamPrefix = '',\n): (request: NextRequest) => Promise<NextResponse> {\n return async (request) => proxyRequest(request, config.casdoor.serverUrl, prefix, upstreamPrefix);\n}\n\nexport function createCasdoorCommerceProxyHandler(\n config: AuthKitConfig,\n prefix = '/auth/api/commerce',\n upstreamPrefix = '/api/commerce',\n): (request: NextRequest) => Promise<NextResponse> {\n return async (request) => proxyRequest(request, config.casdoor.serverUrl, prefix, upstreamPrefix, { suppressRedirects: true });\n}\n"],"mappings":";AAAA,SAAS,oBAAsC;AAG/C,SAAS,iBAAiB,SAAsB,SAAiB,aAAqB,gBAAgC;AACpH,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,QAAM,eAAe,IAAI,SAAS,WAAW,WAAW,IACpD,iBAAiB,IAAI,SAAS,MAAM,YAAY,MAAM,IACtD,IAAI;AACR,QAAM,YAAY,IAAI,IAAI,cAAc,OAAO;AAC/C,YAAU,SAAS,IAAI;AACvB,SAAO,UAAU,SAAS;AAC5B;AAEA,eAAe,aACb,SACA,SACA,aACA,gBACA,UAA2C,CAAC,GACrB;AACvB,QAAM,cAAc,iBAAiB,SAAS,SAAS,aAAa,cAAc;AAClF,QAAM,UAAU,IAAI,QAAQ,QAAQ,OAAO;AAC3C,UAAQ,OAAO,MAAM;AACrB,QAAM,OAAO,QAAQ,WAAW,SAAS,QAAQ,WAAW,SAAS,SAAY,MAAM,QAAQ,YAAY;AAC3G,QAAM,WAAW,MAAM,MAAM,aAAa;AAAA,IACxC,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA;AAAA,IACA,UAAU,QAAQ,oBAAoB,WAAW;AAAA,EACnD,CAAC;AAED,MAAI,QAAQ,qBAAqB,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;AAChF,WAAO,aAAa;AAAA,MAClB;AAAA,QACE,QAAQ;AAAA,QACR,KAAK;AAAA,QACL,UAAU,SAAS,QAAQ,IAAI,UAAU,KAAK;AAAA,MAChD;AAAA,MACA,EAAE,QAAQ,IAAI;AAAA,IAChB;AAAA,EACF;AAEA,QAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;AACpD,kBAAgB,OAAO,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