{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/m2msentinel-com/json-schema/m2msentinel-com-aggregate-stats-schema.json",
  "title": "AggregateStats",
  "x-generated": "2026-11-17",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/m2msentinel-com-openapi.json#/components/schemas/AggregateStats",
  "type": "object",
  "required": [
    "status",
    "bucket",
    "windowDays",
    "generatedAt",
    "totals",
    "revenue",
    "privacy"
  ],
  "properties": {
    "status": {
      "type": "string",
      "const": "SUCCESS"
    },
    "bucket": {
      "type": "string",
      "enum": [
        "production",
        "test"
      ],
      "description": "Which analytics bucket produced these counters. 'test' is authenticated non-customer probe traffic and must never be reported as customer conversion."
    },
    "windowDays": {
      "type": "integer",
      "minimum": 1,
      "maximum": 400
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "totals": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "demoRequested": {
          "type": "integer"
        },
        "demoSucceeded": {
          "type": "integer"
        },
        "demoUnsupported": {
          "type": "integer"
        },
        "demoSampleServed": {
          "type": "integer",
          "description": "Successful responses for the published allowlisted sample route. No caller identifier is retained."
        },
        "demoPreviewServed": {
          "type": "integer",
          "description": "Successful reduced previews for arbitrary-address demo requests. The full paid audit payload is not included."
        },
        "paymentChallengeIssued": {
          "type": "integer"
        },
        "x402PaymentSignaturePresented": {
          "type": "integer",
          "description": "x402 PAYMENT-SIGNATURE headers presented on a payable route. This aggregate ingress count can include malformed or rejected input, does not identify unique buyers, and is not payment confirmation."
        },
        "x402PaymentVerified": {
          "type": "integer",
          "description": "Signed x402 requests for which the facilitator returned a valid verification result."
        },
        "x402PaymentVerificationFailed": {
          "type": "integer",
          "description": "Signed x402 requests whose verification did not succeed; the counter does not distinguish an invalid payment from a facilitator exception."
        },
        "x402Settled": {
          "type": "integer"
        },
        "x402SettlementFailed": {
          "type": "integer",
          "description": "Verified x402 requests for which the facilitator explicitly returned a failed settlement result."
        },
        "x402SettlementUnknown": {
          "type": "integer",
          "description": "Verified x402 requests whose settlement raised a timeout, transport, or protocol exception. UNKNOWN is not proof that settlement failed."
        },
        "x402PaymentCanceled": {
          "type": "integer",
          "description": "Verified x402 requests canceled before settlement because the protected handler failed or threw."
        },
        "authenticatedDecisionServed": {
          "type": "integer"
        },
        "freeChallengeCreated": {
          "type": "integer"
        },
        "freeKeyIssued": {
          "type": "integer"
        },
        "subscriptionIntentCreated": {
          "type": "integer"
        },
        "subscriptionKeyIssued": {
          "type": "integer"
        },
        "subscriptionRenewed": {
          "type": "integer"
        },
        "keyRecovered": {
          "type": "integer"
        },
        "quotaExhausted": {
          "type": "integer"
        },
        "x402RevenueMicrousd": {
          "type": "integer"
        },
        "subscriptionRevenueMicrousd": {
          "type": "integer"
        }
      }
    },
    "productEvents": {
      "type": "array",
      "items": {
        "type": "object",
        "description": "Allowlisted event dimensions plus an aggregate count."
      }
    },
    "revenue": {
      "type": "object",
      "properties": {
        "x402Usd": {
          "type": "number"
        },
        "subscriptionsUsd": {
          "type": "number"
        }
      }
    },
    "diagnostics": {
      "type": "object",
      "description": "Authenticated operator-only natural failure diagnostics. Contains detailed records and aggregate summary.",
      "properties": {
        "summary": {
          "$ref": "#/$defs/NaturalDiagnosticSummary"
        },
        "records": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/NaturalDiagnosticRecord"
          }
        }
      }
    },
    "privacy": {
      "type": "string"
    }
  },
  "$defs": {
    "NaturalDiagnosticRecord": {
      "type": "object",
      "description": "Allowlisted natural failure diagnostic observation. Contains exactly the eight allowlisted properties and closed vocabularies.",
      "additionalProperties": false,
      "required": [
        "timestamp",
        "sourceClass",
        "routeClass",
        "httpStatus",
        "outcomeCode",
        "failureClass",
        "releaseCohort",
        "latencyBucket"
      ],
      "properties": {
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "sourceClass": {
          "type": "string",
          "enum": [
            "synthetic_monitor",
            "genuine_route_attempt"
          ]
        },
        "routeClass": {
          "type": "string",
          "enum": [
            "audit",
            "score",
            "gasFees",
            "dexMetrics",
            "tokenPrice",
            "whaleSignals",
            "transactionPreflight",
            "status",
            "plans",
            "subscribe",
            "keys",
            "demo",
            "events",
            "mcp",
            "health_cron",
            "other"
          ]
        },
        "httpStatus": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 100,
          "maximum": 599
        },
        "outcomeCode": {
          "type": "string",
          "enum": [
            "OK",
            "CHALLENGE_ISSUED",
            "SETTLED",
            "SETTLEMENT_FAILED",
            "SETTLEMENT_UNKNOWN",
            "INVALID_CHALLENGE",
            "MISSING_CHALLENGE",
            "READINESS_TIMEOUT",
            "FAIL_CLOSED_UNAVAILABLE",
            "UNEXPECTED_HTTP_STATUS",
            "RATE_LIMITED",
            "QUOTA_EXHAUSTED",
            "UNAUTHORIZED",
            "BAD_REQUEST",
            "TIMEOUT",
            "NETWORK_ERROR",
            "SKIPPED_CONFIG_GATE",
            "SKIPPED_QUOTA_GUARD",
            "NOT_CONFIGURED",
            "UNKNOWN_OUTCOME"
          ]
        },
        "failureClass": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "READINESS_TIMEOUT",
            "FAIL_CLOSED_UNAVAILABLE",
            "SETTLEMENT_FAILED",
            "SETTLEMENT_TIMEOUT",
            "FACILITATOR_ERROR",
            "HTTP_4XX",
            "HTTP_5XX",
            "TIMEOUT",
            "NETWORK_ERROR",
            "RATE_LIMITED",
            "QUOTA_EXHAUSTED",
            "AUTH_FAILURE",
            "BAD_REQUEST",
            "DATA_SOURCE_UNAVAILABLE",
            "UNKNOWN_FAILURE",
            null
          ]
        },
        "releaseCohort": {
          "type": "string",
          "maxLength": 64
        },
        "latencyBucket": {
          "type": "string",
          "enum": [
            "<50ms",
            "50-100ms",
            "100-250ms",
            "250-500ms",
            "500-1000ms",
            "1-2s",
            "2-5s",
            ">5s",
            "UNKNOWN"
          ]
        }
      }
    },
    "NaturalDiagnosticSummary": {
      "type": "object",
      "description": "Sanitized aggregate summary of natural failure diagnostics. Exposes only closed-vocabulary counts and bounds, never raw records.",
      "additionalProperties": false,
      "required": [
        "totalRecorded",
        "bySourceClass",
        "byRouteClass",
        "byOutcomeCode",
        "byFailureClass",
        "byLatencyBucket",
        "generatedAt"
      ],
      "properties": {
        "totalRecorded": {
          "type": "integer",
          "minimum": 0,
          "maximum": 500
        },
        "bySourceClass": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "byRouteClass": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "byOutcomeCode": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "byFailureClass": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "byLatencyBucket": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "generatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}