"""카페24 — 공통 연동 계층(app/integrations/cafe24) 재사용. 카페24는 이미 OAuth 로 연결해 쓰고 있다(상품관리). 실적 설정에서 인증정보를 따로 받지 않고, 같은 토큰 저장소(cafe24_db)의 연결 상태를 그대로 보여 준다. 주문 수집(다음 단계)에는 카페24 앱 권한에 mall.read_order 추가 + 재연결이 필요하다 (app/integrations/cafe24/config.py 의 ORDER_SCOPES). """ from __future__ import annotations from .base import AdapterContext, AuthFailed, MarketplaceAdapter, NotConfigured, TokenExpired class Cafe24Adapter(MarketplaceAdapter): code = "cafe24" name = "카페24" auth_type = "shared" docs_url = "https://developers.cafe24.com/docs/api/admin/" note = "카페24 상품관리에서 연결한 OAuth 토큰을 함께 씁니다(여기서 따로 입력하지 않음)." def is_configured(self, ctx: AdapterContext) -> bool: return True def authenticate(self, ctx: AdapterContext) -> None: st = self.shared_status(ctx) if not st.get("connected"): if st.get("missing"): raise NotConfigured("카페24 연동 환경변수가 설정되지 않았습니다.") if st.get("needs_reauth") and st.get("reason", "").startswith("refresh"): raise TokenExpired("카페24 연결이 만료되었습니다. 카페24 상품관리 → 시스템에서 재연결하세요.") raise AuthFailed("카페24에 연결되어 있지 않습니다. 카페24 상품관리 → 시스템에서 연결하세요.") def shared_status(self, ctx: AdapterContext) -> dict: from app.integrations.cafe24.config import load_config # 지연 import from app.integrations.cafe24.tokens import TokenService # 지연 import repo = getattr(ctx.app_state, "cafe24_store", None) if ctx.app_state is not None else None config = load_config() if repo is None: return {"connected": False, "missing": config.missing or ["CAFE24_DB_URL"], "needs_reauth": False} return TokenService(repo, config).status() def test_connection(self, ctx: AdapterContext) -> str: self.authenticate(ctx) st = self.shared_status(ctx) scopes = st.get("scopes") or "" if "mall.read_order" not in scopes: return "카페24 연결 정상. 주문 수집에는 주문 읽기 권한(mall.read_order) 추가가 필요합니다." return "카페24 연결 정상."