@jctrans-materials/shared 1.0.11 → 1.0.12

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.
@@ -0,0 +1,67 @@
1
+ /**
2
+ * 判断域名是否为 IP
3
+ */
4
+ export declare function isIpAddress(hostname: string): boolean;
5
+ /**
6
+ * 获取一级域名 (用于 Cookie 跨域共享)
7
+ */
8
+ export declare function getFirstDomain(): string | undefined;
9
+ /**
10
+ * 2. 常量定义 (补全所有业务 Key)
11
+ */
12
+ export declare const TokenKey = "JC-JAVA-Token-Root";
13
+ export declare const HasLoginKey = "hasLogin";
14
+ export declare const PrjId = "prjId";
15
+ export declare const ExpiresInKey = "JC-Expires-In";
16
+ export declare const ExpiresInTimeKey = "JC-Expires-Time-In";
17
+ export declare const RefreshTokenKey = "JC-Refresh-Token";
18
+ export declare const RefreshExpiresInKey = "JC-Refresh-Expires-In";
19
+ export declare const RefreshExpiresInTimeKey = "JC-Refresh-Expires-Time-In";
20
+ export declare const RememberMeAccountKey = "JC-Remember-Account";
21
+ /**
22
+ * 3. 类型定义
23
+ */
24
+ export interface TokenData {
25
+ accessToken?: string;
26
+ expireIn?: number;
27
+ refreshToken?: string;
28
+ refreshTokenExpireIn?: number;
29
+ }
30
+ export declare const TOKEN_ENDPOINTS: Set<string>;
31
+ /**
32
+ * 4. 导出操作方法
33
+ */
34
+ export declare function getProjectId(): string | undefined;
35
+ /**
36
+ * 记住账号 (替代存密码)
37
+ */
38
+ export declare function setRememberMe(account: string, remember: boolean): void;
39
+ /**
40
+ * 整体设置所有凭证
41
+ */
42
+ export declare function setTokenAll(data: TokenData | null | undefined): void;
43
+ export declare function clearAllAuth(): void;
44
+ /**
45
+ * 跨环境获取 AppId (兼容 Vite, Webpack, Nuxt)
46
+ */
47
+ export declare function getAppId(): string;
48
+ /**
49
+ * 跨环境获取 Path
50
+ */
51
+ export declare function getPathFromConfig(config: any): string;
52
+ /**
53
+ * 获取当前的 Access Token
54
+ */
55
+ export declare function getToken(): string | undefined;
56
+ /**
57
+ * 🚀 补全:获取当前的 Refresh Token
58
+ */
59
+ export declare function getRefreshToken(): string | undefined;
60
+ /**
61
+ * 🚀 补全:获取 Access Token 的过期时间戳 (用于判断是否需要刷新)
62
+ */
63
+ export declare function getExpiresTimeIn(): number;
64
+ /**
65
+ * 获取记住的账号
66
+ */
67
+ export declare function getRememberAccount(): string | undefined;
@@ -1,2 +1,2 @@
1
- import { RequestAdapter } from '../types';
2
- export declare const axiosAdapter: RequestAdapter;
1
+ import { RequestAdapter, RequestOptions } from '../types';
2
+ export declare function createAxiosAdapter(options?: RequestOptions): RequestAdapter;
@@ -1,2 +1,5 @@
1
- import { RequestAdapter } from '../types';
2
- export declare function createFetchAdapter(fetchImpl: typeof fetch): RequestAdapter;
1
+ import { RequestAdapter, RequestOptions } from '../types';
2
+ /**
3
+ * 🚀 支持 Nuxt 3 的 Fetch 适配器
4
+ */
5
+ export declare function createFetchAdapter(options?: RequestOptions): RequestAdapter;
@@ -1,12 +1,7 @@
1
- import { RequestAdapter, RequestDriver } from './types';
2
- export declare function createRequest(driver: RequestDriver, options?: {
3
- fetch?: typeof fetch;
4
- }): RequestAdapter;
5
- /**
6
- * 对外统一 request
7
- */
1
+ import { RequestAdapter, RequestDriver, RequestOptions } from './types';
2
+ export declare function createRequest(driver: RequestDriver, options?: RequestOptions): RequestAdapter;
8
3
  declare const request: {
9
- get: (url: string, config?: import('./types').RequestConfig | undefined) => Promise<import('./types').RequestResponse<any>>;
10
- post: (url: string, body?: any, config?: import('./types').RequestConfig | undefined) => Promise<import('./types').RequestResponse<any>>;
4
+ get: (url: string, config?: import('./types').RequestConfig | undefined) => Promise<any>;
5
+ post: (url: string, data?: any, config?: import('./types').RequestConfig | undefined) => Promise<any>;
11
6
  };
12
7
  export default request;
@@ -1,13 +1,15 @@
1
- export type RequestDriver = "fetch" | "axios";
2
1
  export interface RequestConfig {
3
2
  params?: Record<string, any>;
4
3
  headers?: Record<string, string>;
4
+ isToken?: boolean;
5
5
  }
6
- export interface RequestResponse<T = any> {
7
- data: T;
8
- status: number;
6
+ export interface RequestOptions {
7
+ onUnauthorized?: () => void;
8
+ baseURL?: string;
9
+ fetch?: typeof fetch;
9
10
  }
10
11
  export interface RequestAdapter {
11
- get(url: string, config?: RequestConfig): Promise<RequestResponse>;
12
- post(url: string, body?: any, config?: RequestConfig): Promise<RequestResponse>;
12
+ get(url: string, config?: RequestConfig): Promise<any>;
13
+ post(url: string, data?: any, config?: RequestConfig): Promise<any>;
13
14
  }
15
+ export type RequestDriver = "axios" | "fetch";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jctrans-materials/shared",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "private": false,
5
5
  "description": "Shared logic for global modal components.",
6
6
  "main": "dist/index.cjs.js",
@@ -20,10 +20,12 @@
20
20
  "dependencies": {
21
21
  "axios": "^1.13.2",
22
22
  "crypto-js": "^4.2.0",
23
+ "js-cookie": "^3.0.5",
23
24
  "mitt": "^3.0.1"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/crypto-js": "^4.2.2",
28
+ "@types/js-cookie": "^3.0.6",
27
29
  "typescript": "^5.9.3",
28
30
  "vite": "^7.2.6",
29
31
  "vite-plugin-dts": "^4.5.4"