@jctrans-materials/shared 1.0.41-beta.5 → 1.0.41-beta.6

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.
Files changed (2) hide show
  1. package/README.md +133 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,8 @@ JCTrans 前端共享工具库,为 JCTrans 系列项目提供认证、请求、
12
12
  | 统一类型 | `api/searchTypes` | 搜索模块共享类型定义 |
13
13
  | 认证 API | `api/auth` | 登录、注册、第三方登录、密码找回、Session 管理 |
14
14
  | 业务 API | `api/common` + `api/applyData` | 验证码、字典、IP 查询、数据上报 |
15
+ | 反查回显 | `api/reverseLookup` | 按英文展示名反查实体详情 |
16
+ | DW-SDK | `dw-sdk/` | 数据仓库 GraphQL SDK 统一入口 |
15
17
  | 请求封装 | `utils/request` | Axios/Fetch 双适配器 + 拦截器 |
16
18
  | Token 管理 | `utils/storage` | Cookie 凭证存取(Access Token / Refresh Token) |
17
19
  | 加密 | `utils/crypto` | AES 加解密(ECB,与后端对齐) |
@@ -75,8 +77,55 @@ createRequest("axios");
75
77
 
76
78
  // 切换为 Fetch(可传入自定义实现,如 Nuxt 的 $fetch)
77
79
  createRequest("fetch", { fetch: $fetch });
80
+
81
+ // 切换为 Custom(小程序等非浏览器环境,完全透传)
82
+ createRequest("custom", {
83
+ baseURL: "https://cloudapi-sit2.jctrans.net.cn",
84
+ fetch: async ({ url, method, data, params, headers }) => {
85
+ // 用户自己的请求实现,header/token/返回值完全由你控制
86
+ return new Promise((resolve, reject) => {
87
+ wx.request({
88
+ url,
89
+ method: method as any,
90
+ data,
91
+ header: headers,
92
+ success: (res: any) => resolve(res.data),
93
+ fail: reject,
94
+ });
95
+ });
96
+ },
97
+ });
78
98
  ```
79
99
 
100
+ #### ClientId 插件
101
+
102
+ 自动在所有请求 header 中注入客户端唯一标识(`client-uid`),用于无埋点追踪和用户行为分析。
103
+
104
+ ```typescript
105
+ import {
106
+ installClientIdPlugin,
107
+ installFetchClientIdPlugin,
108
+ getOrCreateClientId,
109
+ createRequest,
110
+ } from "@jctrans-materials/shared";
111
+
112
+ // Axios 环境:直接安装插件
113
+ installClientIdPlugin(axiosInstance, {
114
+ headerName: "client-uid", // 可选,默认 'client-uid'
115
+ });
116
+
117
+ // Fetch 环境:先创建请求实例再安装
118
+ const request = createRequest("fetch", { fetch: customFetch });
119
+ installFetchClientIdPlugin({
120
+ headerName: "client-uid", // 可选,默认 'client-uid'
121
+ });
122
+
123
+ // 手动获取 clientId
124
+ const cid = getOrCreateClientId(); // 首次调用自动生成并持久化
125
+ ```
126
+
127
+ > **原理**:使用 `nanoid` 生成,完全 SSR 兼容(无 `window`/`document` 依赖)。ClientId 存储在 `localStorage` 中,跨页面共享。
128
+
80
129
  ### 3. 地理位置搜索
81
130
 
82
131
  #### V2 接口(推荐)
@@ -240,6 +289,14 @@ import { tracker, normalizeClickPageAttrs, GIO_EVENT_CLICK_PAGE } from "@jctrans
240
289
  tracker.init("account-id", "datasource-id", {
241
290
  debug: true,
242
291
  trackPage: true,
292
+ // 性能采集(默认开启首屏加载监控和错误监控,默认关闭网络监控)
293
+ performance: {
294
+ monitor: true, // 首屏加载监控,默认 true
295
+ exception: true, // 错误监控,默认 true
296
+ network: { // 网络监控,不配置则默认关闭
297
+ exclude: /api\.example\.com/, // 排除指定域名的请求
298
+ },
299
+ },
243
300
  });
244
301
 
245
302
  // 设置用户 ID
@@ -304,6 +361,62 @@ await reportNewTypeDataApi({
304
361
  });
305
362
  ```
306
363
 
