@carecard/jwt-read

中文文档
3.45.0发布于 2026/11/03ISCTypeScriptCommonJS构建来源已验证近 30 天下载 3030

Jwt read functions

原始使用文档
文档目录3 节
  1. Verified tokens
  2. Introspection and transport
  3. Validation

@carecard/jwt-read

Generic JWT signature and registered-claim verification. Custom claims are opaque; role semantics, request contexts, application ownership, auth-response aliases, and access lifetimes belong to the owning services and applications.

Verified tokens

jwtReadVerifiedToken(token, parsedJwks, requirements?) returns header and payload only after signature, expiration, issued-at, and not-before validation. Invalid credentials return null. Caller requirements may specify issuer, subject, audience (string or list), maximumAgeSeconds, and validateClaims. The callback defines custom-claim policy explicitly; it must return true to accept the payload.

There is no application audience shape or ten-minute lifetime default. A caller may require a single string audience in validateClaims when its own contract requires one. Malformed requirements raise TypeError.

const { jwtReadVerifiedToken } = require('@carecard/jwt-read');
const parts = jwtReadVerifiedToken(token, verificationJwks, {
  issuer: 'issuer',
  audience: 'receiver',
  maximumAgeSeconds: 900,
  validateClaims: payload => payload.custom === 'expected',
});

Introspection and transport

jwtReadIntrospectedToken(token, introspect, requirements?) accepts caller-normalized { active: true, claims } results and applies the same explicit constraints. It preserves canonical custom claims without inferring service response fields. Introspection failures propagate to the owner.

jwtReadBearerToken(header) accepts exactly one complete HTTP Bearer credential, including outer whitespace, and rejects extra words or internal token whitespace.

jwtGetTokenDeadline(payload, maximumAgeSeconds?) returns the expiration or the earlier explicit maximum age, with no business-policy default. Invalid timing returns null. jwtIsTokenExpired(request, maximumAgeSeconds?) checks current time.

The existing generic jwtGetClientId, jwtGetAgeInSeconds, and jwtIsExpired helpers expose standard subject/timing values. They assign no role or privilege. Express request payload types contain registered and opaque custom claims only.

Validation

Run npm run test:All, npm run lint, and npm run format:check. Tests use the public package root and exercise opaque claims, configurable identities and lifetimes, key rotation, canonical introspection, malformed input, and timing. Business authorization and mapping are tested through owner-local boundaries.

Non-negotiable test order invariance rule: Every test must pass independently of which tests run before or after it, and the suite must pass in every execution order. Each test must establish the state it needs, isolate mutable state, and clean up state it owns; it must never rely on another test's setup, mutations, or cleanup. Default test, CI, and Husky commands must use the test framework's ordinary ordering and must not force randomized ordering. Random-order execution is an explicit diagnostic only, and every failure it exposes must be fixed at the root cause.

Non-negotiable root-cause solution rule: Always identify and solve the verified root cause, use the stronger solution, and deliver a correct, durable, production-quality result. Never treat a temporary workaround, resource increase, retry, suppression, bypass, or symptom-only patch as completion. Validate the root-cause fix against the real failing workflow and prove the end state.

Non-negotiable TDD rule: Always write the failing test first, run it to confirm it fails for the intended reason, then implement the code and rerun the test until it passes. Test Driven Development is required for all coding work and must not be skipped. For documentation- or skill-only edits, run the relevant focused non-test validation before changing the prose; do not add automated tests that inspect prose, files, or repository structure.

Non-negotiable repository isolation rule: Every repository must run its Husky hooks and tests using only files, code, fixtures, dependencies, and services contained within that repository. Tests and Husky scripts must not import, require, read, execute, or otherwise depend on sibling repositories or paths outside the repository root. app-e2e-tests is the only exception because cross-repository end-to-end testing is its explicit responsibility.

Non-negotiable error and warning rule: Never suppress, silence, hide, downgrade, filter, ignore, skip, or bypass errors or warnings from code, tests, tools, compilers, linters, or validation. Fix the root cause, then rerun the affected check and require a clean result. Expected error-path tests may assert errors, but must not conceal unexpected failures.

Non-negotiable TypeScript type rule: Never use the TypeScript type any; always use specific domain types, generics, existing project types, or unknown with explicit narrowing in all TypeScript-family files (.ts, .tsx, .mts, .cts, and .d.ts).

Non-negotiable code organization rule: Functions with the same or equivalent behavior must use the same or clearly corresponding descriptive names across CareCard repositories, and equivalent functionality must live in files with the same names within each repository's established architecture. No backward compatibility names, aliases, or duplicate locations are allowed.

版本与发布记录

@carecard/jwt-read 共发布 67 个版本,首次发布于 2025/12/24;过去 12 个月发布了 67 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.45.0latest2026/11/036 天前
3.44.02026/10/1327 天前
3.42.02026/10/1327 天前
3.41.02026/10/1227 天前
3.40.02026/10/1228 天前
3.39.02026/10/1228 天前

关于 @carecard/jwt-read 的常见问题

@carecard/jwt-read 是什么?

Jwt read functions

如何安装 @carecard/jwt-read?

在项目目录运行 npm install @carecard/jwt-read,或使用 pnpm add / yarn add / bun add。

@carecard/jwt-read 支持 TypeScript 吗?

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

@carecard/jwt-read 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@carecard/jwt-read 需要什么版本的 Node.js?

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

@carecard/jwt-read 可以商用吗?

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

@carecard/jwt-read 的下载量有多少?

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

@carecard/jwt-read 还在维护吗?

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