@calmlens/sdk

中文文档
0.22.0发布于 2026/11/09MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2939

Official CalmLens SDK for JavaScript and TypeScript: content moderation, asset storage and CDN delivery.

原始使用文档
文档目录5 节
  1. Installation
  2. Quick start
  3. What you can do
  4. Testing
  5. Links

CalmLens JavaScript SDK

The official JavaScript and TypeScript SDK for CalmLens: content moderation and classification for text, images, documents and websites, plus optional storage and CDN delivery.

Installation

npm install calmlens

The same package is also published as @calmlens/sdk, at the same version. Import from the name you installed: calmlens/server with calmlens, or @calmlens/sdk/server with @calmlens/sdk.

The package has two clients, each with its own import:

ImportClientRunsAuthenticates with
calmlens/serverCalmLensServerClientOn your server: Node.js 22 or later, Bun, Deno, Cloudflare WorkersA project API key
calmlens/appCalmLensAppClientIn browsers and React Native appsAn upload preset, with an optional upload token from your server

API keys are secret, so CalmLensServerClient refuses to start in a web page or app. Upload from browsers and apps with CalmLensAppClient, and serve private content to them with signed URLs. The package ships ES modules and CommonJS with type declarations. The main, /server and /app entry points load no other packages at runtime. The package depends on zod, which its type declarations and testing helpers use, and on pdfjs-dist and hls.js, which the UI viewers load only when they show a document or a stream.

Versions follow semantic versioning: see Versioning and support.

Quick start

Create an API key under Developer → API Keys in the CalmLens portal. The same page shows your Project ID. Keep both on your server.

import { CalmLensServerClient } from "calmlens/server";

const client = new CalmLensServerClient({
  apiKey: process.env.CALMLENS_API_KEY!,
  projectId: process.env.CALMLENS_PROJECT_ID!,
});

// Text (comments, captions, bios): waits for the decision
const comment = await client.text.classify({ text: "Great photo!", externalId: "comment-42" });

const { status } = comment.classification.moderation;
if (status === "allowed" || status === "limited") {
  // publish it; keep "limited" out of recommendations, trending and notifications
} else {
  // "age-restricted": show it only behind your own age check; "blocked" or "purged": don't publish it
}

// Images and documents: queued, resolved by webhook or assets.retrieve()
const image = await client.assets.create({
  name: "photo.jpg",
  content: { data: file, type: "image/jpeg" },
  externalId: "post-7",
});
console.log(image.classification.status, image.classification.moderation.status); // "processing" "pending"
classification.statusclassification.moderation.statusMeaning
completedallowedSafe to show.
completedlimitedDelivered like allowed; reduce its reach, such as keeping it out of recommendations.
completedage-restrictedDelivered only with viewerClaims.ageConfirmed=true. Show it only to age-checked viewers.
completedblockedYour policy blocked it; the CDN doesn't deliver it. Don't show it.
completedpurgedYour policy blocked it and deleted its content. Don't show it.
queued or processingpendingStill being received or classified.
failedpendingProcessing failed; see assets.retry.

The latest applied review in classification.moderation.manualReviews takes precedence over the automated decision. Treat a status you don't recognise as not allowed. See How CalmLens works.

What you can do

Every public SDK operation accepts one options object, so call sites stay stable as optional fields are added. The SDK reference lists every option and method.

Testing

calmlens/testing runs the real clients against an in-memory CalmLens API and CDN, with moderation outcomes, recorded requests, injected failures and signed webhook deliveries. See JavaScript testing.

calmlens/test-inputs makes signed test codes and images that the project they are signed for moderates as the scenario you choose. A code counts only as the whole text and an image only as the whole upload. See Generate test inputs.

版本与发布记录

@calmlens/sdk 共发布 27 个版本,首次发布于 2026/10/10;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.22.0latest2026/11/09今天
0.21.02026/11/081 天前
0.20.02026/11/054 天前
0.19.02026/11/045 天前
0.18.32026/11/035 天前
0.18.22026/11/035 天前

关于 @calmlens/sdk 的常见问题

@calmlens/sdk 是什么?

Official CalmLens SDK for JavaScript and TypeScript: content moderation, asset storage and CDN delivery.

如何安装 @calmlens/sdk?

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

@calmlens/sdk 支持 TypeScript 吗?

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

@calmlens/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@calmlens/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@calmlens/sdk 可以商用吗?

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

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

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

@calmlens/sdk 还在维护吗?

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