@jctrans-materials/shared 1.0.37 → 1.0.38-beta.2

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
  */
@@ -761,6 +829,30 @@ export declare const HasLoginKey = "hasLogin";
761
829
  */
762
830
  export declare const initSharedConfig: (newConfig: Partial<SharedConfig>) => void;
763
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
+
764
856
  /**
765
857
  * 获取邀请加入公司信息
766
858
  * @param data
@@ -1254,6 +1346,16 @@ export declare function resetGioSessionItems(): void;
1254
1346
  */
1255
1347
  export declare function resetPasswordApi(data: any): Promise<any>;
1256
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
+
1257
1359
  /**
1258
1360
  * 统一搜索接口
1259
1361
  * - 支持 keyword(模糊), displayInfo(数组), ids(按 type), scope(countryId/cityId/provinceId)