@genn-inc/cluebase-frontend-sdk

中文文档
0.0.23发布于 2026/11/11TypeScriptES Module近 30 天下载 2316

Cluebase Frontend SDK — OTel-based observation-source event capture for frontend apps

原始使用文档
文档目录15 节
  1. Minimal integration
  2. Content Security Policy requirement
  3. Responsibility boundary
  4. Default privacy/minimization behavior
  5. Sampling and cost guards
  6. Flush reliability
  7. Keepalive flush contract
  8. Degraded event contract
  9. Privacy and PII handling
  10. 1. Hard-deny: PII / secrets are stripped before transport
  11. 2. Default-masked: arbitrary values are masked unless allow…
  12. 3. Operational consequence: configure server allowlist befo…
  13. Architecture boundary
  14. Explicit Event Emit: cluebase.track
  15. Identity Lifecycle: Organization

@genn-inc/cluebase-frontend-sdk

Cluebase browser ingest SDK.

Minimal integration

After pnpm add @genn-inc/cluebase-frontend-sdk, the intended Next.js integration is:

import cluebase from "@genn-inc/cluebase-frontend-sdk";

cluebase.init({
    projectKey: process.env.NEXT_PUBLIC_CLUEBASE_PROJECT_KEY!,
});

cluebase.identify(user.id, { name: user.name });
cluebase.group("organization", organization.id, { name: organization.name });

For Vite, use import.meta.env.VITE_CLUEBASE_PROJECT_KEY. For React apps that use the Create React App env contract, use process.env.REACT_APP_CLUEBASE_PROJECT_KEY. Other frontend frameworks should use the public project-key env name generated by Cluebase setup.

endpoint is optional and defaults to https://api.cluebase.io. Set it only when the SDK must send to another Cluebase API base URL, such as a local environment.

projectKey is the public ingest key. The API resolves authoritative tenantId, projectId, and dev/prod ProjectService from that key. The SDK appends /api/v1/ingest/browser-tokens and the canonical browser observation batch path internally.

Content Security Policy requirement

