@ capawesome/ cloud- sdk
节点.js SDK 云雾 API (英语).
它为管理组织、应用软件、现场更新频道和部署、本土建筑、应用商店目的地等提供了一个完全打入的、基于承诺的界面.
说明: Capawesome Cloud API仍在开发中,可能会不经通知而改变. 反应类型故意只暴露最相关的属性来尽量减少断裂变化.
SDKs 软件
卡帕韦斯克云API的官方SDKs:
| 语言 | 软件包 | 仓库 |
|---|---|---|
| 节点.js | @capawesome/cloud-sdk | 云节点 |
| 蟒 | capawesome-cloud | 云鹏 |
安装
npm install @capawesome/cloud-sdk
所需经费: 节点.js 20.19 或后. 该软件包仅作为无害环境管理发布,但也可通过CommonJS加载 require()。 。 。 .
开始
在其中创建 API 令牌 彩云控制台 并传递给客户:
import { CapawesomeCloud } from '@capawesome/cloud-sdk';
const client = new CapawesomeCloud({
token: process.env.CAPAWESOME_TOKEN!,
});
const apps = await client.apps.list({ organizationId: process.env.CAPAWESOME_ORGANIZATION_ID! });
console.log(apps);
配置
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
token | string | —— 说 | API 令牌用于认证. |
baseUrl | string | https://api.cloud.capawesome.io | API的基础URL(用于自宿/测试). |
timeout | number | 60000 | 请求超时, 以毫秒计 。 不适用于流媒体下载. |
maxRetries | number | 3 | 暂时性故障(网络、, 429, (中文(简体) ), 5xx) 依一能所请. |
fetch | typeof fetch | globalThis.fetch | 这个 fetch 用于所有请求的执行. |
使用量
所有方法都取出一个单一的选项对象并返回一个打出的承诺. 大多数操作都通过 appId。 。 。 .
组织
const organizations = await client.organizations.list();
const organization = await client.organizations.get({ organizationId });
const members = await client.organizations.members.list({ organizationId });
// Invite a new member
await client.organizations.invitations.create({
organizationId,
email: '[email protected]',
role: 'member',
});
// Group apps and members in a team
const team = await client.organizations.teams.create({ organizationId, name: 'Mobile' });
await client.organizations.teams.apps.create({ organizationId, teamId: team.id, appId });
应用程序
const apps = await client.apps.list({ organizationId });
const app = await client.apps.get({ appId });
const created = await client.apps.create({ name: 'My App', type: 'capacitor' });
await client.apps.update({ appId, name: 'Renamed App' });
await client.apps.delete({ appId });
实时更新
// Create a channel
const channel = await client.apps.channels.create({ appId, name: 'production' });
// Pause / resume a channel
await client.apps.channels.pause({ appId, channelId: channel.id });
await client.apps.channels.resume({ appId, channelId: channel.id });
部署
促进一个构建到一个频道(实时更新)或一个目的地(应用程序商店发布):
// Roll out a live update to half of the devices on a channel
await client.apps.deployments.create({
appId,
appBuildId,
appChannelName: 'production',
rolloutPercentage: 0.5,
});
// Publish a native build to an app store with localized release notes
await client.apps.deployments.create({
appId,
appBuildId,
appDestinationName: 'Google Play',
releaseNotes: {
default: 'Bug fixes and performance improvements.',
'de-DE': 'Fehlerbehebungen und Leistungsverbesserungen.',
},
});
Git 仓库
原生建筑由寄存器创建,一个应用程序链接到:
const [connection] = await client.organizations.gitConnections.list({ organizationId });
const repositories = await client.organizations.gitConnections.listRepositories({
organizationId,
gitConnectionId: connection.id,
});
await client.apps.repository.set({
appId,
gitConnectionId: connection.id,
path: repositories[0].path,
});
原始建筑
const build = await client.apps.builds.create({
appId,
platform: 'ios',
gitRef: 'main',
});
// Poll the job that processes the build
let job = await client.jobs.get({ jobId: build.jobId! });
while (job.status === 'queued' || job.status === 'pending' || job.status === 'in_progress') {
await new Promise((resolve) => setTimeout(resolve, 5000));
job = await client.jobs.get({ jobId: job.id });
}
const logs = await client.jobs.getLogs({ jobId: job.id });
// Explain a failure
if (job.status === 'failed') {
const { summary } = await client.jobs.getFailureSummary({ jobId: job.id });
console.error(summary);
}
建造文物
二进制下载返回 a ReadableStream 所以大文件可以被流到磁盘中而不缓冲内存中的所有内容:
import { Writable } from 'node:stream';
import { createWriteStream } from 'node:fs';
const stream = await client.apps.builds.artifacts.download({ appId, buildId, artifactId });
await stream.pipeTo(Writable.toWeb(createWriteStream('artifact.ipa')));
您也可以获得一个签名的,有时间限制的下载 URL :
const { url, expiresAt } = await client.apps.builds.artifacts.getSignedDownloadUrl({
appId,
buildId,
artifactId,
});
证书
import { readFile } from 'node:fs/promises';
const certificate = await client.apps.certificates.create({
appId,
name: 'Distribution Certificate',
platform: 'ios',
type: 'production',
file: await readFile('distribution.p12'),
fileName: 'distribution.p12',
password: process.env.CERT_PASSWORD,
});
环境、 秘密和变量
const environment = await client.apps.environments.create({ appId, name: 'production' });
await client.apps.environments.secrets.create({
appId,
environmentId: environment.id,
key: 'API_KEY',
value: process.env.API_KEY!,
});
await client.apps.environments.variables.create({
appId,
environmentId: environment.id,
key: 'API_URL',
value: 'https://api.example.com',
});
现有资源
资源映射API的路径等级. 应用范围的资源被嵌入 client.apps.*资源 client.organizations.*;顶级资源直接被曝光在客户端上.
| 资源 | 说明 |
|---|---|
client.apps | 创建,读取,更新,删除并传输应用程序. |
client.apps.channels | 管理实时更新频道(包括暂停/重播). |
client.apps.deployments | 向渠道或目的地推广. |
client.apps.builds | 触发并管理本土建筑. |
client.apps.builds.artifacts | 列出并下载建设文物. |
client.apps.buildSources | 注册和下载本地建筑源. |
client.apps.certificates | 管理签名证书 . |
client.apps.destinations | 管理应用商店出版目的地. |
client.apps.environments | 管理环境,秘密和变量. |
client.apps.automations | 管理构建自动化. |
client.apps.devices | 管理已注册的设备 . |
client.apps.webhooks | 管理 app webhoks . |
client.apps.configurations | 管理本地应用程序配置 . |
client.apps.repository | 链接一个应用程序到 Git 仓库 . |
client.organizations | 创建、阅读和更新组织. |
client.organizations.members | 管理组织成员. |
client.organizations.invitations | 请用户到一个组织. |
client.organizations.teams | 管理团队及其应用程序和成员. |
client.organizations.licenseKeys | 管理内幕软件包的许可证密钥 . |
client.organizations.gitConnections | 管理 Git 连接并浏览仓库 . |
client.jobs | 检查背景工作及其日志. |
client.users | 访问认证用户 . |
处理错误
任何非-2xx响应都被抛出 CapawesomeCloudError数字 :
import { CapawesomeCloudError } from '@capawesome/cloud-sdk';
try {
await client.apps.get({ appId: 'unknown' });
} catch (error) {
if (error instanceof CapawesomeCloudError) {
console.error(error.status); // 404
console.error(error.message); // "App not found."
console.error(error.body); // { message: "App not found." }
}
}
发展
设置
清除寄存器并安装依赖性 :
npm install
这也设置了 Git 钩子(通过 胡斯基),它运行在每一次承诺之前的已上演的文件上. 开发过程中的常见脚本 :
| 脚本 | 说明 |
|---|---|
npm run build | 将软件包构建为 dist/ 与tsdown。 与tsdown. |
npm run dev | 改变时重建( 监视模式) . |
npm run typecheck | 在不排放输出的情况下检查类型 . |
npm run lint | 检查格式和线条 . |
npm run fmt | 自动固定格式化和插件问题. |
测试
测试用 维特 并生活在一个 test/ 目录 :
npm test # run the suite once
npm run test:watch # re-run on change
出版
释放是自动的 释放请,从中生成下一个版本和更改日志条目 常规武器委员会。 。 。 .
每一次推进 main,则 发布工作流程 创建或更新使版本与更新相撞的释放拉出请求 CHANGELOG.md。将拉出请求合并后创建了 git 标记和 GitHub 发布,并将软件包发布到 npm .
许可证
见 自由主义。 。 。 .