@imprun/sdk
v1.0.0
Published
The cloud sdk for imprun.dev cloud function
Readme
@imprun/sdk
imprun.dev 의 Actor 개발을 위한 공식 Cloud SDK입니다.
설치
npm install @imprun/sdk주요 기능
v1.1.0 새로운 기능 🚀
- HTTP Module: Impit 기반 브라우저 TLS fingerprinting으로 봇 탐지 회피
- Logging System: 구조화된 로깅, 민감 정보 마스킹, DataPlane 통합
- Browser Automation: Puppeteer 래퍼 (준비 중)
기존 기능 (v1.0.x)
- Database: MongoDB 프록시
- Token Management: JWT 토큰 생성/파싱
빠른 시작
import cloud from "@imprun/sdk";
// 기본 HTTP 클라이언트 (기본 Chrome 설정)
const response = await cloud.http.get("https://www.hometax.go.kr");
const html = await response.text();
// 또는 커스텀 옵션으로
const http = cloud.createHttp({
browser: "firefox",
timeout: 60000,
});
const response2 = await http.get("https://api.example.com");
// 구조화된 로깅
cloud.log.info("Page fetched", { url: "hometax.go.kr", size: html.length });API 사용법
HTTP 모듈 (v1.1.0+)
import cloud, { CloudHttp } from "@imprun/sdk";
// 기본 사용 (기본 옵션)
const response = await cloud.http.get("https://api.example.com/data");
const json = await response.json();
// 커스텀 옵션으로 HTTP 클라이언트 생성
const customHttp = cloud.createHttp({
browser: "firefox", // Chrome 대신 Firefox 사용
timeout: 60000, // 60초 타임아웃
ignoreTlsErrors: true, // TLS 오류 무시
proxyUrl: "http://proxy:8080", // 프록시 사용
http3: true, // HTTP/3 활성화
retryOptions: {
maxAttempts: 5,
delay: 2000,
backoff: "exponential",
},
});
// 직접 CloudHttp 인스턴스 생성
const http = new CloudHttp({
browser: "chrome",
followRedirects: false, // 리다이렉트 비활성화
maxRedirects: 5,
headers: {
// 기본 헤더 설정
"User-Agent": "MyBot/1.0",
},
localAddress: "192.168.1.100", // 특정 네트워크 인터페이스 사용
cookieJar: {
// 커스텀 쿠키 관리
setCookie: async (cookie, url) => {
// 커스텀 쿠키 저장 로직
},
getCookieString: async (url) => {
// 커스텀 쿠키 반환 로직
return "";
},
},
});로깅 시스템 (v1.1.0+)
// 로그 레벨: debug, info, warn, error
cloud.log.info("Processing started", { batchId: 123 });
cloud.log.error("Failed to process", new Error("Network timeout"));
// 민감 정보 자동 마스킹
cloud.log.info("Login attempt", {
username: "[email protected]",
password: "secret123", // 자동으로 ***MASKED***
});
// 성능 측정
const perfLogger = cloud.createPerfLogger("Database");
await perfLogger.measure("query-users", async () => {
return await db.collection("users").find({});
});데이터베이스
const db = cloud.database();
const users = db.collection("users");
await users.insertOne({ name: "John", age: 30 });
const user = await users.findOne({ name: "John" });마이그레이션 가이드
v1.0.x → v1.1.0은 하위 호환성을 유지합니다:
// 기존 코드 (계속 동작)
cloud.fetch(...); // deprecated
// 새로운 코드 (권장)
cloud.http.get(...); // Impit 기반
cloud.log.info(...); // 구조화된 로깅License
ISC
