@jctrans-materials/shared 1.0.37-beta.9 → 1.0.38-beta.1

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
  */
@@ -271,6 +333,14 @@ export declare function getExpiresTimeIn(): number;
271
333
  */
272
334
  export declare function getFirstDomain(): string | undefined;
273
335
 
336
+ /**
337
+ * 全局获取 GIO 相关 session
338
+ * @returns
339
+ */
340
+ export declare function getGioSessionItems(): {
341
+ registerEntry: string | null;
342
+ };
343
+
274
344
  /**
275
345
  * 兼容全环境的语言判断方法
276
346
  * 逻辑优先级:Nuxt Composables > 浏览器 Cookie > Nuxt SSR 上下文
@@ -320,6 +390,12 @@ export declare function getMobileEmailApi(data: {
320
390
  id: string;
321
391
  }): Promise<any>;
322
392
 
393
+ /**
394
+ * 获取或生成 clientId
395
+ * 优先级: localStorage → sessionStorage → 生成新 nanoid
396
+ */
397
+ export declare function getOrCreateClientId(): string;
398
+
323
399
  /**
324
400
  * 跨环境获取 Path
325
401
  */
@@ -366,6 +442,8 @@ export declare function getSeaport(params?: {
366
442
  countryId?: number;
367
443
  }): Promise<BaseResponse<UnifiedItem>>;
368
444
 
445
+ export declare function getSessionHeaderValue(key: string): string;
446
+
369
447
  /**
370
448
  * 获取当前配置
371
449
  */
@@ -751,6 +829,30 @@ export declare const HasLoginKey = "hasLogin";
751
829
  */
752
830
  export declare const initSharedConfig: (newConfig: Partial<SharedConfig>) => void;
753
831
 
832
+ /**
833
+ * 为 axios 实例添加 clientId 拦截器
834
+ * @param instance axios 实例
835
+ * @param options 配置选项
836
+ */
837
+ export declare function installClientIdPlugin(instance: AxiosInstance, options?: ClientIdPluginOptions): void;
838
+
839
+ /**
840
+ * 在全局 fetch 上安装 clientId 拦截器
841
+ * 仅用于客户端环境,会覆盖全局 fetch
842
+ *
843
+ * @param options 配置选项
844
+ *
845
+ * @example
846
+ * import { installFetchClientId } from '@jctrans-materials/shared'
847
+ *
848
+ * export default defineNuxtPlugin(() => {
849
+ * if (process.client) {
850
+ * installFetchClientId()
851
+ * }
852
+ * })
853
+ */
854
+ export declare function installFetchClientId(options?: FetchClientIdOptions): void;
855
+
754
856
  /**
755
857
  * 获取邀请加入公司信息
756
858
  * @param data
@@ -1231,6 +1333,12 @@ declare interface RequestOptions {
1231
1333
  */
1232
1334
  export declare function resetAuthSessionItems(): void;
1233
1335
 
1336
+ /**
1337
+ * 重置 GIO 相关 session
1338
+ * @returns
1339
+ */
1340
+ export declare function resetGioSessionItems(): void;
1341
+
1234
1342
  /**
1235
1343
  * 重置密码
1236
1344
  * @param data
@@ -1238,6 +1346,16 @@ export declare function resetAuthSessionItems(): void;
1238
1346
  */
1239
1347
  export declare function resetPasswordApi(data: any): Promise<any>;
1240
1348
 
1349
+ /**
1350
+ * 保存 clientId 到 localStorage
1351
+ */
1352
+ export declare function saveClientIdToLocalStorage(clientId: string): void;
1353
+
1354
+ /**
1355
+ * 保存 clientId 到 sessionStorage
1356
+ */
1357
+ export declare function saveClientIdToSessionStorage(clientId: string): void;
1358
+
1241
1359
  /**
1242
1360
  * 统一搜索接口
1243
1361
  * - 支持 keyword(模糊), displayInfo(数组), ids(按 type), scope(countryId/cityId/provinceId)
@@ -1352,6 +1470,14 @@ export declare function setAuthSessionItems(data: {
1352
1470
  compKey?: string | null;
1353
1471
  }): void;
1354
1472
 
1473
+ /**
1474
+ * 全局设置 GIO 相关 session
1475
+ * @param data
1476
+ */
1477
+ export declare function setGioSessionItems(data: {
1478
+ registerEntry?: string | null;
1479
+ }): void;
1480
+
1355
1481
  /**
1356
1482
  * 记住账号 (替代存密码)
1357
1483
  */
@@ -1459,6 +1585,8 @@ export declare interface TokenData {
1459
1585
  */
1460
1586
  export declare const TokenKey = "JC-JAVA-Token-Root";
1461
1587
 
1588
+ export declare function toSafeHeaderValue(value: string): string;
1589
+
1462
1590
  export declare const tracker: GioTracker;
1463
1591
 
1464
1592
  /** 归一化之后的实体 */