resolveApiName.js 2.42 KB
/**
 * ROP method → apiName / axios 配置键 / 签名方式
 * 与 src/api/request.js 保持一致,供浏览器与 Node 共用
 */

const API_NAME_MAPPING = {
	"dj.smartcarlife": "axios",
	"dj": "axios",
	"scrm": "axios2",
	"merchants": "axios3",
	"reportExport": "axios4",
	"glsx.accounts.biz.common.pictureUpload": "common",
	"clue": "axios5",
	"dj.businessSchool": "axios6",
	"script": "axios7",
	"staff": "axios9",
	"riskmanage": "axios10",
	"strategy": "axios_strategy",
	"supervisor": "axios_supervisor",
	"oaapproval": "axios_oaapproval",
	"taskcenter": "axiosTaskCenter",
};

const SIGN_WAY = {
	"dj.smartcarlife": "sha1",
	"dj": "sha1",
	"scrm": "sha1",
	"glsx": "md5",
	"glsx.accounts.biz.common.pictureUpload": "md5",
	"clue": "sha1",
	"script": "sha1",
	"staff": "sha1",
	"riskmanage": "sha1",
	"oaapproval": "sha1",
	"taskcenter": "sha1",
};

/**
 * 根据 ROP method 解析 apiName
 * @param {string} method
 * @returns {string}
 */
function resolveApiName(method = "") {
	if (!method) {
		return "";
	}
	if (method.includes("dj.api.smartcarlife.sop.strategy")) {
		return "strategy";
	}
	if (method.includes("dj.api.smartcarlife")) {
		return "dj";
	}
	if (method.includes("dj.api.script")) {
		return "script";
	}
	if (method.includes("dj.staff.api")) {
		return "staff";
	}
	if (method.includes("dj.smartcarlife.stock")) {
		return "dj.smartcarlife";
	}
	if (method.includes("risk.manage.api")) {
		return "riskmanage";
	}
	if (method.includes("dj.api.strategy")) {
		return "strategy";
	}
	if (method.includes("dj.api.supervisor")) {
		return "supervisor";
	}
	if (method.includes("dj.pad.api")) {
		return "dj";
	}
	if (method.includes("dj.api.oaapproval")) {
		return "oaapproval";
	}
	if (method.includes("dj.api.taskcenter")) {
		return "taskcenter";
	}
	if (method.includes("merchants.api.open.createMerchantWithPermissions") || method.includes("merchants.api.oaapproval")) {
		return "oaapproval";
	}
	if (method.includes("dj.api.marketing")) {
		return "strategy";
	}
	return method.split(".api")[0];
}

/**
 * apiName → baseConfig 中的 axios 块键名
 * @param {string} apiName
 * @returns {string|undefined}
 */
function getAxiosConfigKey(apiName) {
	return API_NAME_MAPPING[apiName];
}

/**
 * apiName → 签名算法
 * @param {string} apiName
 * @returns {string}
 */
function getSignWay(apiName) {
	return SIGN_WAY[apiName] || "sha1";
}

module.exports = {
	resolveApiName,
	getAxiosConfigKey,
	getSignWay,
	API_NAME_MAPPING,
	SIGN_WAY,
};