TencentCloud Node.js SDK

repository·master·Indexed 20 days ago

https://github.com/tencentcloud/tencentcloud-sdk-nodejs

A developer toolset for interacting with TencentCloud API 3.0, allowing Node.js developers to programmatically manage cloud resources such as CVM and VPC. The SDK supports product-specific installations to reduce bundle size, a full SDK version, and a Slim version. It includes a Common Client for generic API calls and supports secure credential management via Instance Roles. Requires Node.js version 10.0.0 or higher.

Tokens
163.7K
Snippets
659
Records
891
Agent score
65%

What's inside tencentcloud-sdk-nodejs

  1. Use the Common Client for generic API calls

    master

    Starting from version 4.0.714, the SDK supports a Common Client approach. By installing the tencentcloud-sdk-nodejs-common package, you can make requests to any product without needing the specific product package installed.

    Warning: You must know the exact parameters required by the API interface, otherwise the call will fail.

  2. Manage credentials using Instance Roles

    master

    For enhanced security, instead of passing static secretId and secretKey, you can use TencentCloud Instance Roles. When a role is bound to your instance, you can use a specialized credential class to fetch temporary credentials automatically.

    Usage Example:

    const CvmRoleCredential = require("tencentcloud-sdk-nodejs/tencentcloud/common/cvm_role_credential").default
    
    const client = new XxxClient({
      credential: new CvmRoleCredential(),
      region: "ap-shanghai",
    })
    const CvmRoleCredential = require("tencentcloud-sdk-nodejs/tencentcloud/common/cvm_role_credential").default
    
    new XxxClient({
      credential: new CvmRoleCredential(),
    })
  3. Install the TencentCloud Node.js SDK

    master

    You can install the SDK via npm using three different approaches depending on your project needs:

    1. Install specific product SDKs (Recommended): To keep your bundle size small, install only the products you need (e.g., cvm for Cloud Virtual Machine or vpc for Virtual Private Cloud).
    2. Install the full SDK: Includes all products and TypeScript definitions. Best if you use many different cloud services but results in a larger package size.
    3. Install the Slim SDK: A compressed version of the full SDK that removes TypeScript type files, ideal for size-sensitive environments.

    Prerequisites:

    • Node.js version 10.0.0 or higher.
    • API Keys (SecretID and SecretKey) obtained from the TencentCloud Console.
    # Install a specific product (Recommended)
    npm install tencentcloud-sdk-nodejs-cvm --save
    npm install tencentcloud-sdk-nodejs-vpc --save
    
    # Install the full SDK
    npm install tencentcloud-sdk-nodejs --save
    
    # Install the Slim version (Compressed, no types)
    npm install tencentcloud-sdk-slim-nodejs --save
  4. Use a specific product SDK

    master

    When installing a specific product SDK (e.g., tencentcloud-sdk-nodejs-cvm), you must update your require or import statements to use the product-specific package name instead of the generic tencentcloud-sdk-nodejs package.

    Example for CVM SDK:

    // Incorrect for product-specific packages
    // const tencentcloud = require("tencentcloud-sdk-nodejs")
    // const CvmClient = tencentcloud.cvm.v20170312.Client
    
    // Correct
    const { cvm } = require("tencentcloud-sdk-nodejs-cvm")
    const CvmClient = cvm.v20170312.Client
    const { cvm } = require("tencentcloud-sdk-nodejs-cvm")
    const CvmClient = cvm.v20170312.Client
  5. Configure KTV Robot Sync Commands

    master

    When creating a KTV Robot via CreateKTVRobotRequest, you can provide an array of SyncRobotCommand objects to initialize the robot with specific instructions. These commands are executed in the order provided.

    Supported Command values include:

    • Play: Start playback.
    • Pause: Pause playback.
    • SwitchPrevious: Play the previous song.
    • SwitchNext: Play the next song.
    • SetPlayMode: Change the playback mode.
    • Seek: Adjust playback position.
    • SetPlaylist: Change the playlist.
    • SetAudioParam: Change audio parameters.
    • SendMessage: Send a custom message.
    • SetDestroyMode: Set the room destruction mode.
    • SetRealVolume: Set the actual volume (replaces the deprecated SetVolume).

    Each command requires its corresponding input object (e.g., PlayCommandInput for Play, SeekCommandInput for Seek).

    // Example of initializing a robot with commands
    const request: CreateKTVRobotRequest = {
      RTCSystem: 'TRTC',
      JoinRoomInput: { /* ... */ },
      SyncRobotCommands: [
        {
          Command: 'SetRealVolume',
          SetRealVolumeCommandInput: { RealVolume: 70 }
        },
        {
          Command: 'Play',
          PlayCommandInput: { Index: 0 }
        }
      ]
    };
  6. Configure Proxy settings

    master

    If you are working in a network environment that requires a proxy, you can configure it in two ways:

    1. Pass the proxy parameter within the profile.httpProfile object when creating the Client.
    2. Set the system environment variable http_proxy.

    Failure to configure a proxy in such environments may result in connection timeout errors.

  7. Monitor Copyright Infringement Results

    master

    The Monitor object provides details about the monitoring status of a copyright work. It includes information such as:

    • WorkId and WorkName
    • WorkType (e.g., 01-Video, 02-Audio, 03-Text, 04-Image)
    • MonitorStatus (e.g., 0-Pending, 1-Monitoring, 2-Not Monitoring, 3-Paused)
    • TortPlatNum and TortURLNum (counts of infringing platforms and URLs)
    • EvidenceStatus (status of evidence preservation)
  8. Configure Access Groups and Rules

    master

    Access control is managed through Access Groups and Access Rules.

    Access Group: A container for rules. Managed via CreateAccessGroupRequest, ModifyAccessGroupRequest, and DeleteAccessGroupRequest.

    Access Rule: Defines specific permissions within a group. Managed via CreateAccessRulesRequest and ModifyAccessRulesRequest.

    AccessRule Properties:

    • Address: Network segment or IP.
    • AccessMode: 1 for Read-only, 2 for Read/Write.
    • Priority: 1 to 100 (lower value = higher priority).
  9. Manage CDWPG Instances via API

    master

    The CDWPG (Cloud Data Warehouse PostgreSQL) service provides several operations to manage cluster instances, including creation, modification, scaling, and destruction.

    Key operations include:

    • CreateInstanceByApi: Creates a new instance with specified resources, VPC, and billing configurations.
    • ModifyInstance: Updates the instance name.
    • ScaleUpInstance: Scales up resources (e.g., changing resource types or specifications).
    • ScaleOutInstance: Scales out by adding more nodes of a specific type.
    • RestartInstance: Restarts specific node types (gtm/cn/dn/fn) or specific node IDs.
    • DestroyInstanceByApi: Destroys an existing instance.
  10. Core components of the TencentCloud SDK

    master

    The tencentcloud-sdk-nodejs package provides the foundational building blocks for interacting with TencentCloud services. The core modules exported from the common entry point include:

    • Abstract Client: The base class for all service clients.
    • Common Client: A generic client used for making requests to services that may not have a dedicated client class.
    • Credential: Used to manage authentication via SecretId and SecretKey.
    • Interfaces: Type definitions and interfaces used throughout the SDK for request and response shapes.