@lark-project/cli
Version:
飞书项目插件开发工具
51 lines (50 loc) • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyAppPerm = exports.getAppPermList = exports.PERM_OPERATE_REMOVE = exports.PERM_OPERATE_ADD = void 0;
const request_1 = require("./request");
const get_tool_auth_headers_1 = require("./get-tool-auth-headers");
/**
* Plugin OpenAPI permission (scope) provisioning — `lpm perm` CLI's wire layer.
*
* Backend: app_center dev-token Tool APIs (reuse the same logic as the console's
* session-authed `/bff/app/development/v1/perm/{list,apply}`):
* - GET /goapi/v5/app/development/tool/perm/list (APIAppDevelopmentToolListPerm
* → reuses GetAppPermInfoWithMetaListRequest/Response)
* - POST /goapi/v5/app/development/tool/perm/apply (APIAppDevelopmentToolApplyPerm
* → reuses SaveAppPermInfoWithReasonRequest/Response)
* Authed via the developer token (same `Authorization: Bearer …` as
* getToolAuthHeaders); the plugin is identified by `app_key` (query for list,
* body for apply) — same pattern as the other `tool/` endpoints. No plugin_secret.
*
* Wire shapes mirror meego_idl `app_center/api/api_app_development.thrift`
* (GetAppPermInfoWithMetaList*, SaveAppPermInfoWithReason*) +
* `api_app_common.thrift` (AppPermInfoWithReason, AppPermMeta, AppResourceMeta).
*/
const LIST_PATH = '/goapi/v5/app/development/tool/perm/list';
const APPLY_PATH = '/goapi/v5/app/development/tool/perm/apply';
/** operate_type for `tool/perm/apply`. */
exports.PERM_OPERATE_ADD = 1;
exports.PERM_OPERATE_REMOVE = 2;
async function getAppPermList(pluginId, siteDomain, keyword) {
const params = { app_key: pluginId };
if (keyword)
params.keyword = keyword;
return (0, request_1.request)(`${siteDomain}${LIST_PATH}`, {
method: 'GET',
headers: await (0, get_tool_auth_headers_1.getToolAuthHeaders)(siteDomain),
params,
});
}
exports.getAppPermList = getAppPermList;
async function applyAppPerm(pluginId, siteDomain, scopeKeys, operateType = exports.PERM_OPERATE_ADD) {
return (0, request_1.request)(`${siteDomain}${APPLY_PATH}`, {
method: 'POST',
headers: await (0, get_tool_auth_headers_1.getToolAuthHeaders)(siteDomain),
data: {
app_key: pluginId,
perm_info: scopeKeys.map(key => ({ key })),
operate_type: operateType,
},
});
}
exports.applyAppPerm = applyAppPerm;