@apm-insight-web/upload-sourcemaps
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -8,8 +8,10 @@ import { Command } from 'clipanion'; | ||
release?: string; | ||
appSecret: string; | ||
appKey: string; | ||
} | ||
export declare class UploadSourcemapsCommand extends Command { | ||
static paths: never[][]; | ||
static upload({ paths, app_id, host, env, release }: UploadOptions): Promise<void>; | ||
static upload({ paths, app_id, host, env, release, appSecret, appKey, }: UploadOptions): Promise<void>; | ||
static getPath(p: string): string; | ||
static uploadDir({ dir, app_id, host, env, release, }: { | ||
static uploadDir({ dir, app_id, host, env, release, appSecret, appKey, }: { | ||
dir: string; | ||
@@ -20,4 +22,6 @@ app_id: string; | ||
release: string; | ||
appSecret: string; | ||
appKey: string; | ||
}): Promise<void>; | ||
static uploadFile({ filePath, mapURL, app_id, host, release, env, }: { | ||
static uploadFile({ filePath, mapURL, app_id, host, release, env, appSecret, appKey, }: { | ||
filePath: string; | ||
@@ -29,2 +33,4 @@ mapURL: string; | ||
env: string; | ||
appSecret: string; | ||
appKey: string; | ||
}): Promise<void>; | ||
@@ -36,2 +42,4 @@ host?: string; | ||
_paths: string[]; | ||
appSecret: string; | ||
appKey: string; | ||
execute(): Promise<void>; | ||
@@ -38,0 +46,0 @@ uploadDirs(): Promise<void>; |
@@ -9,7 +9,8 @@ "use strict"; | ||
const util_1 = require("util"); | ||
const axios_1 = (0, tslib_1.__importDefault)(require("axios")); | ||
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk")); | ||
const clipanion_1 = require("clipanion"); | ||
const node_fetch_1 = (0, tslib_1.__importDefault)(require("node-fetch")); | ||
const URI = '/apmplus_api/eue/webpro/js/sourcemap/upload'; | ||
const HOST = 'apminsight.bytedance.net'; | ||
const md5_1 = require("ts-md5/dist/md5"); | ||
const URI = '/apmplus_api/eue/guest/webpro/sourcemap/upload'; | ||
const HOST = 'console.volcengine.com'; | ||
const DEFAULT_RELEASE = ''; | ||
@@ -37,7 +38,9 @@ const DEFAULT_ENV = 'production'; | ||
this._paths = clipanion_1.Option.Array(`--paths`); | ||
this.appSecret = clipanion_1.Option.String(`--app_secret`); | ||
this.appKey = clipanion_1.Option.String(`--app_key`); | ||
} | ||
static upload({ paths, app_id, host = HOST, env = DEFAULT_ENV, release = DEFAULT_RELEASE }) { | ||
static upload({ paths, app_id, host = HOST, env = DEFAULT_ENV, release = DEFAULT_RELEASE, appSecret, appKey, }) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
for (const dir of paths) { | ||
yield this.uploadDir({ dir: this.getPath(dir), app_id, host, env, release }); | ||
yield this.uploadDir({ dir: this.getPath(dir), app_id, host, env, release, appSecret, appKey }); | ||
} | ||
@@ -54,3 +57,3 @@ }); | ||
} | ||
static uploadDir({ dir, app_id, host, env, release, }) { | ||
static uploadDir({ dir, app_id, host, env, release, appSecret, appKey, }) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
@@ -61,3 +64,3 @@ const files = yield readdirAsync(dir); | ||
const filePath = path_1.default.join(this.getPath(dir), fileName); | ||
yield this.uploadFile({ mapURL: fileName, filePath: filePath, app_id, host, env, release }); | ||
yield this.uploadFile({ mapURL: fileName, filePath: filePath, app_id, host, env, release, appSecret, appKey }); | ||
} | ||
@@ -67,23 +70,29 @@ } | ||
} | ||
static uploadFile({ filePath, mapURL, app_id, host, release, env, }) { | ||
static uploadFile({ filePath, mapURL, app_id, host, release, env, appSecret, appKey, }) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
const Timestamp = `${Date.now()}`; | ||
const md5Token = new md5_1.Md5().appendStr(Timestamp).appendStr(appSecret).end().toString(); | ||
const URL = `https://${host}${URI}`; | ||
try { | ||
const res = yield (0, node_fetch_1.default)(URL, { | ||
method: 'post', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
'X-OpenApi-Timestamp': Timestamp, | ||
'X-OpenApi-AppID': appKey, | ||
'x-app-ids': app_id, | ||
'X-OpenApi-Token': md5Token, | ||
}; | ||
const body = JSON.stringify({ | ||
common: { | ||
aid: Number(app_id), | ||
site_type: 'web', | ||
env, | ||
}, | ||
body: JSON.stringify({ | ||
common: { | ||
aid: Number(app_id), | ||
site_type: 'web', | ||
env, | ||
}, | ||
js_filename: mapURL.split('.map')[0], | ||
sourcemap: fs_1.default.readFileSync(filePath).toString(), | ||
release, | ||
}), | ||
js_filename: mapURL.split('.map')[0], | ||
sourcemap: fs_1.default.readFileSync(filePath).toString(), | ||
release, | ||
}); | ||
const json = yield res.json(); | ||
const res = yield axios_1.default.post(URL, body, { | ||
headers, | ||
}); | ||
const json = yield res.data; | ||
if (json.error_no !== 0) { | ||
@@ -113,2 +122,4 @@ consoleReporter.error(json.error_msg || json.err_detail); | ||
env: (_c = this.env) !== null && _c !== void 0 ? _c : DEFAULT_ENV, | ||
appSecret: this.appSecret, | ||
appKey: this.appKey, | ||
}); | ||
@@ -115,0 +126,0 @@ }); |
{ | ||
"name": "@apm-insight-web/upload-sourcemaps", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "dist/index.js", | ||
@@ -14,6 +14,7 @@ "license": "MIT", | ||
"dependencies": { | ||
"axios": "^0.27.2", | ||
"chalk": "^4.1.2", | ||
"clipanion": "^3.0.1", | ||
"form-data": "^4.0.0", | ||
"node-fetch": "^2.6.1" | ||
"ts-md5": "^1.2.11" | ||
}, | ||
@@ -25,3 +26,3 @@ "noBundle": true, | ||
}, | ||
"gitHead": "62c3a61206f915f0a2c73f64e1816d2a175fe2de" | ||
"gitHead": "0469e0a521a56a77c8760d250b33929eb043fe20" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13677
202
5
+ Addedaxios@^0.27.2
+ Addedts-md5@^1.2.11
+ Addedaxios@0.27.2(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedts-md5@1.3.1(transitive)
- Removednode-fetch@^2.6.1
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)