@jctrans-materials/shared 1.0.37-beta.21 → 1.0.37-beta.22

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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AxiosInstance } from 'axios';
1
2
  import { Emitter } from 'mitt';
2
3
 
3
4
  declare type ActionKeys = (typeof MODAL_ACTION)[keyof typeof MODAL_ACTION];
@@ -94,6 +95,18 @@ export declare function checkMobileCodeApi(data: {
94
95
 
95
96
  export declare function clearAllAuth(): void;
96
97
 
98
+ /**
99
+ * 清除 clientId(用于登出等场景)
100
+ */
101
+ export declare function clearClientId(): void;
102
+
103
+ export declare interface ClientIdPluginOptions {
104
+ /**
105
+ * 自定义 header 名称,默认值:'client-uid'
106
+ */
107
+ headerName?: string;
108
+ }
109
+
97
110
  export declare interface CommonParams {
98
111
  current?: number;
99
112
  size?: number;
@@ -130,6 +143,23 @@ export declare function completeJoinCompanyRedirectApi(data: any): Promise<any>;
130
143
  */
131
144
  export declare type ConfigCallback<T = GioConfigValue> = (value: T) => void;
132
145
 
146
+ /**
147
+ * 创建一个 fetch 拦截器函数
148
+ * 返回一个包装后的 fetch,会自动注入 clientId
149
+ *
150
+ * @param options 配置选项
151
+ * @returns 返回一个新的 fetch 函数
152
+ *
153
+ * @example
154
+ * // 在 Nuxt 插件中使用
155
+ * import { createFetchWithClientId } from '@jctrans-materials/shared'
156
+ *
157
+ * export default defineNuxtPlugin(() => {
158
+ * const $fetch = createFetchWithClientId()
159
+ * })
160
+ */
161
+ export declare function createFetchWithClientId(options?: FetchClientIdOptions): typeof fetch;
162
+
133
163
  export declare function createRequest(driver: RequestDriver, options?: RequestOptions): RequestAdapter;
134
164
 
135
165
  export declare const currentConfig: {
@@ -168,6 +198,21 @@ export declare const ExpiresInKey = "JC-Expires-In";
168
198
 
169
199
  export declare const ExpiresInTimeKey = "JC-Expires-Time-In";
170
200
 
201
+ /**
202
+ * Fetch API ClientId 拦截器
203
+ * 用于在 fetch 请求中自动注入 clientId header
204
+ */
205
+ export declare interface FetchClientIdOptions {
206
+ /**
207
+ * 自定义 header 名称,默认值:'client-uid'
208
+ */
209
+ headerName?: string;
210
+ /**
211
+ * 是否在请求中注入 (默认 true)
212
+ */
213
+ injectRequest?: boolean;
214
+ }
215
+
171
216
  /**
172
217
  * 获取字典列表
173
218
  * @param data
@@ -193,6 +238,18 @@ export declare function findPAreaCodeAPi(data?: {
193
238
  size: number;
194
239
  }): Promise<any>;
195
240
 
241
+ /**
242
+ * ClientId 管理工具
243
+ * 用于生成和管理唯一的客户端标识符
244
+ * 使用 nanoid 生成,完全 SSR 兼容
245
+ * 策略:localStorage → sessionStorage → nanoid
246
+ */
247
+ /**
248
+ * 生成唯一的客户端 ID
249
+ * 使用 nanoid,完全 SSR 兼容
250
+ */
251
+ export declare function generateClientId(): string;
252
+
196
253
  export declare function getAirport(params?: {
197
254
  page?: number;
198
255
  size?: number;
@@ -261,6 +318,11 @@ export declare function getCountry(params?: {
261
318
  ids?: number[];
262
319
  }): Promise<BaseResponse<UnifiedItem>>;
263
320
 
321
+ /**
322
+ * 获取当前的 clientId(不会创建新的)
323
+ */
324
+ export declare function getCurrentClientId(): string | null;
325
+
264
326
  /**
265
327
  * 🚀 补全:获取 Access Token 的过期时间戳 (用于判断是否需要刷新)
266
328
  */
@@ -328,6 +390,12 @@ export declare function getMobileEmailApi(data: {
328
390
  id: string;
329
391
  }): Promise<any>;
330
392
 
393
+ /**
394
+ * 获取或生成 clientId
395
+ * 优先级: localStorage → sessionStorage → 生成新 nanoid
396
+ */
397
+ export declare function getOrCreateClientId(): string;
398
+
331
399
  /**
332
400
  * 跨环境获取 Path
333
401
  */
@@ -419,6 +487,8 @@ export declare function getTracker<T extends GioTracker>(trackerInstance?: T): T
419
487
  */
420
488
  export declare function getUserInfoApi(data: any): Promise<any>;
421
489
 
490
+ export declare const GIO_CLICK_PAGE_REQUIRED_FIELDS: readonly ["companyID_var", "contactPerson_var", "inquiryID_var", "modulePosition_var", "moduleType_var", "pageCode_var", "pageClickName_var", "moduleName_var"];
491
+
422
492
  /**
423
493
  * GIO 属性对象
424
494
  */
@@ -541,6 +611,50 @@ export declare interface GioPageProps {
541
611
  */
542
612
  export declare type GioTimerId = string;
543
613
 
614
+ /**
615
+ * GrowingIO SDK 封装模块
616
+ * 基于 gio-webjs-sdk npm 包
617
+ *
618
+ * @module gio
619
+ *
620
+ * @example
621
+ * ```typescript
622
+ * import { tracker, type GioAttributes, type GioInitOptions } from '@jctrans-materials/shared';
623
+ *
624
+ * // 基础初始化
625
+ * tracker.init('your-account-id', 'your-datasource-id', {
626
+ * debug: true,
627
+ * trackPage: false,
628
+ * });
629
+ *
630
+ * // 微信公众号 H5(需要 appId 和 forceLogin)
631
+ * tracker.init('accountId', 'dataSourceId', 'wx-app-id', {
632
+ * forceLogin: true,
633
+ * debug: true,
634
+ * });
635
+ *
636
+ * // 设置登录用户 ID
637
+ * tracker.setUserId('user-123');
638
+ * tracker.setUserId('user-123', 'user_id', () => {
639
+ * console.log('set user id with userKey done');
640
+ * });
641
+ *
642
+ * // 埋点事件
643
+ * tracker.track('order_submit', {
644
+ * order_type: 'freight',
645
+ * price: 5000,
646
+ * services: ['ocean', 'customs']
647
+ * });
648
+ *
649
+ * // 设置全局属性
650
+ * tracker.setGeneralProps({
651
+ * platform: 'jctrans_web',
652
+ * locale: 'zh-CN'
653
+ * });
654
+ * ```
655
+ */
656
+ export declare type GioTrackAttrs = Record<string, string | number | Array<string | number> | null | undefined>;
657
+
544
658
  declare class GioTracker {
545
659
  private hasInitCalled;
546
660
  private dispatcher;
@@ -761,6 +875,30 @@ export declare const HasLoginKey = "hasLogin";
761
875
  */
762
876
  export declare const initSharedConfig: (newConfig: Partial<SharedConfig>) => void;
763
877
 
878
+ /**
879
+ * 为 axios 实例添加 clientId 拦截器
880
+ * @param instance axios 实例
881
+ * @param options 配置选项
882
+ */
883
+ export declare function installClientIdPlugin(instance: AxiosInstance, options?: ClientIdPluginOptions): void;
884
+
885
+ /**
886
+ * 在全局 fetch 上安装 clientId 拦截器
887
+ * 仅用于客户端环境,会覆盖全局 fetch
888
+ *
889
+ * @param options 配置选项
890
+ *
891
+ * @example
892
+ * import { installFetchClientId } from '@jctrans-materials/shared'
893
+ *
894
+ * export default defineNuxtPlugin(() => {
895
+ * if (process.client) {
896
+ * installFetchClientId()
897
+ * }
898
+ * })
899
+ */
900
+ export declare function installFetchClientId(options?: FetchClientIdOptions): void;
901
+
764
902
  /**
765
903
  * 获取邀请加入公司信息
766
904
  * @param data
@@ -772,6 +910,13 @@ declare interface IResponse<T> {
772
910
  data: T;
773
911
  }
774
912
 
913
+ /**
914
+ * 检查值是否为空
915
+ * @param value 要检查的值
916
+ * @returns 是否为空
917
+ */
918
+ export declare function isEmpty(value: any): boolean;
919
+
775
920
  /**
776
921
  * 检查 GIO 是否可用(浏览器环境且已初始化)
777
922
  *
@@ -1024,27 +1169,17 @@ export declare interface LocationUnifiedItem {
1024
1169
  display?: string;
1025
1170
  displayEn?: string;
1026
1171
  displayCn?: string;
1027
- /** * 通用代码字段 (自动取 scacCode 或 carrierCode)
1028
- * 适用于仅展示用途
1029
- */
1030
1172
  code?: string;
1031
- /** * SCAC 代码 (Standard Carrier Alpha Code) - 通常用于船司
1032
- */
1033
1173
  scacCode?: string;
1034
- /** * IATA 代码 - 通常用于航司
1035
- */
1036
1174
  iataCode?: string;
1037
- /** * 承运人通用代码
1038
- */
1039
1175
  carrierCode?: string;
1040
- /** * 承运人类型: 'air' | 'shipping'
1041
- */
1042
1176
  lineType?: string;
1043
1177
  continent?: Record<string, any>;
1044
1178
  country?: Record<string, any>;
1045
1179
  city?: Record<string, any>;
1046
1180
  province?: Record<string, any>;
1047
1181
  raw?: any;
1182
+ [key: string]: unknown;
1048
1183
  }
1049
1184
 
1050
1185
  /**
@@ -1085,6 +1220,8 @@ export declare function loginByQrCode(data: {
1085
1220
  appId: string;
1086
1221
  redirectPath: string;
1087
1222
  kick: boolean;
1223
+ prjId?: string;
1224
+ formEntry?: string;
1088
1225
  }): Promise<any>;
1089
1226
 
1090
1227
  /**
@@ -1143,6 +1280,10 @@ export declare type ModalEvents = Record<ActionKeys, any> & {
1143
1280
 
1144
1281
  export declare type ModalOpenCallback = () => void;
1145
1282
 
1283
+ export declare const normalizeAttrs: (attrs?: GioTrackAttrs) => GioTrackAttrs;
1284
+
1285
+ export declare const normalizeClickPageAttrs: (eventName: string, attrs?: GioTrackAttrs) => GioTrackAttrs;
1286
+
1146
1287
  /**
1147
1288
  * 页面变更回调
1148
1289
  */
@@ -1215,7 +1356,7 @@ export declare interface reportNewTypeData {
1215
1356
 
1216
1357
  export declare function reportNewTypeDataApi(payload: reportNewTypeData): Promise<{}>;
1217
1358
 
1218
- export declare type ReportType = "City" | "Seaport" | "Airport" | "Line";
1359
+ export declare type ReportType = "City" | "Seaport" | "Airport" | "Line" | "Carrier" | "shipping_line" | "shipping_carrier" | "air_line" | "air_carrier";
1219
1360
 
1220
1361
  declare interface RequestAdapter {
1221
1362
  get(url: string, config?: RequestConfig): Promise<any>;
@@ -1254,6 +1395,16 @@ export declare function resetGioSessionItems(): void;
1254
1395
  */
1255
1396
  export declare function resetPasswordApi(data: any): Promise<any>;
1256
1397
 
1398
+ /**
1399
+ * 保存 clientId 到 localStorage
1400
+ */
1401
+ export declare function saveClientIdToLocalStorage(clientId: string): void;
1402
+
1403
+ /**
1404
+ * 保存 clientId 到 sessionStorage
1405
+ */
1406
+ export declare function saveClientIdToSessionStorage(clientId: string): void;
1407
+
1257
1408
  /**
1258
1409
  * 统一搜索接口
1259
1410
  * - 支持 keyword(模糊), displayInfo(数组), ids(按 type), scope(countryId/cityId/provinceId)