@explorins/pers-shared

中文文档
2.1.230发布于 2026/11/12MITTypeScriptESM + CJS近 30 天下载 2531

Shared library for PERS applications

原始使用文档
文档目录10 节
  1. Public Contracts Library
  2. Bundle Size
  3. Contents
  4. Critical Build Configuration
  5. Usage
  6. Backend/Node.js
  7. Frontend/Browser (Ultra-Light)
  8. 🔧 Build System & Performance
  9. �️ Domain Vocabulary
  10. �🎯 Key Benefits

@explorins/pers-shared

Public Contracts Library

Pure data contracts for frontends, third-party integrations, and API consumers.

Bundle Size

  • Browser Bundle: 0.44 KB (0.30 KB gzipped)
  • Full Bundle: 0.67 KB (0.38 KB gzipped)
  • CommonJS: 1.53 KB (0.72 KB gzipped)
  • Package Size: 1.2 MB (includes all TypeScript definitions)
  • Runtime Impact: < 1 KB with tree shaking

Contents

  • DTOs - Complete API data transfer objects with validation
  • Interfaces - TypeScript contracts for authentication, users, campaigns, transactions
  • Types & Enums - Authentication types, error codes, transaction statuses
  • Value Objects - Immutable data structures (Address, StructuredError)
  • Error Classes - Structured domain errors (AuthenticationRequiredError, etc.)
  • Domain Vocabulary - Domains for SDK events, ErrorDomains for error classification

Critical Build Configuration

SWAGGER COMPATIBILITY ISSUE: This library requires "moduleResolution": "node16" in tsconfig.json to prevent circular dependency errors with NestJS Swagger. Using "node" caused 3 days of debugging for Swagger generation failures.

{
  "compilerOptions": {
    "moduleResolution": "node16", // CRITICAL: Required for Swagger compatibility
    "target": "ES2022",
    "module": "CommonJS"
  }
}

Usage

npm install @explorins/pers-shared

Backend/Node.js

import { 
  UserDTO, 
  TransactionStatus, 
  AuthenticationRequiredError,
  PasskeysAuthRequestDTO 
} from '@explorins/pers-shared';

// Type-safe API requests
const authRequest: PasskeysAuthRequestDTO = {
  authToken: "external_provider_jwt_token"
};

// Structured error handling
try {
  const user = await authenticate(authRequest);
} catch (error) {
  if (error instanceof AuthenticationRequiredError) {
    console.error('Authentication failed:', error.code);
  }
}

Frontend/Browser (Ultra-Light)

// Browser-optimized import - Tree-shaken to 0.44 KB!
import { UserDTO, CampaignDTO, Address } from '@explorins/pers-shared/browser';

// React example with full type safety
interface UserBalanceProps {
  user: UserTokenBalancesDTO;
}

const UserBalance: React.FC<UserBalanceProps> = ({ user }) => (
  <div>
    <h2>{user.email}</h2>
    <p>Wallet: {user.walletAddress?.getValue()}</p>
  </div>
);

🔧 Build System & Performance

  • Dual Builds: CommonJS (Node.js) + ESM (browsers) with automatic selection
  • Exceptional Tree Shaking: 99.9%+ elimination (1.2 MB package → 0.44 KB runtime)
  • Zero Runtime: Pure type definitions with no execution overhead
  • Framework Agnostic: React, Vue, Angular, vanilla JS, Node.js

�️ Domain Vocabulary

Unified domain names for SDK event categorization and error classification:

// SDK success events - business domains only
import { Domains, Domain } from '@explorins/pers-shared';

onSuccess(event: { domain: Domain }) {
  if (event.domain === Domains.TRANSACTION) { ... }
}

// SDK error handler - includes technical categories
import { ErrorDomains, ErrorDomain } from '@explorins/pers-shared';

onError(error: { domain: ErrorDomain }) {
  if (error.domain === ErrorDomains.VALIDATION) { ... }
}

�🎯 Key Benefits

  • Type Safety: Catch API integration errors at compile time
  • Developer Experience: Full IntelliSense and auto-completion
  • Performance: Exceptional tree-shaking (1.2 MB → 0.44 KB runtime)
  • Reliability: Contracts match exact PERS API specifications

版本与发布记录

@explorins/pers-shared 共发布 207 个版本,首次发布于 2025/09/07;过去 12 个月发布了 173 个版本。

版本发布日期距今
2.1.230latest2026/11/122 天前
2.1.2292026/11/122 天前
2.1.2282026/11/112 天前
2.1.2272026/11/104 天前
2.1.2262026/11/094 天前
2.1.2252026/11/094 天前

关于 @explorins/pers-shared 的常见问题

@explorins/pers-shared 是什么?

Shared library for PERS applications

如何安装 @explorins/pers-shared?

在项目目录运行 npm install @explorins/pers-shared,或使用 pnpm add / yarn add / bun add。

@explorins/pers-shared 支持 TypeScript 吗?

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

@explorins/pers-shared 支持 ESM 还是 CommonJS?

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

@explorins/pers-shared 可以商用吗?

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

@explorins/pers-shared 的下载量有多少?

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

@explorins/pers-shared 还在维护吗?

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