跳到主要内容

发布与项目

本节详细介绍可用于管理 blocklet 项目整个生命周期的 mutation,从创建和发布管理到连接 blocklet 商店和发布您的作品。这些 mutation 使您能够以编程方式控制项目的开发、版本控制和分发方式。

要获取与项目相关的数据,请参阅 发布与项目查询 文档。

项目管理

这些 mutation 用于处理开发项目的创建、修改和删除。

createProject

为指定的 blocklet 组件创建一个新项目,为将来的发布和分发做好准备。

参数

  • input RequestCreateProjectInput (required) — 一个包含项目详细信息的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • type PublishType (required) — 项目类型,'resource' 或 'pack'。
    • blockletDid string (required) — 要发布的 blocklet 的 DID。
    • blockletTitle string (required) — blocklet 的标题。
    • componentDid string — 与项目关联的组件的 DID。
    • tenantScope string — 租户的范围。

示例

Create Project

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { project } = await client.mutation.createProject({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      type: 'resource',
      blockletDid: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      blockletTitle: 'My New Blocklet Project',
      componentDid: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
    },
  });
  console.log('项目已创建:', project.id);
} catch (error) {
  console.error('创建项目时出错:', error);
}

响应

  • ResponseProject object
    • code StatusCode — 指示操作的结果。
    • project Project — 新创建的项目对象。

updateProject

更新现有项目的详细信息,例如其标题、描述或简介。

参数

  • input RequestUpdateProjectInput (required) — 一个包含要更新的项目详细信息的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • projectId string (required) — 要更新的项目的 ID。
    • blockletTitle string — blocklet 的新标题。
    • blockletDescription string — blocklet 的新描述。
    • blockletIntroduction string — blocklet 的新简介。
    • autoUpload boolean — 是否自动上传资源。
    • possibleSameStore boolean — 是否可以发布到同一个商店。
    • blockletSupport string — blocklet 支持的 URL。
    • blockletCommunity string — blocklet 社区的 URL。
    • blockletHomepage string — blocklet 主页的 URL。

示例

Update Project

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { project } = await client.mutation.updateProject({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
      blockletTitle: 'My Updated Blocklet Project',
      blockletDescription: 'An updated description for my project.',
    },
  });
  console.log('项目已更新:', project.id);
} catch (error) {
  console.error('更新项目时出错:', error);
}

响应

  • ResponseProject object
    • code StatusCode — 指示操作的结果。
    • project Project — 已更新的项目对象。

deleteProject

永久删除一个项目。此操作无法撤销。

参数

  • input RequestProjectInput (required) — 一个包含项目标识符的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • projectId string (required) — 要删除的项目的 ID。

示例

Delete Project

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.deleteProject({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
    },
  });
  console.log('项目已成功删除。');
} catch (error) {
  console.error('删除项目时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

发布管理

这些 mutation 用于为您的项目创建和管理发布。

createRelease

为项目创建一个新发布,捕获 blocklet 的特定版本及其关联的元数据。

参数

  • input RequestCreateReleaseInput (required) — 一个包含发布详细信息的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • projectId string (required) — 此发布所属项目的 ID。
    • blockletDid string (required) — 此发布的 blocklet 版本的 DID。
    • blockletVersion string (required) — blocklet 的版本号。
    • note string — 发布说明或变更摘要。
    • blockletTitle string — 此发布的标题。
    • blockletDescription string — 此发布的描述。
    • blockletScreenshots string[] — 截图 URL 的数组。

示例

Create Release

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { release } = await client.mutation.createRelease({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
      blockletDid: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      blockletVersion: '1.0.0',
      note: 'Initial release with core features.',
    },
  });
  console.log('发布已创建:', release.id);
} catch (error) {
  console.error('创建发布时出错:', error);
}

响应

  • ResponseRelease object
    • code StatusCode — 指示操作的结果。
    • release Release — 新创建的发布对象。

deleteRelease

从项目中永久删除一个发布。

参数

  • input RequestReleaseInput (required) — 一个包含发布标识符的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • projectId string (required) — 包含该发布的项目的 ID。
    • releaseId string (required) — 要删除的发布的 ID。

示例

