{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.mildport.com/spec/import-contract.v1.schema.json",
  "title": "Mildport Portable Import Contract v1",
  "description": "A signed, data-free, executable pre-flight bundle: what a receiving tenant accepts (pinned target-catalog snapshot, required columns, policy limits, engine parity pins), exported so a counterparty — human or agent — can check a file before sending it. Content-addressed (sha256 over the canonical form with 'id' excluded) and signed as a detached JWS.",
  "$comment": "License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Generated from the Mildport contract sources — do not edit by hand.",
  "type": "object",
  "properties": {
    "contract": {
      "type": "object",
      "properties": {
        "contractVersion": {
          "type": "number",
          "const": 1
        },
        "id": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "issuer": {
          "type": "object",
          "properties": {
            "tenant": {
              "type": "string"
            },
            "keyId": {
              "type": "string"
            }
          },
          "required": [
            "tenant",
            "keyId"
          ],
          "additionalProperties": false
        },
        "title": {
          "type": "string",
          "maxLength": 200
        },
        "profile": {
          "type": "object",
          "properties": {
            "version": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "fingerprint": {
              "type": "string",
              "maxLength": 4000
            },
            "headerRow": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "mapping": {
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {
                "type": "string"
              }
            },
            "recipe": {}
          },
          "required": [
            "version"
          ],
          "additionalProperties": false
        },
        "catalog": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "label": {
                "type": "string"
              },
              "aliases": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "fields": {
                "default": [],
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string",
                      "minLength": 1
                    },
                    "label": {
                      "type": "string"
                    },
                    "required": {
                      "type": "boolean"
                    },
                    "description": {
                      "type": "string"
                    },
                    "example": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "columnSize": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "exclusiveMinimum": 0,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "columnType": {
                      "default": "string",
                      "type": "string",
                      "enum": [
                        "string",
                        "int",
                        "float",
                        "percentage",
                        "boolean",
                        "category",
                        "date",
                        "date_dmy",
                        "date_mdy",
                        "date_iso",
                        "datetime",
                        "time_hms",
                        "time_hms_24",
                        "time_hm",
                        "time_hm_24",
                        "email",
                        "url",
                        "url_www",
                        "url_https",
                        "phone",
                        "iban",
                        "bic",
                        "vat_eu",
                        "gtin",
                        "zip_code_de",
                        "country_code_alpha_2",
                        "country_code_alpha_3",
                        "currency_code",
                        "currency_eur",
                        "currency_usd"
                      ]
                    },
                    "validations": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "validate": {
                                "type": "string",
                                "enum": [
                                  "required",
                                  "unique",
                                  "regex",
                                  "required_with",
                                  "required_without",
                                  "required_with_all",
                                  "required_without_all",
                                  "required_with_values",
                                  "required_without_values",
                                  "required_with_all_values",
                                  "required_without_all_values",
                                  "compare",
                                  "reference_required",
                                  "reference_exists",
                                  "reference_unique"
                                ]
                              },
                              "regex": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "columnValues": {
                                "anyOf": [
                                  {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string"
                                    },
                                    "additionalProperties": {
                                      "anyOf": [
                                        {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "number"
                                            },
                                            {
                                              "type": "boolean"
                                            }
                                          ]
                                        },
                                        {
                                          "type": "array",
                                          "items": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "number"
                                              },
                                              {
                                                "type": "boolean"
                                              }
                                            ]
                                          }
                                        }
                                      ]
                                    }
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              },
                              "columns": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              },
                              "op": {
                                "type": "string",
                                "enum": [
                                  "eq",
                                  "ne",
                                  "gt",
                                  "gte",
                                  "lt",
                                  "lte"
                                ]
                              },
                              "column": {
                                "type": "string"
                              },
                              "value": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "number"
                                  },
                                  {
                                    "type": "boolean"
                                  }
                                ]
                              },
                              "fn": {
                                "type": "string",
                                "enum": [
                                  "sum",
                                  "product"
                                ]
                              },
                              "errorMessage": {
                                "type": "string"
                              },
                              "severity": {
                                "type": "string",
                                "enum": [
                                  "error",
                                  "warning"
                                ]
                              }
                            },
                            "required": [
                              "validate"
                            ],
                            "additionalProperties": false
                          }
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "alternativeMatches": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "dropdownOptions": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "oneOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "label": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "alternativeMatches": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    }
                                  },
                                  "validations": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "validate": {
                                          "$ref": "#/$defs/__schema0"
                                        },
                                        "errorMessage": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "validate"
                                      ],
                                      "additionalProperties": false
                                    }
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "type": {
                                    "type": "string",
                                    "const": "string"
                                  },
                                  "value": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "label",
                                  "type",
                                  "value"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "label": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "alternativeMatches": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    }
                                  },
                                  "validations": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "validate": {
                                          "$ref": "#/$defs/__schema0"
                                        },
                                        "errorMessage": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "validate"
                                      ],
                                      "additionalProperties": false
                                    }
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "type": {
                                    "type": "string",
                                    "const": "int"
                                  },
                                  "value": {
                                    "type": "integer",
                                    "minimum": -9007199254740991,
                                    "maximum": 9007199254740991
                                  }
                                },
                                "required": [
                                  "label",
                                  "type",
                                  "value"
                                ],
                                "additionalProperties": false
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "label": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "alternativeMatches": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    }
                                  },
                                  "validations": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "validate": {
                                          "$ref": "#/$defs/__schema0"
                                        },
                                        "errorMessage": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "validate"
                                      ],
                                      "additionalProperties": false
                                    }
                                  },
                                  "description": {
                                    "type": "string"
                                  },
                                  "type": {
                                    "type": "string",
                                    "const": "float"
                                  },
                                  "value": {
                                    "type": "number"
                                  }
                                },
                                "required": [
                                  "label",
                                  "type",
                                  "value"
                                ],
                                "additionalProperties": false
                              }
                            ]
                          }
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "valueDetectors": {
                      "type": "array",
                      "items": {
                        "oneOf": [
                          {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "const": "builtin"
                              },
                              "name": {
                                "type": "string",
                                "enum": [
                                  "string",
                                  "int",
                                  "float",
                                  "percentage",
                                  "boolean",
                                  "category",
                                  "date",
                                  "date_dmy",
                                  "date_mdy",
                                  "date_iso",
                                  "datetime",
                                  "time_hms",
                                  "time_hms_24",
                                  "time_hm",
                                  "time_hm_24",
                                  "email",
                                  "url",
                                  "url_www",
                                  "url_https",
                                  "phone",
                                  "iban",
                                  "bic",
                                  "vat_eu",
                                  "gtin",
                                  "zip_code_de",
                                  "country_code_alpha_2",
                                  "country_code_alpha_3",
                                  "currency_code",
                                  "currency_eur",
                                  "currency_usd"
                                ]
                              },
                              "minRatio": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 1
                              },
                              "weight": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 100
                              }
                            },
                            "required": [
                              "kind",
                              "name"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "const": "regex"
                              },
                              "pattern": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 512
                              },
                              "flags": {
                                "type": "string",
                                "maxLength": 8
                              },
                              "minRatio": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 1
                              },
                              "weight": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 100
                              }
                            },
                            "required": [
                              "kind",
                              "pattern"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "const": "oneOf"
                              },
                              "values": {
                                "minItems": 1,
                                "type": "array",
                                "items": {
                                  "type": "string",
                                  "minLength": 1
                                }
                              },
                              "caseInsensitive": {
                                "type": "boolean"
                              },
                              "minRatio": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 1
                              },
                              "weight": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 100
                              }
                            },
                            "required": [
                              "kind",
                              "values"
                            ],
                            "additionalProperties": false
                          }
                        ]
                      }
                    },
                    "reference": {
                      "type": "object",
                      "properties": {
                        "entity": {
                          "type": "string",
                          "minLength": 1
                        },
                        "matchOn": {
                          "minItems": 1,
                          "type": "array",
                          "items": {
                            "type": "string",
                            "minLength": 1
                          }
                        },
                        "cardinality": {
                          "default": "one",
                          "type": "string",
                          "enum": [
                            "one",
                            "many"
                          ]
                        },
                        "separator": {
                          "type": "string",
                          "minLength": 1
                        },
                        "onMissing": {
                          "default": "error",
                          "type": "string",
                          "enum": [
                            "create",
                            "error",
                            "null",
                            "ignore"
                          ]
                        },
                        "resolve": {
                          "type": "object",
                          "properties": {
                            "exact": {
                              "default": true,
                              "type": "boolean"
                            },
                            "fuzzy": {
                              "default": false,
                              "type": "boolean"
                            },
                            "learned": {
                              "default": false,
                              "type": "boolean"
                            },
                            "minScore": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 100
                            }
                          },
                          "required": [
                            "exact",
                            "fuzzy",
                            "learned"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "entity",
                        "matchOn",
                        "cardinality",
                        "onMissing"
                      ],
                      "additionalProperties": false
                    },
                    "isMultiSelect": {
                      "type": "boolean"
                    },
                    "outputFormat": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "allowCustomOptions": {
                      "type": "boolean"
                    },
                    "numberFormat": {
                      "type": "string",
                      "enum": [
                        "eu",
                        "us"
                      ]
                    },
                    "optionMappingMode": {
                      "type": "string",
                      "enum": [
                        "smart",
                        "exact"
                      ]
                    },
                    "hidden": {
                      "type": "boolean"
                    },
                    "disabled": {
                      "type": "boolean"
                    },
                    "scope": {
                      "type": "string",
                      "enum": [
                        "row",
                        "document"
                      ]
                    }
                  },
                  "required": [
                    "key",
                    "columnType"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "id",
              "fields"
            ],
            "additionalProperties": false
          }
        },
        "keySeparator": {
          "type": "string",
          "maxLength": 8
        },
        "engine": {
          "type": "object",
          "properties": {
            "matcher": {
              "type": "string"
            },
            "transform": {
              "type": "string"
            }
          },
          "required": [
            "matcher",
            "transform"
          ],
          "additionalProperties": false
        },
        "policy": {
          "type": "object",
          "properties": {
            "requiredColumns": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "maxRows": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "maximum": 9007199254740991
            },
            "encodings": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "requiredColumns"
          ],
          "additionalProperties": false
        },
        "createdAt": {
          "type": "string"
        },
        "expiresAt": {
          "type": "string"
        }
      },
      "required": [
        "contractVersion",
        "id",
        "issuer",
        "title",
        "profile",
        "catalog",
        "engine",
        "policy",
        "createdAt"
      ],
      "additionalProperties": false
    },
    "signature": {
      "type": "object",
      "properties": {
        "protected": {
          "type": "string"
        },
        "signature": {
          "type": "string"
        }
      },
      "required": [
        "protected",
        "signature"
      ],
      "additionalProperties": false
    },
    "keyId": {
      "type": "string"
    }
  },
  "required": [
    "contract",
    "signature",
    "keyId"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "anyOf": [
          {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              }
            ]
          },
          {
            "$ref": "#/$defs/__schema0"
          }
        ]
      }
    }
  }
}
