[30388f42] Infrastructure Hardening: Repaired CE/Connector DB schema, fixed frontend styling build, implemented robust echo shield in worker v2.1.1, and integrated Lead Engine into gateway.

This commit is contained in:
2026-03-07 14:08:42 +00:00
parent 35c30bc39a
commit d1b77fd2f6
415 changed files with 24100 additions and 13301 deletions

View File

@@ -1,89 +1,50 @@
# connector-superoffice/discover_fields.py (Standalone & Robust)
import os
import requests
import json
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv(override=True)
from superoffice_client import SuperOfficeClient
# Configuration
SO_ENV = os.getenv("SO_ENVIRONMENT", "sod") # sod, stage, online
SO_CLIENT_ID = os.getenv("SO_CLIENT_ID") or os.getenv("SO_SOD")
SO_CLIENT_SECRET = os.getenv("SO_CLIENT_SECRET")
# SO_REDIRECT_URI often required for validation even in refresh flow
SO_REDIRECT_URI = os.getenv("SO_REDIRECT_URI", "http://localhost")
SO_REFRESH_TOKEN = os.getenv("SO_REFRESH_TOKEN")
# Force unbuffered stdout
sys.stdout.reconfigure(line_buffering=True)
def get_access_token():
"""Refreshes the access token using the refresh token."""
url = f"https://{SO_ENV}.superoffice.com/login/common/oauth/tokens"
data = {
"grant_type": "refresh_token",
"client_id": SO_CLIENT_ID,
"client_secret": SO_CLIENT_SECRET,
"refresh_token": SO_REFRESH_TOKEN,
"redirect_uri": SO_REDIRECT_URI
}
def discover():
print("🔍 Starting SuperOffice Discovery Tool (Direct Sending)...")
print(f"DEBUG: Refreshing token at {url} for Client ID {SO_CLIENT_ID[:5]}...")
response = requests.post(url, data=data)
if response.status_code == 200:
print("✅ Access Token refreshed.")
return response.json().get("access_token")
else:
print(f"❌ Error getting token: {response.text}")
return None
def discover_udfs(base_url, token, entity="Contact"):
"""
Fetches the UDF layout for a specific entity.
entity: 'Contact' (Firma) or 'Person'
"""
endpoint = "Contact" if entity == "Contact" else "Person"
url = f"{base_url}/api/v1/{endpoint}?$top=1&$select=userDefinedFields"
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/json"
}
print(f"\n--- DISCOVERING UDFS FOR: {entity} ---")
try:
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
if data['value']:
item = data['value'][0]
udfs = item.get('userDefinedFields', {})
print(f"Found {len(udfs)} UDFs on this record.")
# Filter logic: Show interesting fields
relevant_udfs = {k: v for k, v in udfs.items() if "marketing" in k.lower() or "robotic" in k.lower() or "challenge" in k.lower() or "ai" in k.lower()}
if relevant_udfs:
print("✅ FOUND RELEVANT FIELDS (ProgId : Value):")
print(json.dumps(relevant_udfs, indent=2))
else:
print("⚠️ No fields matching 'marketing/robotic/ai' found.")
print("First 5 UDFs for context:")
print(json.dumps(list(udfs.keys())[:5], indent=2))
else:
print("No records found to inspect.")
else:
print(f"Error {response.status_code}: {response.text}")
client = SuperOfficeClient()
except Exception as e:
print(f"Request failed: {e}")
print(f"❌ Failed to init client: {e}")
return
if not client.access_token:
print("❌ Auth failed. Check .env")
return
# 4. Check Sending Endpoints
print("\n--- 4. Direct Sending Endpoints ---")
# EMail Agent
print(f"Checking Endpoint: Agents/EMail/GetDefaultEMailFromAddress...")
try:
res = client._get("Agents/EMail/GetDefaultEMailFromAddress")
if res:
print(f"✅ Agents/EMail active. Default From: {json.dumps(res)}")
else:
print(f"❓ Agents/EMail returned None (likely 404/403).")
except Exception as e:
print(f"❌ Agents/EMail check failed: {e}")
# TicketMessage
print(f"Checking Endpoint: Archive/dynamic (Ticket)...")
try:
res = client._get("Archive/dynamic?$select=all&$top=1&entity=ticket")
if res:
print(f"✅ Ticket entities found. Service module active.")
else:
print(f"❓ No Ticket entities found (Service module inactive?).")
except Exception as e:
print(f"❌ Ticket check failed: {e}")
if __name__ == "__main__":
token = get_access_token()
if token:
# Hardcoded Base URL for Cust55774 (Fix: Use app-sod as per README)
base_url = "https://app-sod.superoffice.com/Cust55774"
discover_udfs(base_url, token, "Person")
discover_udfs(base_url, token, "Contact")
else:
print("Could not get Access Token. Check .env")
discover()