Delete Release

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.deleteRelease({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
      releaseId: 'release_67890',
    },
  });
  console.log('发布已成功删除。');
} catch (error) {
  console.error('删除发布时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

资源管理

此 mutation 用于管理与项目发布相关的资源。

updateSelectedResources

更新项目中某个组件特定发布所选的资源列表。

参数

  • input RequestUpdateSelectedResourcesInput (required) — 一个包含资源选择详细信息的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • projectId string (required) — 项目的 ID。
    • releaseId string (required) — 发布的 ID。
    • componentDid string (required) — 正在更新其资源的组件的 DID。
    • resources string[] (required) — 要选择的资源标识符数组。

示例

Update Selected Resources

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.updateSelectedResources({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
      releaseId: 'release_67890',
      componentDid: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      resources: ['resource_a', 'resource_b'],
    },
  });
  console.log('所选资源已更新。');
} catch (error) {
  console.error('更新资源时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

商店与端点连接

这些 mutation 管理您的项目与各种发布目标(如 Blocklet 商店和端点)之间的连接。

connectToStore

在项目和 Blocklet 商店之间启动连接,返回一个用于完成授权过程的 URL。

参数

  • input RequestConnectToStoreInput (required) — 一个包含商店连接详细信息的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • storeId string (required) — Blocklet 商店的唯一标识符。
    • storeUrl string (required) — Blocklet 商店的 URL。
    • storeName string (required) — Blocklet 商店的名称。
    • projectId string (required) — 要连接的项目的 ID。

示例

Connect to Store

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { url } = await client.mutation.connectToStore({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
      storeId: 'store_abc',
      storeUrl: 'https://store.example.com',
      storeName: 'Example Store',
    },
  });
  console.log('连接到商店的 URL:', url);
} catch (error) {
  console.error('连接到商店时出错:', error);
}

响应

  • ResponseConnectToStore object
    • code StatusCode — 指示操作的结果。
    • url string — 用于完成连接的授权 URL。

publishToStore

将项目的特定发布发布到已连接的 Blocklet 商店。

参数

  • input RequestPublishToStoreInput (required) — 一个包含发布详细信息的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • projectId string (required) — 要发布的项目的 ID。
    • releaseId string (required) — 要发布的发布的 ID。
    • type string (required) — 要发布的内容类型(例如 'resource')。
    • storeId string (required) — 目标 Blocklet 商店的 ID。

示例

Publish to Store

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { url } = await client.mutation.publishToStore({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
      releaseId: 'release_67890',
      storeId: 'store_abc',
      type: 'resource',
    },
  });
  console.log('发布到商店的 URL:', url);
} catch (error) {
  console.error('发布到商店时出错:', error);
}

响应

  • ResponsePublishToStore object
    • code StatusCode — 指示操作的结果。
    • url string — 用于跟踪发布过程状态的 URL。

disconnectFromStore

将项目与 Blocklet 商店断开连接,移除关联。

参数

  • input RequestDisconnectFromStoreInput (required) — 一个包含从商店断开连接详细信息的对象。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • storeId string (required) — 要断开连接的商店的 ID。
    • projectId string (required) — 要断开连接的项目的 ID。
    • storeScope string — 商店连接的范围。

示例

Disconnect from Store

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.disconnectFromStore({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      projectId: 'project_12345',
      storeId: 'store_abc',
    },
  });
  console.log('已成功从商店断开连接。');
} catch (error) {
  console.error('从商店断开连接时出错:', error);
}

响应

  • ResponseDisconnectFromStore object
    • code StatusCode — 指示操作的结果。

connectToAigne

将一个 blocklet 连接到 AIGNE 服务,该服务提供 AI 功能。

参数

  • input RequestConnectToAigneInput (required) — 一个包含 AIGNE 连接详细信息的对象。
    • did string (required) — 要连接的 blocklet 的 DID。
    • baseUrl string (required) — AIGNE 服务的基础 URL。
    • provider string (required) — AI 提供商(例如 'openai')。
    • model string (required) — 要使用的具体模型(例如 'gpt-4')。

示例

Connect to AIGNE

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { url } = await client.mutation.connectToAigne({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      baseUrl: 'https://aigne.example.com',
      provider: 'openai',
      model: 'gpt-4-turbo',
    },
  });
  console.log('连接到 AIGNE 的 URL:', url);
} catch (error) {
  console.error('连接到 AIGNE 时出错:', error);
}

响应

  • ResponseConnectToEndpoint object
    • code StatusCode — 指示操作的结果。
    • url string — 用于完成连接的授权 URL。

disconnectToAigne

将一个 blocklet 从 AIGNE 服务断开连接。

参数

  • input RequestDisconnectToAigneInput (required) — 一个包含从 AIGNE 断开连接详细信息的对象。
    • did string (required) — 要断开连接的 blocklet 的 DID。
    • url string (required) — 要断开连接的 AIGNE 服务的 URL。
    • key string (required) — 用于连接的 API 密钥。

示例

Disconnect from AIGNE

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.disconnectToAigne({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      url: 'https://aigne.example.com',
      key: 'your-api-key',
    },
  });
  console.log('已成功从 AIGNE 断开连接。');
} catch (error) {
  console.error('从 AIGNE 断开连接时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

verifyAigneConnection

验证 blocklet 与 AIGNE 服务的连接。

参数

  • input RequestVerifyAigneConnectionInput (required) — 一个包含 blocklet DID 的对象。
    • did string (required) — 需要验证 AIGNE 连接的 blocklet 的 DID。

示例

Verify AIGNE Connection

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.verifyAigneConnection({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
    },
  });
  console.log('AIGNE 连接验证成功。');
} catch (error) {
  console.error('验证 AIGNE 连接时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

connectToEndpoint

在项目和通用发布端点之间建立连接。

参数

  • input RequestConnectToEndpointInput (required) — 连接到端点的详细信息。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • endpointId string (required) — 要连接的端点的 ID。
    • projectId string (required) — 项目的 ID。

示例

Connect to Endpoint

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { url } = await client.mutation.connectToEndpoint({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      endpointId: 'endpoint_xyz',
      projectId: 'project_12345',
    },
  });
  console.log('连接到端点的 URL:', url);
} catch (error) {
  console.error('连接到端点时出错:', error);
}

