{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Configuration for Rush's build cache.",
  "description": "For use with the Rush tool, this file provides configuration options for cached project build output. See http://rushjs.io for details.",
  "definitions": {
    "anything": {
      "type": ["array", "boolean", "integer", "number", "object", "string"],
      "items": {
        "$ref": "#/definitions/anything"
      }
    }
  },
  "type": "object",
  "allOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "required": ["buildCacheEnabled", "cacheProvider"],
      "properties": {
        "$schema": {
          "description": "Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.",
          "type": "string"
        },
        "buildCacheEnabled": {
          "description": "Set this to true to enable the build cache feature.",
          "type": "boolean"
        },
        "cacheProvider": {
          "description": "Specify the cache provider to use",
          "type": "string"
        },
        "cacheEntryNamePattern": {
          "type": "string",
          "description": "Setting this property overrides the cache entry ID. If this property is set, it must contain a [hash] token. It may also contain one of the following tokens: [projectName], [projectName:normalize], [phaseName], [phaseName:normalize], [phaseName:trimPrefix], [os], and [arch]."
        },
        "cacheHashSalt": {
          "type": "string",
          "description": "An optional salt to inject during calculation of the cache key. This can be used to invalidate the cache for all projects when the salt changes."
        },
        "azureBlobStorageConfiguration": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "storageAccountName": {
              "type": "string",
              "description": "(Required) The name of the the Azure storage account to use for build cache."
            },
            "storageContainerName": {
              "type": "string",
              "description": "(Required) The name of the container in the Azure storage account to use for build cache."
            },
            "azureEnvironment": {
              "type": "string",
              "description": "The Azure environment the storage account exists in. Defaults to AzurePublicCloud.",
              "enum": ["AzurePublicCloud", "AzureChina", "AzureGermany", "AzureGovernment"]
            },
            "loginFlow": {
              "type": "string",
              "description": "The Entra ID login flow to use. Defaults to 'AdoCodespacesAuth' on GitHub Codespaces, 'InteractiveBrowser' otherwise.",
              "enum": ["AdoCodespacesAuth", "InteractiveBrowser", "DeviceCode"]
            },
            "blobPrefix": {
              "type": "string",
              "description": "An optional prefix for cache item blob names."
            },
            "isCacheWriteAllowed": {
              "type": "boolean",
              "description": "If set to true, allow writing to the cache. Defaults to false."
            },
            "readRequiresAuthentication": {
              "type": "boolean",
              "description": "If set to true, reading the cache requires authentication. Defaults to false."
            }
          }
        },
        "amazonS3Configuration": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "s3Bucket": {
              "type": "string",
              "description": "(Required unless s3Endpoint is specified) The name of the bucket to use for build cache (e.g. \"my-bucket\")."
            },
            "s3Endpoint": {
              "type": "string",
              "description": "(Required unless s3Bucket is specified) The Amazon S3 endpoint of the bucket to use for build cache (e.g. \"my-bucket.s3.us-east-2.amazonaws.com\" or \"http://localhost:9000\").\nThis shold not include any path, use the s3Prefix to set the path."
            },
            "s3Region": {
              "type": "string",
              "description": "(Required) The Amazon S3 region of the bucket to use for build cache (e.g. \"us-east-1\")."
            },
            "s3Prefix": {
              "type": "string",
              "description": "An optional prefix (\"folder\") for cache items. Should not start with /"
            },
            "isCacheWriteAllowed": {
              "type": "boolean",
              "description": "If set to true, allow writing to the cache. Defaults to false."
            }
          }
        },
        "httpConfiguration": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "url": {
              "type": "string",
              "description": "(Required) The URL of the server that stores the caches (e.g. \"https://build-caches.example.com\").",
              "format": "uri"
            },
            "uploadMethod": {
              "type": "string",
              "description": "(Optional) The HTTP method to use when writing to the cache (defaults to PUT).",
              "enum": ["PUT", "POST", "PATCH"],
              "default": "PUT"
            },
            "headers": {
              "type": "object",
              "description": "(Optional) HTTP headers to pass to the cache server",
              "properties": {},
              "additionalProperties": {
                "type": "string"
              }
            },
            "tokenHandler": {
              "type": "object",
              "description": "(Optional) Shell command that prints the authorization token needed to communicate with the HTTPS server and exits with code 0. This command will be executed from the root of the monorepo.",
              "properties": {
                "exec": {
                  "type": "string",
                  "description": "(Required) The command or script to execute."
                },
                "args": {
                  "type": "array",
                  "description": "(Optional) Arguments to pass to the command or script.",
                  "items": {
                    "type": "string"
                  }
                }
              }
            },
            "cacheKeyPrefix": {
              "type": "string",
              "description": "(Optional) prefix for cache keys."
            },
            "isCacheWriteAllowed": {
              "type": "boolean",
              "description": "(Optional) If set to true, allow writing to the cache. Defaults to false."
            }
          }
        }
      },
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "cacheProvider": {
              "type": "string",
              "pattern": "^(?:(?!local-only|azure-blob-storage|amazon-s3|http).)*$"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "cacheProvider": {
              "type": "string",
              "enum": ["local-only"]
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "cacheProvider": {
              "type": "string",
              "enum": ["azure-blob-storage"]
            },
            "azureBlobStorageConfiguration": {
              "type": "object",
              "additionalProperties": true,
              "required": ["storageAccountName", "storageContainerName"],
              "properties": {
                "storageAccountName": {
                  "$ref": "#/definitions/anything"
                },
                "storageContainerName": {
                  "$ref": "#/definitions/anything"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "cacheProvider": {
              "type": "string",
              "enum": ["amazon-s3"]
            },
            "amazonS3Configuration": {
              "type": "object",
              "additionalProperties": true,
              "oneOf": [
                {
                  "type": "object",
                  "required": ["s3Region", "s3Endpoint"],
                  "properties": {
                    "s3Endpoint": {
                      "$ref": "#/definitions/anything"
                    },
                    "s3Region": {
                      "$ref": "#/definitions/anything"
                    }
                  }
                },
                {
                  "type": "object",
                  "required": ["s3Region", "s3Bucket"],
                  "properties": {
                    "s3Bucket": {
                      "$ref": "#/definitions/anything"
                    },
                    "s3Region": {
                      "$ref": "#/definitions/anything"
                    }
                  }
                }
              ]
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "cacheProvider": {
              "type": "string",
              "enum": ["http"]
            },
            "httpConfiguration": {
              "type": "object",
              "additionalProperties": true,
              "required": ["url"],
              "properties": {
                "url": {
                  "$ref": "#/definitions/anything"
                }
              }
            }
          }
        }
      ]
    }
  ]
}
