@lark-apaas/client-toolkit 1.2.48-alpha.15 → 1.2.48-alpha.17

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/lib/auth.d.ts CHANGED
@@ -1,4 +1,2 @@
1
1
  export { AuthProvider, useAuth, Can, CanRole, useCan, AbilityContext, useUserPermissions, PermissionClient, ROLE_SUBJECT, } from '@lark-apaas/auth-sdk';
2
2
  export type { AuthProviderProps, PermissionApiResponse, PermissionApiConfig, PermissionPointData, AuthSdkConfig, } from '@lark-apaas/auth-sdk';
3
- export { authClient, AccountClient } from '@lark-apaas/auth-sdk';
4
- export type { AccountClient as AuthClient, AccountServiceResponse, AccountServiceError, SearchParams, User, UserResponse, SignInRedirectionOptions, UserBaseInfo, UserInfoResponse, Avatar, } from '@lark-apaas/auth-sdk';
package/lib/auth.js CHANGED
@@ -1,2 +1,2 @@
1
- import { AbilityContext, AccountClient, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, authClient, useAuth, useCan, useUserPermissions } from "@lark-apaas/auth-sdk";
2
- export { AbilityContext, AccountClient, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, authClient, useAuth, useCan, useUserPermissions };
1
+ import { AbilityContext, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, useAuth, useCan, useUserPermissions } from "@lark-apaas/auth-sdk";
2
+ export { AbilityContext, AuthProvider, Can, CanRole, PermissionClient, ROLE_SUBJECT, useAuth, useCan, useUserPermissions };
@@ -0,0 +1,53 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { render, screen } from "@testing-library/react";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { slardar } from "@lark-apaas/internal-slardar";
6
+ import { SafetyErrorBoundary } from "../safety-error-boundary.js";
7
+ vi.mock('@lark-apaas/internal-slardar', ()=>({
8
+ slardar: {
9
+ sendLog: vi.fn()
10
+ }
11
+ }));
12
+ describe('SafetyErrorBoundary', ()=>{
13
+ it('renders children when no error', ()=>{
14
+ render(/*#__PURE__*/ jsx(SafetyErrorBoundary, {
15
+ children: /*#__PURE__*/ jsx("div", {
16
+ "data-testid": "child",
17
+ children: "child content"
18
+ })
19
+ }));
20
+ expect(screen.getByTestId('child').textContent).toBe('child content');
21
+ });
22
+ it('renders null fallback when child throws', ()=>{
23
+ const Throwing = ()=>{
24
+ throw new Error('Failed to fetch dynamically imported module: safety-XXX.js');
25
+ };
26
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(()=>{});
27
+ const { container } = render(/*#__PURE__*/ jsx(SafetyErrorBoundary, {
28
+ children: /*#__PURE__*/ jsx(Throwing, {})
29
+ }));
30
+ expect(container.innerHTML).toBe('');
31
+ errSpy.mockRestore();
32
+ });
33
+ it('logs error via slardar when child throws', ()=>{
34
+ const Throwing = ()=>{
35
+ throw new Error('chunk load failed');
36
+ };
37
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(()=>{});
38
+ slardar.sendLog.mockClear();
39
+ render(/*#__PURE__*/ jsx(SafetyErrorBoundary, {
40
+ children: /*#__PURE__*/ jsx(Throwing, {})
41
+ }));
42
+ expect(slardar.sendLog).toHaveBeenCalledTimes(1);
43
+ expect(slardar.sendLog).toHaveBeenCalledWith(expect.objectContaining({
44
+ content: expect.stringContaining('chunk load failed'),
45
+ level: 'error',
46
+ extra: expect.objectContaining({
47
+ stack: expect.any(String),
48
+ componentStack: expect.any(String)
49
+ })
50
+ }));
51
+ errSpy.mockRestore();
52
+ });
53
+ });
@@ -7,6 +7,7 @@ import IframeBridge from "./IframeBridge.js";
7
7
  import { Toaster } from "./sonner.js";
8
8
  import { PageHoc } from "./PageHoc.js";
9
9
  import { reportTeaEvent } from "./utils/tea.js";
10
+ import { SafetyErrorBoundary } from "./safety-error-boundary.js";
10
11
  import { useAppInfo } from "../../hooks/index.js";
11
12
  import { TrackKey } from "../../types/tea.js";
