=== maca Hub Connector ===
Contributors: maca
Tags: maca, hub, connector, api
Requires at least: 6.0
Requires PHP: 7.4
Stable tag: 0.1.49
License: GPLv2 or later

Connects a WordPress site to Maca Hub and exposes basic Maca plugin status.

== Description ==

Maca Hub Connector is the free base plugin for connecting a WordPress site to the Maca Hub app.

Version 0.1 focuses on:

* Local site identity.
* Short-lived pairing codes.
* Hashed bearer tokens for Hub requests.
* Central Maca API base URL: https://api.maca.se.
* Basic site information.
* Detection of installed Maca plugins.
* Basic active/inactive plugin status.

This plugin should stay small. Plugin-specific Pro features belong in each Maca plugin, while cross-site and cross-plugin features can later belong in Maca Hub Pro.

== Pairing ==

Maca Hub Connector does not expose a static API key.

Pairing flow:

1. A WordPress admin opens Maca Hub in wp-admin.
2. The admin creates a pairing code.
3. The code is valid for 10 minutes, can only be used once, and is locked after repeated failed attempts.
4. Maca Hub exchanges the code with:

* POST /wp-json/maca-hub/v1/pairing/complete

Request body:

	{
		"code": "ABCD-EFGH-JKLM",
		"client_name": "Maca Hub"
	}

The response contains a bearer token. The plain token is only returned once. WordPress stores only a hash of the token.

== Protected REST API ==

Protected endpoints require:

* Header: Authorization: Bearer your-access-token

Endpoints:

* GET /wp-json/maca-hub/v1/status
* GET /wp-json/maca-hub/v1/plugins
* GET /wp-json/maca-hub/v1/plugins/{slug}/details
* GET /wp-json/maca-hub/v1/site
* GET /wp-json/maca-hub/v1/changes

Endpoint URLs and connected tokens are shown in WordPress admin under Maca Hub.
Tokens can be revoked from the admin page.

== Central API Boundary ==

Maca Hub Connector should use the existing central Maca API domain, but Hub routes must stay isolated from other products.

When API-side work starts, use Maca Hub-specific route names/namespaces only. Do not change Smartcar or McDrive API routes, handlers, database tables, or payload contracts for Hub Connector work.

== Plugin Integration ==

Other Maca plugins can customize the status shown in Maca Hub by using:

	maca_hub_connector_plugin_summary

Plugins can expose richer detail data by using:

	maca_hub_connector_plugin_details_{slug}

Example:

	add_filter('maca_hub_connector_plugin_summary_maca-sec', function ($summary, $plugin_file, $plugin_data) {
		$summary['status'] = 'ok';
		$summary['message'] = 'Security monitoring is active.';

		return $summary;
	}, 10, 3);

	add_filter('maca_hub_connector_plugin_details_maca-sec', function ($details, $plugin) {
		$details['maca_sec'] = [
			'security_score' => 90,
		];

		return $details;
	}, 10, 2);

== Roadmap ==

1. Connect Maca Hub app to these endpoints.
2. Add a better pairing flow.
3. Let Maca Sec expose a summarized security status.
4. Move Hub-specific connection logic out of Maca Sec.

== Changelog ==

= 0.1.45 =
* Fix: accept-issue reads issue_id from JSON body more reliably.
* Includes accept-issue and fix-issue REST routes for Hub remediation.

= 0.1.38 =
* HTTP 429-hantering: pausar utgående telemetri efter WAF-svar, enklare admin-test (ett POST), tydligare varning i API-loggen.

= 0.1.37 =
* API-logg i wp-admin: loggar utgående telemetri/synk till api.maca.se (ersätter saknad serverlogg på Loopia). Knapp «Kör test nu».

= 0.1.36 =
* When maca Hub polls dashboard or plugins, Connector reports installed maca plugins (including maca Sec) to api.maca.se — works even when individual plugin telemetry fails on some hosts.

= 0.1.33 =
* Installation telemetry via api.maca.se and optional deactivation feedback on the Plugins screen.

= 0.1.14 =
* Changes API: GET /wp-json/maca-hub/v1/changes for efficient Hub polling.
* Pairing response includes changes endpoint URL.
* Background status tick and change hooks for maca Sec and core site data.
* Admin page shows changes endpoint URL.

= 0.1.13 =
* Dashboard, maca Sec scan, plugin details, and site endpoints.