The SDK converts each OpenTelemetry span through a WebAssembly module, so a host page that sends a Content-Security-Policy header must allow it:

  • script-src must include 'wasm-unsafe-eval'. Without it the browser blocks WebAssembly.instantiate and the module never initializes. 'unsafe-eval' also works but is a far wider grant, so prefer 'wasm-unsafe-eval'.
  • connect-src must allow the origin that serves the bundled cluebase_sdk_core_wasm_bg.wasm asset (usually 'self'), because the module is fetched at runtime relative to the SDK bundle.
  • connect-src must also allow the Cluebase API origin (endpoint, by default https://api.cluebase.io).

Bundlers must emit the .wasm asset. Webpack 5, Vite, and Next.js do this automatically for the new URL(..., import.meta.url) form the SDK uses.

If the module fails to initialize, every span export is dropped and counted as a dropped span; the SDK does not fall back to a JavaScript implementation. Verify the policy in a staging environment before launch.

Responsibility boundary

  • SDK captures browser signals and applies local minimization where the signal is obviously high-risk.
  • API ingest privacy gate is authoritative for final allow/deny/unmask policy.
  • Worker-side sanitize is defense-in-depth only.
  • SDK sends projectKey, schemaVersion, sdkType, sdkVersion, stable keys, and minimized capture payloads.
  • SDK does not authoritatively stamp tenant_id, project_id, environment_id, or final raw-ingest request/response payloads.

The frontend SDK does not own final raw-ingest allowlist decisions.

Default privacy/minimization behavior

The frontend SDK avoids shipping obvious high-risk plaintext and keeps the MVP default event surface intentionally narrow.

  • input_change.value -> local value metadata only
  • selection_text -> metadata only
  • raw selector/path -> never serialized; stable key only

Current MVP defaults:

  • successful network emits one request_finished
  • failed network emits one request_failed
  • standard action capture emits element_clicked, form_submitted, input_committed, toggle_changed, selection_committed, file_selected, and drag_drop_completed
  • normal batching flushes when the queued payload reaches the 48KB send threshold, every 180 seconds by default, or when the page is leaving
  • event type does not change the delivery rule in MVP

Stable key precedence:

  1. data-testid
  2. data-qa
  3. safe name
  4. safe aria-label
  5. structural fallback

Cluebase-specific DOM attributes are not part of the MVP stable-key contract. Captured stable keys are best-effort evidence, not authoritative business meaning.

Sampling and cost guards

  • sampling.sessionSampleRate controls whether a session emits normal capture
  • oversized events degrade in stages before final drop:
    • no raw payload body
    • metadata/schema only
    • shell only
  • oversized batches stay below the configured payload hard max

Flush reliability

The SDK flushes on:

  • visibilitychange -> hidden
  • pagehide

beforeunload is intentionally not used: it disables the back/forward cache and is unreliable on mobile browsers.

The page-leave flush is best effort. The SDK persists unsent source events in localStorage and removes them only after the ingest API accepts the batch. Lifecycle session URLs strip query strings and hashes before they enter the raw SDK event payload.

Token acquisition failures reschedule the next flush with exponential backoff and jitter (base 1s, cap 30s, falling back to the normal flush cadence after 5 attempts); permanent failures (e.g. revoked project) stop retrying instead of spinning forever.

Keepalive flush contract

  • unload / hidden flush always attempts delivery through authenticated fetch with the keepalive hint, whether or not a browser token is already cached
  • when the batch carries only the two authentication values that have a URL-safe fallback (project_key, browser_token — see the backend's fix/browser-ingest-token-query-fallback) and the payload plus those query parameters fit the shared 64 KiB fetch/sendBeacon budget, the unload flush also tries navigator.sendBeacon first, which keeps delivering after the page is torn down. A sendBeacon queue success is never treated as a confirmed delivery (the browser API cannot report server-side outcome); it falls back to the same persisted-outbox retry and idempotency_key dedupe as any other unresolved send

Degraded event contract

Downstream ingest must accept these as normal input:

  • no raw payload body
  • metadata + schema only
  • shell-only event

Privacy and PII handling

The SDK applies a layered privacy model:

1. Hard-deny: PII / secrets are stripped before transport

The SDK strips a built-in set of property keys before the event leaves the browser. These keys cannot be unmasked by the delivered privacy policy — selecting body.email in the Cluebase privacy screen does not bypass the hard-deny.

Hard-deny categories (case- and separator-insensitive — userEmail, user-email, USER_EMAIL, email_address all match):

  • Auth credentials: authorization, cookie, set-cookie, password, passwd, secret, token, access_token, refresh_token, session, session_token, api_key, apikey, private_key
  • PII categories: email, phone, credit_card, ssn

This list is a strict superset of the server-side ingest hard-deny (@cluebase/shared INGEST_HARD_DENY_KEYS), enforced by CI parity tests in all three SDKs.

2. Default-masked: arbitrary values are masked unless allowlisted

Properties that pass the hard-deny gate are still masked by default. The SDK emits a fingerprint or shape-only digest, not the raw value.

To capture a specific field in plaintext, two things must both be true:

  1. The field path is selected in the Cluebase privacy screen. Cluebase delivers that choice to the SDK with the ingest response, and the SDK applies it. This is not an init option: until a policy arrives, and whenever the delivered policy cannot be read, every value stays masked.
  2. The same property key appears in the project's server-side project service observationAnalysisPropertyAllowlist.

If condition 1 holds but condition 2 does not, the value is stored in raw observation storage only — facts_json.analysisProperties.projected will be empty and the field will not appear in Cluebase's analysis UI.

3. Operational consequence: configure server allowlist before launch

Customers who launch without setting observationAnalysisPropertyAllowlist on their resolved project service will see custom event names land in observation_type but no projected properties in dashboards. The raw observation store keeps masked/raw-only evidence for debugging, while analysis projection remains empty until the server allowlist includes the field. Configure the server allowlist via the Cluebase admin UI or project service allowlist API after taking a privacy review of which property names you want to project for analytics.

Architecture boundary

The frontend SDK is a browser wrapper around capture, privacy minimization, correlation propagation, and transport. It sends source-signal envelopes such as sdk_source_signal_observed; the Cluebase backend ingest core performs final classification, unknown diagnostic handling, backend request correlation, and raw-ingest normalization.

browser capture / OTel network span
  -> frontend SDK source-signal envelope
  -> /api/v1/ingest/browser
  -> apps/api/src/modules/ingest core

Rules:

  • Keep browser code limited to raw facts, correlation context, standard OTel attributes, local minimization, and transport.
  • Do not add frontend-only classification, source-hint strategy, semantic DOM annotations, or custom fallback behavior.
  • Add classifier behavior in the backend ingest core so frontend-originated requests, Node.js, Python, and future SDK wrappers receive the same behavior.
  • Preserve interaction_id, request_span_id, request_id, and trace_id whenever they are available. User-action linkage is an ingest contract, not a display-only field.

Explicit Event Emit: cluebase.track

When DOM auto-capture cannot infer the operation (e.g. a custom keyboard shortcut, an API-only background sync, or a multi-step UI flow), the host app may emit an explicit semantic action:

import cluebase from "@genn-inc/cluebase-frontend-sdk";

cluebase.track("report.create", { source: "shortcut", result: "success" });

cluebase.track emits a custom_emitted event for product actions that are not covered by DOM auto-capture. Keep properties privacy-safe and stable; the worker derives higher-level semantics downstream. Event names must match ^[A-Za-z0-9_.:-]{1,128}$; invalid names are dropped with a public warning.

Identity Lifecycle: Organization

The frontend SDK exposes the MVP identity lifecycle APIs that the worker uses to preserve anonymous → identified user → organization evidence:

cluebase.identify("user_42", { plan: "pro" });
cluebase.group("organization", "org_3", { name: "Acme Inc." });
cluebase.reset();

MVP does not expose Cluebase account or workspace as public group types. If the customer product calls its company concept an account, workspace, tenant, or team, pass that stable company id as cluebase.group("organization", ...). Blank or non-string identify user ids and organization group ids are dropped with a public warning and do not update SDK identity state.

版本与发布记录

@genn-inc/cluebase-frontend-sdk 共发布 16 个版本,首次发布于 2026/09/12;过去 12 个月发布了 16 个版本。

版本发布日期距今
0.0.23latest2026/11/114 天前
0.0.202026/11/115 天前
0.0.192026/11/096 天前
0.0.182026/11/0510 天前
0.0.172026/11/0511 天前
0.0.152026/11/0213 天前

关于 @genn-inc/cluebase-frontend-sdk 的常见问题

@genn-inc/cluebase-frontend-sdk 是什么?

Cluebase Frontend SDK — OTel-based observation-source event capture for frontend apps

如何安装 @genn-inc/cluebase-frontend-sdk?

在项目目录运行 npm install @genn-inc/cluebase-frontend-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@opentelemetry/api(>=1.10.0 <1.11.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@genn-inc/cluebase-frontend-sdk 支持 TypeScript 吗?

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

@genn-inc/cluebase-frontend-sdk 支持 ESM 还是 CommonJS?

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

@genn-inc/cluebase-frontend-sdk 可以商用吗?

@genn-inc/cluebase-frontend-sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@genn-inc/cluebase-frontend-sdk 的下载量有多少?

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

@genn-inc/cluebase-frontend-sdk 还在维护吗?

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