# replace

> Replace content at a contiguous document selection. Text path accepts a SelectionTarget or ref plus replacement text. Rich string path accepts HTML or Markdown plus a BlockNodeAddress, SelectionTarget, or ref. Structural path accepts the same locator forms plus SDFragment content. An explicit {kind:'story', storyType:'body'} target replaces the complete main body in direct mode while preserving the destination DOCX package.



- Member path: `doc.replace(…)`
- Mutates document: yes
- Idempotency: `conditional`
- Supports tracked mode: yes
- Supports dry run: yes

## Expected result

Returns an SDMutationReceipt with applied status; receipt reports NO_OP if the target range already contains identical content.

## Input schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "SelectionTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "selection"
        },
        "start": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "end": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "coordinateSpace": {
          "$ref": "#/$defs/TextCoordinateSpace"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "start",
        "end"
      ]
    },
    "SelectionPoint": {
      "description": "A point in the document. Use {kind:'text', blockId, offset} for character positions or {kind:'nodeEdge', node:{kind:'block', nodeType, nodeId}, edge:'before'|'after'} for block boundaries.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "text"
            },
            "blockId": {
              "type": "string"
            },
            "offset": {
              "type": "integer",
              "minimum": 0
            },
            "story": {
              "$ref": "#/$defs/StoryLocator"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "blockId",
            "offset"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "nodeEdge"
            },
            "node": {
              "$ref": "#/$defs/SelectionEdgeNodeAddress"
            },
            "edge": {
              "enum": [
                "before",
                "after"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "node",
            "edge"
          ]
        }
      ]
    },
    "StoryLocator": {
      "description": "Story scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "body"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterSlot"
            },
            "section": {
              "$ref": "#/$defs/SectionAddress"
            },
            "headerFooterKind": {
              "enum": [
                "header",
                "footer"
              ]
            },
            "variant": {
              "enum": [
                "default",
                "first",
                "even"
              ]
            },
            "resolution": {
              "enum": [
                "effective",
                "explicit"
              ]
            },
            "onWrite": {
              "enum": [
                "materializeIfInherited",
                "editResolvedPart",
                "error"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "section",
            "headerFooterKind",
            "variant"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterPart"
            },
            "refId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "refId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "footnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "endnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "textbox"
            },
            "textboxId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "textboxId"
          ]
        }
      ]
    },
    "SectionAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "section"
        },
        "sectionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "sectionId"
      ]
    },
    "SelectionEdgeNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "table",
            "tableOfContents",
            "sdt",
            "image"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "TextCoordinateSpace": {
      "enum": [
        "visible",
        "tracked"
      ]
    },
    "BlockNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "listItem",
            "table",
            "tableRow",
            "tableCell",
            "tableOfContents",
            "image",
            "sdt"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    }
  },
  "oneOf": [
    {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "target": {
              "$ref": "#/$defs/SelectionTarget",
              "description": "Selection target: {kind:'selection', start:{kind:'text', blockId, offset}, end:{kind:'text', blockId, offset}}. Use 'ref' instead when you have a search result handle."
            },
            "in": {
              "$ref": "#/$defs/StoryLocator"
            },
            "text": {
              "type": "string",
              "description": "Replacement text content."
            }
          },
          "additionalProperties": false,
          "required": [
            "target",
            "text"
          ]
        },
        {
          "type": "object",
          "properties": {
            "ref": {
              "type": "string",
              "description": "Handle ref string from a superdoc_search result. Pass the handle.ref value directly (e.g. 'text:eyJ...'). Preferred over 'target' for inline formatting."
            },
            "in": {
              "$ref": "#/$defs/StoryLocator"
            },
            "text": {
              "type": "string",
              "description": "Replacement text content."
            }
          },
          "additionalProperties": false,
          "required": [
            "ref",
            "text"
          ]
        }
      ]
    },
    {
      "type": "object",
      "properties": {
        "target": {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "body"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType"
          ]
        },
        "text": {
          "type": "string",
          "description": "Complete replacement text for the main body."
        }
      },
      "additionalProperties": false,
      "required": [
        "target",
        "text"
      ]
    },
    {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "in": {
              "$ref": "#/$defs/StoryLocator"
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                },
                {
                  "$ref": "#/$defs/SelectionTarget"
                }
              ],
              "description": "Target block or selection to replace."
            },
            "content": {
              "oneOf": [
                {
                  "type": "object"
                },
                {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              ],
              "description": "Document fragment to replace with (structured content)."
            },
            "nestingPolicy": {
              "type": "object",
              "properties": {
                "tables": {
                  "enum": [
                    "forbid",
                    "allow"
                  ]
                }
              },
              "additionalProperties": false,
              "description": "Controls nesting behavior. tables: 'allow' permits inserting tables inside other tables."
            }
          },
          "additionalProperties": false,
          "required": [
            "target",
            "content"
          ]
        },
        {
          "type": "object",
          "properties": {
            "in": {
              "$ref": "#/$defs/StoryLocator"
            },
            "ref": {
              "type": "string",
              "description": "Reference handle from a previous search result."
            },
            "content": {
              "oneOf": [
                {
                  "type": "object"
                },
                {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              ],
              "description": "Document fragment to replace with (structured content)."
            },
            "nestingPolicy": {
              "type": "object",
              "properties": {
                "tables": {
                  "enum": [
                    "forbid",
                    "allow"
                  ]
                }
              },
              "additionalProperties": false,
              "description": "Controls nesting behavior. tables: 'allow' permits inserting tables inside other tables."
            }
          },
          "additionalProperties": false,
          "required": [
            "ref",
            "content"
          ]
        },
        {
          "type": "object",
          "properties": {
            "target": {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "story"
                },
                "storyType": {
                  "const": "body"
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "storyType"
              ]
            },
            "content": {
              "oneOf": [
                {
                  "type": "object"
                },
                {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              ],
              "description": "Document fragment that replaces the complete main body."
            }
          },
          "additionalProperties": false,
          "required": [
            "target",
            "content"
          ]
        }
      ]
    },
    {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "in": {
              "$ref": "#/$defs/StoryLocator"
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                },
                {
                  "$ref": "#/$defs/SelectionTarget"
                }
              ]
            },
            "value": {
              "type": "string",
              "description": "HTML or Markdown replacement content."
            },
            "type": {
              "enum": [
                "html",
                "markdown"
              ]
            },
            "nestingPolicy": {
              "type": "object",
              "properties": {
                "tables": {
                  "enum": [
                    "forbid",
                    "allow"
                  ]
                }
              },
              "additionalProperties": false,
              "description": "Controls nesting behavior. tables: 'allow' permits inserting tables inside other tables."
            }
          },
          "additionalProperties": false,
          "required": [
            "target",
            "value",
            "type"
          ]
        },
        {
          "type": "object",
          "properties": {
            "in": {
              "$ref": "#/$defs/StoryLocator"
            },
            "ref": {
              "type": "string",
              "minLength": 1
            },
            "value": {
              "type": "string",
              "description": "HTML or Markdown replacement content."
            },
            "type": {
              "enum": [
                "html",
                "markdown"
              ]
            },
            "nestingPolicy": {
              "type": "object",
              "properties": {
                "tables": {
                  "enum": [
                    "forbid",
                    "allow"
                  ]
                }
              },
              "additionalProperties": false,
              "description": "Controls nesting behavior. tables: 'allow' permits inserting tables inside other tables."
            }
          },
          "additionalProperties": false,
          "required": [
            "ref",
            "value",
            "type"
          ]
        },
        {
          "type": "object",
          "properties": {
            "target": {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "story"
                },
                "storyType": {
                  "const": "body"
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "storyType"
              ]
            },
            "value": {
              "type": "string",
              "description": "HTML or Markdown that replaces the complete main body."
            },
            "type": {
              "enum": [
                "html",
                "markdown"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "target",
            "value",
            "type"
          ]
        }
      ]
    }
  ]
}
```

## Output schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "TextAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "text"
        },
        "blockId": {
          "type": "string"
        },
        "range": {
          "$ref": "#/$defs/Range"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "blockId",
        "range"
      ]
    },
    "Range": {
      "type": "object",
      "properties": {
        "start": {
          "type": "integer"
        },
        "end": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "required": [
        "start",
        "end"
      ]
    },
    "StoryLocator": {
      "description": "Story scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "body"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterSlot"
            },
            "section": {
              "$ref": "#/$defs/SectionAddress"
            },
            "headerFooterKind": {
              "enum": [
                "header",
                "footer"
              ]
            },
            "variant": {
              "enum": [
                "default",
                "first",
                "even"
              ]
            },
            "resolution": {
              "enum": [
                "effective",
                "explicit"
              ]
            },
            "onWrite": {
              "enum": [
                "materializeIfInherited",
                "editResolvedPart",
                "error"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "section",
            "headerFooterKind",
            "variant"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterPart"
            },
            "refId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "refId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "footnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "endnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "textbox"
            },
            "textboxId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "textboxId"
          ]
        }
      ]
    },
    "SectionAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "section"
        },
        "sectionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "sectionId"
      ]
    },
    "BlockNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "listItem",
            "table",
            "tableRow",
            "tableCell",
            "tableOfContents",
            "image",
            "sdt"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "TextMutationRange": {
      "type": "object",
      "properties": {
        "from": {
          "type": "integer"
        },
        "to": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "required": [
        "from",
        "to"
      ]
    },
    "SelectionTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "selection"
        },
        "start": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "end": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "coordinateSpace": {
          "$ref": "#/$defs/TextCoordinateSpace"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "start",
        "end"
      ]
    },
    "SelectionPoint": {
      "description": "A point in the document. Use {kind:'text', blockId, offset} for character positions or {kind:'nodeEdge', node:{kind:'block', nodeType, nodeId}, edge:'before'|'after'} for block boundaries.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "text"
            },
            "blockId": {
              "type": "string"
            },
            "offset": {
              "type": "integer",
              "minimum": 0
            },
            "story": {
              "$ref": "#/$defs/StoryLocator"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "blockId",
            "offset"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "nodeEdge"
            },
            "node": {
              "$ref": "#/$defs/SelectionEdgeNodeAddress"
            },
            "edge": {
              "enum": [
                "before",
                "after"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "node",
            "edge"
          ]
        }
      ]
    },
    "SelectionEdgeNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "table",
            "tableOfContents",
            "sdt",
            "image"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "TextCoordinateSpace": {
      "enum": [
        "visible",
        "tracked"
      ]
    },
    "EntityAddress": {
      "oneOf": [
        {
          "$ref": "#/$defs/CommentAddress"
        },
        {
          "$ref": "#/$defs/TrackedChangeAddress"
        }
      ]
    },
    "CommentAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "entity"
        },
        "entityType": {
          "const": "comment"
        },
        "entityId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "entityType",
        "entityId"
      ]
    },
    "TrackedChangeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "entity"
        },
        "entityType": {
          "const": "trackedChange"
        },
        "entityId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "entityType",
        "entityId"
      ]
    },
    "AffectedRef": {
      "oneOf": [
        {
          "$ref": "#/$defs/TextAddress"
        },
        {
          "$ref": "#/$defs/BookmarkAddress"
        },
        {
          "$ref": "#/$defs/CommentAddress"
        },
        {
          "$ref": "#/$defs/TrackedChangeAddress"
        },
        {
          "$ref": "#/$defs/BlockNavigationAddress"
        }
      ]
    },
    "BookmarkAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "entity"
        },
        "entityType": {
          "const": "bookmark"
        },
        "name": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "entityType",
        "name"
      ]
    },
    "BlockNavigationAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeId": {
          "type": "string"
        },
        "nodeType": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeId"
      ]
    },
    "AffectedRefRemapping": {
      "type": "object",
      "properties": {
        "from": {
          "$ref": "#/$defs/AffectedRef"
        },
        "to": {
          "$ref": "#/$defs/AffectedRef"
        }
      },
      "additionalProperties": false,
      "required": [
        "from",
        "to"
      ]
    },
    "TextRangeShift": {
      "type": "object",
      "properties": {
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "atChar": {
          "type": "integer"
        },
        "blockId": {
          "type": "string"
        },
        "atCharInBlock": {
          "type": "integer"
        },
        "delta": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "required": [
        "story",
        "atChar",
        "delta"
      ]
    },
    "ReviewWarning": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "feature": {
          "enum": [
            "comments",
            "trackedChanges"
          ]
        },
        "severity": {
          "const": "warning"
        },
        "affectedObjectId": {
          "type": "string"
        },
        "affectedPartUri": {
          "type": "string"
        },
        "canProceed": {
          "type": "boolean"
        }
      },
      "additionalProperties": false,
      "required": [
        "code",
        "message",
        "feature",
        "severity",
        "canProceed"
      ]
    },
    "ReceiptEffects": {
      "type": "object",
      "properties": {
        "insertedText": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TextMutationEffect"
          }
        },
        "insertedBlocks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/BlockMutationEffect"
          }
        }
      },
      "additionalProperties": false
    },
    "TextMutationEffect": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "insertedText"
        },
        "sourcePath": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          }
        },
        "target": {
          "$ref": "#/$defs/TextAddress"
        },
        "selectionTarget": {
          "$ref": "#/$defs/SelectionTarget"
        },
        "text": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "target",
        "selectionTarget",
        "text"
      ]
    },
    "BlockMutationEffect": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "insertedBlock"
        },
        "sourcePath": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          }
        },
        "target": {
          "$ref": "#/$defs/BlockNodeAddress"
        },
        "insertedText": {
          "$ref": "#/$defs/TextMutationEffect"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "target"
      ]
    }
  },
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "success": {
          "const": true
        },
        "outcome": {
          "enum": [
            "preserved",
            "preserved-with-warnings",
            "simplified",
            "rejected",
            "no-op",
            "invalid-target",
            "outdated"
          ]
        },
        "resolution": {
          "type": "object",
          "properties": {
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/TextAddress"
                },
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "const": "story"
                    },
                    "storyType": {
                      "const": "body"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "kind",
                    "storyType"
                  ]
                }
              ]
            },
            "range": {
              "$ref": "#/$defs/TextMutationRange"
            },
            "selectionTarget": {
              "$ref": "#/$defs/SelectionTarget"
            }
          },
          "additionalProperties": false,
          "required": [
            "target",
            "range"
          ]
        },
        "id": {
          "type": "string"
        },
        "inserted": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/EntityAddress"
          }
        },
        "updated": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/EntityAddress"
          }
        },
        "removed": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/EntityAddress"
          }
        },
        "invalidatedRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AffectedRef"
          }
        },
        "remappedRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AffectedRefRemapping"
          }
        },
        "affectedStories": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StoryLocator"
          }
        },
        "textRangeShifts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TextRangeShift"
          }
        },
        "txId": {
          "type": "string"
        },
        "warnings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ReviewWarning"
          }
        },
        "effects": {
          "$ref": "#/$defs/ReceiptEffects"
        },
        "evaluatedRevision": {
          "type": "object",
          "properties": {
            "before": {
              "type": "string"
            },
            "after": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "before",
            "after"
          ]
        },
        "conversion": {
          "type": "object",
          "properties": {
            "format": {
              "enum": [
                "html",
                "markdown"
              ]
            },
            "lossy": {
              "type": "boolean"
            },
            "diagnostics": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "code": {
                    "enum": [
                      "conversion-normalized-construct",
                      "conversion-unsupported-construct",
                      "conversion-dropped-style",
                      "conversion-unsafe-content",
                      "conversion-unsafe-url",
                      "conversion-source-limit-exceeded",
                      "conversion-depth-limit-exceeded",
                      "conversion-malformed-input",
                      "conversion-empty-result"
                    ]
                  },
                  "severity": {
                    "enum": [
                      "error",
                      "warning",
                      "info"
                    ]
                  },
                  "message": {
                    "type": "string"
                  },
                  "path": {
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "integer"
                        }
                      ]
                    }
                  },
                  "construct": {
                    "enum": [
                      "document",
                      "source",
                      "text",
                      "paragraph",
                      "emptyParagraph",
                      "softBreak",
                      "lineBreak",
                      "heading",
                      "bold",
                      "italic",
                      "underline",
                      "strike",
                      "hyperlink",
                      "list",
                      "table",
                      "tableHeader",
                      "colSpan",
                      "rowSpan",
                      "horizontalRule",
                      "inlineCode",
                      "codeBlock",
                      "blockquote",
                      "taskList",
                      "image",
                      "footnote",
                      "rawHtml",
                      "unknownWrapper",
                      "script",
                      "style",
                      "eventHandler"
                    ]
                  },
                  "disposition": {
                    "enum": [
                      "preserved",
                      "normalized",
                      "downgraded",
                      "dropped",
                      "rejected"
                    ]
                  },
                  "lossy": {
                    "type": "boolean"
                  },
                  "source": {
                    "type": "object",
                    "properties": {
                      "format": {
                        "enum": [
                          "html",
                          "markdown"
                        ]
                      },
                      "range": {
                        "type": "object",
                        "properties": {
                          "startOffset": {
                            "type": "integer",
                            "minimum": 0
                          },
                          "endOffset": {
                            "type": "integer",
                            "minimum": 0
                          },
                          "startLine": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "startColumn": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "endLine": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "endColumn": {
                            "type": "integer",
                            "minimum": 1
                          }
                        },
                        "additionalProperties": false,
                        "required": [
                          "startOffset",
                          "endOffset"
                        ]
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "format"
                    ]
                  }
                },
                "additionalProperties": false,
                "required": [
                  "code",
                  "severity",
                  "message",
                  "construct",
                  "disposition",
                  "lossy",
                  "source"
                ]
              }
            }
          },
          "additionalProperties": false,
          "required": [
            "format",
            "lossy",
            "diagnostics"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "success"
      ]
    },
    {
      "type": "object",
      "properties": {
        "success": {
          "const": false
        },
        "outcome": {
          "enum": [
            "preserved",
            "preserved-with-warnings",
            "simplified",
            "rejected",
            "no-op",
            "invalid-target",
            "outdated"
          ]
        },
        "failure": {
          "type": "object",
          "properties": {
            "code": {
              "enum": [
                "INVALID_TARGET",
                "NO_OP",
                "INVALID_NESTING",
                "INVALID_PLACEMENT",
                "INVALID_PAYLOAD",
                "CAPABILITY_UNSUPPORTED",
                "ADDRESS_STALE",
                "DUPLICATE_ID",
                "INVALID_CONTEXT",
                "RAW_MODE_REQUIRED",
                "PRESERVE_ONLY_VIOLATION",
                "INVALID_INPUT",
                "TARGET_NOT_FOUND",
                "PRECONDITION_FAILED",
                "REVISION_MISMATCH",
                "CHECK_MISMATCH",
                "INTERNAL_ERROR"
              ]
            },
            "message": {
              "type": "string"
            },
            "path": {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "integer"
                  }
                ]
              }
            },
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                },
                {
                  "$ref": "#/$defs/TextAddress"
                },
                {
                  "$ref": "#/$defs/SelectionTarget"
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "const": "story"
                    },
                    "storyType": {
                      "const": "body"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "kind",
                    "storyType"
                  ]
                }
              ]
            },
            "details": {}
          },
          "additionalProperties": false,
          "required": [
            "code",
            "message"
          ]
        },
        "resolution": {
          "type": "object",
          "properties": {
            "target": {
              "oneOf": [
                {
                  "$ref": "#/$defs/TextAddress"
                },
                {
                  "$ref": "#/$defs/BlockNodeAddress"
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "const": "story"
                    },
                    "storyType": {
                      "const": "body"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "kind",
                    "storyType"
                  ]
                }
              ]
            },
            "range": {
              "$ref": "#/$defs/TextMutationRange"
            },
            "selectionTarget": {
              "$ref": "#/$defs/SelectionTarget"
            }
          },
          "additionalProperties": false,
          "required": [
            "target",
            "range"
          ]
        },
        "evaluatedRevision": {
          "type": "object",
          "properties": {
            "before": {
              "type": "string"
            },
            "after": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "before",
            "after"
          ]
        },
        "conversion": {
          "type": "object",
          "properties": {
            "format": {
              "enum": [
                "html",
                "markdown"
              ]
            },
            "lossy": {
              "type": "boolean"
            },
            "diagnostics": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "code": {
                    "enum": [
                      "conversion-normalized-construct",
                      "conversion-unsupported-construct",
                      "conversion-dropped-style",
                      "conversion-unsafe-content",
                      "conversion-unsafe-url",
                      "conversion-source-limit-exceeded",
                      "conversion-depth-limit-exceeded",
                      "conversion-malformed-input",
                      "conversion-empty-result"
                    ]
                  },
                  "severity": {
                    "enum": [
                      "error",
                      "warning",
                      "info"
                    ]
                  },
                  "message": {
                    "type": "string"
                  },
                  "path": {
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "integer"
                        }
                      ]
                    }
                  },
                  "construct": {
                    "enum": [
                      "document",
                      "source",
                      "text",
                      "paragraph",
                      "emptyParagraph",
                      "softBreak",
                      "lineBreak",
                      "heading",
                      "bold",
                      "italic",
                      "underline",
                      "strike",
                      "hyperlink",
                      "list",
                      "table",
                      "tableHeader",
                      "colSpan",
                      "rowSpan",
                      "horizontalRule",
                      "inlineCode",
                      "codeBlock",
                      "blockquote",
                      "taskList",
                      "image",
                      "footnote",
                      "rawHtml",
                      "unknownWrapper",
                      "script",
                      "style",
                      "eventHandler"
                    ]
                  },
                  "disposition": {
                    "enum": [
                      "preserved",
                      "normalized",
                      "downgraded",
                      "dropped",
                      "rejected"
                    ]
                  },
                  "lossy": {
                    "type": "boolean"
                  },
                  "source": {
                    "type": "object",
                    "properties": {
                      "format": {
                        "enum": [
                          "html",
                          "markdown"
                        ]
                      },
                      "range": {
                        "type": "object",
                        "properties": {
                          "startOffset": {
                            "type": "integer",
                            "minimum": 0
                          },
                          "endOffset": {
                            "type": "integer",
                            "minimum": 0
                          },
                          "startLine": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "startColumn": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "endLine": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "endColumn": {
                            "type": "integer",
                            "minimum": 1
                          }
                        },
                        "additionalProperties": false,
                        "required": [
                          "startOffset",
                          "endOffset"
                        ]
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "format"
                    ]
                  }
                },
                "additionalProperties": false,
                "required": [
                  "code",
                  "severity",
                  "message",
                  "construct",
                  "disposition",
                  "lossy",
                  "source"
                ]
              }
            }
          },
          "additionalProperties": false,
          "required": [
            "format",
            "lossy",
            "diagnostics"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "success",
        "failure"
      ]
    }
  ]
}
```

