@cosmicdrift/kumiko-renderer-puppeteer-client

中文文档
0.419.0发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 1.4万

Renderer-Foundation plugin: HTTP client for puppeteer-service (PDF + image snapshot via remote browser).

原始使用文档
文档目录7 节
  1. Architecture
  2. Mount
  3. Configuration (env vars)
  4. Retry strategy
  5. Caller pattern
  6. Tests
  7. Out of scope

renderer-puppeteer-client

Plugin for renderer-foundation. Renders kind=["document-pdf", "image-snapshot"] requests via an HTTP call to puppeteer-service (separate app in apps/puppeteer-service in this repository).

Architecture

Caller (e.g. Solon NKA-PDF-Generator)
   │
   │ const renderer = foundation.createRendererForTenant({ tenantId, kind: "document-pdf" })
   │ await renderer.render({ kind: "document-pdf", payload: { content: "<html>…" } }, ctx)
   ▼
renderer-puppeteer-client (THIS package)
   │
   │ POST {PUPPETEER_SERVICE_URL}/render
   │ Authorization: Bearer {PUPPETEER_AUTH_TOKEN}
   │ Retry: 5xx + network-error (exponential backoff)
   ▼
puppeteer-service (separate app, K8s deployment)
   │
   │ Launches Puppeteer browser, renders HTML
   ▼
{kind: "document-pdf", pdfBytes, ...}

Mount

import { createRendererPuppeteerClientFeature } from "@cosmicdrift/kumiko-renderer-puppeteer-client";
import { createRendererFoundationFeature } from "@cosmicdrift/kumiko-bundled-features/renderer-foundation";

const features = [
  createRendererFoundationFeature(),
  createRendererPuppeteerClientFeature(),
  // additional renderer plugins (renderer-mail-html, …)
];

// In createKumikoApp's extraContext:
extraContext: ({ db, registry }) => ({
  rendererFoundation: createRendererFoundationApi(collectRendererPlugins(registry)),
});

Configuration (env vars)

App-wide, set via K8s Secret + ConfigMap:

VarDefaultDescription
PUPPETEER_SERVICE_URLhttp://puppeteer-service:3000Internal cluster URL of the service
PUPPETEER_AUTH_TOKENrequiredShared secret (>=16 chars, matching the service)
PUPPETEER_CLIENT_TIMEOUT_MS60000Per-request timeout (client side)
PUPPETEER_CLIENT_MAX_RETRIES3Number of retries for 5xx/network errors

Per tenant? Currently no. All tenants use the same service. Per-tenant overrides via a config bundle will be added when there is a real need, for example a dedicated Puppeteer pool for enterprise tenants.

Retry strategy

ResponseAction
2xxSuccess, return bytes
4xx (validation, auth, 413)NO retry. Return RendererError("invalid_payload") immediately
5xx (render error, service crash)Retry with exponential backoff (200ms × 2^attempt) + ±50% jitter
Network-error (ECONNREFUSED, timeout)Retry as for 5xx

After PUPPETEER_CLIENT_MAX_RETRIES is exhausted: RendererError("other") with the original error message.

Caller pattern

import { requireRendererFoundation } from "@cosmicdrift/kumiko-bundled-features/renderer-foundation";

async function generatePdf(ctx, tenantId, htmlContent) {
  const foundation = requireRendererFoundation(ctx, "generatePdf");
  const renderer = foundation.createRendererForTenant({ tenantId, kind: "document-pdf" });

  const result = await renderer.render(
    {
      kind: "document-pdf",
      payload: { content: htmlContent },
      options: { format: "A4", marginMm: { top: 15, bottom: 15 } },
    },
    { db: ctx.db, registry: ctx.registry, tenantId },
  );

  if (result.kind !== "document-pdf") throw new Error("unexpected kind");
  return result.pdfBytes; // → S3 upload or directly to the caller
}

Tests

  • 15 unit tests (config + HTTP client + render + contract). No actual network call, fetch mocked via vi.stubGlobal.
  • No integration test with a real service. The service stack requires puppeteer-service to be running at a URL, which is an E2E setup (step 7). Here, only unit coverage of the HTTP layer.

Out of scope

  • HTML sanitization: the caller provides trusted HTML (from template-resolver with tenant scoping)
  • File storage: the response always contains inline bytes, and the caller persists them to S3 if necessary
  • Tenant-specific URLs: currently app-wide, possibly via a config bundle later

版本与发布记录

@cosmicdrift/kumiko-renderer-puppeteer-client 共发布 63 个版本,首次发布于 2026/10/17;过去 12 个月发布了 63 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.419.0latest2026/11/11今天
0.418.02026/11/101 天前
0.417.02026/11/091 天前
0.416.02026/11/082 天前
0.415.02026/11/064 天前
0.414.02026/11/055 天前

关于 @cosmicdrift/kumiko-renderer-puppeteer-client 的常见问题

@cosmicdrift/kumiko-renderer-puppeteer-client 是什么?

Renderer-Foundation plugin: HTTP client for puppeteer-service (PDF + image snapshot via remote browser).

如何安装 @cosmicdrift/kumiko-renderer-puppeteer-client?

在项目目录运行 npm install @cosmicdrift/kumiko-renderer-puppeteer-client,或使用 pnpm add / yarn add / bun add。

@cosmicdrift/kumiko-renderer-puppeteer-client 支持 TypeScript 吗?

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

@cosmicdrift/kumiko-renderer-puppeteer-client 支持 ESM 还是 CommonJS?

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

@cosmicdrift/kumiko-renderer-puppeteer-client 可以商用吗?

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

@cosmicdrift/kumiko-renderer-puppeteer-client 的下载量有多少?

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

@cosmicdrift/kumiko-renderer-puppeteer-client 还在维护吗?

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