deleteDocument

The deleteDocument is responsible for deleting a document from the underlying content source.

Netlify Create calls this method when the user deletes a document using the Netlify Create UI.

Parameters

This method receives an options object with the following properties:

  • document:Document: object representing the document being deleted, as stored in the Netlify Create cache.
  • userContext?: UserContext: An object that contains the user's email, name, and optional OAuth access tokens defined by the UserContext generic type.

Return Value

This method should return a Promise that resolves with a void, indicating that the document has been successfully deleted.

Example

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
import type { ContentSourceInterface } from '@stackbit/types'

interface UserContext {
  accessToken: string
}

export class MyContentSource
  implements
    ContentSourceInterface<
      UserContext,
      SchemaContext,
      DocumentContext,
      AssetContext
    >
{
  async updateDocument(options: {
    document: Document<DocumentContext>
    userContext?: UserContext
  }): Promise<void> {
    // delete the document
    await this.apiClient.deleteDocument({
      accessToken: options.userContext?.accessToken,
      documentId: options.document.id,
    })
  }

  // other methods ...
}