Represents an interface to a y-sweet document management endpoint.

Constructors

Properties

baseUrl: string

The base URL of the remote document manager API.

token?: string

A string that grants the bearer access to the document management API.

Methods

  • Creates a new document on the y-sweet server given an optional docId. If a document with given ID already exists, this is a no-op.

    Parameters

    • Optional docId: string

      The ID of the document to be created. If not provided, a random ID will be generated.

    Returns Promise<DocCreationResult>

    A DocCreationResult object containing the ID of the created document.

  • Internal helper for making an authorized fetch request to the API.

    Parameters

    • url: string
    • method: "GET"

    Returns Promise<Response>

  • Internal helper for making an authorized fetch request to the API.

    Parameters

    • url: string
    • method: "POST"
    • body: Record<string, any>

    Returns Promise<Response>

  • Get a client token for the given document.

    If you are using authorization, this is expected to be called from your server after a user has authenticated. The returned token should then be passed to the client.

    Parameters

    Returns Promise<ClientToken>

    A ClientToken object containing the URL and token needed to connect to the document.

  • A convenience wrapper around DocumentManager.createDoc and DocumentManager.getClientToken for getting a client token for a document. If a docId is provided, ensures that a document exists with that ID or that one is created. If no docId is provided, a new document is created with a random ID.

    Parameters

    • Optional docId: string

      The ID of the document to get or create. If not provided, a new document with a random ID will be created.

    Returns Promise<ClientToken>

    A ClientToken object containing the URL and token needed to connect to the document.