@jcoder-stack/abp-react 0.3.0 → 0.4.0
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/auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CookieOptions, T as TokenClient } from './oidc-
|
|
2
|
-
export { A as Auth, a as COOKIE_CHUNK_SIZE, b as
|
|
1
|
+
import { C as CookieOptions, T as TokenClient } from './oidc-DRn2tomK.js';
|
|
2
|
+
export { A as Auth, a as COOKIE_CHUNK_SIZE, b as CULTURE_COOKIE, c as Codec, d as CodecSchema, O as OidcMetadata, e as OidcStrategy, S as SessionManager, f as TokenClientConfig, g as TokenGrant, h as chunkCookieValue, i as clearChunkedCookie, j as clearCookie, k as createAuth, l as createCodec, m as createSessionManager, n as createTokenClient, o as discoverMetadata, p as formatCultureCookie, q as oidcMetadataSchema, r as oidcStrategy, s as parseCookieHeader, t as parseCultureCookie, u as readChunkedCookie, v as serializeCookie, w as toTokenResult } from './oidc-DRn2tomK.js';
|
|
3
3
|
import { e as Logger } from './logger-BSnS65IC.js';
|
|
4
4
|
import { S as SessionStore, A as AuthStrategy } from './types-BeHmw3RC.js';
|
|
5
5
|
export { a as AuthSession, B as BeginInput, C as CompleteInput, F as FetchFn, H as Handshake, I as Identity, b as IdentityContext, c as IdentityResolver, T as TokenResult, d as authSessionSchema, e as authTokensSchema, h as handshakeSchema } from './types-BeHmw3RC.js';
|
|
@@ -14,11 +14,6 @@ declare function createCookieSessionStore(opts: {
|
|
|
14
14
|
logger?: Logger;
|
|
15
15
|
}): SessionStore;
|
|
16
16
|
|
|
17
|
-
/** 解析 ASP.NET Core 文化 cookie 值(`c=zh-Hans|uic=zh-Hans`)为文化名,无则 null。 */
|
|
18
|
-
declare function parseCultureCookie(value: string | undefined): string | null;
|
|
19
|
-
/** 组 ASP.NET Core 文化 cookie 值。 */
|
|
20
|
-
declare function formatCultureCookie(culture: string): string;
|
|
21
|
-
|
|
22
17
|
type AuthErrorCode =
|
|
23
18
|
/** 调用方给策略喂了它不受理的输入。属于编程错误,不该当成用户可修复的失败渲染。 */
|
|
24
19
|
"invalid_input" | "invalid_state"
|
|
@@ -53,4 +48,4 @@ declare function passwordStrategy(cfg: {
|
|
|
53
48
|
logger?: Logger;
|
|
54
49
|
}): AuthStrategy;
|
|
55
50
|
|
|
56
|
-
export { AuthError, type AuthErrorCode, AuthStrategy, CookieOptions, SessionStore, TokenClient, createCookieSessionStore, decodeIdTokenClaims,
|
|
51
|
+
export { AuthError, type AuthErrorCode, AuthStrategy, CookieOptions, SessionStore, TokenClient, createCookieSessionStore, decodeIdTokenClaims, generatePkce, generateRandomString, passwordStrategy, sanitizeReturnUrl };
|
package/dist/auth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthError,
|
|
3
3
|
COOKIE_CHUNK_SIZE,
|
|
4
|
+
CULTURE_COOKIE,
|
|
4
5
|
authSessionSchema,
|
|
5
6
|
authTokensSchema,
|
|
6
7
|
chunkCookieValue,
|
|
@@ -26,10 +27,11 @@ import {
|
|
|
26
27
|
sanitizeReturnUrl,
|
|
27
28
|
serializeCookie,
|
|
28
29
|
toTokenResult
|
|
29
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-NVHYMIYS.js";
|
|
30
31
|
export {
|
|
31
32
|
AuthError,
|
|
32
33
|
COOKIE_CHUNK_SIZE,
|
|
34
|
+
CULTURE_COOKIE,
|
|
33
35
|
authSessionSchema,
|
|
34
36
|
authTokensSchema,
|
|
35
37
|
chunkCookieValue,
|
|
@@ -529,6 +529,7 @@ function createAuth(opts) {
|
|
|
529
529
|
}
|
|
530
530
|
|
|
531
531
|
// src/auth/culture.ts
|
|
532
|
+
var CULTURE_COOKIE = ".AspNetCore.Culture";
|
|
532
533
|
function parseCultureCookie(value) {
|
|
533
534
|
if (!value) return null;
|
|
534
535
|
for (const part of value.split("|")) {
|
|
@@ -689,6 +690,7 @@ export {
|
|
|
689
690
|
createTokenClient,
|
|
690
691
|
createSessionManager,
|
|
691
692
|
createAuth,
|
|
693
|
+
CULTURE_COOKIE,
|
|
692
694
|
parseCultureCookie,
|
|
693
695
|
formatCultureCookie,
|
|
694
696
|
decodeIdTokenClaims,
|
|
@@ -174,6 +174,14 @@ declare function createAuth(opts: {
|
|
|
174
174
|
coalesceTtlMs?: number;
|
|
175
175
|
}): Auth;
|
|
176
176
|
|
|
177
|
+
/** ASP.NET Core 文化 cookie 名,与 ABP 后端约定共享。定义在这里而不是 proxy:边界页在浏览器里
|
|
178
|
+
* 也要读它,而 proxy 子路径引着 node:fs/tls(tls-trust),一进客户端模块图整棵树就求值失败。 */
|
|
179
|
+
declare const CULTURE_COOKIE = ".AspNetCore.Culture";
|
|
180
|
+
/** 解析 ASP.NET Core 文化 cookie 值(`c=zh-Hans|uic=zh-Hans`)为文化名,无则 null。 */
|
|
181
|
+
declare function parseCultureCookie(value: string | undefined): string | null;
|
|
182
|
+
/** 组 ASP.NET Core 文化 cookie 值。 */
|
|
183
|
+
declare function formatCultureCookie(culture: string): string;
|
|
184
|
+
|
|
177
185
|
interface OidcStrategy extends AuthStrategy {
|
|
178
186
|
begin(input: BeginInput): Promise<{
|
|
179
187
|
redirectUrl: string;
|
|
@@ -199,4 +207,4 @@ declare function oidcStrategy(cfg: {
|
|
|
199
207
|
handshakeMaxAgeSeconds?: number;
|
|
200
208
|
}): OidcStrategy;
|
|
201
209
|
|
|
202
|
-
export { type Auth as A, type CookieOptions as C, type OidcMetadata as O, type SessionManager as S, type TokenClient as T, COOKIE_CHUNK_SIZE as a, type Codec as
|
|
210
|
+
export { type Auth as A, type CookieOptions as C, type OidcMetadata as O, type SessionManager as S, type TokenClient as T, COOKIE_CHUNK_SIZE as a, CULTURE_COOKIE as b, type Codec as c, type CodecSchema as d, type OidcStrategy as e, type TokenClientConfig as f, type TokenGrant as g, chunkCookieValue as h, clearChunkedCookie as i, clearCookie as j, createAuth as k, createCodec as l, createSessionManager as m, createTokenClient as n, discoverMetadata as o, formatCultureCookie as p, oidcMetadataSchema as q, oidcStrategy as r, parseCookieHeader as s, parseCultureCookie as t, readChunkedCookie as u, serializeCookie as v, toTokenResult as w };
|
package/dist/proxy.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { e as Logger } from './logger-BSnS65IC.js';
|
|
2
2
|
import { a as AuthSession, I as Identity, c as IdentityResolver, F as FetchFn, H as Handshake } from './types-BeHmw3RC.js';
|
|
3
|
-
import { A as Auth,
|
|
3
|
+
import { A as Auth, e as OidcStrategy, c as Codec, C as CookieOptions } from './oidc-DRn2tomK.js';
|
|
4
|
+
export { b as CULTURE_COOKIE } from './oidc-DRn2tomK.js';
|
|
4
5
|
import { A as ApplicationConfiguration } from './application-configuration-DhOZRqtz.js';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
|
|
@@ -63,8 +64,7 @@ declare function createAbpProxy(opts: {
|
|
|
63
64
|
|
|
64
65
|
/** 租户切换 cookie / 头名,与 ABP 后端约定共享。 */
|
|
65
66
|
declare const TENANT_COOKIE = "__tenant";
|
|
66
|
-
|
|
67
|
-
declare const CULTURE_COOKIE = ".AspNetCore.Culture";
|
|
67
|
+
|
|
68
68
|
/** abp-call/identity 只认代理、会话与日志三样;宿主的完整 runtime 结构上兼容此形状。 */
|
|
69
69
|
interface AbpCallRuntime {
|
|
70
70
|
proxy: AbpProxy;
|
|
@@ -233,4 +233,4 @@ type InstallExtraCaResult = "installed" | "already-installed" | "unsupported";
|
|
|
233
233
|
*/
|
|
234
234
|
declare function installExtraCa(caFile: string, caApi?: RuntimeCaApi): InstallExtraCaResult;
|
|
235
235
|
|
|
236
|
-
export { type AbpAuthEnv, type AbpAuthRuntimeOptions, type AbpCallRuntime, type AbpProxy, type AbpProxyAuth, type AbpProxyBody, AbpProxyError, type AbpProxyRequest, type AbpProxyResponse, type AppState, type AuthCookieConfig, type AuthCookieSettings, type AuthRuntime,
|
|
236
|
+
export { type AbpAuthEnv, type AbpAuthRuntimeOptions, type AbpCallRuntime, type AbpProxy, type AbpProxyAuth, type AbpProxyBody, AbpProxyError, type AbpProxyRequest, type AbpProxyResponse, type AppState, type AuthCookieConfig, type AuthCookieSettings, type AuthRuntime, DEFAULT_LOGIN_COOKIE, DEFAULT_LOGIN_COOKIE_MAX_AGE, DEFAULT_SESSION_COOKIE, DEFAULT_SESSION_COOKIE_MAX_AGE, type InstallExtraCaResult, SWITCH_COOKIE_MAX_AGE, TENANT_COOKIE, abpAuthEnvSchema, buildPolicyHeaders, callAbpWithSession, cookieAttributesOf, createAbpAuthRuntime, createAbpIdentityResolver, createAbpProxy, deriveIdentity, handleCallback, handleLogin, handleLogout, handleSetCulture, handleSetTenant, installExtraCa, loadAppState, resolveAbpAuthEnv, tlsTrustFailureCode, tlsTrustFailureMessage, upstreamUnreachableCode, upstreamUnreachableMessage };
|
package/dist/proxy.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-UDMHSDXZ.js";
|
|
5
5
|
import {
|
|
6
6
|
AuthError,
|
|
7
|
+
CULTURE_COOKIE,
|
|
7
8
|
clearCookie,
|
|
8
9
|
createAuth,
|
|
9
10
|
createCodec,
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
passwordStrategy,
|
|
18
19
|
sanitizeReturnUrl,
|
|
19
20
|
serializeCookie
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-NVHYMIYS.js";
|
|
21
22
|
import {
|
|
22
23
|
parseApplicationConfiguration,
|
|
23
24
|
toHttpError
|
|
@@ -25,7 +26,6 @@ import {
|
|
|
25
26
|
|
|
26
27
|
// src/proxy/abp-call.ts
|
|
27
28
|
var TENANT_COOKIE = "__tenant";
|
|
28
|
-
var CULTURE_COOKIE = ".AspNetCore.Culture";
|
|
29
29
|
function buildPolicyHeaders(session, cookieHeader) {
|
|
30
30
|
const cookies = parseCookieHeader(cookieHeader);
|
|
31
31
|
const headers = {};
|
|
@@ -173,10 +173,9 @@ function resolveAbpAuthEnv(env, opts = {}) {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
// src/proxy/tls-trust.ts
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
import tls from "tls";
|
|
176
|
+
function builtin(id) {
|
|
177
|
+
return process.getBuiltinModule(id);
|
|
178
|
+
}
|
|
180
179
|
var TRUST_FAILURE_CODES = /* @__PURE__ */ new Set([
|
|
181
180
|
"CERT_HAS_EXPIRED",
|
|
182
181
|
"CERT_NOT_YET_VALID",
|
|
@@ -230,22 +229,26 @@ function tlsTrustFailureMessage(code, url) {
|
|
|
230
229
|
}
|
|
231
230
|
function expandHome(path) {
|
|
232
231
|
if (path !== "~" && !path.startsWith("~/")) return path;
|
|
233
|
-
return join(homedir(), path.slice(2));
|
|
232
|
+
return builtin("node:path").join(builtin("node:os").homedir(), path.slice(2));
|
|
234
233
|
}
|
|
235
|
-
function installExtraCa(caFile, caApi
|
|
236
|
-
if (typeof
|
|
234
|
+
function installExtraCa(caFile, caApi) {
|
|
235
|
+
if (typeof process === "undefined" || typeof process.getBuiltinModule !== "function") {
|
|
236
|
+
return "unsupported";
|
|
237
|
+
}
|
|
238
|
+
const api = caApi ?? builtin("node:tls");
|
|
239
|
+
if (typeof api.getCACertificates !== "function" || typeof api.setDefaultCACertificates !== "function") {
|
|
237
240
|
return "unsupported";
|
|
238
241
|
}
|
|
239
242
|
const resolved = expandHome(caFile);
|
|
240
243
|
let pem;
|
|
241
244
|
try {
|
|
242
|
-
pem = readFileSync(resolved, "utf8");
|
|
245
|
+
pem = builtin("node:fs").readFileSync(resolved, "utf8");
|
|
243
246
|
} catch (error) {
|
|
244
247
|
throw new Error(`extra CA file is not readable: ${resolved}`, { cause: error });
|
|
245
248
|
}
|
|
246
|
-
const current =
|
|
249
|
+
const current = api.getCACertificates("default");
|
|
247
250
|
if (current.includes(pem)) return "already-installed";
|
|
248
|
-
|
|
251
|
+
api.setDefaultCACertificates([...current, pem]);
|
|
249
252
|
return "installed";
|
|
250
253
|
}
|
|
251
254
|
|
|
@@ -260,6 +263,7 @@ var AbpProxyError = class extends Error {
|
|
|
260
263
|
};
|
|
261
264
|
var IDEMPOTENT = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
262
265
|
var isRetryableStatus = (status) => status >= 500 || status === 429;
|
|
266
|
+
var utf8KeepingBom = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
263
267
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
264
268
|
var discardBody = (res) => res.body?.cancel().catch(() => {
|
|
265
269
|
});
|
|
@@ -414,7 +418,7 @@ function createAbpProxy(opts) {
|
|
|
414
418
|
return {
|
|
415
419
|
status: res.status,
|
|
416
420
|
headers: exposeHeaders(res.headers),
|
|
417
|
-
body: isText ? await res.
|
|
421
|
+
body: isText ? utf8KeepingBom.decode(await res.arrayBuffer()) : await res.arrayBuffer(),
|
|
418
422
|
setCookies
|
|
419
423
|
};
|
|
420
424
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoder-stack/abp-react",
|
|
3
3
|
"description": "Pure-React runtime for ABP backends: logging, ABP types with zod parsing, fetch client, auth sessions, the ABP proxy gateway, permissions, i18n, React providers/hooks, and TanStack Router guards — exported per domain via subpaths",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|