@lark-apaas/client-toolkit-lite 1.1.45 → 1.1.46-alpha.20261201140643
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/README.en-US.md +300 -0
- package/README.md +32 -0
- package/dist/index.cjs +293 -276
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -73
- package/dist/index.d.ts +90 -73
- package/dist/index.js +288 -273
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
package/README.en-US.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# @lark-apaas/client-toolkit-lite
|
|
2
|
+
|
|
3
|
+
[中文](./README.md) | English
|
|
4
|
+
|
|
5
|
+
A lightweight client toolkit for the Express/Vite stack. It is trimmed down from `@lark-apaas/client-toolkit`, keeping the core capabilities (AppContainer, hooks, utilities, route components, DataLoom) and dropping heavy dependencies (antd, Observable, Auth SDK, Slardar, Sonner and so on).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @lark-apaas/client-toolkit-lite
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Peer Dependencies
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install react react-dom react-router-dom @tanstack/react-query
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
### 1. Use AppContainer
|
|
22
|
+
|
|
23
|
+
`AppContainer` is the application root container. It integrates:
|
|
24
|
+
- **Safety** — the "Built with Miaoda (Spark)" safety badge in production
|
|
25
|
+
- **QueryProvider** — React Query data management
|
|
26
|
+
- **useAppInfo** — keeps document title / favicon / OG meta in sync automatically
|
|
27
|
+
- **Tea tracking** — reports page view events automatically in production
|
|
28
|
+
- **Runtime** — React DevTools Hook + global Axios CSRF injection (guarded against double injection)
|
|
29
|
+
|
|
30
|
+
> Theme styles are **not injected automatically**; import them manually at the app entry. See the next section.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
// App.tsx
|
|
34
|
+
import { AppContainer } from '@lark-apaas/client-toolkit-lite';
|
|
35
|
+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
|
36
|
+
|
|
37
|
+
function App() {
|
|
38
|
+
return (
|
|
39
|
+
<BrowserRouter>
|
|
40
|
+
<AppContainer>
|
|
41
|
+
<Routes>
|
|
42
|
+
<Route path="/" element={<Home />} />
|
|
43
|
+
<Route path="/about" element={<About />} />
|
|
44
|
+
</Routes>
|
|
45
|
+
</AppContainer>
|
|
46
|
+
</BrowserRouter>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
You can also use `QueryProvider` on its own (when you don't need the other AppContainer features):
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { QueryProvider } from '@lark-apaas/client-toolkit-lite';
|
|
55
|
+
|
|
56
|
+
<QueryProvider>{children}</QueryProvider>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Import styles
|
|
60
|
+
|
|
61
|
+
The theme styles consist of 4 parts: `theme-layer` (layer order declaration) / `tailwind-theme` (color palette variables + `.dark` mode) / `override` (base fallbacks) / `font-family` (Lark fonts). Import the aggregate entry manually:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// main.ts / main.tsx
|
|
65
|
+
import '@lark-apaas/client-toolkit-lite/styles.css';
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Tailwind v4 source scanning
|
|
69
|
+
|
|
70
|
+
lite's `Drawer` / `Popover` / `ErrorRender` and other components use Tailwind classes. Because v4 does not scan `node_modules` by default, you need to declare the source explicitly in your own main css (otherwise these components will have no styling):
|
|
71
|
+
|
|
72
|
+
```css
|
|
73
|
+
/* Your main.css */
|
|
74
|
+
@import 'tailwindcss';
|
|
75
|
+
@import '@lark-apaas/client-toolkit-lite/styles.css';
|
|
76
|
+
|
|
77
|
+
/* The path is relative to this css file */
|
|
78
|
+
@source "../node_modules/@lark-apaas/client-toolkit-lite/dist";
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### shadcn semantic variables (add as needed)
|
|
82
|
+
|
|
83
|
+
`override.css` and `Drawer` / `Popover` use shadcn-style semantic variables such as `--background` / `--foreground` / `--border` / `--ring` / `--popover` / `--popover-foreground` / `--muted-foreground`. lite's built-in palette (`tailwind-theme.css`) **only provides the full `--color-*` palette** and does not include these semantic variables, so define them in your own css to match your theme:
|
|
84
|
+
|
|
85
|
+
```css
|
|
86
|
+
:root {
|
|
87
|
+
--background: var(--color-neutral-00);
|
|
88
|
+
--foreground: var(--color-neutral-950);
|
|
89
|
+
--border: var(--color-neutral-300);
|
|
90
|
+
--ring: var(--color-blue-500);
|
|
91
|
+
--popover: var(--color-neutral-00);
|
|
92
|
+
--popover-foreground: var(--color-neutral-950);
|
|
93
|
+
--muted-foreground: var(--color-neutral-700);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### Importing individual parts
|
|
98
|
+
|
|
99
|
+
If you only need the palette or the fonts, import them separately:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import '@lark-apaas/client-toolkit-lite/styles/tailwind-theme.css';
|
|
103
|
+
import '@lark-apaas/client-toolkit-lite/styles/font-family.css';
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 3. Hooks
|
|
107
|
+
|
|
108
|
+
#### useAppInfo
|
|
109
|
+
|
|
110
|
+
Gets the app metadata and syncs it to document title / favicon / OG meta automatically:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { useAppInfo } from '@lark-apaas/client-toolkit-lite';
|
|
114
|
+
|
|
115
|
+
const { appName, appLogo, description } = useAppInfo();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### useCurrentUserProfile
|
|
119
|
+
|
|
120
|
+
Gets the current signed-in user's information (fetched through DataLoom):
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
import { useCurrentUserProfile } from '@lark-apaas/client-toolkit-lite';
|
|
124
|
+
|
|
125
|
+
const { user_id, name, email, avatar } = useCurrentUserProfile();
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### useIsMobile
|
|
129
|
+
|
|
130
|
+
Responsive mobile detection (768px breakpoint):
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { useIsMobile } from '@lark-apaas/client-toolkit-lite';
|
|
134
|
+
|
|
135
|
+
const isMobile = useIsMobile();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### useLogout
|
|
139
|
+
|
|
140
|
+
Signs out (through DataLoom session.signOut):
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import { useLogout } from '@lark-apaas/client-toolkit-lite';
|
|
144
|
+
|
|
145
|
+
const { handlerLogout, isLoading } = useLogout();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 4. Route components
|
|
149
|
+
|
|
150
|
+
Requires `react-router-dom`:
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import { ActiveLink, NavLink, UniversalLink } from '@lark-apaas/client-toolkit-lite';
|
|
154
|
+
|
|
155
|
+
// NavLink with hash anchor support and automatic active detection
|
|
156
|
+
<ActiveLink to="/page#section">Section</ActiveLink>
|
|
157
|
+
|
|
158
|
+
// Enhanced NavLink with hash support + scroll to top
|
|
159
|
+
<NavLink to="/about">About</NavLink>
|
|
160
|
+
|
|
161
|
+
// Universal link: Link for internal routes, an a tag for external URLs (detected automatically)
|
|
162
|
+
<UniversalLink to="https://example.com">External</UniversalLink>
|
|
163
|
+
<UniversalLink to="/internal">Internal</UniversalLink>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 5. Utilities
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import {
|
|
170
|
+
// Platform
|
|
171
|
+
getAppId, // Get the app ID (from window.appId)
|
|
172
|
+
getCsrfToken, // Extract the CSRF token from cookies
|
|
173
|
+
getEnvPath, // Preview/runtime path
|
|
174
|
+
resolveAppUrl, // Resolve an app-relative path, adding CLIENT_BASE_PATH automatically
|
|
175
|
+
|
|
176
|
+
// HTTP
|
|
177
|
+
getAxiosForBackend, // Get the backend axios instance (with a login redirect interceptor)
|
|
178
|
+
axiosForBackend, // Same as above, as a pre-created singleton
|
|
179
|
+
initAxiosConfig, // Initialize axios interceptors (CSRF token injection)
|
|
180
|
+
|
|
181
|
+
// Storage
|
|
182
|
+
scopedStorage, // App-isolated localStorage (keys prefixed with appId)
|
|
183
|
+
|
|
184
|
+
// Styles
|
|
185
|
+
clsxWithTw, // Tailwind class merging (clsx + twMerge)
|
|
186
|
+
|
|
187
|
+
// Utilities
|
|
188
|
+
copyToClipboard, // Copy to clipboard
|
|
189
|
+
safeStringify, // Safe JSON serialization (handles circular references/BigInt)
|
|
190
|
+
isPreview, // Whether in preview mode
|
|
191
|
+
normalizeBasePath, // Path normalization (strips the trailing slash)
|
|
192
|
+
getWsPath, // WebSocket path
|
|
193
|
+
|
|
194
|
+
// Device detection
|
|
195
|
+
isIpad, isMobile, isIOS,
|
|
196
|
+
} from '@lark-apaas/client-toolkit-lite';
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 6. Data integration
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
import { getAppInfo, getCurrentUserProfile, getDataloom } from '@lark-apaas/client-toolkit-lite';
|
|
203
|
+
|
|
204
|
+
// Get app metadata (cached in window._appInfo)
|
|
205
|
+
const appInfo = await getAppInfo();
|
|
206
|
+
|
|
207
|
+
// Get the current user (from window._userInfo)
|
|
208
|
+
const userProfile = getCurrentUserProfile();
|
|
209
|
+
|
|
210
|
+
// Get the DataLoom client (singleton, lazily initialized)
|
|
211
|
+
const dataloom = await getDataloom();
|
|
212
|
+
const users = await dataloom.service.user.search({ name: '张三' });
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 7. Image resources
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
import { avatarImages, bannerImages, coverImages } from '@lark-apaas/client-toolkit-lite';
|
|
219
|
+
|
|
220
|
+
// avatarImages.avatarImg1 ~ avatarImg11 (11 default avatar CDN URLs)
|
|
221
|
+
// bannerImages (24 banners in tech/professional/minimal categories)
|
|
222
|
+
// coverImages (36 covers in office/architecture/landscape/tech/3D and other categories)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 8. Type exports
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import type {
|
|
229
|
+
AppInfoPayload, // { name, avatar, description }
|
|
230
|
+
IUserProfile, // { user_id, email, name, avatar, status }
|
|
231
|
+
IJson, // Record<string, unknown>
|
|
232
|
+
IFileAttachment, // { bucket_id, file_path }
|
|
233
|
+
} from '@lark-apaas/client-toolkit-lite';
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Full export list
|
|
237
|
+
|
|
238
|
+
| Category | Exports |
|
|
239
|
+
|------|------|
|
|
240
|
+
| Components | AppContainer, QueryProvider |
|
|
241
|
+
| Route Components | ActiveLink, NavLink, UniversalLink |
|
|
242
|
+
| Hooks | useAppInfo, useCurrentUserProfile, useIsMobile, useLogout |
|
|
243
|
+
| Utils | clsxWithTw, isPreview, normalizeBasePath, getWsPath, getAppId, getCsrfToken, scopedStorage, copyToClipboard, isIpad, isMobile, isIOS, resolveAppUrl, getEnvPath, safeStringify, getAxiosForBackend, axiosForBackend, initAxiosConfig |
|
|
244
|
+
| Integrations | getAppInfo, getCurrentUserProfile, getDataloom |
|
|
245
|
+
| Tea | reportTeaEvent, TrackKey, TrackParams |
|
|
246
|
+
| Types | AppInfoPayload, IUserProfile, IJson, IFileAttachment |
|
|
247
|
+
| Constants | avatarImages, bannerImages, coverImages |
|
|
248
|
+
|
|
249
|
+
## Differences from client-toolkit
|
|
250
|
+
|
|
251
|
+
| Capability | client-toolkit | lite |
|
|
252
|
+
|------|:-:|:-:|
|
|
253
|
+
| AppContainer (full) | ✅ | Trimmed |
|
|
254
|
+
| antd ConfigProvider | ✅ | ❌ |
|
|
255
|
+
| AuthProvider / CanRole | ✅ | ❌ |
|
|
256
|
+
| Observable / Slardar | ✅ | ❌ |
|
|
257
|
+
| Sonner toast | ✅ | ❌ |
|
|
258
|
+
| Logger (batched reporting) | ✅ | ❌ |
|
|
259
|
+
| MiaodaInspector | ✅ | ❌ |
|
|
260
|
+
| Basic UI components | ✅ | ❌ |
|
|
261
|
+
| User components | ✅ | ❌ |
|
|
262
|
+
| Runtime (full) | ✅ | Trimmed |
|
|
263
|
+
| DataLoom | ✅ | ✅ |
|
|
264
|
+
| Hooks | 6 | 4 |
|
|
265
|
+
| Route components | ✅ | ✅ |
|
|
266
|
+
| Utilities | ✅ | ✅ |
|
|
267
|
+
|
|
268
|
+
## Brand, Settings and i18n
|
|
269
|
+
|
|
270
|
+
URLs, the image CDN and tracking parameters come from the settings of `@lark-apaas/miaoda-common-settings` (selected by region, brand and env, or read from the complete settings mounted on window by the host); components never hard-code domestic domains.
|
|
271
|
+
|
|
272
|
+
**Settings read**
|
|
273
|
+
|
|
274
|
+
| Setting | Used for | When empty |
|
|
275
|
+
|------|------|------|
|
|
276
|
+
| `domainConf.staticCdn` (via `getStaticUrl`) | Avatar / banner / cover images, placeholder and error illustrations, watermark logos | URLs become empty strings |
|
|
277
|
+
| `domainConf.landingUrl` | "Learn about Spark" in the watermark menu | Hide “Learn about Spark” |
|
|
278
|
+
| `domainConf.tnsReportUrl` | "Report" in the watermark menu | Report menu item is hidden |
|
|
279
|
+
| `domainConf.mainDomain` (via `getParentOrigin`) | Target origin for postMessage to the main site during preview; legacy force domains keep their old mapping | No message is sent when no origin is available |
|
|
280
|
+
| `doubaoConf.name` / `doubaoConf.brandImage` / `doubaoConf.downloadUrl` | Product name, brand text image and "Download" link on the watermark of apps created from Doubao (`MIAODA_APP_SOURCE=5`) | "Download" opens nothing |
|
|
281
|
+
| `apm.tea` | TEA `appId` and `channel` | TEA is not initialized |
|
|
282
|
+
| `env` | Environment parameter in tracking (`BOE` / `PRE` / `ONLINE`) | Inferred by the settings package |
|
|
283
|
+
|
|
284
|
+
**Which language the text uses**
|
|
285
|
+
|
|
286
|
+
| Audience | Text | Language |
|
|
287
|
+
|------|------|------|
|
|
288
|
+
| End users | Watermark, placeholder and error pages, login notice, quota notice, and console logs (`src/locales/messages.json`) | Follows the UI language (`createI18nForRuntime(messages)`) |
|
|
289
|
+
| Agent | The "one-click fix" hint written by ErrorRender (`src/locales/messages.json`) | Uses the configured `locale` (`createI18nForDev(messages)`) |
|
|
290
|
+
| Internal errors | e.g. the observability SDK failing to start | Written in English |
|
|
291
|
+
|
|
292
|
+
`<html lang>` is set from the current language on page load (`zh` for Chinese, `en` for English), only when the page declares `zh`, `en` or nothing; any other value written by the developer is kept. The `name` returned by `useCurrentUserProfile` is stored and compared by app code, so it uses the configured locale: Chinese first for zh-CN, English first for en-US.
|
|
293
|
+
|
|
294
|
+
**Acceptance**
|
|
295
|
+
|
|
296
|
+
- **Verification**: `src/__test__/overseas-feishu.test.tsx` (values under Feishu settings match the pre-refactor values), `src/__test__/overseas-lark.test.tsx` (no domestic domains or Chinese under JP settings in English).
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
|
|
300
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @lark-apaas/client-toolkit-lite
|
|
2
2
|
|
|
3
|
+
中文 | [English](./README.en-US.md)
|
|
4
|
+
|
|
3
5
|
轻量版客户端工具包,面向 Express/Vite 技术栈。从 `@lark-apaas/client-toolkit` 精简而来,保留核心能力(AppContainer、hooks、工具函数、路由组件、DataLoom),去掉重量级依赖(antd、Observable、Auth SDK、Slardar、Sonner 等)。
|
|
4
6
|
|
|
5
7
|
## 安装
|
|
@@ -263,6 +265,36 @@ import type {
|
|
|
263
265
|
| 路由组件 | ✅ | ✅ |
|
|
264
266
|
| 工具函数 | ✅ | ✅ |
|
|
265
267
|
|
|
268
|
+
## 品牌、配置与多语
|
|
269
|
+
|
|
270
|
+
地址、图片 CDN、埋点参数等取自 `@lark-apaas/miaoda-common-settings` 的配置(根据 region、brand、env 选择包内配置;浏览器也可读取宿主挂载的完整配置),组件内不写死国内域名。
|
|
271
|
+
|
|
272
|
+
**读了哪些配置**
|
|
273
|
+
|
|
274
|
+
| 配置 | 用途 | 为空时 |
|
|
275
|
+
|------|------|------|
|
|
276
|
+
| `domainConf.staticCdn`(经 `getStaticUrl`) | 头像 / 横幅 / 封面图、占位页和错误页插图、水印 logo | 地址为空字符串 |
|
|
277
|
+
| `domainConf.landingUrl` | 水印菜单「了解妙搭」 | 隐藏「了解妙搭」 |
|
|
278
|
+
| `domainConf.tnsReportUrl` | 水印菜单「投诉与举报」 | 隐藏举报菜单项 |
|
|
279
|
+
| `domainConf.mainDomain`(经 `getParentOrigin`) | 预览时与主站 postMessage 的目标地址;force 老域名沿用原映射 | 拿不到地址时不发消息 |
|
|
280
|
+
| `doubaoConf.name` / `doubaoConf.brandImage` / `doubaoConf.downloadUrl` | 豆包来源应用(`MIAODA_APP_SOURCE=5`)水印的产品名、品牌字图、「下载」地址 | 「下载」不打开链接 |
|
|
281
|
+
| `apm.tea` | TEA 埋点的 `appId`、`channel` | 不初始化 TEA |
|
|
282
|
+
| `env` | 埋点里的环境参数(`BOE` / `PRE` / `ONLINE`) | 由基础包推断 |
|
|
283
|
+
|
|
284
|
+
**文案跟随什么语言**
|
|
285
|
+
|
|
286
|
+
| 受众 | 文案 | 语言 |
|
|
287
|
+
|------|------|------|
|
|
288
|
+
| 最终用户 | 水印、占位页、错误页、登录提示、额度耗尽提示,以及控制台日志(`src/locales/messages.json`) | 跟随界面语言(`createI18nForRuntime(messages)`) |
|
|
289
|
+
| Agent | ErrorRender 写给「一键修复」的提示(`src/locales/messages.json`) | 读取配置 `locale`(`createI18nForDev(messages)`) |
|
|
290
|
+
| 内部异常 | 如可观测 SDK 启动失败 | 直接写英文 |
|
|
291
|
+
|
|
292
|
+
页面加载时按当前语言设置 `<html lang>`(中文 `zh`、英文 `en`);页面原来声明的是 `zh`、`en` 或没声明时才改,开发者自己写的其他值保留。`useCurrentUserProfile` 返回的 `name` 会被应用代码写库、比对,按配置 locale 取:zh-CN 优先中文名,en-US 优先英文名。
|
|
293
|
+
|
|
294
|
+
**验收**
|
|
295
|
+
|
|
296
|
+
- **验收**:`src/__test__/overseas-feishu.test.tsx`(飞书配置下取值与改造前一致)、`src/__test__/overseas-lark.test.tsx`(JP 配置、英文环境下无国内域名和中文)。
|
|
297
|
+
|
|
266
298
|
## License
|
|
267
299
|
|
|
268
300
|
MIT
|