tencentcloud-sdk-nodejs-common
Advanced tools
Comparing version
{ | ||
"name": "tencentcloud-sdk-nodejs-common", | ||
"version": "4.0.1053", | ||
"description": "Tencent Cloud API NODEJS SDK", | ||
"main": "tencentcloud/index.js", | ||
"version": "4.1.0", | ||
"description": "腾讯云 API NODEJS SDK", | ||
"main": "./tencentcloud/index.js", | ||
"module": "./es/index.js", | ||
"types": "./tencentcloud/index.d.ts", | ||
"scripts": { | ||
"test": "mocha -t 10000", | ||
"build": "tsc", | ||
"prettier": "prettier --config prettier.config.js --write 'src/**/*.{tsx,ts,jsx,js,css,json,vue}'" | ||
"build": "concurrently 'npm:build:cjs' 'npm:build:es'", | ||
"build:cjs": "tsc -p tsconfig.json", | ||
"build:es": "tsc -p tsconfig.es.json", | ||
"prettier": "prettier --config prettier.config.js --write 'src/**/*.{tsx,ts,jsx,js,css,json,vue}'", | ||
"clean": "rimraf tencentcloud es" | ||
}, | ||
@@ -14,2 +19,6 @@ "engines": { | ||
}, | ||
"files": [ | ||
"tencentcloud", | ||
"es" | ||
], | ||
"keywords": [ | ||
@@ -44,4 +53,2 @@ "tencentcloudapi", | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.2", | ||
"eslint-plugin-react": "^7.17.0", | ||
"@types/form-data": "^2.5.0", | ||
@@ -54,9 +61,13 @@ "@types/json-bigint": "^1.0.1", | ||
"@typescript-eslint/parser": "^2.34.0", | ||
"babel-eslint": "^10.0.2", | ||
"chai": "^4.2.0", | ||
"concurrently": "^6.5.1", | ||
"eslint": "^6.8.0", | ||
"mocha": "^8.1.1", | ||
"eslint-plugin-react": "^7.17.0", | ||
"mocha": "^8.4.0", | ||
"prettier": "^2.3.0", | ||
"rimraf": "^5.0.10", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.7" | ||
} | ||
} | ||
} |
@@ -55,6 +55,20 @@ # 简介 | ||
1. 前往 [GitHub 仓库](https://github.com/tencentcloud/tencentcloud-sdk-nodejs) 或者 [Gitee 仓库](https://gitee.com/tencentcloud/tencentcloud-sdk-nodejs) 下载源码压缩包。 | ||
2. 解压源码包到您项目合适的位置,例如 `sdk/tencentcloud-sdk-nodejs`。 | ||
3. 执行 `npm install ./sdk/tencentcloud-sdk-nodejs`。 | ||
4. 使用 `require("tencentcloud-sdk-nodejs")` 的方式引入 SDK,具体可参考示例。 | ||
1. clone 代码到本地: | ||
``` | ||
git clone https://github.com/tencentcloud/tencentcloud-sdk-nodejs | ||
# 或者 | ||
git clone https://gitee.com/tencentcloud/tencentcloud-sdk-nodejs | ||
``` | ||
2. 在项目根目录执行以下命令完成构建: | ||
``` | ||
npm install && npm run build | ||
``` | ||
3. 打包 NPM 压缩文件,例如 `tencentcloud-sdk-nodejs-4.0.0.tgz` | ||
``` | ||
npm pack | ||
``` | ||
4. 安装包到你的项目里: | ||
``` | ||
npm install /path/to/tencentcloud-sdk-nodejs/tencentcloud-sdk-nodejs-4.0.0.tgz | ||
``` | ||
@@ -61,0 +75,0 @@ # 示例 |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbstractClient = void 0; | ||
const tslib_1 = require("tslib"); | ||
const sdk_version_1 = require("./sdk_version"); | ||
const interface_1 = require("./interface"); | ||
const sign_1 = require("./sign"); | ||
const sign_1 = tslib_1.__importDefault(require("./sign")); | ||
const http_connection_1 = require("./http/http_connection"); | ||
const tencent_cloud_sdk_exception_1 = require("./exception/tencent_cloud_sdk_exception"); | ||
const tencent_cloud_sdk_exception_1 = tslib_1.__importDefault(require("./exception/tencent_cloud_sdk_exception")); | ||
const sse_response_model_1 = require("./sse_response_model"); | ||
@@ -10,0 +11,0 @@ const uuid_1 = require("uuid"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fetch_1 = require("./http/fetch"); | ||
const tslib_1 = require("tslib"); | ||
const fetch_1 = tslib_1.__importDefault(require("./http/fetch")); | ||
const META_URL = "http://metadata.tencentyun.com/latest/meta-data/"; | ||
@@ -5,0 +6,0 @@ const ROLE_URL = META_URL + "cam/security-credentials/"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const node_fetch_1 = require("node-fetch"); | ||
const HttpsProxyAgent = require("https-proxy-agent"); | ||
const tslib_1 = require("tslib"); | ||
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch")); | ||
const https_proxy_agent_1 = tslib_1.__importDefault(require("https-proxy-agent")); | ||
function default_1(url, options) { | ||
@@ -9,3 +10,3 @@ const instanceOptions = options || {}; | ||
if (!options.agent && proxy) { | ||
instanceOptions.agent = new HttpsProxyAgent(proxy); | ||
instanceOptions.agent = new https_proxy_agent_1.default(proxy); | ||
} | ||
@@ -12,0 +13,0 @@ return node_fetch_1.default(url, instanceOptions); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HttpConnection = void 0; | ||
const QueryString = require("querystring"); | ||
const tslib_1 = require("tslib"); | ||
const querystring_1 = tslib_1.__importDefault(require("querystring")); | ||
const url_1 = require("url"); | ||
const isStream = require("is-stream"); | ||
const getStream = require("get-stream"); | ||
const FormData = require("form-data"); | ||
const sign_1 = require("../sign"); | ||
const fetch_1 = require("./fetch"); | ||
const JSONBigInt = require("json-bigint"); | ||
const JSONbigNative = JSONBigInt({ useNativeBigInt: true }); | ||
const is_stream_1 = tslib_1.__importDefault(require("is-stream")); | ||
const get_stream_1 = tslib_1.__importDefault(require("get-stream")); | ||
const form_data_1 = tslib_1.__importDefault(require("form-data")); | ||
const sign_1 = tslib_1.__importDefault(require("../sign")); | ||
const fetch_1 = tslib_1.__importDefault(require("./fetch")); | ||
const json_bigint_1 = tslib_1.__importDefault(require("json-bigint")); | ||
const JSONbigNative = json_bigint_1.default({ useNativeBigInt: true }); | ||
/** | ||
@@ -27,7 +28,7 @@ * @inner | ||
if (method === "GET") { | ||
url += "?" + QueryString.stringify(data); | ||
url += "?" + querystring_1.default.stringify(data); | ||
} | ||
else { | ||
config.headers["Content-Type"] = "application/x-www-form-urlencoded"; | ||
config.body = QueryString.stringify(data); | ||
config.body = querystring_1.default.stringify(data); | ||
} | ||
@@ -49,3 +50,3 @@ return await fetch_1.default(url, config); | ||
data = mergeData(data); | ||
url += "?" + QueryString.stringify(data); | ||
url += "?" + querystring_1.default.stringify(data); | ||
} | ||
@@ -92,3 +93,3 @@ if (method === "POST") { | ||
if (method === "POST" && multipart) { | ||
form = new FormData(); | ||
form = new form_data_1.default(); | ||
for (const key in data) { | ||
@@ -119,4 +120,4 @@ form.append(key, data[key]); | ||
for (const key in data) { | ||
if (isStream(data[key])) { | ||
data[key] = await getStream.buffer(data[key]); | ||
if (is_stream_1.default(data[key])) { | ||
data[key] = await get_stream_1.default.buffer(data[key]); | ||
} | ||
@@ -165,3 +166,3 @@ } | ||
function isObject(x) { | ||
return typeof x === "object" && !isArray(x) && !isStream(x) && !isBuffer(x) && x !== null; | ||
return typeof x === "object" && !isArray(x) && !is_stream_1.default(x) && !isBuffer(x) && x !== null; | ||
} | ||
@@ -168,0 +169,0 @@ function isNull(x) { |
@@ -1,1 +0,1 @@ | ||
export declare const sdkVersion = "4.0.1053"; | ||
export declare const sdkVersion = "4.1.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sdkVersion = void 0; | ||
exports.sdkVersion = "4.0.1053"; | ||
exports.sdkVersion = "4.1.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tencent_cloud_sdk_exception_1 = require("./exception/tencent_cloud_sdk_exception"); | ||
const crypto = require("crypto"); | ||
const tslib_1 = require("tslib"); | ||
const tencent_cloud_sdk_exception_1 = tslib_1.__importDefault(require("./exception/tencent_cloud_sdk_exception")); | ||
const crypto = tslib_1.__importStar(require("crypto")); | ||
const url_1 = require("url"); | ||
const JSONBigInt = require("json-bigint"); | ||
const JSONbigNative = JSONBigInt({ useNativeBigInt: true }); | ||
const json_bigint_1 = tslib_1.__importDefault(require("json-bigint")); | ||
const JSONbigNative = json_bigint_1.default({ useNativeBigInt: true }); | ||
/** | ||
@@ -9,0 +10,0 @@ * @inner |
@@ -14,2 +14,3 @@ /// <reference types="node" /> | ||
private stream; | ||
private readline; | ||
private eventSource; | ||
@@ -16,0 +17,0 @@ constructor(stream: NodeJS.ReadableStream); |
@@ -5,2 +5,3 @@ "use strict"; | ||
const events_1 = require("events"); | ||
const readline_1 = require("readline"); | ||
class SSEEventEmitter extends events_1.EventEmitter { | ||
@@ -11,2 +12,6 @@ } | ||
this.stream = stream; | ||
this.readline = readline_1.createInterface({ | ||
input: stream, | ||
crlfDelay: Infinity, | ||
}); | ||
this.eventSource = new SSEEventEmitter(); | ||
@@ -19,13 +24,16 @@ this.init(); | ||
init() { | ||
const { stream, eventSource } = this; | ||
stream.on("data", (chunk) => { | ||
if (chunk !== null) { | ||
const messages = chunk.toString().split("\n\n"); | ||
for (let i = 0; i < messages.length; i++) { | ||
if (messages[i].length > 0) { | ||
eventSource.emit("message", this.parseSSEMessage(messages[i])); | ||
} | ||
} | ||
const { stream, readline, eventSource } = this; | ||
let lines = []; | ||
readline.on("line", (line) => { | ||
if (line) { | ||
lines.push(line); | ||
return; | ||
} | ||
eventSource.emit("message", this.parseSSEMessage(lines.splice(0))); | ||
}); | ||
readline.on("close", () => { | ||
if (lines.length > 0) { | ||
eventSource.emit("message", this.parseSSEMessage(lines.splice(0))); | ||
} | ||
}); | ||
stream.on("close", () => { | ||
@@ -41,3 +49,3 @@ eventSource.emit("close"); | ||
*/ | ||
parseSSEMessage(chunk) { | ||
parseSSEMessage(lines) { | ||
const message = { | ||
@@ -49,3 +57,2 @@ data: "", | ||
}; | ||
const lines = chunk.split("\n"); | ||
for (let i = 0; i < lines.length; i++) { | ||
@@ -89,14 +96,15 @@ const line = lines[i]; | ||
async *[Symbol.asyncIterator]() { | ||
for await (const chunk of this.stream) { | ||
if (chunk !== null) { | ||
const messages = chunk.toString().split("\n\n"); | ||
for (let i = 0; i < messages.length; i++) { | ||
if (messages[i].length > 0) { | ||
yield this.parseSSEMessage(messages[i]); | ||
} | ||
} | ||
let lines = []; | ||
for await (const line of this.readline) { | ||
if (line) { | ||
lines.push(line); | ||
continue; | ||
} | ||
yield this.parseSSEMessage(lines.splice(0)); | ||
} | ||
if (lines.length > 0) { | ||
yield this.parseSSEMessage(lines.splice(0)); | ||
} | ||
} | ||
} | ||
exports.SSEResponseModel = SSEResponseModel; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
196
7.69%81386
-8.3%17
13.33%39
-11.36%1816
-19.57%2
100%7
600%