Skip to content

Commit

Permalink
feat: 支持postBucketInventory;优化d.ts (#190)
Browse files Browse the repository at this point in the history
* feat: 支持postBucketInventory;优化d.ts

* fix: 修复单测
  • Loading branch information
livehigh authored Jun 1, 2023
1 parent 5aa0c9f commit afc8200
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 31 deletions.
50 changes: 49 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@ function deleteBucketLogging() {
}

function putBucketInventory() {
var AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1);
cos.putBucketInventory(
{
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Expand Down Expand Up @@ -966,6 +965,54 @@ function putBucketInventory() {
);
}

function postBucketInventory() {
cos.postBucketInventory(
{
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
Id: 'inventory_test6',
InventoryConfiguration: {
Id: 'inventory_test6',
Destination: {
COSBucketDestination: {
Format: 'CSV',
AccountId: config.Uin,
Bucket: 'qcs::cos:' + config.Region + '::' + config.Bucket,
Prefix: 'inventory6',
Encryption: {
SSECOS: '',
},
},
},
Filter: {
Prefix: 'myPrefix',
// Period: {
// StartTime: new Date('2023-05-01').getTime()/1000,
// EndTime: new Date('2023-05-31').getTime()/1000,
// },
// And: {
// Prefix: 'myPrefix',
// Tag: [{ Key: 'test1', Value: '1'}, { Key: 'test2', Value: '2' }]
// }
},
IncludedObjectVersions: 'All',
OptionalFields: [
'Size',
'LastModifiedDate',
'ETag',
'StorageClass',
'IsMultipartUploaded',
'ReplicationStatus',
'Tag',
],
},
},
function (err, data) {
logger.log('postBucketInventory:', err || data);
},
);
}

function getBucketInventory() {
cos.getBucketInventory(
{
Expand Down Expand Up @@ -4673,6 +4720,7 @@ function postSnapshot() {
'getBucketLogging',
'deleteBucketLogging',
'putBucketInventory',
'postBucketInventory',
'getBucketInventory',
'deleteBucketInventory',
'listBucketInventory',
Expand Down
26 changes: 22 additions & 4 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -6948,7 +6948,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.4.17\",\"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 test/test.js server/sts.js\",\"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 --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\":{\"@xmldom/xmldom\":\"^0.8.6\"},\"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\",\"jest-localstorage-mock\":\"^2.4.26\",\"prettier\":\"2.8.8\",\"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.4.18\",\"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 test/test.js server/sts.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\":{\"@xmldom/xmldom\":\"^0.8.6\"},\"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\":\"2.8.8\",\"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 @@ -10007,7 +10007,7 @@ function getBucketLogging(params, callback) {
*/


function putBucketInventory(params, callback) {
function submitBucketInventory(method, params, callback) {
var InventoryConfiguration = util.clone(params['InventoryConfiguration']);

if (InventoryConfiguration.OptionalFields) {
Expand All @@ -10032,9 +10032,10 @@ function putBucketInventory(params, callback) {
var headers = params.Headers;
headers['Content-Type'] = 'application/xml';
headers['Content-MD5'] = util.b64(util.md5(xml));
var action = method === 'PUT' ? 'name/cos:PutBucketInventory' : 'name/cos:PostBucketInventory';
submitRequest.call(this, {
Action: 'name/cos:PutBucketInventory',
method: 'PUT',
Action: action,
method: method,
Bucket: params.Bucket,
Region: params.Region,
body: xml,
Expand All @@ -10058,6 +10059,22 @@ function putBucketInventory(params, callback) {
});
});
}
/**
* 创建一个清单任务
*/


function putBucketInventory(params, callback) {
return submitBucketInventory.call(this, 'PUT', params, callback);
}
/**
* 创建一个一次性清单任务 会立即执行
*/


function postBucketInventory(params, callback) {
return submitBucketInventory.call(this, 'POST', params, callback);
}
/**
* 获取 Bucket 的清单任务信息
* @param {Object} params 参数对象,必须
Expand Down Expand Up @@ -12527,6 +12544,7 @@ var API_MAP = {
getBucketLogging: getBucketLogging,
putBucketInventory: putBucketInventory,
// BucketInventory
postBucketInventory: postBucketInventory,
getBucketInventory: getBucketInventory,
listBucketInventory: listBucketInventory,
deleteBucketInventory: deleteBucketInventory,
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

54 changes: 44 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,27 +1010,30 @@ declare namespace COS {
BucketLoggingStatus: BucketLoggingStatus;
}

// putBucketInventory
/** putBucketInventory 接口参数 */
interface InventoryConfiguration {
interface BaseInventoryConfiguration {
/** 清单的名称,与请求参数中的 id 对应,可选 */
Id: string;
/** 清单是否启用的标识:如果设置为 true,清单功能将生效,如果设置为 false,将不生成任何清单,必选 */
IsEnabled: BooleanString;
/** 是否在清单中包含对象版本:如果设置为 All,清单中将会包含所有对象版本,并在清单中增加 VersionId,IsLatest,DeleteMarker 这几个字段,如果设置为 Current,则清单中不包含对象版本信息,必选 */
IncludedObjectVersions: 'All' | 'Current';
/** 筛选待分析对象。清单功能将分析符合 Filter 中设置的前缀的对象,可选 */
Filter?: {
/** 筛选待分析对象。清单功能将分析符合 Filter 中设置的前缀的对象,可选 */
Prefix?: Prefix;
/** 需要分析的对象的创建时间范围 */
Period?: {
StartTime?: number;
EndTime?: number;
};
/** 筛选待分析对象时,可以用对象标签(支持多个)作为过滤条件 */
Tag?: Tag[];
/** 筛选待分析对象时,如果同时需要前缀与对象标签条件,需要用 And 包装 */
And?: {
Prefix: Prefix;
Tag: Tag[];
};
};
/** 设置清单结果中应包含的分析项目,可选 */
OptionalFields?: string[];
/** 配置清单任务周期,必选 */
Schedule: {
/** 清单任务周期,可选项为按日或者按周,枚举值:Daily、Weekly,必选 */
Frequency: 'Daily' | 'Weekly';
};
/** 描述存放清单结果的信息,必选 */
Destination: {
/** 清单结果导出后存放的存储桶信息,必选 */
Expand All @@ -1051,6 +1054,19 @@ declare namespace COS {
};
};
}

// putBucketInventory
/** putBucketInventory 接口参数 */
interface InventoryConfiguration extends BaseInventoryConfiguration {
/** 清单是否启用的标识:如果设置为 true,清单功能将生效,如果设置为 false,将不生成任何清单,必选 */
IsEnabled: BooleanString;
/** 配置清单任务周期,必选 */
Schedule: {
/** 清单任务周期,可选项为按日或者按周,枚举值:Daily、Weekly,必选 */
Frequency: 'Daily' | 'Weekly';
};
}

interface PutBucketInventoryParams extends BucketParams {
/** 清单的名称,与请求参数中的 id 对应 */
Id: string;
Expand All @@ -1060,6 +1076,17 @@ declare namespace COS {
/** putBucketInventory 接口返回值 */
interface PutBucketInventoryResult extends GeneralResult {}

// postBucketInventory
/** postBucketInventory 接口参数 */
interface PostBucketInventoryParams extends BucketParams {
/** 清单的名称,与请求参数中的 id 对应 */
Id: string;
/** 包含清单任务的详细信息 */
InventoryConfiguration: BaseInventoryConfiguration;
}
/** postBucketInventory 接口返回值 */
interface PostBucketInventoryResult extends GeneralResult {}

// getBucketInventory
/** getBucketInventory 接口参数 */
interface GetBucketInventoryParams extends BucketParams {
Expand Down Expand Up @@ -2256,6 +2283,13 @@ declare class COS {
): void;
putBucketInventory(params: COS.PutBucketInventoryParams): Promise<COS.PutBucketInventoryResult>;

/** 创建/编辑 Bucket 一次性清单任务 @see https://cloud.tencent.com/document/product/436/83382 */
postBucketInventory(
params: COS.PostBucketInventoryParams,
callback: (err: COS.CosError, data: COS.PostBucketInventoryResult) => void,
): void;
postBucketInventory(params: COS.PostBucketInventoryParams): Promise<COS.PostBucketInventoryResult>;

/** 获取 Bucket 的清单任务信息 @see https://cloud.tencent.com/document/product/436/33705 */
getBucketInventory(
params: COS.GetBucketInventoryParams,
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
collectCoverage: true, // 是否显示覆盖率报告
// 告诉 jest 哪些文件需要经过单元测试测试
collectCoverageFrom: ['**/src/*.js', '!**/src/tracker.js', '!**/src/session.js', '!**/src/async.js', '!**/src/util.js'],
collectCoverageFrom: ['**/src/*.js'],
coverageThreshold: {
global: {
statements: 90, // 保证每个语句都执行了
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "1.4.17",
"version": "1.4.18",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "dist/cos-js-sdk-v5.js",
"types": "index.d.ts",
Expand All @@ -10,7 +10,7 @@
"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 --coverage"
"test": "jest --runInBand --coverage"
},
"repository": {
"type": "git",
Expand All @@ -36,7 +36,6 @@
"express": "^4.16.4",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jest-localstorage-mock": "^2.4.26",
"prettier": "2.8.8",
"qcloud-cos-sts": "^3.0.2",
"request": "^2.87.0",
Expand Down
23 changes: 20 additions & 3 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ function getBucketLogging(params, callback) {
* @return {Object} err 请求失败的错误,如果请求成功,则为空。https://cloud.tencent.com/document/product/436/7730
* @return {Object} data 返回数据
*/
function putBucketInventory(params, callback) {
function submitBucketInventory(method, params, callback) {
var InventoryConfiguration = util.clone(params['InventoryConfiguration']);

if (InventoryConfiguration.OptionalFields) {
Expand Down Expand Up @@ -1607,11 +1607,13 @@ function putBucketInventory(params, callback) {
headers['Content-Type'] = 'application/xml';
headers['Content-MD5'] = util.b64(util.md5(xml));

var action = method === 'PUT' ? 'name/cos:PutBucketInventory' : 'name/cos:PostBucketInventory';

submitRequest.call(
this,
{
Action: 'name/cos:PutBucketInventory',
method: 'PUT',
Action: action,
method,
Bucket: params.Bucket,
Region: params.Region,
body: xml,
Expand All @@ -1635,6 +1637,20 @@ function putBucketInventory(params, callback) {
);
}

/**
* 创建一个清单任务
*/
function putBucketInventory(params, callback) {
return submitBucketInventory.call(this, 'PUT', params, callback);
}

/**
* 创建一个一次性清单任务 会立即执行
*/
function postBucketInventory(params, callback) {
return submitBucketInventory.call(this, 'POST', params, callback);
}

/**
* 获取 Bucket 的清单任务信息
* @param {Object} params 参数对象,必须
Expand Down Expand Up @@ -4134,6 +4150,7 @@ var API_MAP = {
putBucketLogging: putBucketLogging, // BucketLogging
getBucketLogging: getBucketLogging,
putBucketInventory: putBucketInventory, // BucketInventory
postBucketInventory: postBucketInventory,
getBucketInventory: getBucketInventory,
listBucketInventory: listBucketInventory,
deleteBucketInventory: deleteBucketInventory,
Expand Down
Loading

0 comments on commit afc8200

Please sign in to comment.