@autional/shared 0.1.0-rc.44 → 0.1.0-rc.46
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/package.json
CHANGED
package/src/auth/roles.ts
CHANGED
|
@@ -92,14 +92,18 @@ export function isAuthLoginSurface(): boolean {
|
|
|
92
92
|
return segs.length === 2 && segs[1] === 'login'; // `/<slug>/login`
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export function buildLoginUrl(
|
|
95
|
+
export function buildLoginUrl(
|
|
96
|
+
returnUrl?: string,
|
|
97
|
+
fromRequireAuth?: boolean,
|
|
98
|
+
tenantSlug?: string | null,
|
|
99
|
+
): string {
|
|
96
100
|
const base = getPortalUrl('auth');
|
|
97
101
|
if (!base) return '/';
|
|
98
102
|
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
let loginBase = base;
|
|
102
|
-
if (returnUrl) {
|
|
103
|
+
// 租户上下文优先级:显式 tenantSlug > returnUrl 首段推导 > auth 根(租户选择页)。
|
|
104
|
+
// 显式参数用于「站点在根路径(无 slug)但已知当前/最近租户」的场景。
|
|
105
|
+
let loginBase = tenantSlug ? `${base}/${encodeURIComponent(tenantSlug)}/login` : base;
|
|
106
|
+
if (!tenantSlug && returnUrl) {
|
|
103
107
|
try {
|
|
104
108
|
const clean = new URL(returnUrl, typeof window !== 'undefined' ? window.location.origin : '');
|
|
105
109
|
const baseOrigin = new URL(base).origin;
|
|
@@ -48,11 +48,17 @@ export function applyBrandColors(color: string, darkOverride?: string): void {
|
|
|
48
48
|
setColorVar(root, '--color-on-brand-dark', pickOnColor(dark));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export interface UseBrandingOptions {
|
|
52
|
+
/** 是否注入租户自定义 CSS;默认 true。认证器/验证码页应传 false。 */
|
|
53
|
+
applyCustomCss?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
/**
|
|
52
57
|
* 把当前租户品牌落到 DOM(CSS 变量 / favicon / customCss)。
|
|
53
58
|
* 需与 `<BrandingInitializer/>` 同时挂载:前者负责写 store,这里负责呈现。
|
|
54
59
|
*/
|
|
55
|
-
export function useBranding(): void {
|
|
60
|
+
export function useBranding(options?: UseBrandingOptions): void {
|
|
61
|
+
const applyCustomCss = options?.applyCustomCss ?? true;
|
|
56
62
|
const branding = useTenantBrandingStore((s) => s.branding);
|
|
57
63
|
const slug = useTenantSlugFromUrl();
|
|
58
64
|
const styleRef = useRef<HTMLStyleElement | null>(null);
|
|
@@ -84,18 +90,26 @@ export function useBranding(): void {
|
|
|
84
90
|
favicon.href = branding.faviconUrl;
|
|
85
91
|
}
|
|
86
92
|
|
|
87
|
-
if (branding.customCss) {
|
|
93
|
+
if (branding.customCss && applyCustomCss) {
|
|
88
94
|
if (!styleRef.current) {
|
|
89
95
|
styleRef.current = document.createElement('style');
|
|
90
96
|
styleRef.current.setAttribute('data-tenant-css', '');
|
|
91
97
|
document.head.appendChild(styleRef.current);
|
|
92
98
|
}
|
|
93
99
|
styleRef.current.textContent = branding.customCss;
|
|
100
|
+
} else if (styleRef.current) {
|
|
101
|
+
styleRef.current.textContent = '';
|
|
102
|
+
styleRef.current.remove();
|
|
103
|
+
styleRef.current = null;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
return () => {
|
|
97
107
|
applyBrandColors('');
|
|
98
|
-
if (styleRef.current)
|
|
108
|
+
if (styleRef.current) {
|
|
109
|
+
styleRef.current.textContent = '';
|
|
110
|
+
styleRef.current.remove();
|
|
111
|
+
styleRef.current = null;
|
|
112
|
+
}
|
|
99
113
|
};
|
|
100
|
-
}, [branding]);
|
|
114
|
+
}, [branding, applyCustomCss]);
|
|
101
115
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// GENERATED FILE — DO NOT EDIT.
|
|
2
2
|
// Source: contracts/errors.semantics.json(@autional/shared 仓内镜像,源 = service-core base/error/testdata/errors.semantics.json)
|
|
3
3
|
// Regenerate: pnpm gen:errors · Verify: pnpm gen:errors:check
|
|
4
|
-
// rows:
|
|
4
|
+
// rows: 798 · source sha256: e82f038da18dc0935623718a7516ede07d741ed071275aad4ca1610db00a8d5d
|
|
5
5
|
//
|
|
6
6
|
// 单一真源链:service-core/base/error/semantics.go(Go)→ errors.semantics.json → 本文件。
|
|
7
7
|
// ⚠️ 禁止在本文件或页面里手抄错误码分支:请消费 ERROR_SEMANTICS / UNPROVISIONED_CODES。
|
|
@@ -374,11 +374,15 @@ export const ERROR_SEMANTICS: Readonly<Record<number, ErrorSemantics>> = {
|
|
|
374
374
|
61000408: { code: 61000408, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000408' },
|
|
375
375
|
61000409: { code: 61000409, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', name: 'MFA_CODE_ALREADY_USED', retryable: false, docsPath: '/errors/61000409' },
|
|
376
376
|
61000410: { code: 61000410, httpStatus: 429, class: 'limit', absence: '', uiObservation: 'rate_limited', name: 'MFA_ATTEMPTS_THROTTLED', retryable: true, docsPath: '/errors/61000410' },
|
|
377
|
+
61000411: { code: 61000411, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'forbidden', name: 'MFA_AUTHENTICATOR_DISABLED', retryable: false, docsPath: '/errors/61000411' },
|
|
377
378
|
61000501: { code: 61000501, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000501' },
|
|
378
379
|
61000502: { code: 61000502, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000502' },
|
|
379
380
|
61000601: { code: 61000601, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000601' },
|
|
380
381
|
61000701: { code: 61000701, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000701' },
|
|
381
382
|
61000702: { code: 61000702, httpStatus: 500, class: 'internal', absence: '', uiObservation: 'unexpected', retryable: false, docsPath: '/errors/61000702' },
|
|
383
|
+
61000703: { code: 61000703, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000703' },
|
|
384
|
+
61000704: { code: 61000704, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000704' },
|
|
385
|
+
61000705: { code: 61000705, httpStatus: 503, class: 'unavailable', absence: '', uiObservation: 'transient', retryable: true, docsPath: '/errors/61000705' },
|
|
382
386
|
61000801: { code: 61000801, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61000801' },
|
|
383
387
|
61000802: { code: 61000802, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61000802' },
|
|
384
388
|
61000803: { code: 61000803, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61000803' },
|
|
@@ -671,6 +675,8 @@ export const ERROR_SEMANTICS: Readonly<Record<number, ErrorSemantics>> = {
|
|
|
671
675
|
61100021: { code: 61100021, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61100021' },
|
|
672
676
|
61100022: { code: 61100022, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61100022' },
|
|
673
677
|
61100023: { code: 61100023, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61100023' },
|
|
678
|
+
61100024: { code: 61100024, httpStatus: 413, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61100024' },
|
|
679
|
+
61100025: { code: 61100025, httpStatus: 409, class: 'conflict', absence: '', uiObservation: 'conflict', retryable: false, docsPath: '/errors/61100025' },
|
|
674
680
|
61110002: { code: 61110002, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61110002' },
|
|
675
681
|
61110003: { code: 61110003, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'forbidden', retryable: false, docsPath: '/errors/61110003' },
|
|
676
682
|
61110004: { code: 61110004, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61110004' },
|
|
@@ -853,8 +859,8 @@ export const UNPROVISIONED_CODES: ReadonlySet<number> = new Set([]);
|
|
|
853
859
|
export const EMPTY_STATE_CODES: ReadonlySet<number> = new Set([]);
|
|
854
860
|
|
|
855
861
|
export const ERROR_SEMANTICS_META = {
|
|
856
|
-
rowCount:
|
|
857
|
-
sourceSha256: '
|
|
862
|
+
rowCount: 798,
|
|
863
|
+
sourceSha256: 'e82f038da18dc0935623718a7516ede07d741ed071275aad4ca1610db00a8d5d',
|
|
858
864
|
} as const;
|
|
859
865
|
|
|
860
866
|
/** 具名错误码常量(契约 name → code)。页面只消费常量,不写数字字面量。 */
|
|
@@ -865,6 +871,7 @@ export const ERROR_CODES = {
|
|
|
865
871
|
MFA_CHALLENGE_ATTEMPTS_EXCEEDED: 61000405,
|
|
866
872
|
MFA_CODE_ALREADY_USED: 61000409,
|
|
867
873
|
MFA_ATTEMPTS_THROTTLED: 61000410,
|
|
874
|
+
MFA_AUTHENTICATOR_DISABLED: 61000411,
|
|
868
875
|
} as const;
|
|
869
876
|
|
|
870
877
|
export type ErrorCodeName = keyof typeof ERROR_CODES;
|