Skip to content

Commit

Permalink
feat: 丰富上报参数 (#223)
Browse files Browse the repository at this point in the history
* feat: 丰富上报参数
  • Loading branch information
livehigh authored Dec 19, 2024
1 parent bf87152 commit cafc412
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 21 deletions.
87 changes: 69 additions & 18 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,36 @@ module.exports = {

/***/ }),

/***/ "./node_modules/fast-xml-parser/src/ignoreAttributes.js":
/*!**************************************************************!*\
!*** ./node_modules/fast-xml-parser/src/ignoreAttributes.js ***!
\**************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {

function getIgnoreAttributesFn(ignoreAttributes) {
if (typeof ignoreAttributes === 'function') {
return ignoreAttributes
}
if (Array.isArray(ignoreAttributes)) {
return (attrName) => {
for (const pattern of ignoreAttributes) {
if (typeof pattern === 'string' && attrName === pattern) {
return true
}
if (pattern instanceof RegExp && pattern.test(attrName)) {
return true
}
}
}
}
return () => false
}

module.exports = getIgnoreAttributesFn

/***/ }),

/***/ "./node_modules/fast-xml-parser/src/util.js":
/*!**************************************************!*\
!*** ./node_modules/fast-xml-parser/src/util.js ***!
Expand Down Expand Up @@ -2019,6 +2049,7 @@ function getPositionFromMatch(match) {

//parse Empty Node as self closing node
const buildFromOrderedJs = __webpack_require__(/*! ./orderedJs2Xml */ "./node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js");
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")

const defaultOptions = {
attributeNamePrefix: '@_',
Expand Down Expand Up @@ -2056,11 +2087,12 @@ const defaultOptions = {

function Builder(options) {
this.options = Object.assign({}, defaultOptions, options);
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
this.isAttribute = function(/*a*/) {
return false;
};
} else {
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
this.attrPrefixLen = this.options.attributeNamePrefix.length;
this.isAttribute = isAttribute;
}
Expand Down Expand Up @@ -2089,13 +2121,14 @@ Builder.prototype.build = function(jObj) {
[this.options.arrayNodeName] : jObj
}
}
return this.j2x(jObj, 0).val;
return this.j2x(jObj, 0, []).val;
}
};

