@12-apps/impersonation

中文文档
1.6.0发布于 2026/10/13MITTypeScriptES Module构建来源已验证近 30 天下载 3.3万

Generic, portable impersonation / preview sessions. An operator previews as a tenant user: reads are scoped, writes are refused unless opted in, money paths are always refused, and revoking the entitlement ends the session live. Framework-free core (cooki

原始使用文档
文档目录5 节
  1. The two kinds of session
  2. What the package owns
  3. What stays the host's
  4. The inversion worth reading before you edit the tables
  5. Subpaths

@12-apps/impersonation

An operator previews as a tenant user. Reads are scoped, writes are refused unless opted in, money paths are always refused, and revoking the entitlement refuses every request under the session — including the reads — while leaving the exit reachable, so the operator is told to leave rather than locked in.

Both halves ship here, each behind a single factory that takes a config object:

const { routes, guard } = createApiImpersonation({ … }); // @12-apps/impersonation/server
const { banner, dialog } = createWebImpersonation({ … }); // @12-apps/impersonation/react

The two kinds of session

kindwho it resolves asceiling (the host's)writes
operatorthe TARGET usernone — be exactly themonly with allowWrites, asked for at start
preview, memberthe previewed MEMBERthe actor's own setnever
preview, rolethe actor themselvesthe previewed ROLE's setallowed

The ceiling column is the host's obligation, not this package's. Enforcing it needs the host's permission engine, its role storage and its scope vocabulary, none of which ship here — so the package states the rule (previewCeilingKind, outsideBoundedTenant) and ADOPTING makes it step 8. A host that skips it gets a member preview granting the previewer their OWN full rights while the banner says otherwise, and nothing here would notice.

The role row is not a hole. A role preview substitutes no one: the subject stays the actor and the previewed role only ever INTERSECTS their own rights, so every write it permits is one they could already have made under their own name. A member preview resolves as somebody else and is therefore refused whatever the cookie says — the rule is re-derived from the session's shape, never from a flag a caller could set.

What the package owns

  • The cookie. Minting, reading, ending. There is no sliding renewal, and that is structural rather than un-implemented: a decoded session is not assignable to the mint's input, so no expression can re-stamp a live window.
  • The tenant bound. outsideBoundedTenant — three lines every host must get right, and silent when wrong: the write gate checks the path and the kind, never the scope.
  • The write gate. The branch order is the feature — the exit first (a session that cannot be stopped is worse than any write it might make), then the live revocation, then money, then accounts, then the read shortcut, then the per-kind rule.
  • The routes. Three verbs on one resource for the platform mount (start, stop, describe), two on the tenant mount (start a preview, stop).
  • The browser half. The bar that cannot scroll away, be dismissed or be covered; the countdown that recomputes from the clock; the chrome offset; the wake-up handling; the exit's ordering; the start handshake; and the start dialog.
  • The journeys. @12-apps/impersonation/e2e ships the Gherkin, its steps and the port a host implements to run them.

What stays the host's

Everything below is REQUIRED config with no default. A default here fails open: it hands a second host another product's URLs, vocabulary or language, silently.

  • Who is calling — the resolved actor: user id, e-mail, platform authority, the permission ids they hold, and whether the request came from a machine token.
  • The cipher — an authenticated codec whose tag is the integrity check.
  • The time box — per kind, in milliseconds.
  • The path tables — where money moves, which of those GETs are proven pure, which prefixes hold a person's own account, and where this package's own routes were mounted.
  • The directory — who may be impersonated, in which tenant, and whether a target holds platform authority itself.
  • The trail — start, end, and every refused attempt.
  • The entitlement — the tenant's plan and its own consent switch, when the host has them.
  • Every sentence — both halves take all their copy as config.

The inversion worth reading before you edit the tables

On a money path the METHOD decides nothing. Payment surfaces routinely settle state on a GET — a status poll that confirms an order paid, a verification landing that activates a provider, an OAuth callback that stores credentials — because the provider, not the application, chose when the browser came back. So a read is let through only when it appears in paths.moneyReads, an enumerated allowlist anchored to the WHOLE pathname. A new route under a money subtree is refused until a human reads it and adds it: that costs a bug report, where the other order costs a charge.

Account paths are the opposite and get a separate table for exactly that reason: nothing under them is a redirect target, so no GET there is forced to settle state, and reads are allowed while every write is refused.

Subpaths

subpathwhat it ispeers
.the framework-free core: codec, path rules, write rule, permissions, wire shapes—
./servercreateApiImpersonation — route descriptors, the write gate, the ports—
./honothe two mounts as routershono
./reactcreateWebImpersonation — the banner and the start dialogreact
./e2ethe packaged journeys, their steps, and the world port@playwright/test, playwright-bdd

Adoption contract, step by step: ADOPTING.md.

版本与发布记录

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

版本发布日期距今
1.6.0latest2026/10/1326 天前
1.5.22026/09/281 个月前
1.5.12026/08/262 个月前
1.5.02026/08/262 个月前
1.4.02026/08/252 个月前
1.3.12026/08/252 个月前

关于 @12-apps/impersonation 的常见问题

@12-apps/impersonation 是什么?

Generic, portable impersonation / preview sessions. An operator previews as a tenant user: reads are scoped, writes are refused unless opted in, money paths are always refused, and revoking the entitlement ends the session live. Framework-free core (cooki

如何安装 @12-apps/impersonation?

在项目目录运行 npm install @12-apps/impersonation,或使用 pnpm add / yarn add / bun add。

@12-apps/impersonation 支持 TypeScript 吗?

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

@12-apps/impersonation 支持 ESM 还是 CommonJS?

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

@12-apps/impersonation 需要什么版本的 Node.js?

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

@12-apps/impersonation 可以商用吗?

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

@12-apps/impersonation 的下载量有多少?

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

@12-apps/impersonation 还在维护吗?

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