364
+ ### 10. 反查回显
365
+
366
+ 通过英文展示名(nameEnShow)反查实体详情,用于从外部链接或 URL 参数回显数据。
367
+
368
+ ```typescript
369
+ import {
370
+ getAirportByNameEnShow,
371
+ getCountryByNameEnShow,
372
+ getCityByNameEnShow,
373
+ getSeaportByNameEnShow,
374
+ } from "@jctrans-materials/shared";
375
+
376
+ // 按英文展示名查询机场详情
377
+ const airport = await getAirportByNameEnShow("Shanghai Pudong International Airport");
378
+
379
+ // 按英文展示名查询国家详情
380
+ const country = await getCountryByNameEnShow("China");
381
+
382
+ // 按英文展示名查询城市详情
383
+ const city = await getCityByNameEnShow("Shanghai");
384
+
385
+ // 按英文展示名查询港口详情
386
+ const seaport = await getSeaportByNameEnShow("Shanghai Port");
387
+ ```
388
+
389
+ ### 11. DW-SDK(数据仓库 GraphQL SDK)
390
+
391
+ 对 `@jctrans/dw-sdk` 的零配置封装,自动注入 baseUrl 和 Authorization Token。
392
+
393
+ ```typescript
394
+ import {
395
+ queryOpportunityBoard,
396
+ GraphQLClientError,
397
+ } from "@jctrans-materials/shared";
398
+ import type {
399
+ OpportunityBoardParams,
400
+ BoardQueryResult,
401
+ DateType,
402
+ } from "@jctrans-materials/shared";
403
+
404
+ // 查询商机有效看板数据
405
+ const result = await queryOpportunityBoard({
406
+ compId: 12345,
407
+ dateType: "QUARTER",
408
+ dateValue: "2026-Q2",
409
+ });
410
+
411
+ if (result.success) {
412
+ console.log(result.data.records);
413
+ } else {
414
+ console.error(result.error);
415
+ }
416
+ ```
417
+
418
+ > **原理**:每次调用内部新建 `createDwSdk()` 实例,调用后即销毁,无状态污染。`baseUrl` 自动从 `initSharedConfig` 的 `prefixPath + '/data'` 拼接。
419
+
307
420
  ## 核心 API 参考
308
421
 
309
422
  ### 配置
@@ -363,6 +476,23 @@ await reportNewTypeDataApi({
363
476
  | `setAuthSessionItems` / `getAuthSessionItems` / `resetAuthSessionItems` | Auth Session 管理 |
364
477
  | `setGioSessionItems` / `getGioSessionItems` / `resetGioSessionItems` | GIO Session 管理 |
365
478
 
479
+ ### 反查回显
480
+
481
+ | 方法 | 说明 |
482
+ |------|------|
483
+ | `getAirportByNameEnShow` | 按英文展示名查询机场 |
484
+ | `getCountryByNameEnShow` | 按英文展示名查询国家 |
485
+ | `getCityByNameEnShow` | 按英文展示名查询城市 |
486
+ | `getSeaportByNameEnShow` | 按英文展示名查询港口 |
487
+
488
+ ### DW-SDK
489
+
490
+ | 方法 | 说明 |
491
+ |------|------|
492
+ | `queryOpportunityBoard` | 查询商机有效看板(分页) |
493
+
494
+ 导出类型:`OpportunityBoardParams`, `BoardQueryResult`, `DateType`, `GraphQLClientError`。
495
+
366
496
  ### Token & Cookie
367
497
 
368
498
  | 方法 | 说明 |
@@ -377,13 +507,15 @@ await reportNewTypeDataApi({
377
507
 
378
508
  | 方法 | 说明 |
379
509
  |------|------|
380
- | `isEmpty` | 判断值是否为空(支持 string/array/object/Map/Set |
510
+ | `isEmpty` | 判断值是否为空(null/undefined/空字符串/空数组/空对象/空 Map/空 Set)。数字、布尔值等原始类型返回 `false` |
381
511
  | `isIpAddress` / `getFirstDomain` | 域名工具 |
382
512
  | `getAppId` / `getProjectId` | 跨环境 ID 获取 |
383
513
  | `getLanguage` | 获取当前语言 |
384
514
  | `getSessionHeaderValue` / `toSafeHeaderValue` | HTTP Header 安全工具 |
385
515
  | `encrypt` / `decrypt` | AES 加解密 |
386
516
  | `generateClientId` / `getOrCreateClientId` | 客户端唯一标识 |
517
+ | `installClientIdPlugin` | 为 Axios 实例注入 client-uid header |
518
+ | `installFetchClientIdPlugin` | 为 Fetch 请求注入 client-uid header |
387
519
 
388
520
  ## 类型定义
389
521
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jctrans-materials/shared",
3
- "version": "1.0.41-beta.5",
3
+ "version": "1.0.41-beta.6",
4
4
  "private": false,
5
5
  "description": "Shared utilities including auth, request, crypto, and GrowingIO analytics.",
6
6
  "main": "dist/index.cjs.js",