Builder.prototype.j2x = function(jObj, level) {
Builder.prototype.j2x = function(jObj, level, ajPath) {
let attrStr = '';
let val = '';
const jPath = ajPath.join('.')
for (let key in jObj) {
if(!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
if (typeof jObj[key] === 'undefined') {
Expand All @@ -2118,9 +2151,9 @@ Builder.prototype.j2x = function(jObj, level) {
} else if (typeof jObj[key] !== 'object') {
//premitive type
const attr = this.isAttribute(key);
if (attr) {
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
}else {
} else if (!attr) {
//tag value
if (key === this.options.textNodeName) {
let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
Expand All @@ -2133,6 +2166,7 @@ Builder.prototype.j2x = function(jObj, level) {
//repeated nodes
const arrLen = jObj[key].length;
let listTagVal = "";
let listTagAttr = "";
for (let j = 0; j < arrLen; j++) {
const item = jObj[key][j];
if (typeof item === 'undefined') {
Expand All @@ -2142,17 +2176,27 @@ Builder.prototype.j2x = function(jObj, level) {
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
} else if (typeof item === 'object') {
if(this.options.oneListGroup ){
listTagVal += this.j2x(item, level + 1).val;
if(this.options.oneListGroup){
const result = this.j2x(item, level + 1, ajPath.concat(key));
listTagVal += result.val;
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
listTagAttr += result.attrStr
}
}else{
listTagVal += this.processTextOrObjNode(item, key, level)
listTagVal += this.processTextOrObjNode(item, key, level, ajPath)
}
} else {
listTagVal += this.buildTextValNode(item, key, '', level);
if (this.options.oneListGroup) {
let textValue = this.options.tagValueProcessor(key, item);
textValue = this.replaceEntitiesValue(textValue);
listTagVal += textValue;
} else {
listTagVal += this.buildTextValNode(item, key, '', level);
}
}
}
if(this.options.oneListGroup){
listTagVal = this.buildObjectNode(listTagVal, key, '', level);
listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
}
val += listTagVal;
} else {
Expand All @@ -2164,7 +2208,7 @@ Builder.prototype.j2x = function(jObj, level) {
attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
}
} else {
val += this.processTextOrObjNode(jObj[key], key, level)
val += this.processTextOrObjNode(jObj[key], key, level, ajPath)
}
}
}
Expand All @@ -2179,8 +2223,8 @@ Builder.prototype.buildAttrPairStr = function(attrName, val){
} else return ' ' + attrName + '="' + val + '"';
}

function processTextOrObjNode (object, key, level) {
const result = this.j2x(object, level + 1);
function processTextOrObjNode (object, key, level, ajPath) {
const result = this.j2x(object, level + 1, ajPath.concat(key));
if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
} else {
Expand Down Expand Up @@ -2672,6 +2716,7 @@ const util = __webpack_require__(/*! ../util */ "./node_modules/fast-xml-parser/
const xmlNode = __webpack_require__(/*! ./xmlNode */ "./node_modules/fast-xml-parser/src/xmlparser/xmlNode.js");
const readDocType = __webpack_require__(/*! ./DocTypeReader */ "./node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js");
const toNumber = __webpack_require__(/*! strnum */ "./node_modules/strnum/strnum.js");
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")

// const regx =
// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
Expand Down Expand Up @@ -2720,6 +2765,7 @@ class OrderedObjParser{
this.readStopNodeData = readStopNodeData;
this.saveTextToParentTag = saveTextToParentTag;
this.addChild = addChild;
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
}

}
Expand Down Expand Up @@ -2792,7 +2838,7 @@ function resolveNameSpace(tagname) {
const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');

function buildAttributesMap(attrStr, jPath, tagName) {
if (!this.options.ignoreAttributes && typeof attrStr === 'string') {
if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
// attrStr = attrStr.replace(/\r?\n/g, ' ');
//attrStr = attrStr || attrStr.trim();

Expand All @@ -2801,6 +2847,9 @@ function buildAttributesMap(attrStr, jPath, tagName) {
const attrs = {};
for (let i = 0; i < len; i++) {
const attrName = this.resolveNameSpace(matches[i][1]);
if (this.ignoreAttributesFn(attrName, jPath)) {
continue
}
let oldVal = matches[i][4];
let aName = this.options.attributeNamePrefix + attrName;
if (attrName.length) {
Expand Down Expand Up @@ -3883,7 +3932,7 @@ module.exports = function(module) {
/*! exports provided: name, version, description, main, types, scripts, repository, keywords, author, license, bugs, homepage, dependencies, devDependencies, default */
/***/ (function(module) {

module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.8.6\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"prettier\":\"prettier --write src demo/demo.js demo/CIDemos/*.js test/test.js server/sts.js lib/request.js index.d.ts\",\"server\":\"node server/sts.js\",\"dev\":\"cross-env NODE_ENV=development webpack -w --mode=development\",\"build\":\"cross-env NODE_ENV=production webpack --mode=production\",\"cos-auth.min.js\":\"uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m\",\"test\":\"jest --runInBand --coverage\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/tencentyun/cos-js-sdk-v5.git\"},\"keywords\":[],\"author\":\"carsonxu\",\"license\":\"ISC\",\"bugs\":{\"url\":\"https://github.com/tencentyun/cos-js-sdk-v5/issues\"},\"homepage\":\"https://github.com/tencentyun/cos-js-sdk-v5#readme\",\"dependencies\":{\"fast-xml-parser\":\"^4.4.0\"},\"devDependencies\":{\"@babel/core\":\"7.17.9\",\"@babel/plugin-transform-runtime\":\"7.18.10\",\"@babel/preset-env\":\"7.16.11\",\"babel-loader\":\"8.2.5\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^5.2.0\",\"express\":\"^4.16.4\",\"jest\":\"^29.3.1\",\"jest-environment-jsdom\":\"^29.3.1\",\"prettier\":\"^3.0.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"uglifyjs\":\"^2.4.11\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.8.7\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"prettier\":\"prettier --write src demo/demo.js demo/CIDemos/*.js test/test.js server/sts.js lib/request.js index.d.ts\",\"server\":\"node server/sts.js\",\"dev\":\"cross-env NODE_ENV=development webpack -w --mode=development\",\"build\":\"cross-env NODE_ENV=production webpack --mode=production\",\"cos-auth.min.js\":\"uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m\",\"test\":\"jest --runInBand --coverage\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/tencentyun/cos-js-sdk-v5.git\"},\"keywords\":[],\"author\":\"carsonxu\",\"license\":\"ISC\",\"bugs\":{\"url\":\"https://github.com/tencentyun/cos-js-sdk-v5/issues\"},\"homepage\":\"https://github.com/tencentyun/cos-js-sdk-v5#readme\",\"dependencies\":{\"fast-xml-parser\":\"4.5.0\"},\"devDependencies\":{\"@babel/core\":\"7.17.9\",\"@babel/plugin-transform-runtime\":\"7.18.10\",\"@babel/preset-env\":\"7.16.11\",\"babel-loader\":\"8.2.5\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^5.2.0\",\"express\":\"^4.16.4\",\"jest\":\"^29.3.1\",\"jest-environment-jsdom\":\"^29.3.1\",\"prettier\":\"^3.0.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"uglifyjs\":\"^2.4.11\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");

/***/ }),

Expand Down Expand Up @@ -9135,6 +9184,8 @@ function _submitRequest(params, callback) {
params.AuthData.ClientIP && (opt.headers['clientIP'] = params.AuthData.ClientIP);
params.AuthData.ClientUA && (opt.headers['clientUA'] = params.AuthData.ClientUA);
params.AuthData.SecurityToken && (opt.headers[token] = params.AuthData.SecurityToken);
params.Action && (opt.action = params.Action);
opt.key = params.Key || params.ResourceKey;

// 清理 undefined 和 null 字段
opt.headers && (opt.headers = util.clearKey(opt.headers));
Expand Down Expand Up @@ -10394,9 +10445,9 @@ module.exports = Tracker;
/* WEBPACK VAR INJECTION */(function(process) {

var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var md5 = __webpack_require__(/*! ../lib/md5 */ "./lib/md5.js");
var CryptoJS = __webpack_require__(/*! ../lib/crypto */ "./lib/crypto.js");
var _require = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/src/fxp.js"),
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "1.8.6",
"version": "1.8.7",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "dist/cos-js-sdk-v5.js",
"types": "index.d.ts",
Expand All @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/tencentyun/cos-js-sdk-v5#readme",
"dependencies": {
"fast-xml-parser": "^4.4.0"
"fast-xml-parser": "4.5.0"
},
"devDependencies": {
"@babel/core": "7.17.9",
Expand Down
2 changes: 2 additions & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4153,6 +4153,8 @@ function _submitRequest(params, callback) {
params.AuthData.ClientIP && (opt.headers['clientIP'] = params.AuthData.ClientIP);
params.AuthData.ClientUA && (opt.headers['clientUA'] = params.AuthData.ClientUA);
params.AuthData.SecurityToken && (opt.headers[token] = params.AuthData.SecurityToken);
params.Action && (opt.action = params.Action);
opt.key = params.Key || params.ResourceKey;

// 清理 undefined 和 null 字段
opt.headers && (opt.headers = util.clearKey(opt.headers));
Expand Down

0 comments on commit cafc412

Please sign in to comment.