## Pre-apply throws

- `TARGET_NOT_FOUND`
- `CAPABILITY_UNAVAILABLE`
- `INVALID_TARGET`
- `INVALID_INPUT`
- `ADDRESS_STALE`
- `DUPLICATE_ID`
- `RAW_MODE_REQUIRED`
- `PRESERVE_ONLY_VIOLATION`
- `CAPABILITY_UNSUPPORTED`
- `STORY_NOT_FOUND`
- `STORY_MISMATCH`
- `STORY_NOT_SUPPORTED`
- `CROSS_STORY_PLAN`
- `MATERIALIZATION_FAILED`

## Non-applied receipt codes

- `INVALID_TARGET`
- `NO_OP`
- `INVALID_NESTING`
- `INVALID_PLACEMENT`
- `INVALID_PAYLOAD`
- `CAPABILITY_UNSUPPORTED`
- `ADDRESS_STALE`
- `DUPLICATE_ID`
- `INVALID_CONTEXT`
- `RAW_MODE_REQUIRED`
- `PRESERVE_ONLY_VIOLATION`
- `INVALID_INPUT`
- `TARGET_NOT_FOUND`
- `PRECONDITION_FAILED`
- `REVISION_MISMATCH`
- `CHECK_MISMATCH`
- `INTERNAL_ERROR`

