@lark-apaas/client-toolkit 1.2.48-alpha.14 → 1.2.48-alpha.16

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,2 +1,4 @@
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, 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 };
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 };
@@ -7,7 +7,6 @@ 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";
11
10
  import { useAppInfo } from "../../hooks/index.js";
12
11
  import { TrackKey } from "../../types/tea.js";
13
12
  import { slardar } from "@lark-apaas/internal-slardar";
@@ -197,11 +196,9 @@ const AppContainer_AppContainer = (props)=>{
197
196
  };
198
197
  return /*#__PURE__*/ jsxs(Fragment, {
199
198
  children: [
200
- /*#__PURE__*/ jsx(SafetyErrorBoundary, {
201
- children: /*#__PURE__*/ jsx(Suspense, {
202
- fallback: null,
203
- children: /*#__PURE__*/ jsx(Safety, {})
204
- })
199
+ /*#__PURE__*/ jsx(Suspense, {
200
+ fallback: null,
201
+ children: /*#__PURE__*/ jsx(Safety, {})
205
202
  }),
206
203
  /*#__PURE__*/ jsx(QueryProvider, {
207
204
  children: /*#__PURE__*/ jsx(ConfigProvider, {
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import react from "react";
3
- import { getDataloom } from "../../integrations/dataloom.js";
3
+ import { authClient } from "@lark-apaas/auth-sdk";
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,8 +67,7 @@ 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 dataloom = await getDataloom();
71
- const response = await dataloom.service.user.getByIds(normalizedIds);
70
+ const response = await authClient.user.getByIds(normalizedIds);
72
71
  const fetchedList = Array.isArray(response?.data) ? response?.data : Array.isArray(response?.data?.user_list) ? response?.data?.user_list : [];
73
72
  const fetchedMap = new Map();
74
73
  fetchedList.forEach((profile)=>{
@@ -115,8 +114,7 @@ const UserSelect = ({ mode = 'single', defaultValue, value, onChange, placeholde
115
114
  const fetchUsersImpl = react.useCallback(async (search)=>{
116
115
  if (fetchUsers) return fetchUsers(search);
117
116
  try {
118
- const dataloom = await getDataloom();
119
- const { data } = await dataloom.service.user.search({
117
+ const { data } = await authClient.user.search({
120
118
  name: search,
121
119
  pageSize: 20
122
120
  });
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useState } from "react";
2
+ import { authClient } from "@lark-apaas/auth-sdk";
2
3
  import { logger } from "../logger/index.js";
3
4
  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,8 +35,7 @@ const useCurrentUserProfile = ()=>{
35
35
  useEffect(()=>{
36
36
  let cancelled = false;
37
37
  const fetchAndSetUserInfo = async ()=>{
38
- const dataloom = await getDataloom();
39
- const result = await dataloom?.service?.session?.getUserInfo();
38
+ const result = await authClient.session.getUserInfo();
40
39
  if (cancelled) return;
41
40
  const info = result?.data?.user_info;
42
41
  const userName = getNameFromArray(info?.name);
@@ -1,13 +1,12 @@
1
1
  import { useState } from "react";
2
- import { getDataloom } from "../integrations/dataloom.js";
2
+ import { authClient } from "@lark-apaas/auth-sdk";
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
- const dataloom = await getDataloom();
10
- await dataloom.service.session.signOut();
9
+ await authClient.session.signOut();
11
10
  } catch (error) {
12
11
  console.error('登出失败', error);
13
12
  } finally{
@@ -1,5 +1,6 @@
1
1
  import { splitWorkspaceUrl } from "../utils/url.js";
2
2
  import { createClient } from "@lark-apaas/dataloom";
3
+ import { authClient } from "@lark-apaas/auth-sdk";
3
4
  import { getAppId } from "../utils/getAppId.js";
4
5
  import { getAppPublished } from "../utils/getInitialInfo.js";
5
6
  const createDataLoomClient = (url, pat)=>{
@@ -12,7 +13,11 @@ const createDataLoomClient = (url, pat)=>{
12
13
  enableDataloomLog: 'production' !== process.env.NODE_ENV,
13
14
  requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
14
15
  brandName: 'miaoda',
15
- appId
16
+ appId,
17
+ accountServices: {
18
+ user: authClient.user,
19
+ session: authClient.session
20
+ }
16
21
  }
17
22
  });
18
23
  };
@@ -1,10 +1,8 @@
1
- import { getDataloom } from "../integrations/dataloom.js";
1
+ import { authClient } from "@lark-apaas/auth-sdk";
2
2
  const pendingRequests = new Map();
3
3
  async function fetchUserProfilesByIds(ids) {
4
4
  try {
5
- const dataloom = await getDataloom();
6
- if (!dataloom) throw new Error('Dataloom client is unavailable');
7
- const response = await dataloom.service.user.getByIds(ids);
5
+ const response = await authClient.user.getByIds(ids);
8
6
  return Array.isArray(response?.data) ? response.data : response?.data?.user_list || [];
9
7
  } catch (error) {
10
8
  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.14",
3
+ "version": "1.2.48-alpha.16",
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.4",
103
- "@lark-apaas/client-capability": "^0.1.6",
104
- "@lark-apaas/dataloom": "^0.1.1",
102
+ "@lark-apaas/auth-sdk": "^0.1.5",
103
+ "@lark-apaas/client-capability": "^0.1.7",
104
+ "@lark-apaas/dataloom": "0.1.3-alpha.12",
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",
@@ -1,53 +0,0 @@
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
- });
@@ -1,23 +0,0 @@
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 {};
@@ -1,29 +0,0 @@
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 };