@autional/shared 0.1.0-rc.43 → 0.1.0-rc.45
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/LICENSE +661 -661
- package/package.json +1 -1
- package/src/auth/roles.ts +9 -5
- package/src/branding/useBranding.ts +18 -4
- package/src/generated/error-semantics.ts +23 -5
- package/src/index.ts +2 -1
- package/src/utils/error-semantics.ts +10 -3
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: 792 · source sha256: 962af7ad9e1f41b957fa8cacb6f1bdbf0f0a56cb8cbdf144107e1329df80c0cd
|
|
5
5
|
//
|
|
6
6
|
// 单一真源链:service-core/base/error/semantics.go(Go)→ errors.semantics.json → 本文件。
|
|
7
7
|
// ⚠️ 禁止在本文件或页面里手抄错误码分支:请消费 ERROR_SEMANTICS / UNPROVISIONED_CODES。
|
|
@@ -42,6 +42,7 @@ export interface ErrorSemantics {
|
|
|
42
42
|
class: ErrorClass;
|
|
43
43
|
absence: Absence;
|
|
44
44
|
uiObservation: UIObservation;
|
|
45
|
+
name?: string;
|
|
45
46
|
retryable: boolean;
|
|
46
47
|
docsPath: string;
|
|
47
48
|
}
|
|
@@ -364,11 +365,15 @@ export const ERROR_SEMANTICS: Readonly<Record<number, ErrorSemantics>> = {
|
|
|
364
365
|
61000301: { code: 61000301, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000301' },
|
|
365
366
|
61000302: { code: 61000302, httpStatus: 409, class: 'conflict', absence: '', uiObservation: 'conflict', retryable: false, docsPath: '/errors/61000302' },
|
|
366
367
|
61000401: { code: 61000401, httpStatus: 401, class: 'unauthorized', absence: '', uiObservation: 'session_expired', retryable: false, docsPath: '/errors/61000401' },
|
|
367
|
-
61000402: { code: 61000402, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000402' },
|
|
368
|
-
61000403: { code: 61000403, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'reauth_required', retryable: false, docsPath: '/errors/61000403' },
|
|
368
|
+
61000402: { code: 61000402, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', name: 'MFA_INVALID_CODE', retryable: false, docsPath: '/errors/61000402' },
|
|
369
|
+
61000403: { code: 61000403, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'reauth_required', name: 'MFA_CHALLENGE_REQUIRED', retryable: false, docsPath: '/errors/61000403' },
|
|
370
|
+
61000404: { code: 61000404, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'reauth_required', name: 'MFA_CHALLENGE_USED', retryable: false, docsPath: '/errors/61000404' },
|
|
371
|
+
61000405: { code: 61000405, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'reauth_required', name: 'MFA_CHALLENGE_ATTEMPTS_EXCEEDED', retryable: false, docsPath: '/errors/61000405' },
|
|
369
372
|
61000406: { code: 61000406, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'forbidden', retryable: false, docsPath: '/errors/61000406' },
|
|
370
373
|
61000407: { code: 61000407, httpStatus: 410, class: 'gone', absence: '', uiObservation: 'expired', retryable: false, docsPath: '/errors/61000407' },
|
|
371
374
|
61000408: { code: 61000408, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000408' },
|
|
375
|
+
61000409: { code: 61000409, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', name: 'MFA_CODE_ALREADY_USED', retryable: false, docsPath: '/errors/61000409' },
|
|
376
|
+
61000410: { code: 61000410, httpStatus: 429, class: 'limit', absence: '', uiObservation: 'rate_limited', name: 'MFA_ATTEMPTS_THROTTLED', retryable: true, docsPath: '/errors/61000410' },
|
|
372
377
|
61000501: { code: 61000501, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000501' },
|
|
373
378
|
61000502: { code: 61000502, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61000502' },
|
|
374
379
|
61000601: { code: 61000601, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61000601' },
|
|
@@ -554,6 +559,7 @@ export const ERROR_SEMANTICS: Readonly<Record<number, ErrorSemantics>> = {
|
|
|
554
559
|
61050012: { code: 61050012, httpStatus: 409, class: 'conflict', absence: '', uiObservation: 'conflict', retryable: false, docsPath: '/errors/61050012' },
|
|
555
560
|
61050013: { code: 61050013, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61050013' },
|
|
556
561
|
61050014: { code: 61050014, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61050014' },
|
|
562
|
+
61050015: { code: 61050015, httpStatus: 403, class: 'forbidden', absence: '', uiObservation: 'forbidden', retryable: false, docsPath: '/errors/61050015' },
|
|
557
563
|
61050020: { code: 61050020, httpStatus: 404, class: 'not_found', absence: 'entity', uiObservation: 'not_found_page', retryable: false, docsPath: '/errors/61050020' },
|
|
558
564
|
61050021: { code: 61050021, httpStatus: 429, class: 'limit', absence: '', uiObservation: 'rate_limited', retryable: true, docsPath: '/errors/61050021' },
|
|
559
565
|
61050022: { code: 61050022, httpStatus: 400, class: 'invalid', absence: '', uiObservation: 'form_error', retryable: false, docsPath: '/errors/61050022' },
|
|
@@ -847,6 +853,18 @@ export const UNPROVISIONED_CODES: ReadonlySet<number> = new Set([]);
|
|
|
847
853
|
export const EMPTY_STATE_CODES: ReadonlySet<number> = new Set([]);
|
|
848
854
|
|
|
849
855
|
export const ERROR_SEMANTICS_META = {
|
|
850
|
-
rowCount:
|
|
851
|
-
sourceSha256: '
|
|
856
|
+
rowCount: 792,
|
|
857
|
+
sourceSha256: '962af7ad9e1f41b957fa8cacb6f1bdbf0f0a56cb8cbdf144107e1329df80c0cd',
|
|
852
858
|
} as const;
|
|
859
|
+
|
|
860
|
+
/** 具名错误码常量(契约 name → code)。页面只消费常量,不写数字字面量。 */
|
|
861
|
+
export const ERROR_CODES = {
|
|
862
|
+
MFA_INVALID_CODE: 61000402,
|
|
863
|
+
MFA_CHALLENGE_REQUIRED: 61000403,
|
|
864
|
+
MFA_CHALLENGE_USED: 61000404,
|
|
865
|
+
MFA_CHALLENGE_ATTEMPTS_EXCEEDED: 61000405,
|
|
866
|
+
MFA_CODE_ALREADY_USED: 61000409,
|
|
867
|
+
MFA_ATTEMPTS_THROTTLED: 61000410,
|
|
868
|
+
} as const;
|
|
869
|
+
|
|
870
|
+
export type ErrorCodeName = keyof typeof ERROR_CODES;
|
package/src/index.ts
CHANGED
|
@@ -248,6 +248,7 @@ export type { PaginationInfo, ListResult } from './utils/response';
|
|
|
248
248
|
|
|
249
249
|
export {
|
|
250
250
|
EMPTY_STATE_CODES,
|
|
251
|
+
ERROR_CODES,
|
|
251
252
|
ERROR_SEMANTICS,
|
|
252
253
|
ERROR_SEMANTICS_META,
|
|
253
254
|
MAX_RETRIES,
|
|
@@ -262,4 +263,4 @@ export {
|
|
|
262
263
|
semanticsOfError,
|
|
263
264
|
shouldRetry,
|
|
264
265
|
} from './utils/error-semantics';
|
|
265
|
-
export type { Absence, ErrorClass, ErrorSemantics, UIObservation } from './utils/error-semantics';
|
|
266
|
+
export type { Absence, ErrorClass, ErrorCodeName, ErrorSemantics, UIObservation } from './utils/error-semantics';
|
|
@@ -16,14 +16,21 @@
|
|
|
16
16
|
import { getHttpStatus, isForbiddenError, isRetryableError } from './query-state';
|
|
17
17
|
import {
|
|
18
18
|
EMPTY_STATE_CODES,
|
|
19
|
+
ERROR_CODES,
|
|
19
20
|
ERROR_SEMANTICS,
|
|
20
21
|
ERROR_SEMANTICS_META,
|
|
21
22
|
UNPROVISIONED_CODES,
|
|
22
23
|
} from '../generated/error-semantics';
|
|
23
|
-
import type {
|
|
24
|
+
import type {
|
|
25
|
+
Absence,
|
|
26
|
+
ErrorClass,
|
|
27
|
+
ErrorCodeName,
|
|
28
|
+
ErrorSemantics,
|
|
29
|
+
UIObservation,
|
|
30
|
+
} from '../generated/error-semantics';
|
|
24
31
|
|
|
25
|
-
export { EMPTY_STATE_CODES, ERROR_SEMANTICS, ERROR_SEMANTICS_META, UNPROVISIONED_CODES };
|
|
26
|
-
export type { Absence, ErrorClass, ErrorSemantics, UIObservation };
|
|
32
|
+
export { EMPTY_STATE_CODES, ERROR_CODES, ERROR_SEMANTICS, ERROR_SEMANTICS_META, UNPROVISIONED_CODES };
|
|
33
|
+
export type { Absence, ErrorClass, ErrorCodeName, ErrorSemantics, UIObservation };
|
|
27
34
|
export { getHttpStatus, isForbiddenError, isRetryableError };
|
|
28
35
|
|
|
29
36
|
/** 单次查询最多重试次数(策略参数,唯一出处)。 */
|