#!/usr/bin/env python3 from __future__ import annotations import json import os ACCESS_TOKEN_ENV = "NEXUSCRM_OWNER_DIRECTORY_ACCESS_TOKEN" def reconcile_from_environment( environment: dict[str, str] | None = None, *, runtime=None, ) -> dict[str, object]: if runtime is None: import deploy_offline_env as runtime envv = dict(os.environ if environment is None else environment) backend_port = str(envv.get("BACKEND_PORT", "")).strip() if not backend_port: raise runtime.DeployError( "missing BACKEND_PORT for HubSpot owner-directory reconciliation" ) if not str(envv.get("EXP_HUBSPOT_ACCESS_TOKEN", "")).strip(): raise runtime.DeployError( "missing EXP_HUBSPOT_ACCESS_TOKEN for HubSpot owner-directory reconciliation" ) access_token = str(envv.get(ACCESS_TOKEN_ENV, "")).strip() if not access_token: raise runtime.DeployError( f"missing {ACCESS_TOKEN_ENV} for HubSpot owner-directory reconciliation" ) base_url = f"http://127.0.0.1:{backend_port}" applied = runtime.sync_hubspot_owner_directory_bindings_from_api( envv, base_url, access_token, ) binding_count, exception_count = ( runtime.verify_hubspot_owner_directory_lifecycle_effect( base_url, access_token, ) ) return { "status": "passed", "applied": applied, "binding_count": binding_count, "exception_count": exception_count, } def main() -> int: print(json.dumps(reconcile_from_environment(), sort_keys=True)) return 0 if __name__ == "__main__": raise SystemExit(main())