12
13
  import { slardar } from "@lark-apaas/internal-slardar";
@@ -196,9 +197,11 @@ const AppContainer_AppContainer = (props)=>{
196
197
  };
197
198
  return /*#__PURE__*/ jsxs(Fragment, {
198
199
  children: [
199
- /*#__PURE__*/ jsx(Suspense, {
200
- fallback: null,
201
- children: /*#__PURE__*/ jsx(Safety, {})
200
+ /*#__PURE__*/ jsx(SafetyErrorBoundary, {
201
+ children: /*#__PURE__*/ jsx(Suspense, {
202
+ fallback: null,
203
+ children: /*#__PURE__*/ jsx(Safety, {})
204
+ })
202
205
  }),
203
206
  /*#__PURE__*/ jsx(QueryProvider, {
204
207
  children: /*#__PURE__*/ jsx(ConfigProvider, {
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ children: React.ReactNode;
4
+ }
5
+ interface State {
6
+ hasError: boolean;
7
+ }
8
+ /**
9
+ * SafetyErrorBoundary - 包裹 Safety 徽章的 lazy import 失败兜底
10
+ *
11
+ * Why: AppContainer 内 `<Suspense fallback={null}><Safety /></Suspense>` 中 Safety 是 React.lazy
12
+ * 拆出的非核心徽章 chunk。chunk 加载失败(CDN 缓存窗 / 部署漂移 / dev preview hash 漂移 / 网络抖动)
13
+ * 时 rejected Promise 越过 Suspense 上抛,会冒到 React root 让整应用 unmount = 白屏。
14
+ *
15
+ * ErrorBoundary 把失败局限在徽章自身:徽章不显示,应用继续跑。同时上报 slardar 便于事后归因。
16
+ */
17
+ export declare class SafetyErrorBoundary extends React.Component<Props, State> {
18
+ state: State;
19
+ static getDerivedStateFromError(): State;
20
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
21
+ render(): React.ReactNode;
22
+ }
23
+ export {};
@@ -0,0 +1,29 @@
1
+ import react from "react";
2
+ import { slardar } from "@lark-apaas/internal-slardar";
3
+ class SafetyErrorBoundary extends react.Component {
4
+ state = {
5
+ hasError: false
6
+ };
7
+ static getDerivedStateFromError() {
8
+ return {
9
+ hasError: true
10
+ };
11
+ }
12
+ componentDidCatch(error, errorInfo) {
13
+ try {
14
+ slardar.sendLog({
15
+ content: `safety_chunk_load_error: ${error.message}`,
16
+ level: 'error',
17
+ extra: {
18
+ stack: error.stack ?? '',
19
+ componentStack: errorInfo.componentStack ?? ''
20
+ }
21
+ });
22
+ } catch {}
23
+ }
24
+ render() {
25
+ if (this.state.hasError) return null;
26
+ return this.props.children;
27
+ }
28
+ }
29
+ export { SafetyErrorBoundary };
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import react from "react";
3
- import { authClient } from "@lark-apaas/auth-sdk";
3
+ import { getDataloom } from "../../integrations/dataloom.js";
4
4
  import { UserSelectUI } from "./UserSelectUI/index.js";
5
5
  const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholder, fetchUsers })=>{
6
6
  const normalizedIds = react.useMemo(()=>{
@@ -67,7 +67,8 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
67
67
  if (!normalizedIds.length) return void setUiValue(void 0);
68
68
  const fetchProfiles = async ()=>{
69
69
  try {
70
- const response = await authClient.user.getByIds(normalizedIds);
70
+ const dataloom = await getDataloom();
71
+ const response = await dataloom.service.user.getByIds(normalizedIds);
71
72
  const fetchedList = Array.isArray(response?.data) ? response?.data : Array.isArray(response?.data?.user_list) ? response?.data?.user_list : [];
72
73
  const fetchedMap = new Map();
73
74
  fetchedList.forEach((profile)=>{
@@ -114,7 +115,8 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
114
115
  const fetchUsersImpl = react.useCallback(async (search)=>{
115
116
  if (fetchUsers) return fetchUsers(search);
116
117
  try {
117
- const { data } = await authClient.user.search({
118
+ const dataloom = await getDataloom();
119
+ const { data } = await dataloom.service.user.search({
118
120
  name: search,
119
121
  pageSize: 20
120
122
  });
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useState } from "react";
2
- import { authClient } from "@lark-apaas/auth-sdk";
3
2
  import { logger } from "../logger/index.js";
4
3
  import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
4
+ import { getDataloom } from "../integrations/dataloom.js";
5
5
  import { isSparkRuntime } from "../utils/utils.js";
6
6
  import { getAxiosForBackend } from "../utils/getAxiosForBackend.js";
7
7
  function getNameFromArray(nameArray) {
@@ -35,7 +35,8 @@ const useCurrentUserProfile = ()=>{
35
35
  useEffect(()=>{
36
36
  let cancelled = false;
37
37
  const fetchAndSetUserInfo = async ()=>{
38
- const result = await authClient.session.getUserInfo();
38
+ const dataloom = await getDataloom();
39
+ const result = await dataloom?.service?.session?.getUserInfo();
39
40
  if (cancelled) return;
40
41
  const info = result?.data?.user_info;
41
42
  const userName = getNameFromArray(info?.name);
@@ -1,12 +1,13 @@
1
1
  import { useState } from "react";
2
- import { authClient } from "@lark-apaas/auth-sdk";
2
+ import { getDataloom } from "../integrations/dataloom.js";
3
3
  function useLogout() {
4
4
  const [isLoading, setIsLoading] = useState(false);
5
5
  async function handlerLogout() {
6
6
  if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
7
7
  setIsLoading(true);
8
8
  try {
9
- await authClient.session.signOut();
9
+ const dataloom = await getDataloom();
10
+ await dataloom.service.session.signOut();
10
11
  } catch (error) {
11
12
  console.error('登出失败', error);
12
13
  } finally{
@@ -1,6 +1,5 @@
1
1
  import { splitWorkspaceUrl } from "../utils/url.js";
2
2
  import { createClient } from "@lark-apaas/dataloom";
3
- import { authClient } from "@lark-apaas/auth-sdk";
4
3
  import { getAppId } from "../utils/getAppId.js";
5
4
  import { getAppPublished } from "../utils/getInitialInfo.js";
6
5
  const createDataLoomClient = (url, pat)=>{
@@ -13,11 +12,7 @@ const createDataLoomClient = (url, pat)=>{
13
12
  enableDataloomLog: 'production' !== process.env.NODE_ENV,
14
13
  requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
15
14
  brandName: 'miaoda',
16
- appId,
17
- accountServices: {
18
- user: authClient.user,
19
- session: authClient.session
20
- }
15
+ appId
21
16
  }
22
17
  });
23
18
  };
@@ -1,8 +1,10 @@
1
- import { authClient } from "@lark-apaas/auth-sdk";
1
+ import { getDataloom } from "../integrations/dataloom.js";
2
2
  const pendingRequests = new Map();
3
3
  async function fetchUserProfilesByIds(ids) {
4
4
  try {
5
- const response = await authClient.user.getByIds(ids);
5
+ const dataloom = await getDataloom();
6
+ if (!dataloom) throw new Error('Dataloom client is unavailable');
7
+ const response = await dataloom.service.user.getByIds(ids);
6
8
  return Array.isArray(response?.data) ? response.data : response?.data?.user_list || [];
7
9
  } catch (error) {
8
10
  console.error(`Failed to fetch profiles for user IDs ${ids.join(', ')}:`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.48-alpha.15",
3
+ "version": "1.2.48-alpha.17",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -99,9 +99,9 @@
99
99
  "@ant-design/colors": "^7.2.1",
100
100
  "@ant-design/cssinjs": "^1.24.0",
101
101
  "@lark-apaas/aily-web-sdk": "^0.0.11",
102
- "@lark-apaas/auth-sdk": "^0.1.5",
103
- "@lark-apaas/client-capability": "^0.1.7",
104
- "@lark-apaas/dataloom": "0.1.3-alpha.11",
102
+ "@lark-apaas/auth-sdk": "^0.1.4",
103
+ "@lark-apaas/client-capability": "^0.1.6",
104
+ "@lark-apaas/dataloom": "^0.1.1",
105
105
  "@lark-apaas/internal-slardar": "^0.0.3",
106
106
  "@lark-apaas/miaoda-inspector": "^1.0.23",
107
107
  "@lark-apaas/observable-web": "^1.0.6",