npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tencentcloud-serverless-nodejs

v1.0.3

Published

Tencentcloud-serverless SDK for Nodejs

Downloads

70

Readme

Tencentcloud-Serverless-Nodejs

GitHub license NPM Version NODE Version

腾讯云云函数SDK,集成云函数业务流接口

配置需求

  • 打开函数外网访问权限
  • 如果没有手动传入secretId和secretKey等参数,函数需绑定有SCF Invoke 权限(或者包含SCF Invoke,比如SCF FullAccess)的角色

Install

npm install tencentcloud-serverless-nodejs

Example

const { SDK, LogType }  = require('tencentcloud-serverless-nodejs')

exports.main_handler = async (event, context) => {
  context.callbackWaitsForEmptyEventLoop = false
  const sdk = new SDK({
    region:'ap-guangzhou'
  }) //如果在云函数中运行并且绑定了有SCF调用资格的运行角色,会默认取环境变量中的鉴权信息
  const res = await sdk.invoke({
    functionName: 'test_function',
    logType: LogType.Tail,
    data: {
      name: 'juli',
      role: 'big boss'
    }
  })
  console.log(res)
  // {
  //  "RequestId":"195434cd-ecf1-43d1-b707-90a293f5a282",
  //  "Result":{
  //     "BillDuration":3,
  //     "Duration":3,
  //     "ErrMsg":"",
  //     "FunctionRequestId":"195434cd-ecf1-43d1-b707-90a293f5a282",
  //     "InvokeResult":0,
  //     "Log":"START RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282\nEvent RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282\n2020-06-15T12:48:44.194Z\t195434cd-ecf1-43d1-b707-90a293f5a282\tHello World 111\n2020-06-15T12:48:44.194Z\t195434cd-ecf1-43d1-b707-90a293f5a282\t{ name: 'juli', role: 'big boss' }\n2020-06-15T12:48:44.196Z\t195434cd-ecf1-43d1-b707-90a293f5a282\tundefined\n2020-06-15T12:48:44.196Z\t195434cd-ecf1-43d1-b707-90a293f5a282\t{\n  callbackWaitsForEmptyEventLoop: [Getter/Setter],\n  getRemainingTimeInMillis: [Function: getRemainingTimeInMillis],\n  memory_limit_in_mb: 128,\n  time_limit_in_ms: 3000,\n  request_id: '195434cd-ecf1-43d1-b707-90a293f5a282',\n  environment: '{\"SCF_NAMESPACE\":\"default\"}',\n  environ: 'SCF_NAMESPACE=default;SCF_NAMESPACE=default',\n  function_version: '$LATEST',\n  function_name: 'test_function',\n  namespace: 'default',\n  tencentcloud_region: '',\n  tencentcloud_appid: 'xxxxxxxx',\n  tencentcloud_uin: 'xxxxxxxxxx'\n}\n\nEND RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282\nReport RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282 Duration:3ms Memory:128MB MemUsage:10.5977MB",
  //     "MemUsage":11112448,
  //     "RetMsg":"{\"name\":\"juli\",\"role\":\"big boss\"}"
  //  }
}
};

API

Init

new SDK(Params)

使用SDK前,需要先初始化SDK,参数中undefined的值会被忽略。

Params:

| 参数名 | 是否必填 | 类型 | 描述 | | :-------- | :------: | :----: | -----------------------------------------: | | region | 否 | string | 地域,默认广州(ap-guangzhou) | | secretId | 否 | string | 默认会取process.env.TENCENTCLOUD_SECRETID | | secretKey | 否 | string | 默认会取process.env.TENCENTCLOUD_SECRETKEY | | token | 否 | string | 默认会取process.env.TENCENTCLOUD_SESSIONTOKEN |

Invoke

invoke(Params)

调用函数。支持同步和异步调用

Params:

| 参数名 | 是否必填 | 类型 | 描述 | | :----------- | :------: | :----: | ----------------------: | | functionName | 是 | string | 函数名称 | | qualifier | 否 | string | 函数版本,默认为$LATEST | | data | 否 | string | object | 函数运行入参 | | namespace | 否 | string | 命名空间,默认为default | | invocationType | 否 | 'RequestResponse' | 'Event' | 同步/异步调用 | routingKey | 否 | string | object | 函数灰度流量控制调用,以json格式传入,例如{"k":"v"},注意kv都需要是字符串类型,最大支持的参数长度是1024字节 | logType | 否 | 'None'| 'Tail' | 日志类型,默认None,如传入Tail会返回调用过程中打印的日志

Return:

正常调用返回一个带有返回值结果和RequestId的object

 {
   "RequestId":"195434cd-ecf1-43d1-b707-90a293f5a282",
   "Result":{
      "BillDuration":3,
      "Duration":3,
      "ErrMsg":"",
      "FunctionRequestId":"195434cd-ecf1-43d1-b707-90a293f5a282",
      "InvokeResult":0,
      "Log":"START RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282\nEvent RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282\n2020-06-15T12:48:44.194Z\t195434cd-ecf1-43d1-b707-90a293f5a282\tHello World 111\n2020-06-15T12:48:44.194Z\t195434cd-ecf1-43d1-b707-90a293f5a282\t{ name: 'juli', role: 'big boss' }\n2020-06-15T12:48:44.196Z\t195434cd-ecf1-43d1-b707-90a293f5a282\tundefined\n2020-06-15T12:48:44.196Z\t195434cd-ecf1-43d1-b707-90a293f5a282\t{\n  callbackWaitsForEmptyEventLoop: [Getter/Setter],\n  getRemainingTimeInMillis: [Function: getRemainingTimeInMillis],\n  memory_limit_in_mb: 128,\n  time_limit_in_ms: 3000,\n  request_id: '195434cd-ecf1-43d1-b707-90a293f5a282',\n  environment: '{\"SCF_NAMESPACE\":\"default\"}',\n  environ: 'SCF_NAMESPACE=default;SCF_NAMESPACE=default',\n  function_version: '$LATEST',\n  function_name: 'test_function',\n  namespace: 'default',\n  tencentcloud_region: '',\n  tencentcloud_appid: 'xxxxxxxx',\n  tencentcloud_uin: 'xxxxxxxxxx'\n}\n\nEND RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282\nReport RequestId: 195434cd-ecf1-43d1-b707-90a293f5a282 Duration:3ms Memory:128MB MemUsage:10.5977MB",
      "MemUsage":11112448,
      "RetMsg":"{\"name\":\"juli\",\"role\":\"big boss\"}"
   }

错误调用返回一个带有错误信息,错误码,以及RequestId的object,【错误码详情】

{
   "Error":{
      "Code":"ResourceNotFound.FunctionName",
      "Message":"Function not found: [n11112]"
   },
   "RequestId":"bb994f2f-526e-4142-bf9b-b8cf482c14ea"
}

Licence

MIT