Commit 6cb890e9 by liimin

refactor(core): 重构项目目录结构,将功能模块分类到对应目录

- 将核心模块(request, defaults, interceptor, methods)移动到core目录
- 将安全相关模块(signature, whitelist)移动到security目录
- 将监控模块(sentry, traces, events)移动到monitoring目录
- 将工具模块(error, retry, index)移动到utils目录
- 移除不再使用的qs依赖
- 更新所有相关文件的引用路径
1 parent dd898f2a
......@@ -39,8 +39,6 @@
},
"dependencies": {
"@sentry/browser": "^7.101.1",
"@types/qs": "^6.14.0",
"crypto-js": "^4.2.0",
"qs": "^6.14.0"
"crypto-js": "^4.2.0"
}
}
import { RequestError } from '../../error';
import { RequestError } from '../../utils/error';
import type { RequestConfig, ResponseData } from '../../types';
import { buildURL } from '../utils';
import { processResponse } from '../handlers/response-handler';
......
import { RequestError } from '../../error';
import { RequestError } from '../../utils/error';
import type { RequestConfig } from '../../types';
/**
......
......@@ -6,7 +6,7 @@ import uniappAdapter from './adapters/uniapp';
import { detectEnvironment, EnvironmentType } from '../utils';
// 重新导出签名相关功能
export { generateSignature, type SignatureOptions, type SignatureResult } from '../signature';
export { generateSignature, type SignatureOptions, type SignatureResult } from '../security/signature';
/**
* 获取适合当前环境的适配器
......
import type { RequestConfig, RetryConfig } from "./types";
import { generateSignature } from "./signature";
import type { RequestConfig, RetryConfig } from "../types";
import { generateSignature } from "../security/signature";
/**
* 请求默认配置类
......
import type { InterceptorHandler, RequestError } from './types';
import type { InterceptorHandler, RequestError } from '../types';
class InterceptorManager<T = any> {
private handlers: (InterceptorHandler<T> | null)[] = [];
......
import type { RequestConfig } from "./types";
import type { RequestConfig } from "../types";
/**
* 为Request类添加HTTP方法别名
* @param {Object} instance Request实例
......
......@@ -3,23 +3,23 @@ import {
generateSignature,
type SignatureOptions,
type SignatureResult,
} from "./signature";
import type { RequestConfig, ResponseData } from "./types";
import { RequestError } from "./error";
import { getAdapter, type Adapter } from "./adapter";
import { dispatchEvent } from "./events";
import { sendRequestWithRetry } from "./retry";
} from "../security/signature";
import type { RequestConfig, ResponseData } from "../types";
import { RequestError } from "../utils/error";
import { getAdapter, type Adapter } from "../adapter";
import { dispatchEvent } from "../monitoring/events";
import { sendRequestWithRetry } from "../utils/retry";
import { addMethodAliases } from "./methods";
import {
preloadWhitelist,
checkWhitelist,
isWhitelistPreloaded,
} from "./whitelist";
import { subscribeEvents } from "./events";
import Trace from "./traces";
} from "../security/whitelist";
import { subscribeEvents } from "../monitoring/events";
import Trace from "../monitoring/traces";
import Defaults from "./defaults";
import { initSentry, reportNetworkError } from "./sentry";
import { buildURL } from "./adapter/utils";
import { initSentry, reportNetworkError } from "../monitoring/sentry";
import { buildURL } from "../adapter/utils";
interface Interceptors {
request: InterceptorManager<RequestConfig>;
......
import Request from './request';
import Defaults from './defaults';
import * as Sentry from './sentry';
import Request from './core/request';
import Defaults from './core/defaults';
import * as Sentry from './monitoring/sentry';
// 导出主类
export default Request;
// 导出 Defaults 类,方便用户直接使用
export { Defaults, Sentry };
// 导出类型定义
export type { RequestConfig, ResponseData, RequestHeaders } from './types';
export type { SentryOptions, ErrorReportOptions } from './sentry';
\ No newline at end of file
export type { SentryOptions, ErrorReportOptions } from './monitoring/sentry';
\ No newline at end of file
// 根据环境动态导入Sentry
import { detectEnvironment, EnvironmentType } from './utils';
import { detectEnvironment, EnvironmentType } from '../utils';
// 预先导入可能使用的模块
import * as SentryBrowser from '@sentry/browser';
import { Sentry as SentryMiniapp } from './libs';
import { Sentry as SentryMiniapp } from '../libs';
let Sentry: any;
......
import CryptoJS from 'crypto-js';
import { processGetSignatureParams, processPostSignatureParams } from './utils';
import { processGetSignatureParams, processPostSignatureParams } from '../utils';
export interface SignatureOptions {
appId: string;
......
import Trace from "./traces";
import Trace from "../monitoring/traces";
/**
* 检查URL是否在白名单中
......
import { reportNetworkError } from './sentry';
import { reportNetworkError } from '../monitoring/sentry';
/**
* 请求错误类
......
import { RequestConfig, ResponseData } from "./types";
import { RequestConfig, ResponseData } from "../types";
import { RequestError } from "./error";
/**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!