@autional/shared 0.1.0-rc.36 → 0.1.0-rc.37
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/auth-queries.ts +3 -6
- package/src/components/TenantIndexGuard.tsx +4 -4
- package/src/components/__tests__/TenantIndexGuard.test.tsx +4 -3
- package/src/generated/error-semantics.ts +852 -0
- package/src/index.ts +17 -0
- package/src/utils/__tests__/error-semantics.test.ts +56 -0
- package/src/utils/error-semantics.ts +91 -0
package/package.json
CHANGED
package/src/auth/auth-queries.ts
CHANGED
|
@@ -58,8 +58,7 @@ export function usePermissionsQuery(tenantId?: string | null, enabled = true) {
|
|
|
58
58
|
[]) as string[];
|
|
59
59
|
},
|
|
60
60
|
staleTime: AUTH_DATA_STALE_TIME,
|
|
61
|
-
|
|
62
|
-
retryDelay: 1000,
|
|
61
|
+
// 重试策略不在此声明:交给消费方的 QueryClient 默认(本包不得有 per-query 覆盖,否则会盖过默认)。
|
|
63
62
|
// 无 token 时禁止发起请求:未登录时该查询必然 401 → apiClient 401 拦截
|
|
64
63
|
// → refreshToken() 无 refresh token → onUnauthorized() 抢跑 buildLoginUrl,
|
|
65
64
|
// 与 RequireAuth 的 OAuth PKCE 触发形成时序竞争(跨域 admin 场景偶发 302 回登录页)。
|
|
@@ -92,8 +91,7 @@ export function useTenantsQuery(tenantId?: string | null, enabled = true) {
|
|
|
92
91
|
}>;
|
|
93
92
|
},
|
|
94
93
|
staleTime: AUTH_DATA_STALE_TIME,
|
|
95
|
-
|
|
96
|
-
retryDelay: 1000,
|
|
94
|
+
// 重试策略不在此声明:交给消费方的 QueryClient 默认(本包不得有 per-query 覆盖,否则会盖过默认)。
|
|
97
95
|
// 与 usePermissionsQuery 一致:无 token 时禁止发起请求,
|
|
98
96
|
// 避免 401 → onUnauthorized 抢跑 RequireAuth 的 OAuth PKCE 流程。
|
|
99
97
|
enabled,
|
|
@@ -112,7 +110,6 @@ export function useMeQuery() {
|
|
|
112
110
|
return extractItem(res.data) ?? res.data;
|
|
113
111
|
},
|
|
114
112
|
staleTime: AUTH_DATA_STALE_TIME,
|
|
115
|
-
|
|
116
|
-
retryDelay: 1000,
|
|
113
|
+
// 重试策略不在此声明:交给消费方的 QueryClient 默认(本包不得有 per-query 覆盖,否则会盖过默认)。
|
|
117
114
|
});
|
|
118
115
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* (不复制 4 份,违反 DRY)。
|
|
6
6
|
*
|
|
7
7
|
* - usePublicTenantSlugs: 调公开 tenants API(无认证端点),staleTime 5m 缓存,
|
|
8
|
-
*
|
|
8
|
+
* 8s 超时(重试由消费方默认策略决定);失败上抛(不吞成空数组成功)——放行语义由消费方
|
|
9
9
|
* (TenantIndexGuard / TenantRootRedirect)在失败态自行 fail-open(rc.35)。
|
|
10
10
|
* - TenantIndexGuard: 租户 slug 白名单守卫(P0-2),防止未知 slug 被贪婪渲染为
|
|
11
11
|
* 租户内容(index 首页与 /:slug/... 子路由通用)。404 页由各 portal 通过
|
|
@@ -32,7 +32,7 @@ export interface PublicTenantInfo {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** 公开租户名单请求超时(ms)。跨境链路(Vercel edge → 源站)实测新连接丢 ~45%,
|
|
35
|
-
* 失败连接 edge 端要 ~31s 才吐 502;正常成功 ≤2s,8s 留 4x
|
|
35
|
+
* 失败连接 edge 端要 ~31s 才吐 502;正常成功 ≤2s,8s 留 4x 余量,失败快速交由消费方的重试策略。
|
|
36
36
|
* (rc.35:此前无超时 + catch 吞错 → retry 死码、失败被当"空名单"成功。) */
|
|
37
37
|
export const PUBLIC_TENANTS_FETCH_TIMEOUT_MS = 8000;
|
|
38
38
|
|
|
@@ -40,7 +40,7 @@ export const PUBLIC_TENANTS_FETCH_TIMEOUT_MS = 8000;
|
|
|
40
40
|
* 公开租户列表(无认证端点,用于校验 URL slug 有效性)。
|
|
41
41
|
* 从 end-user-portal App.tsx 原样抽取。
|
|
42
42
|
* - staleTime 5m(plan §5 资源列:public tenants API 有缓存)
|
|
43
|
-
* -
|
|
43
|
+
* - 非 2xx / 网络错 / 超时一律上抛(不吞成空数组成功)——
|
|
44
44
|
* error 态不落缓存,下次调用自然重试
|
|
45
45
|
* - 消费方 fail-open:名单缺失(error 态 data=undefined 或空数组)→ 不拦截
|
|
46
46
|
* (TenantIndexGuard 渲染 children;TenantRootRedirect 漏斗 brand;
|
|
@@ -69,7 +69,7 @@ export function usePublicTenantSlugs() {
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
staleTime: 5 * 60 * 1000,
|
|
72
|
-
|
|
72
|
+
// 重试策略交给消费方 QueryClient 默认(本包不得有 per-query 覆盖)。
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -9,9 +9,10 @@ import { TenantIndexGuard, usePublicTenantSlugs } from '../TenantIndexGuard';
|
|
|
9
9
|
function createQueryClient() {
|
|
10
10
|
return new QueryClient({
|
|
11
11
|
defaultOptions: {
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
12
|
+
// 重试由**本测试客户端**声明(生产里由消费方 QueryClient 默认决定;本包不再声明 retry,
|
|
13
|
+
// 否则会盖过消费方默认 —— rc.35 起如此)。retry:1 + retryDelay:0 让
|
|
14
|
+
// 「重试耗尽后错误必须上抛」这一断言仍可验证,且失败用例不白等默认退避。
|
|
15
|
+
queries: { retry: 1, retryDelay: 0, gcTime: Infinity },
|
|
15
16
|
},
|
|
16
17
|
});
|
|
17
18
|
}
|