ForcePilot/backend/package/yuxi/external_systems/integrations/hubspot/metadata.py
Kris 74709ba2d3 feat: 完成外部系统限界上下文核心代码实现
新增六边形架构核心代码包,包含:
1. 协议适配器层:HTTP/SMTP/IMAP/SSH/GRPC等多协议适配器实现
2. 认证插件体系:基础认证、API密钥、HMAC等多类型认证插件
3. 执行编排框架:工具执行器、上下文构建、运行时治理组件
4. 用例端口与DTO:定义领域服务端口与数据传输对象
5. 厂商集成包框架:支持第三方系统集成扩展
6. 基础设施装配层:实现依赖注入与服务装配

所有代码遵循六边形架构设计原则,实现端口与适配器解耦,支持动态扩展与自动发现。
2026-06-20 22:12:42 +08:00

111 lines
4.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""HubSpot 厂商集成元数据。
定义 ``IntegrationMetadata(key="hubspot", ...)``,由 ``__init__.py`` 自注册到
``IntegrationRegistry``。元数据为内存态,不持久化到数据库。
同时定义 HubSpot API 端点常量与标准对象类型 ID 表,供 ``operations.py`` /
``generators.py`` 复用。
版本路径策略(见设计文档 §6.2
| API 类别 | 推荐路径 | 原因 |
| --- | --- | --- |
| 元数据发现 | ``/crm/v3/...`` | 元数据 API 稳定v3 路径主流兼容 |
| 对象 CRUD 与 Search | ``/crm/v3/objects/{objectTypeId}`` | 兼容性最佳 |
| 关联 | ``/crm/v4/associations/...`` | v4 支持带标签关联 |
| OAuth 认证端点 | ``/oauth/2026-03/...`` | 强制使用日期版本 |
| 健康检查 | ``/account-info/v3/details`` | v3 路径稳定 |
"""
from __future__ import annotations
from yuxi.external_systems.integrations.schemas import IntegrationMetadata
# ── API 基础 URL 与 OAuth 端点 ────────────────────────────────────────────
API_BASE_URL = "https://api.hubapi.com"
OAUTH_AUTHORIZE_URL = "https://app.hubspot.com/oauth/authorize"
OAUTH_TOKEN_URL = "https://api.hubapi.com/oauth/2026-03/token"
OAUTH_INTROSPECT_URL = "https://api.hubapi.com/oauth/2026-03/token/introspect"
OAUTH_REVOKE_URL = "https://api.hubapi.com/oauth/2026-03/token/revoke"
# ── 账户信息路径(健康检查推荐)──────────────────────────────────────────
ACCOUNT_INFO_PATH = "/account-info/v3/details"
# ── 元数据发现路径常量 ────────────────────────────────────────────────────
SCHEMAS_PATH = "/crm/v3/schemas"
PROPERTIES_PATH_TEMPLATE = "/crm/v3/properties/{object_type_id}"
ASSOCIATIONS_PATH_TEMPLATE = "/crm/v4/associations/{from}/{to}/labels"
PIPELINES_PATH_TEMPLATE = "/crm/v3/pipelines/{object_type_id}"
# ── 对象 CRUD / Search / Batch 路径模板 ───────────────────────────────────
OBJECTS_PATH_TEMPLATE = "/crm/v3/objects/{object_type_id}"
SEARCH_PATH_TEMPLATE = "/crm/v3/objects/{object_type_id}/search"
BATCH_PATH_TEMPLATE = "/crm/v3/objects/{object_type_id}/batch/{operation}"
ASSOCIATION_BATCH_PATH_TEMPLATE = "/crm/v4/associations/{from}/{to}/batch/create"
# ── 标准对象类型 ID 表(见设计文档 §4.2)─────────────────────────────────
STANDARD_OBJECT_TYPE_IDS: dict[str, str] = {
"contacts": "0-1",
"companies": "0-2",
"deals": "0-3",
"tickets": "0-5",
"products": "0-7",
"line_items": "0-8",
"quotes": "0-14",
"calls": "0-48",
"emails": "0-49",
"meetings": "0-47",
"tasks": "0-27",
"notes": "0-46",
"leads": "0-136",
"invoices": "0-53",
"goals": "0-74",
}
# ── 默认发现的标准对象 FQN 列表 ──────────────────────────────────────────
DEFAULT_STANDARD_OBJECTS: list[str] = [
"contacts",
"companies",
"deals",
"tickets",
]
HUBSPOT_METADATA = IntegrationMetadata(
key="hubspot",
display_name="HubSpot",
description="HubSpot CRM 集成,支持对象 CRUD / Search / 关联 / 批量 / 导入",
adapter_type="http",
source_types=["hubspot"],
supported_auth_types=[
"oauth2_authorization_code",
"private_app_token",
],
tags=["CRM", "Marketing", "SaaS"],
icon="hubspot",
docs_url="https://developers.hubspot.com/docs/api/overview",
connection_extra_schema={
"type": "object",
"properties": {
"base_url": {
"type": "string",
"default": API_BASE_URL,
"description": "API 基础 URL默认 https://api.hubapi.com",
},
"authorize_url": {
"type": "string",
"default": OAUTH_AUTHORIZE_URL,
"description": "OAuth 2.1 授权端点,前端拼接授权 URL 时使用",
},
},
},
example_config={
"base_url": API_BASE_URL,
"authorize_url": OAUTH_AUTHORIZE_URL,
},
dependency_note=(
"多租户场景推荐 oauth2_authorization_codeOAuth 2.1access token 30 分钟自动刷新);"
"内部集成推荐 private_app_tokenBearer pat-...,长期有效,需定期轮换)。"
"api_key 已于 2022-11-30 弃用,不再支持。"
),
)