@nasl/cli 0.1.15 → 0.1.17
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.
- package/build/nasl.bundle.js +4970 -4941
- package/dist/bin/nasl.mjs +243 -51
- package/dist/bin/nasl.mjs.map +1 -1
- package/dist/bin/naslc.mjs +196 -16
- package/dist/bin/naslc.mjs.map +1 -1
- package/dist/index.mjs +212 -49
- package/dist/index.mjs.map +1 -1
- package/out/apis/compileApi.d.ts.map +1 -1
- package/out/apis/compileApi.js +2 -4
- package/out/apis/compileApi.js.map +1 -1
- package/out/apis/createAppApi.js +1 -1
- package/out/apis/createAppApi.js.map +1 -1
- package/out/apis/createAxios.d.ts +7 -1
- package/out/apis/createAxios.d.ts.map +1 -1
- package/out/apis/createAxios.js +34 -5
- package/out/apis/createAxios.js.map +1 -1
- package/out/apis/openapi.d.ts +34 -0
- package/out/apis/openapi.d.ts.map +1 -0
- package/out/apis/openapi.js +114 -0
- package/out/apis/openapi.js.map +1 -0
- package/out/apis/transformApi.d.ts +1 -1
- package/out/apis/transformApi.d.ts.map +1 -1
- package/out/apis/transformApi.js +4 -6
- package/out/apis/transformApi.js.map +1 -1
- package/out/bin/nasl.js +63 -1
- package/out/bin/nasl.js.map +1 -1
- package/out/commands/check.d.ts.map +1 -1
- package/out/commands/check.js +1 -4
- package/out/commands/check.js.map +1 -1
- package/out/commands/compile.d.ts.map +1 -1
- package/out/commands/compile.js +1 -4
- package/out/commands/compile.js.map +1 -1
- package/out/commands/transform.d.ts.map +1 -1
- package/out/commands/transform.js +7 -19
- package/out/commands/transform.js.map +1 -1
- package/out/types/api.d.ts +8 -0
- package/out/types/api.d.ts.map +1 -1
- package/out/types/command.d.ts +1 -0
- package/out/types/command.d.ts.map +1 -1
- package/out/types/config.d.ts +6 -0
- package/out/types/config.d.ts.map +1 -1
- package/out/types/config.js +2 -2
- package/out/types/config.js.map +1 -1
- package/package.json +3 -1
package/dist/bin/naslc.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import require$$5 from 'assert';
|
|
|
15
15
|
import require$$3 from 'http';
|
|
16
16
|
import require$$4$1 from 'https';
|
|
17
17
|
import require$$0$6 from 'url';
|
|
18
|
-
import
|
|
18
|
+
import crypto$1 from 'crypto';
|
|
19
19
|
import http2 from 'http2';
|
|
20
20
|
import zlib from 'zlib';
|
|
21
21
|
|
|
@@ -22077,7 +22077,7 @@ function requireForm_data () {
|
|
|
22077
22077
|
var parseUrl = require$$0$6.parse;
|
|
22078
22078
|
var fs = require$$0$2;
|
|
22079
22079
|
var Stream = stream$4.Stream;
|
|
22080
|
-
var crypto =
|
|
22080
|
+
var crypto = crypto$1;
|
|
22081
22081
|
var mime = requireMimeTypes();
|
|
22082
22082
|
var asynckit = requireAsynckit();
|
|
22083
22083
|
var setToStringTag = /*@__PURE__*/ requireEsSetTostringtag();
|
|
@@ -22986,7 +22986,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
|
22986
22986
|
let str = '';
|
|
22987
22987
|
const {length} = alphabet;
|
|
22988
22988
|
const randomValues = new Uint32Array(size);
|
|
22989
|
-
|
|
22989
|
+
crypto$1.randomFillSync(randomValues);
|
|
22990
22990
|
for (let i = 0; i < size; i++) {
|
|
22991
22991
|
str += alphabet[randomValues[i] % length];
|
|
22992
22992
|
}
|
|
@@ -28771,14 +28771,199 @@ const {
|
|
|
28771
28771
|
mergeConfig
|
|
28772
28772
|
} = axios;
|
|
28773
28773
|
|
|
28774
|
-
|
|
28775
|
-
|
|
28774
|
+
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
28775
|
+
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
28776
|
+
// generators (like Math.random()).
|
|
28777
|
+
let getRandomValues;
|
|
28778
|
+
const rnds8 = new Uint8Array(16);
|
|
28779
|
+
function rng() {
|
|
28780
|
+
// lazy load so that environments that need to polyfill have a chance to do so
|
|
28781
|
+
if (!getRandomValues) {
|
|
28782
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
|
28783
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
28784
|
+
|
|
28785
|
+
if (!getRandomValues) {
|
|
28786
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
28787
|
+
}
|
|
28788
|
+
}
|
|
28789
|
+
|
|
28790
|
+
return getRandomValues(rnds8);
|
|
28791
|
+
}
|
|
28792
|
+
|
|
28793
|
+
/**
|
|
28794
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
28795
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
28796
|
+
*/
|
|
28797
|
+
|
|
28798
|
+
const byteToHex = [];
|
|
28799
|
+
|
|
28800
|
+
for (let i = 0; i < 256; ++i) {
|
|
28801
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
28802
|
+
}
|
|
28803
|
+
|
|
28804
|
+
function unsafeStringify(arr, offset = 0) {
|
|
28805
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
28806
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
28807
|
+
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
|
28808
|
+
}
|
|
28809
|
+
|
|
28810
|
+
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
28811
|
+
var native = {
|
|
28812
|
+
randomUUID
|
|
28813
|
+
};
|
|
28814
|
+
|
|
28815
|
+
function v4(options, buf, offset) {
|
|
28816
|
+
if (native.randomUUID && true && !options) {
|
|
28817
|
+
return native.randomUUID();
|
|
28818
|
+
}
|
|
28819
|
+
|
|
28820
|
+
options = options || {};
|
|
28821
|
+
const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
28822
|
+
|
|
28823
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
28824
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
28825
|
+
|
|
28826
|
+
return unsafeStringify(rnds);
|
|
28827
|
+
}
|
|
28828
|
+
|
|
28829
|
+
/**
|
|
28830
|
+
* 构建签名字符串
|
|
28831
|
+
*/
|
|
28832
|
+
function buildStringToSign(appKey, nonce, timestamp, secretKey) {
|
|
28833
|
+
return `${appKey}&${nonce}&${timestamp}&${secretKey}`;
|
|
28834
|
+
}
|
|
28835
|
+
/**
|
|
28836
|
+
* 生成 MD5 签名
|
|
28837
|
+
*/
|
|
28838
|
+
function generateSignature(plainText) {
|
|
28839
|
+
return crypto$1.createHash('md5').update(plainText).digest('hex');
|
|
28840
|
+
}
|
|
28841
|
+
/**
|
|
28842
|
+
* 生成客户端签名信息
|
|
28843
|
+
* @param appKey AppKey
|
|
28844
|
+
* @param secretKey SecretKey
|
|
28845
|
+
* @returns 签名信息
|
|
28846
|
+
*/
|
|
28847
|
+
function generateClientSignature(appKey, secretKey) {
|
|
28848
|
+
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
28849
|
+
const nonce = v4();
|
|
28850
|
+
const plainText = buildStringToSign(appKey, nonce, timestamp, secretKey);
|
|
28851
|
+
const signature = generateSignature(plainText);
|
|
28852
|
+
return {
|
|
28853
|
+
appKey,
|
|
28854
|
+
timestamp,
|
|
28855
|
+
nonce,
|
|
28856
|
+
signature,
|
|
28857
|
+
};
|
|
28858
|
+
}
|
|
28859
|
+
/**
|
|
28860
|
+
* 生成基础认证头
|
|
28861
|
+
* @param ak AppKey
|
|
28862
|
+
* @param sk SecretKey
|
|
28863
|
+
* @returns 基础认证头
|
|
28864
|
+
*/
|
|
28865
|
+
function generateBaseHeaders(ak, sk) {
|
|
28866
|
+
const { timestamp, signature, nonce } = generateClientSignature(ak, sk);
|
|
28867
|
+
return {
|
|
28868
|
+
'Content-Type': 'application/json',
|
|
28869
|
+
'x-appKey': ak,
|
|
28870
|
+
'x-timestamp': timestamp,
|
|
28871
|
+
'x-nonce': nonce,
|
|
28872
|
+
'x-signature': signature,
|
|
28873
|
+
};
|
|
28874
|
+
}
|
|
28875
|
+
/**
|
|
28876
|
+
* 获取租户的 signInfo
|
|
28877
|
+
* @param options 服务器选项
|
|
28878
|
+
* @param baseHeaders 基础认证头
|
|
28879
|
+
* @returns x-signInfo 值
|
|
28880
|
+
*/
|
|
28881
|
+
async function fetchSignInfo(options, baseHeaders) {
|
|
28882
|
+
const tenantName = options.tenantName || 'defaulttenant';
|
|
28883
|
+
const userName = tenantName === 'defaulttenant' ? 'admin' : `${tenantName}-admin`;
|
|
28884
|
+
const data = {
|
|
28885
|
+
tenantName,
|
|
28886
|
+
userName,
|
|
28887
|
+
source: 'Normal',
|
|
28888
|
+
};
|
|
28889
|
+
const url = `${options.serverBaseURL}/openapi/v3/auth/getSignInfo`;
|
|
28890
|
+
try {
|
|
28891
|
+
const tempAxios = axios.create({
|
|
28892
|
+
headers: baseHeaders,
|
|
28893
|
+
timeout: 120000,
|
|
28894
|
+
});
|
|
28895
|
+
const response = await tempAxios.post(url, data);
|
|
28896
|
+
return response?.data?.result || null;
|
|
28897
|
+
}
|
|
28898
|
+
catch (error) {
|
|
28899
|
+
console.error('Error fetching sign info:', error.response?.data);
|
|
28900
|
+
return null;
|
|
28901
|
+
}
|
|
28902
|
+
}
|
|
28903
|
+
/**
|
|
28904
|
+
* 生成完整的认证头(包含 x-signInfo)
|
|
28905
|
+
* @param options 服务器选项
|
|
28906
|
+
* @returns 完整的认证头
|
|
28907
|
+
*/
|
|
28908
|
+
async function generateCompleteHeaders(options) {
|
|
28909
|
+
const headers = {
|
|
28910
|
+
'Content-Type': 'application/json',
|
|
28911
|
+
};
|
|
28912
|
+
const OPENAPI_AK = options.OPENAPI_AK || process.env.LCAP_OPENAPI_AK;
|
|
28913
|
+
const OPENAPI_SK = options.OPENAPI_SK || process.env.LCAP_OPENAPI_SK;
|
|
28914
|
+
// 如果没有提供 ak 和 sk,返回基础 headers
|
|
28915
|
+
if (!OPENAPI_AK || !OPENAPI_SK) {
|
|
28916
|
+
throw new Error(`配置了 useOPENAPI,但没有提供 OPENAPI_AK 和 OPENAPI_SK:
|
|
28917
|
+
- 可取消配置 useOPENAPI
|
|
28918
|
+
- 在 nasl.config.json 中配置 OPENAPI_AK 和 OPENAPI_SK,或者在环境变量中配置 LCAP_OPENAPI_AK 和 LCAP_OPENAPI_SK`);
|
|
28919
|
+
}
|
|
28920
|
+
// 生成基础认证头
|
|
28921
|
+
const baseHeaders = generateBaseHeaders(OPENAPI_AK, OPENAPI_SK);
|
|
28922
|
+
Object.assign(headers, baseHeaders);
|
|
28923
|
+
// 获取 signInfo
|
|
28924
|
+
const signInfo = await fetchSignInfo(options, headers);
|
|
28925
|
+
if (signInfo) {
|
|
28926
|
+
headers['x-signInfo'] = signInfo;
|
|
28927
|
+
}
|
|
28928
|
+
return headers;
|
|
28929
|
+
}
|
|
28930
|
+
|
|
28931
|
+
/**
|
|
28932
|
+
* 创建 Axios 实例
|
|
28933
|
+
* @param options 服务器选项,包含认证信息
|
|
28934
|
+
* @returns Axios 实例
|
|
28935
|
+
*/
|
|
28936
|
+
async function createAxios(options) {
|
|
28937
|
+
// 如果需要鉴权,拼接 /openapi/v3/nasl;否则使用原始 URL
|
|
28938
|
+
const serverBaseURL = new URL(options.serverBaseURL).origin;
|
|
28939
|
+
const useOPENAPI = options.useOPENAPI || process.env.USE_LCAP_OPENAPI === 'true';
|
|
28940
|
+
const baseURL = useOPENAPI ? `${serverBaseURL}/openapi/v3/nasl` : `${serverBaseURL}/api/v1/nasl`;
|
|
28941
|
+
// 如果需要鉴权,生成完整的认证头;否则只使用基础 headers
|
|
28942
|
+
const headers = useOPENAPI ? await generateCompleteHeaders(options) : { 'Content-Type': 'application/json' };
|
|
28943
|
+
console.log('本次服务调用方为:', baseURL);
|
|
28944
|
+
const instance = axios.create({
|
|
28776
28945
|
baseURL,
|
|
28777
|
-
headers
|
|
28778
|
-
'Content-Type': 'application/json',
|
|
28779
|
-
},
|
|
28946
|
+
headers,
|
|
28780
28947
|
timeout: 120000,
|
|
28781
28948
|
});
|
|
28949
|
+
const oldPost = instance.post;
|
|
28950
|
+
instance.post = async (url, data, config) => {
|
|
28951
|
+
return oldPost(url, data, config).then((res) => {
|
|
28952
|
+
const data = res.data;
|
|
28953
|
+
if (data.code !== 200)
|
|
28954
|
+
throw new Error(JSON.stringify(data));
|
|
28955
|
+
return res;
|
|
28956
|
+
}).catch((err) => {
|
|
28957
|
+
// console.log(err.response ? err.response.data : err);
|
|
28958
|
+
if (err.response) {
|
|
28959
|
+
throw new Error(JSON.stringify(err.response.data));
|
|
28960
|
+
}
|
|
28961
|
+
else {
|
|
28962
|
+
throw err;
|
|
28963
|
+
}
|
|
28964
|
+
});
|
|
28965
|
+
};
|
|
28966
|
+
return instance;
|
|
28782
28967
|
}
|
|
28783
28968
|
|
|
28784
28969
|
/**
|
|
@@ -28788,13 +28973,11 @@ function createAxios(baseURL) {
|
|
|
28788
28973
|
async function compileApi(fullNaturalTS, options) {
|
|
28789
28974
|
// 这里需要调用实际的编译服务接口
|
|
28790
28975
|
// 示例实现:
|
|
28791
|
-
const axios = createAxios(options
|
|
28976
|
+
const axios = await createAxios(options);
|
|
28792
28977
|
const res = await axios.post(`/compile/tsx?ideVersion=${options.ideVersion}&needAnnotation=true`, fullNaturalTS, {
|
|
28793
28978
|
headers: { 'Content-Type': 'text/plain' },
|
|
28794
28979
|
});
|
|
28795
28980
|
const data = res.data;
|
|
28796
|
-
if (data.code !== 200)
|
|
28797
|
-
throw new Error(data.message);
|
|
28798
28981
|
const { bundle } = data.result;
|
|
28799
28982
|
const fileMap = bundle.frontendBundle.files;
|
|
28800
28983
|
const files = Object.keys(fileMap).map((key) => {
|
|
@@ -37667,10 +37850,7 @@ async function compile(entry, options) {
|
|
|
37667
37850
|
logger.info('正在调用编译服务...');
|
|
37668
37851
|
try {
|
|
37669
37852
|
const fullNaturalTS = composeToString(collectedFiles);
|
|
37670
|
-
const outputFiles = await compileApi(fullNaturalTS,
|
|
37671
|
-
serverBaseURL: config.serverBaseURL,
|
|
37672
|
-
ideVersion: config.ideVersion,
|
|
37673
|
-
});
|
|
37853
|
+
const outputFiles = await compileApi(fullNaturalTS, config);
|
|
37674
37854
|
logger.success('编译成功!');
|
|
37675
37855
|
// 写入输出文件
|
|
37676
37856
|
for (const file of outputFiles) {
|
|
@@ -37697,7 +37877,7 @@ async function tryCompile(entry, options) {
|
|
|
37697
37877
|
}
|
|
37698
37878
|
}
|
|
37699
37879
|
|
|
37700
|
-
var version = "0.1.
|
|
37880
|
+
var version = "0.1.17";
|
|
37701
37881
|
var pkg = {
|
|
37702
37882
|
version: version};
|
|
37703
37883
|
|