Files
ALwrity/backend/services/integrations/wix/auth.py
ajaysi 923fa671fe feat: ContentGuardianAgent, onboarding UX, Team Activity action wiring, docs, agent help modal
ContentGuardianAgent consolidation:
- Merge 3 duplicate classes into single source in specialized/content_guardian.py
- Watchdog audit_committee() with heuristic scoring, coverage gaps, overlaps, alerts
- Remove misleading rejection_rate() helper; use acceptance_rate directly
- Integrate audit + alerts + trend signals into today_workflow_service.py

Team Activity page:
- QualityAuditPanel: health ring, per-agent critiques, coverage gaps, overlaps
- TrendSignalsPanel: opportunity cards with urgency/impact/coverage bars
- AlertBanner: persistent dismiss via POST /alerts/{id}/mark-read
- AgentHelpModal: dialog showing all 8 agents with descriptions, tools, schedule
- QualityAuditPanel action buttons: Fill gap -> /content-planning, Resolve overlap, View CTA on alerts/issues
- TrendSignalsPanel action buttons: Create content from this trend -> /blog-writer with trend context state

Onboarding system:
- Step 4 validation: no auto-pass via basic_ready; requires persona data or explicit progression
- Step 5 validation: logs warning on auto-pass without integration data
- OnboardingCompletionService: single DB session, transactional task creation, upsert pattern
- Business-without-website: nullable website_url on SIFIndexingTask and MarketTrendsTask
- DeepCompetitorAnalysisExecutor: 5-min timeout, 10-competitor cap, asyncio.wait_for
- Persona generation: async with 30s timeout, falls back to scheduler
- OnboardingProgressService.reset_onboarding(): resets session + pauses all DB tasks
- OnboardingControlService.reset_onboarding(): also cancels APScheduler jobs
- FinalStep TaskSchedulingPanel: shows scheduled/failed tasks after completion, 8s auto-redirect
- onboarding_completed agent activity event logged to feed

Documentation:
- docs-site/features/onboarding/: overview, steps, scheduler-tasks, technical-reference (4 pages)
- docs-site/mkdocs.yml: added Onboarding System nav section
- docs-site/features/sif-agents/: overview, agent-directory, committee-system, content-guardian (4 pages)
- docs-site/features/team-activity/: overview, quality-audit, trend-signals, alert-system (4 pages)
- docs-site/features/todays-workflow/: updated overview, technical-architecture, workflow-guide, api-reference
2026-06-01 12:24:31 +05:30

90 lines
3.6 KiB
Python

from typing import Any, Dict, Optional, Tuple
import requests
from loguru import logger
import base64
import hashlib
import secrets
class WixAuthService:
def __init__(self, client_id: Optional[str], redirect_uri: str, base_url: str):
self.client_id = client_id
self.redirect_uri = redirect_uri
self.base_url = base_url
def generate_authorization_url(self, state: Optional[str] = None) -> Tuple[str, str]:
if not self.client_id:
raise ValueError("Wix client ID not configured")
code_verifier = base64.urlsafe_b64encode(secrets.token_bytes(32)).decode('utf-8').rstrip('=')
code_challenge = base64.urlsafe_b64encode(
hashlib.sha256(code_verifier.encode('utf-8')).digest()
).decode('utf-8').rstrip('=')
oauth_url = 'https://www.wix.com/oauth/authorize'
from urllib.parse import urlencode
params = {
'client_id': self.client_id,
'redirect_uri': self.redirect_uri,
'response_type': 'code',
'scope': (
'BLOG.CREATE-DRAFT,BLOG.PUBLISH-POST,BLOG.READ-CATEGORY,'
'BLOG.CREATE-CATEGORY,BLOG.READ-TAG,BLOG.CREATE-TAG,'
'MEDIA.SITE_MEDIA_FILES_IMPORT'
),
'code_challenge': code_challenge,
'code_challenge_method': 'S256'
}
if state:
params['state'] = state
return f"{oauth_url}?{urlencode(params)}", code_verifier
def exchange_code_for_tokens(self, code: str, code_verifier: str) -> Dict[str, Any]:
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': self.redirect_uri,
'client_id': self.client_id,
'code_verifier': code_verifier,
}
token_url = f'{self.base_url}/oauth2/token'
logger.info(f"Wix token exchange: client_id={self.client_id}, redirect_uri={self.redirect_uri}, code_verifier_prefix={code_verifier[:10]}...")
response = requests.post(token_url, headers=headers, data=data)
if response.status_code != 200:
logger.error(f"Wix token exchange failed: {response.status_code} {response.text}")
response.raise_for_status()
return response.json()
def refresh_access_token(self, refresh_token: str) -> Dict[str, Any]:
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id': self.client_id,
}
token_url = f'{self.base_url}/oauth2/token'
response = requests.post(token_url, headers=headers, data=data)
response.raise_for_status()
return response.json()
def get_site_info(self, access_token: str) -> Dict[str, Any]:
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
response = requests.get(f"{self.base_url}/sites/v1/site", headers=headers)
response.raise_for_status()
return response.json()
def get_current_member(self, access_token: str, client_id: Optional[str]) -> Dict[str, Any]:
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
if client_id:
headers['wix-client-id'] = client_id
response = requests.get(f"{self.base_url}/members/v1/members/my", headers=headers)
response.raise_for_status()
return response.json()