DocAuthDocument
DocAuthDocument:
{ transactionWithReport(callback: TransactionCallback<T>, options?: TransactionOptions): Promise<TransactionWithReportResult<T>>;}A document instance. Holds the content and provides methods for saving, exporting to PDF/DOCX, and more.
Create documents via DocAuthEditor and/or DocAuthSystem.
Methods
Section titled “Methods”getParticipant():
Participant
Returns the participant currently acting on this document.
The participant determines whether programmatic transactions and editor input may mutate or adjudicate the document. The author is only a label; hosts must bind participants to authenticated users themselves because the SDK does not authenticate.
Returns
Section titled “Returns”setParticipant(
participant):void
Sets the participant that acts on subsequent programmatic transactions and editor input for this document.
Owners have full access. Reviewers may create tracked changes and comments and withdraw their own pending suggestions, but may not accept or reject suggestions or make untracked content changes. Readers are read-only. The author is only a label; hosts must bind participants to authenticated users themselves because the SDK does not authenticate.
Parameters
Section titled “Parameters”participant
Section titled “participant”Returns
Section titled “Returns”saveDocument()
Section titled “saveDocument()”Returns the current document in the Document Authoring format as a JavaScript object. This object can be safely persisted.
Returns
Section titled “Returns”Returns the current document in the Document Authoring format as a JSON string. This string can be safely persisted.
Pass { canonical: true } to return the canonical DocJSON string used as the
content identity for transaction report digests. Omitting the option preserves
the existing JSON string output.
Parameters
Section titled “Parameters”options?
Section titled “options?”Optional JSON serialization options.
Returns
Section titled “Returns”exportPDF()
Section titled “exportPDF()”exportPDF(
options?):Promise<ArrayBuffer>
Exports a snapshot of the current document as a PDF file.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”exportDOCX()
Section titled “exportDOCX()”exportDOCX(
options?):Promise<ArrayBuffer>
Exports a snapshot of the current document as a DOCX file.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”export(
config):Promise<ArrayBuffer>
Exports a snapshot of the current document in the specified format.
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”transaction<
T>(callback,options?):Promise<T>
Executes a transaction to programmatically read or modify the document.
Type Parameters
Section titled “Type Parameters”T = void
Parameters
Section titled “Parameters”callback
Section titled “callback”A TransactionCallback function that receives a draft document
Transaction options.
Returns
Section titled “Returns”Promise<T>
A Promise that resolves to the result value from the callback
Remarks
Section titled “Remarks”Provides programmatic access to the document structure through a draft document that can be read and modified. Changes are atomic and isolated until the transaction commits.
The callback executes after all pending transactions and input have been processed. While the callback runs, document access is blocked, preventing any UI interactions until the transaction completes.
Example
Section titled “Example”await doc.transaction(async ({ draft }) => { const section = draft.body().sections()[0]; const para = section.content().addParagraph(); para.asTextView().setText('Hello, World!'); return { commit: true };});TransactionCallbackfor the callback function signatureTransactionResultfor return value optionsProgrammaticfor the full programmatic API namespace
transactionWithReport<
T>(callback,options?):Promise<TransactionWithReportResult<T>>
Executes a document transaction and returns its callback result with a verifiable report.
Type Parameters
Section titled “Type Parameters”T = void
Parameters
Section titled “Parameters”callback
Section titled “callback”A TransactionCallback function that receives a draft document.
options?
Section titled “options?”Transaction options.
Returns
Section titled “Returns”Promise<TransactionWithReportResult<T>>
The callback result and transaction report.
Remarks
Section titled “Remarks”The report’s beforeDigest and afterDigest identify the document’s canonical DocJSON
content, including its model and resources. To verify a saved document, hash the exact
string returned by saveDocumentJSONString({ canonical: true }) with SHA-256.
Report generation is opt-in because it serializes and hashes the document before and
after the transaction. DocAuthDocument.transaction remains digest-free.
Report txId values are scoped to the current document session and are not stable
across sessions.
docAuthSystem()
Section titled “docAuthSystem()”docAuthSystem():
DocAuthSystem
The DocAuthSystem this document is bound to.
Returns
Section titled “Returns”on(
event,handler):DocAuthDocument
Adds an event listener that will be called every time the specified document event is emitted.
The document starts tracking events when its first listener is added and stops after its last listener is removed. Adding a listener later uses the current document state as the new baseline.
Parameters
Section titled “Parameters”EventName
handler
Section titled “handler”(payload: EventPayload) => void
Returns
Section titled “Returns”DocAuthDocument
The document instance for method chaining.
Example
Section titled “Example”document .on('revision.accepted', ({ ids, origin }) => { console.log('Accepted revisions', ids, origin); }) .on('content.change', () => console.log('Document changed'));Available Events
Section titled “Available Events”| Event name | Event payload | Description |
|---|---|---|
revision.created | RevisionEventPayload | Fired when one or more tracked-change revisions are created. |
revision.edited | RevisionEventPayload | Fired when one or more existing tracked-change revisions are edited. |
revision.accepted | RevisionEventPayload | Fired when one or more tracked-change revisions are accepted. |
revision.rejected | RevisionEventPayload | Fired when one or more tracked-change revisions are rejected. |
revision.withdrawn | RevisionEventPayload | Fired when one or more tracked-change revisions are withdrawn. |
comment.threadAdded | CommentEventPayload | Fired when one or more comment threads are added. |
comment.replied | CommentEventPayload | Fired when one or more replies are added to comment threads. |
comment.edited | CommentEventPayload | Fired when the text of one or more comments or replies is edited. |
comment.resolved | CommentEventPayload | Fired when one or more comment threads are resolved. |
comment.unresolved | CommentEventPayload | Fired when one or more comment threads are marked unresolved. |
comment.removed | `CommentEventPayload & { reason: “removed" | "anchor-deleted” }` |
content.change | none | Fired after every committed transaction following document initialization. |
off(
event,handler?):DocAuthDocument
Removes a document event listener. If no handler is provided, removes all listeners for the event.
Parameters
Section titled “Parameters”EventName
handler?
Section titled “handler?”(payload: EventPayload) => void
Returns
Section titled “Returns”DocAuthDocument
The document instance for method chaining.
Example
Section titled “Example”document.on('revision.accepted', handleAccepted);
// Remove one handler.document.off('revision.accepted', handleAccepted);
// Remove every handler for this event.document.off('revision.accepted');Available Events
Section titled “Available Events”| Event name | Event payload | Description |
|---|---|---|
revision.created | RevisionEventPayload | Fired when one or more tracked-change revisions are created. |
revision.edited | RevisionEventPayload | Fired when one or more existing tracked-change revisions are edited. |
revision.accepted | RevisionEventPayload | Fired when one or more tracked-change revisions are accepted. |
revision.rejected | RevisionEventPayload | Fired when one or more tracked-change revisions are rejected. |
revision.withdrawn | RevisionEventPayload | Fired when one or more tracked-change revisions are withdrawn. |
comment.threadAdded | CommentEventPayload | Fired when one or more comment threads are added. |
comment.replied | CommentEventPayload | Fired when one or more replies are added to comment threads. |
comment.edited | CommentEventPayload | Fired when the text of one or more comments or replies is edited. |
comment.resolved | CommentEventPayload | Fired when one or more comment threads are resolved. |
comment.unresolved | CommentEventPayload | Fired when one or more comment threads are marked unresolved. |
comment.removed | `CommentEventPayload & { reason: “removed" | "anchor-deleted” }` |
content.change | none | Fired after every committed transaction following document initialization. |
once(
event,handler):DocAuthDocument
Adds an event listener that will be called only once when the specified document event is emitted. The listener is automatically removed after being called.
Parameters
Section titled “Parameters”EventName
handler
Section titled “handler”(payload: EventPayload) => void
Returns
Section titled “Returns”DocAuthDocument
The document instance for method chaining.
Example
Section titled “Example”document.once('comment.threadAdded', ({ ids }) => { console.log('First added comment thread', ids);});Available Events
Section titled “Available Events”| Event name | Event payload | Description |
|---|---|---|
revision.created | RevisionEventPayload | Fired when one or more tracked-change revisions are created. |
revision.edited | RevisionEventPayload | Fired when one or more existing tracked-change revisions are edited. |
revision.accepted | RevisionEventPayload | Fired when one or more tracked-change revisions are accepted. |
revision.rejected | RevisionEventPayload | Fired when one or more tracked-change revisions are rejected. |
revision.withdrawn | RevisionEventPayload | Fired when one or more tracked-change revisions are withdrawn. |
comment.threadAdded | CommentEventPayload | Fired when one or more comment threads are added. |
comment.replied | CommentEventPayload | Fired when one or more replies are added to comment threads. |
comment.edited | CommentEventPayload | Fired when the text of one or more comments or replies is edited. |
comment.resolved | CommentEventPayload | Fired when one or more comment threads are resolved. |
comment.unresolved | CommentEventPayload | Fired when one or more comment threads are marked unresolved. |
comment.removed | `CommentEventPayload & { reason: “removed" | "anchor-deleted” }` |
content.change | none | Fired after every committed transaction following document initialization. |