响应

  • ResponseConnectToEndpoint object
    • code StatusCode — 指示操作的结果。
    • url string — 用于完成连接的授权 URL。

publishToEndpoint

将项目的特定发布发布到已连接的端点。

参数

  • input RequestPublishToEndpointInput (required) — 发布到端点的详细信息。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • endpointId string (required) — 目标端点的 ID。
    • projectId string (required) — 要发布的项目的 ID。
    • releaseId string (required) — 要发布的发布的 ID。

示例

Publish to Endpoint

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { url } = await client.mutation.publishToEndpoint({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      endpointId: 'endpoint_xyz',
      projectId: 'project_12345',
      releaseId: 'release_67890',
    },
  });
  console.log('发布到端点的 URL:', url);
} catch (error) {
  console.error('发布到端点时出错:', error);
}

响应

  • ResponsePublishToEndpoint object
    • code StatusCode — 指示操作的结果。
    • url string — 用于跟踪发布状态的 URL。

disconnectFromEndpoint

将项目与发布端点断开连接。

参数

  • input RequestDisconnectFromEndpointInput (required) — 从端点断开连接的详细信息。
    • did string (required) — 拥有该项目的 blocklet 的 DID。
    • endpointId string (required) — 要断开连接的端点的 ID。
    • projectId string (required) — 项目的 ID。

示例

Disconnect from Endpoint

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.disconnectFromEndpoint({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      endpointId: 'endpoint_xyz',
      projectId: 'project_12345',
    },
  });
  console.log('已成功从端点断开连接。');
} catch (error) {
  console.error('从端点断开连接时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

addUploadEndpoint

为团队添加一个新的上传端点。

参数

  • input RequestAddUploadEndpointInput (required) — 新上传端点的详细信息。
    • teamDid string (required) — 团队的 DID。
    • url string (required) — 上传端点的 URL。
    • scope string — 端点的范围。

示例

Add Upload Endpoint

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.addUploadEndpoint({
    input: {
      teamDid: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      url: 'https://uploads.example.com',
      scope: 'images',
    },
  });
  console.log('上传端点已成功添加。');
} catch (error) {
  console.error('添加上传端点时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

deleteUploadEndpoint

删除一个现有的上传端点。

参数

  • input RequestDeleteUploadEndpointInput (required) — 删除上传端点的详细信息。
    • teamDid string (required) — 团队的 DID。
    • did string (required) — 要删除的上传端点的 DID。
    • scope string — 端点的范围。
    • projectId string — 关联项目的 ID。

示例

Delete Upload Endpoint

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  await client.mutation.deleteUploadEndpoint({
    input: {
      teamDid: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      did: 'endpoint_did_123',
    },
  });
  console.log('上传端点已成功删除。');
} catch (error) {
  console.error('删除上传端点时出错:', error);
}

响应

  • GeneralResponse object
    • code StatusCode — 指示操作的结果。

connectByStudio

通过 Blocklet Studio 与 Blocklet 商店建立连接。

参数

  • input RequestConnectByStudioInput (required) — 通过 Blocklet Studio 连接的详细信息。
    • did string (required) — blocklet 的 DID。
    • storeId string (required) — 商店的 ID。
    • storeUrl string (required) — 商店的 URL。
    • storeName string (required) — 商店的名称。
    • blockletTitle string (required) — blocklet 的标题。
    • type string (required) — 连接类型。
    • tenantScope string — 租户的范围。
    • componentDid string — 组件的 DID。
    • messageId string — 用于跟踪的消息 ID。

示例

Connect by Studio

javascript
import BlockletServerClient from '@blocklet/server-js';

const client = new BlockletServerClient();

try {
  const { url } = await client.mutation.connectByStudio({
    input: {
      did: 'z8iZpA522J9Q2i8mY8J2mY6J2mY8J2mY6J2',
      storeId: 'store_abc',
      storeUrl: 'https://studio.blocklet.dev',
      storeName: 'Blocklet Studio',
      blockletTitle: 'My Awesome Blocklet',
      type: 'publish',
    },
  });
  console.log('通过 Studio 连接的 URL:', url);
} catch (error) {
  console.error('通过 Studio 连接时出错:', error);
}

响应

  • ResponseConnectByStudio object
    • code StatusCode — 指示操作的结果。
    • url string — 用于完成连接过程的 URL。