npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@croco/impersonation-core

v0.0.2

Published

사용자 사칭(Impersonation) 기능을 위한 핵심 패키지입니다. 관리자가 다른 사용자로 로그인하여 지원을 제공할 수 있습니다.

Downloads

34

Readme

@croco/impersonation-core

사용자 사칭(Impersonation) 기능을 위한 핵심 패키지입니다. 관리자가 다른 사용자로 로그인하여 지원을 제공할 수 있습니다.

설치

pnpm add @croco/impersonation-core

주요 기능

ImpersonationService

사칭 세션 관리를 위한 서비스입니다.

import { ImpersonationService } from "@croco/impersonation-core";

const service = new ImpersonationService(store, authProvider, config);

// 사칭 시작
const session = await service.start("admin-1", "user-123", "Support request");

// 사칭 종료
await service.end(session.sessionId);

// 컨텍스트에서 사칭 여부 확인
const isImpersonating = service.isImpersonating(context);

// 사칭자 ID 가져오기
const impersonatorId = service.getImpersonator(context);

// 타겟 사용자 ID 가져오기
const targetUserId = service.getTargetUser(context);

ImpersonationContext

사칭 컨텍스트 타입은 RequestContext를 확장합니다.

import type { ImpersonationContext } from "@croco/impersonation-core";

const context: ImpersonationContext = {
  requestId: "req-1",
  impersonation: {
    sessionId: "imp-123",
    impersonatorId: "admin-1",
    targetUserId: "user-123",
    reason: "Support request",
    startedAt: new Date(),
    expiresAt: new Date(),
  },
};

ImpersonationStartedEvent

사칭 세션 시작 이벤트입니다.

import { ImpersonationStartedEvent } from "@croco/impersonation-core";

const event = new ImpersonationStartedEvent(session);
await eventPublisher.publish(event);

ImpersonationEndedEvent

사칭 세션 종료 이벤트입니다.

import { ImpersonationEndedEvent } from "@croco/impersonation-core";

const event = new ImpersonationEndedEvent(session);
await eventPublisher.publish(event);

BlockDuringImpersonation 데코레이터

사칭 중 특정 작업을 차단합니다.

import { BlockDuringImpersonation } from "@croco/impersonation-core";

class UserService {
  @BlockDuringImpersonation()
  async deleteUser(userId: string) {
    // 사칭 중에는 이 메서드 실행 불가
  }
}

ImpersonationGuard

사칭 여부를 확인하고 차단합니다.

import { ImpersonationGuard } from "@croco/impersonation-core";

const guard = new ImpersonationGuard(service);

if (guard.canPerformAction(context, "deleteUser")) {
  // 작업 수행
}

InMemoryImpersonationStore

인메모리 사칭 세션 저장소입니다.

import { InMemoryImpersonationStore } from "@croco/impersonation-core";

const store = new InMemoryImpersonationStore();

API

ImpersonationService

| 메서드 | 설명 | | ---------------------------------------------- | ------------------- | | start(impersonatorId, targetUserId, reason?) | 사칭 세션 시작 | | end(sessionId) | 사칭 세션 종료 | | isImpersonating(context) | 사칭 여부 확인 | | getImpersonator(context) | 사칭자 ID 반환 | | getTargetUser(context) | 타겟 사용자 ID 반환 |

ImpersonationConfig

| 속성 | 타입 | 설명 | | ---------------- | -------- | ----------------------- | | maxDurationMs | number | 최대 지속 시간 (밀리초) | | requireReason | boolean | 사칭 사유 필수 여부 | | blockedActions | string[] | 차단할 작업 목록 |

ImpersonationState

| 속성 | 타입 | 설명 | | ---------------- | ------------------- | -------------- | | sessionId | string | 세션 ID | | impersonatorId | string | 사칭자 ID | | targetUserId | string | 타겟 사용자 ID | | reason | string | undefined | 사칭 사유 | | startedAt | Date | 시작 시간 | | expiresAt | Date | 만료 시간 |

타입 안전성

모든 타입은 strict TypeScript 모드에서 안전하게 동작합니다.

  • as any 사용 없이 타입 추론이 완벽하게 동작
  • 모든 컨텍스트 타입은 타입 가드와 함께 사용 가능

사용 예시

완전한 예시

import "reflect-metadata";
import { Container } from "@croco/framework-context";
import { ImpersonationService } from "@croco/impersonation-core";
import { InMemoryImpersonationStore } from "@croco/impersonation-core";
import type { AuthProvider } from "@croco/impersonation-core";

class MyAuthProvider implements AuthProvider {
  getCurrentUserId(): string | null {
    return "admin-1";
  }
}

const store = new InMemoryImpersonationStore();
const authProvider = new MyAuthProvider();
const config = {
  maxDurationMs: 30 * 60 * 1000,
  requireReason: true,
  blockedActions: ["deleteUser", "updatePassword"],
};

const service = new ImpersonationService(store, authProvider, config);

const session = await service.start("admin-1", "user-123", "Customer support");

const context: ImpersonationContext = {
  requestId: "req-1",
  impersonation: session,
};

const isImpersonating = service.isImpersonating(context);
console.log(isImpersonating);