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 🙏

© 2026 – Pkg Stats / Ryan Hefner

phala-cloud-sdk

v0.1.0

Published

SDK for interacting with Phala Cloud services

Readme

Phala Cloud SDK

用于与 Phala Cloud TEE 服务交互的JavaScript/TypeScript SDK。

安装

使用 npm:

npm install phala-cloud-sdk

使用 yarn:

yarn add phala-cloud-sdk

使用 pnpm:

pnpm add phala-cloud-sdk

基本用法

import { PhalaCloud } from 'phala-cloud-sdk';

// 创建SDK实例
const phalaCloud = new PhalaCloud({
  apiKey: 'YOUR_API_KEY_HERE',
  // apiUrl: 'OPTIONAL_CUSTOM_API_URL'
});

// 获取用户信息
const userInfo = await phalaCloud.getUserInfo();
console.log('User info:', userInfo);

// 列出所有CVM实例
const cvms = await phalaCloud.listCvms();
console.log(`Found ${cvms.length} CVM instances`);

功能示例

部署Docker容器

以下示例展示如何将Docker Hub上的镜像部署到Phala Cloud TEE环境:

import { PhalaCloud } from 'phala-cloud-sdk';
import path from 'path';

// 创建SDK实例
const phalaCloud = new PhalaCloud({
  apiKey: 'YOUR_API_KEY_HERE',
});

// 部署容器
const deployResult = await phalaCloud.deploy({
  type: 'phala',
  mode: 'docker-compose',
  name: 'my-application',
  compose: './docker-compose.yml',  // 指向您的docker-compose.yml文件
  env: ['KEY1=value1', 'KEY2=value2'],  // 可选的环境变量
  // 可选配置参数
  // vcpu: 1,               // 默认值: 1
  // memory: 2048,          // 默认值: 2048 MB
  // diskSize: 40,          // 默认值: 40 GB
  // image: 'dstack-dev-0.3.5', // 默认值: dstack-dev-0.3.5
  // teepodId: 3            // 默认值: 3,也可以自动寻找可用teepod
});

console.log('部署成功!');
console.log('应用ID:', deployResult.app_id);
console.log('应用URL:', deployResult.app_url);

使用环境变量文件

您也可以使用环境变量文件(.env):

// 使用环境变量文件部署
const deployResult = await phalaCloud.deploy({
  type: 'phala',
  mode: 'docker-compose',
  name: 'my-application',
  compose: './docker-compose.yml',
  envFile: './.env'  // 指向您的.env文件
});

升级现有部署

// 升级现有部署
const upgradeResult = await phalaCloud.upgrade({
  name: 'my-application',  // 现有部署的名称,即应用ID
  compose: './docker-compose.yml',  // 新的配置文件
  env: ['KEY1=new-value', 'DEBUG=true']  // 更新的环境变量
});

console.log('升级成功!');
console.log('详情:', upgradeResult.detail);

完整示例

项目的examples目录中包含了以下完整示例:

  1. deploy-container.ts - 基本的容器部署示例
  2. deploy-with-env-file.ts - 使用环境变量文件部署的示例
  3. upgrade-container.ts - 升级现有部署的示例

要运行这些示例,首先安装必要的依赖:

npm install -g ts-node
npm install

然后运行示例:

# 确保替换示例中的API_KEY
ts-node examples/deploy-container.ts

API参考

初始化

// 使用API密钥进行认证
const phalaCloud = new PhalaCloud({
  apiKey: 'YOUR_API_KEY_HERE'
});

用户与CVM操作

// 获取当前用户信息
const userInfo = await phalaCloud.getUserInfo();

// 列出所有CVM实例
const cvms = await phalaCloud.listCvms();

// 通过应用ID获取CVM信息
const cvm = await phalaCloud.getCvmByAppId('app-id-here');

// 获取CVM的公钥
const pubkey = await phalaCloud.getPubkeyFromCvm('app-id-here');

部署与升级

// 部署一个新的TEE实例
const deployResponse = await phalaCloud.deploy({
  type: 'phala',
  mode: 'docker-compose',
  name: 'my-app',
  compose: './docker-compose.yml',
  env: ['KEY1=value1', 'KEY2=value2'],
  vcpu: 1,
  memory: 2048,
  diskSize: 40,
  image: 'dstack-dev-0.3.5',
  teepodId: 3
});

// 升级现有的TEE实例
const upgradeResponse = await phalaCloud.upgrade({
  name: 'my-app',
  compose: './docker-compose.yml',
  env: ['KEY1=value1', 'KEY2=value2']
});

监控部署状态

// 监控部署状态
await phalaCloud.monitorDeploymentStatus('app-id-here', {
  interval: 5000,        // 检查间隔时间(毫秒),默认5000
  maxRetries: 36,        // 最大尝试次数,默认36 (约3分钟)
  queryTimeout: 8000,    // 状态查询超时时间(毫秒),默认8000
  onStatusChange: (status, cvm) => {
    console.log(`状态变化: ${status}`);
  },
  onSuccess: (cvm) => {
    console.log('部署成功!');
  },
  onFailure: (status, cvm) => {
    console.log(`部署失败: ${status}`);
  },
  onTimeout: (cvm) => {
    console.log('部署超时');
  },
  onError: (error) => {
    console.error('监控部署状态时发生错误:', error);
  }
});

调试

设置环境变量 PHALA_SDK_DEBUG=true 可以启用详细日志输出。

许可证

MIT