@backifydev/sdk

中文文档
0.2.0发布于 2026/11/07MITTypeScriptES Module近 30 天下载 2735

Provider-independent application platform SDK for Backify

原始使用文档

@backifydev/sdk

Backify applications declare one server entry and ship one image with web, worker and migrate process roles. Import server APIs from @backifydev/sdk/app, typed configuration from @backifydev/sdk/config, and test helpers from @backifydev/sdk/testing. Browser code calls the application's API with fetch; database credentials and workload tokens stay on the server.

import { defineBackend, database, defineJob, schedule, z } from "@backifydev/sdk/app";
export const api = defineBackend();
api.get("/api/items", { auth: "user" }, async ({ user }) =>
  (await database().query("SELECT id, title FROM items WHERE owner_id = $1", [user.id])).rows);
export const cleanup = defineJob("cleanup", async () => {
  await database().query("DELETE FROM items WHERE archived AND created_at < now() - interval '30 days'");
});
schedule("nightly-cleanup", { cron: "0 3 * * *" }, cleanup);

Declare routes, jobs, schedules and event subscriptions at module top level with literal names. Every route defaults to authenticated access; use auth: "public" only deliberately. The SDK verifies signed gateway identity and enforces route roles or permissions before handlers run. Handlers must scope all rows and files to the authenticated user or organization.

Use database() for PostgreSQL, transaction() for atomic writes, and events.publish(name, payload, { client: tx }) for a transactional event outbox. bucket(name) gets short-lived scoped storage credentials from the broker. AI, mail, governed HTTP and integrations use broker services. secret(name) and config(key) read platform-injected values.

Create a project with backify new my-app --template web|api|worker. Run backify dev locally, backify lock to generate the deterministic release contract, and backify check before committing. Local development uses real private PostgreSQL and a local broker; test identity helpers never belong in production code.

The legacy root, /server, /local and /runtime imports were removed with functions, browser-direct database access, HCR bindings and workload packaging. See the runtime contract and Expense Manager.

版本与发布记录

@backifydev/sdk 共发布 19 个版本,首次发布于 2026/10/01;过去 12 个月发布了 19 个版本。

版本发布日期距今
0.2.0latest2026/11/07今天
0.1.162026/11/061 天前
0.1.152026/10/308 天前
0.1.142026/10/2810 天前
0.1.132026/10/2612 天前
0.1.122026/10/2315 天前

关于 @backifydev/sdk 的常见问题

@backifydev/sdk 是什么?

Provider-independent application platform SDK for Backify

如何安装 @backifydev/sdk?

在项目目录运行 npm install @backifydev/sdk,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 backify-run,可以用 npx backify-run 直接运行。

@backifydev/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@backifydev/sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@backifydev/sdk 可以商用吗?

@backifydev/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@backifydev/sdk 的下载量有多少?

根据 npm 官方下载统计,@backifydev/sdk 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,735 次,日均约 91 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@backifydev/sdk 还在维护吗?

最新版本 0.2.0 发布于 2026/11/07(今天);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/10/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。