@lark-project/cli
Version:
飞书项目插件开发工具
79 lines (78 loc) • 4.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertAppTypeAllowedForOnlineWrite = exports.formatOnlineWriteAppTypeError = exports.isAppTypeAllowedForOnlineWrite = exports.getAllowedAppTypesForOnlineWrite = exports.assertAppTypeAllowedForOperation = exports.formatAppTypeOperationError = exports.isAppTypeAllowedForOperation = exports.getAllowedAppTypesForOperation = exports.ONLINE_WRITE_APP_TYPE_ALLOWLIST = exports.APP_TYPE_OPERATION_ALLOWLIST = void 0;
const types_1 = require("../types");
/**
* Commands whose implementation is app-type-specific must opt in each
* supported app type here. This includes online writes plus schema/config
* workflows that are unavailable until their point type is supported.
* Keep the arrays explicit so a newly added AppType is denied until every
* guarded path has been reviewed deliberately.
*
* start / init / release are intentionally outside this gate.
*/
exports.APP_TYPE_OPERATION_ALLOWLIST = {
[types_1.ECommandName.create]: ['normal', 'ai_node', 'ai_field'],
[types_1.ECommandName.update]: ['normal', 'ai_node', 'ai_field'],
[types_1.ECommandName.publish]: ['normal', 'ai_node', 'ai_field'],
[types_1.ECommandName.updateDescription]: ['normal', 'ai_node', 'ai_field'],
'perm.apply': ['normal'],
[types_1.ECommandName.schema]: ['normal', 'ai_node', 'ai_field'],
'local-config.set': ['normal', 'ai_node', 'ai_field'],
'local-config.diff': ['normal', 'ai_node', 'ai_field'],
'check.diff': ['normal', 'ai_node', 'ai_field'],
};
// Backward-compatible online-write view. Values are references into the one
// authoritative operation allowlist above; do not define a second policy.
exports.ONLINE_WRITE_APP_TYPE_ALLOWLIST = {
[types_1.ECommandName.create]: exports.APP_TYPE_OPERATION_ALLOWLIST[types_1.ECommandName.create],
[types_1.ECommandName.update]: exports.APP_TYPE_OPERATION_ALLOWLIST[types_1.ECommandName.update],
[types_1.ECommandName.publish]: exports.APP_TYPE_OPERATION_ALLOWLIST[types_1.ECommandName.publish],
[types_1.ECommandName.updateDescription]: exports.APP_TYPE_OPERATION_ALLOWLIST[types_1.ECommandName.updateDescription],
'perm.apply': exports.APP_TYPE_OPERATION_ALLOWLIST['perm.apply'],
};
function getAllowedAppTypesForOperation(operation) {
return exports.APP_TYPE_OPERATION_ALLOWLIST[operation];
}
exports.getAllowedAppTypesForOperation = getAllowedAppTypesForOperation;
function isAppTypeAllowedForOperation(operation, appType) {
return appType !== undefined && getAllowedAppTypesForOperation(operation).includes(appType);
}
exports.isAppTypeAllowedForOperation = isAppTypeAllowedForOperation;
function formatAppTypeOperationError(operation, appType) {
const appTypeLabel = appType === undefined ? '(missing)' : `"${appType}"`;
const onlineWriteOperations = [
types_1.ECommandName.create,
types_1.ECommandName.update,
types_1.ECommandName.publish,
types_1.ECommandName.updateDescription,
'perm.apply',
];
const isOnlineWrite = onlineWriteOperations.includes(operation);
return (`The ${operation} operation is not available for app_type ${appTypeLabel}. ` +
`Allowed app types: ${getAllowedAppTypesForOperation(operation).join(', ')}. ` +
(isOnlineWrite ? 'No online data was changed.' : 'No data was changed.'));
}
exports.formatAppTypeOperationError = formatAppTypeOperationError;
function assertAppTypeAllowedForOperation(operation, appType) {
if (isAppTypeAllowedForOperation(operation, appType))
return;
throw new Error(formatAppTypeOperationError(operation, appType));
}
exports.assertAppTypeAllowedForOperation = assertAppTypeAllowedForOperation;
function getAllowedAppTypesForOnlineWrite(operation) {
return getAllowedAppTypesForOperation(operation);
}
exports.getAllowedAppTypesForOnlineWrite = getAllowedAppTypesForOnlineWrite;
function isAppTypeAllowedForOnlineWrite(operation, appType) {
return isAppTypeAllowedForOperation(operation, appType);
}
exports.isAppTypeAllowedForOnlineWrite = isAppTypeAllowedForOnlineWrite;
function formatOnlineWriteAppTypeError(operation, appType) {
return formatAppTypeOperationError(operation, appType);
}
exports.formatOnlineWriteAppTypeError = formatOnlineWriteAppTypeError;
function assertAppTypeAllowedForOnlineWrite(operation, appType) {
assertAppTypeAllowedForOperation(operation, appType);
}
exports.assertAppTypeAllowedForOnlineWrite = assertAppTypeAllowedForOnlineWrite;