Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update component-toolkit to v2 #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app: appDemo
stage: dev
component: nextjs
component: nextjs@dev
name: nextjsDemo

inputs:
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
12 changes: 7 additions & 5 deletions src/serverless.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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.'
)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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'
)
Expand Down Expand Up @@ -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'
)
Expand Down
14 changes: 7 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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'
)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
)
Expand All @@ -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
Expand Down