"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tencentcloud = require("tencentcloud-sdk-nodejs");
const actionName = require("../constants/actionName");
const { Client, Models } = tencentcloud.tcb.v20180608;
const { Credential, ClientProfile, HttpProfile } = tencentcloud.common;
const actionMapping = {
[actionName.InvokeFunction]: 'functions',
[actionName.GetUploadFileUrl]: 'storage',
[actionName.GetDownloadUrls]: 'storage',
[actionName.DeleteFiles]: 'storage',
[actionName.CreateDocument]: 'database',
[actionName.DeleteDocument]: 'database',
[actionName.DescribeDocument]: 'database',
[actionName.ModifyDocument]: 'database',
[actionName.CreateCollection]: 'database'
};
function cloudApiRequest(args) {
const { config, params, action } = args;
Iif (!actionName[action]) {
throw new Error(`invalid action: ${action}`);
}
let cred = new Credential(config.secretId, config.secretKey);
let httpProfile = new HttpProfile();
httpProfile.endpoint = "tcb.tencentcloudapi.com";
httpProfile.reqMethod = "POST";
let clientProfile = new ClientProfile();
clientProfile.httpProfile = httpProfile;
let client = new Client(cred, "ap-shanghai", clientProfile);
return new Promise((resolve, reject) => {
let req = new Models[`${action}Request`]();
req.deserialize(Object.assign({}, params, { CommParam: {
EnvName: config.envName,
Module: actionMapping[action]
} }));
client[action](req, function (errMsg, response) {
Iif (errMsg) {
reject(errMsg);
return;
}
resolve(response);
});
});
}
exports.default = cloudApiRequest;
|