# mutations.commitTemporary

> Commit the visible temporary preview as one undo entry, optionally applying final operations atomically.



- Member path: `await doc.mutations.commitTemporary(…)`
- Mutates document: yes
- Idempotency: `non-idempotent`
- Supports tracked mode: conditional
- Supports dry run: no

## Expected result

Returns a temporary mutation receipt with preview identity and caller tag.

## Input schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {},
  "type": "object",
  "properties": {
    "previewId": {
      "type": "string",
      "minLength": 1
    },
    "expectedRevision": {
      "type": "string"
    },
    "operations": {
      "type": "array",
      "minItems": 1,
      "maxItems": 200,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "operation": {
            "enum": [
              "insert",
              "replace",
              "delete",
              "blocks.delete",
              "trackChanges.decide",
              "comments.create"
            ]
          },
          "input": {
            "type": "object"
          },
          "options": {
            "type": "object"
          }
        },
        "additionalProperties": false,
        "required": [
          "operation",
          "input"
        ]
      }
    }
  },
  "additionalProperties": false,
  "required": [
    "previewId"
  ]
}
```

## Output schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "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"
      ]
    },
    "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"
      ]
    },
    "AffectedRef": {
      "oneOf": [
        {
          "$ref": "#/$defs/TextAddress"
        },
        {
          "$ref": "#/$defs/BookmarkAddress"
        },
        {
          "$ref": "#/$defs/CommentAddress"
        },
        {
          "$ref": "#/$defs/TrackedChangeAddress"
        },
        {
          "$ref": "#/$defs/BlockNavigationAddress"
        }
      ]
    },
    "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"
      ]
    },
    "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"
        },
        "replacedLength": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "story",
        "atChar",
        "delta"
      ]
    },
    "TrackedTextRangeShift": {
      "type": "object",
      "properties": {
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "blockId": {
          "type": "string"
        },
        "atCharInBlock": {
          "type": "integer"
        },
        "delta": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "required": [
        "story",
        "blockId",
        "atCharInBlock",
        "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"
          }
        },
        "resultText": {
          "$ref": "#/$defs/TextTarget"
        }
      },
      "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"
      ]
    },
    "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",
            "listItem",
            "table",
            "tableOfContents",
            "sdt",
            "image"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "TextCoordinateSpace": {
      "enum": [
        "visible",
        "tracked"
      ]
    },
    "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"
      ]
    },
    "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"
      ]
    },
    "TextTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "text"
        },
        "segments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TextSegment"
          },
          "minItems": 1
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "coordinateSpace": {
          "$ref": "#/$defs/TextCoordinateSpace"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "segments"
      ]
    },
    "TextSegment": {
      "type": "object",
      "properties": {
        "blockId": {
          "type": "string"
        },
        "range": {
          "$ref": "#/$defs/Range"
        }
      },
      "additionalProperties": false,
      "required": [
        "blockId",
        "range"
      ]
    }
  },
  "type": "object",
  "properties": {
    "changeTag": {
      "type": "string",
      "description": "Caller correlation for this commit only; never persisted or replayed on Undo/Redo."
    },
    "temporary": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "phase": {
          "enum": [
            "begin",
            "replace",
            "rollback",
            "commit"
          ]
        },
        "tag": {
          "type": "string"
        },
        "onNativeEdit": {
          "enum": [
            "cancel",
            "preserve"
          ],
          "type": "string"
        },
        "cancelledBy": {
          "const": "native-edit",
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "id",
        "phase",
        "tag"
      ]
    },
    "appliedChangeMode": {
      "enum": [
        "direct",
        "tracked"
      ]
    },
    "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"
      }
    },
    "trackedTextRangeShifts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/TrackedTextRangeShift"
      }
    },
    "txId": {
      "type": "string"
    },
    "warnings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ReviewWarning"
      }
    },
    "effects": {
      "$ref": "#/$defs/ReceiptEffects"
    },
    "trackedChangeRefs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/TrackedChangeAddress"
      }
    },
    "trackedChangeCount": {
      "type": "integer",
      "minimum": 0
    },
    "changed": {
      "type": "boolean"
    },
    "success": {
      "const": true
    },
    "revision": {
      "type": "object",
      "properties": {
        "before": {
          "type": "string"
        },
        "after": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "before",
        "after"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "success",
    "temporary",
    "revision"
  ]
}
```

## Pre-apply throws

- `INVALID_INPUT`
- `TARGET_NOT_FOUND`
- `REVISION_MISMATCH`
- `PRECONDITION_FAILED`
- `CAPABILITY_UNSUPPORTED`
- `CAPABILITY_UNAVAILABLE`

## Non-applied receipt codes

- None

