diff --git a/example/serverless.yml b/example/serverless.yml index d2da5a5..db8ef05 100644 --- a/example/serverless.yml +++ b/example/serverless.yml @@ -1,6 +1,6 @@ app: appDemo stage: dev -component: nextjs +component: nextjs@dev name: nextjsDemo inputs: diff --git a/src/package.json b/src/package.json index 7b66920..c50b8dc 100644 --- a/src/package.json +++ b/src/package.json @@ -2,7 +2,7 @@ "dependencies": { "adm-zip": "^0.4.16", "download": "^8.0.0", - "tencent-component-toolkit": "^1.20.10", + "tencent-component-toolkit": "^2.0.6", "type": "^2.1.0" } } diff --git a/src/serverless.js b/src/serverless.js index 27da950..6b4b37c 100644 --- a/src/serverless.js +++ b/src/serverless.js @@ -1,6 +1,6 @@ const { Component } = require('@serverless/core') const { Scf, Apigw, Cns, Cam, Metrics, Cos, Cdn } = require('tencent-component-toolkit') -const { TypeError } = require('tencent-component-toolkit/src/utils/error') +const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error') const { deepClone, uploadCodeToCos, @@ -16,7 +16,7 @@ class ServerlessComopnent extends Component { const { tmpSecrets } = this.credentials.tencent if (!tmpSecrets || !tmpSecrets.TmpSecretId) { - throw new TypeError( + throw new ApiTypeError( 'CREDENTIAL', 'Cannot get secretId/Key, your account could be sub-account and does not have the access to use SLS_QcsRole, please make sure the role exists first, then visit https://cloud.tencent.com/document/product/1154/43006, follow the instructions to bind the role to your account.' ) @@ -357,6 +357,8 @@ class ServerlessComopnent extends Component { const credentials = this.getCredentials() + console.log({ credentials }) + const removeHandlers = [] for (let i = 0; i < regionList.length; i++) { const curRegion = regionList[i] @@ -393,14 +395,14 @@ class ServerlessComopnent extends Component { async metrics(inputs = {}) { console.log(`Get ${CONFIGS.compFullname} Metrics Datas...`) if (!inputs.rangeStart || !inputs.rangeEnd) { - throw new TypeError( + throw new ApiTypeError( `PARAMETER_${CONFIGS.compName.toUpperCase()}_METRICS`, 'rangeStart and rangeEnd are require inputs' ) } const { region } = this.state if (!region) { - throw new TypeError( + throw new ApiTypeError( `PARAMETER_${CONFIGS.compName.toUpperCase()}_METRICS`, 'No region property in state' ) @@ -428,7 +430,7 @@ class ServerlessComopnent extends Component { ) return metricResults } - throw new TypeError( + throw new ApiTypeError( `PARAMETER_${CONFIGS.compName.toUpperCase()}_METRICS`, 'Function name not define' ) diff --git a/src/utils.js b/src/utils.js index b699e24..80fbbce 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,6 @@ const path = require('path') const { Cos } = require('tencent-component-toolkit') -const { TypeError } = require('tencent-component-toolkit/src/utils/error') +const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error') const ensureObject = require('type/object/ensure') const ensureIterable = require('type/iterable/ensure') const ensureString = require('type/string/ensure') @@ -62,13 +62,13 @@ const removeAppid = (str, appid) => { const validateTraffic = (num) => { if (getType(num) !== 'Number') { - throw new TypeError( + throw new ApiTypeError( `PARAMETER_${CONFIGS.compName.toUpperCase()}_TRAFFIC`, 'traffic must be a number' ) } if (num < 0 || num > 1) { - throw new TypeError( + throw new ApiTypeError( `PARAMETER_${CONFIGS.compName.toUpperCase()}_TRAFFIC`, 'traffic must be a number between 0 and 1' ) @@ -92,7 +92,7 @@ const getCodeZipPath = async (instance, inputs) => { filename: `${filename}.zip` }) } catch (e) { - throw new TypeError(`DOWNLOAD_TEMPLATE`, 'Download default template failed.') + throw new ApiTypeError(`DOWNLOAD_TEMPLATE`, 'Download default template failed.') } zipPath = `${downloadPath}/${filename}.zip` } else { @@ -217,7 +217,7 @@ const prepareStaticCosInputs = async (instance, inputs, appId, codeZipPath, regi staticCosInputs } } catch (e) { - throw new TypeError( + throw new ApiTypeError( `UTILS_${CONFIGS.compName.toUpperCase()}_prepareStaticCosInputs`, e.message, e.stack @@ -245,7 +245,7 @@ const prepareStaticCdnInputs = async (instance, inputs, origin) => { // using these default configs, for making user's config more simple cdnInputs.forceRedirect = cdnConf.https.forceRedirect || CONFIGS.defaultCdnConf.forceRedirect if (!cdnConf.https.certId) { - throw new TypeError( + throw new ApiTypeError( `PARAMETER_${CONFIGS.compName.toUpperCase()}_HTTPS`, 'https.certId is required' ) @@ -269,7 +269,7 @@ const prepareStaticCdnInputs = async (instance, inputs, origin) => { return cdnInputs } catch (e) { - throw new TypeError( + throw new ApiTypeError( `UTILS_${CONFIGS.compName.toUpperCase()}_prepareStaticCdnInputs`, e.message, e.stack