#!/usr/bin/env python3 import os import re print("🔧 [Patch] Applying safe LinkedIn Personal scopes and prompt patch...") target_dirs = ["/app/apps", "/app/dist", "/app/libraries"] patterns = [ r",\s*['\"]r_basicprofile['\"]", r",\s*['\"]rw_organization_admin['\"]", r",\s*['\"]w_organization_social['\"]", r",\s*['\"]r_organization_social['\"]" ] patched = 0 for target in target_dirs: if not os.path.exists(target): continue for root, _, files in os.walk(target): for f in files: if f.endswith((".js", ".mjs")): filepath = os.path.join(root, f) try: with open(filepath, "r", encoding="utf-8", errors="ignore") as fh: content = fh.read() except Exception: continue modified = False # 1. Replace prompt=none with prompt=consent if "prompt=none" in content: content = content.replace("prompt=none", "prompt=consent") modified = True # 2. Trim organization scopes from LinkedIn scopes array if "r_organization_social" in content: for p in patterns: content = re.sub(p, "", content) modified = True if modified: with open(filepath, "w", encoding="utf-8") as fh: fh.write(content) patched += 1 print(f" ✓ Patched {filepath}") print(f"✅ [Patch] Completed successfully. Total files patched: {patched}")