document

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShareConflict = fmt.Errorf("environment share conflict")

ErrShareConflict is returned when creating an environment share fails because one already exists for the document (HTTP 409). Callers can use errors.Is to detect this case without fragile string matching.

View Source
var ErrVersionConflict = fmt.Errorf("document version conflict")

ErrVersionConflict is returned when a document PATCH fails due to optimistic locking (HTTP 409). Callers can use errors.Is to detect this without string matching.

Functions

This section is empty.

Types

type AddDirectShareRecipientsOptions

type AddDirectShareRecipientsOptions struct {
	// SuppressNotification stops the API from notifying the added recipients.
	SuppressNotification bool
}

AddDirectShareRecipientsOptions controls side effects of adding recipients.

type CreateDirectShareRequest

type CreateDirectShareRequest struct {
	DocumentID string      `json:"documentId"`
	Access     string      `json:"access"` // "read" or "read-write"
	Recipients []SsoEntity `json:"recipients"`

	// SuppressNotification stops the API from notifying the recipients. It is
	// sent as a query parameter, not in the body. The API notifies by default,
	// and a group recipient means every member of the group.
	SuppressNotification bool `json:"-"`
}

CreateDirectShareRequest contains the data needed to create a direct share

type CreateEnvironmentShareRequest

type CreateEnvironmentShareRequest struct {
	DocumentID string `json:"documentId"`
	Access     string `json:"access"` // "read" or "read-write"
}

CreateEnvironmentShareRequest contains the data needed to create an environment share. The Document Service API schema is asymmetric: GET returns access as an array (e.g. ["read"] or ["read","write"]), but POST accepts a single level string ("read" or "read-write") and the server expands it server-side into the array.

type CreateRequest

type CreateRequest struct {
	ID          string   // Optional - if not provided, system generates one
	Name        string   // Required
	Type        string   // Required - e.g., "dashboard", "notebook"
	Description string   // Optional
	Content     []byte   // Required - the document content
	Labels      []string // Optional - classification labels stored in document metadata
}

CreateRequest contains the data needed to create a new document

type DeletionInfo

type DeletionInfo struct {
	DeletedBy   string    `json:"deletedBy" yaml:"deletedBy"`
	DeletedTime time.Time `json:"deletedTime" yaml:"deletedTime"`
}

DeletionInfo contains deletion metadata

type DirectShare

type DirectShare struct {
	ID         string   `json:"id"`
	DocumentID string   `json:"documentId"`
	Access     []string `json:"access"`
}

DirectShare represents a direct share for a document

func (DirectShare) ExactAccess

func (s DirectShare) ExactAccess(level string) bool

ExactAccess reports whether the share grants exactly the given access level.

type DirectShareList

type DirectShareList struct {
	Shares      []DirectShare `json:"direct-shares"`
	TotalCount  int           `json:"totalCount"`
	NextPageKey string        `json:"nextPageKey,omitempty"`
}

DirectShareList represents a list of direct shares

type Document

type Document struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Type        string    `json:"type"`
	Owner       string    `json:"owner"`
	IsPrivate   bool      `json:"isPrivate"`
	Created     time.Time `json:"-"`
	Description string    `json:"description,omitempty"`
	Version     int       `json:"version"`
	Modified    time.Time `json:"-"`
	Content     []byte    `json:"-"`

	OriginAppID       string       `json:"originAppId,omitempty" yaml:"originAppId,omitempty"`
	OriginExtensionID string       `json:"originExtensionId,omitempty" yaml:"originExtensionId,omitempty"`
	Labels            []string     `json:"labels,omitempty" yaml:"labels,omitempty"`
	ShareInfo         *ShareInfo   `json:"shareInfo,omitempty" yaml:"shareInfo,omitempty"`
	UserContext       *UserContext `json:"userContext,omitempty" yaml:"userContext,omitempty"`
}

Document represents a document resource.

The trailing optional fields (OriginAppID, OriginExtensionID, Labels, ShareInfo, UserContext) are populated only when requested via DocumentFilters.AddFields. They are tagged `omitempty` so default JSON/YAML output stays minimal.

func ParseMultipartDocument

func ParseMultipartDocument(resp *resty.Response) (*Document, error)

ParseMultipartDocument parses a multipart response into a Document

func (Document) MarshalJSON

func (d Document) MarshalJSON() ([]byte, error)

MarshalJSON custom marshaler for Document to include content when present

func (Document) MarshalYAML

func (d Document) MarshalYAML() (interface{}, error)

MarshalYAML custom marshaler for Document to include content for YAML output

func (*Document) UnmarshalJSON

func (d *Document) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaler for Document to handle nested modificationInfo and version as string or int.

type DocumentFilters

type DocumentFilters struct {
	Type        string   // e.g., "dashboard", "notebook"
	Name        string   // Filter by name
	Owner       string   // Filter by owner ID
	Filter      string   // Raw filter string, sent verbatim (overrides Type/Name/Owner)
	ChunkSize   int64    // Page size for pagination (0 = no chunking, use API default)
	Sort        string   // Sort fields, comma-separated, prefix with "-" for descending
	AddFields   []string // Fields the API omits by default (e.g. "originExtensionId", "labels")
	AdminAccess bool     // List as effective owner; requires document:documents:admin
}

DocumentFilters contains filter options for listing documents. When Filter is non-empty it is sent verbatim and overrides Type/Name/Owner.

type DocumentList

type DocumentList struct {
	Documents   []DocumentMetadata `json:"documents"`
	TotalCount  int                `json:"totalCount"`
	NextPageKey string             `json:"nextPageKey,omitempty"`
}

DocumentList represents a list of documents

type DocumentMetadata

type DocumentMetadata struct {
	ID                string           `json:"id"`
	Name              string           `json:"name"`
	Type              string           `json:"type"`
	Description       string           `json:"description,omitempty"`
	Version           int              `json:"version"`
	Owner             string           `json:"owner"`
	IsPrivate         bool             `json:"isPrivate"`
	ModificationInfo  ModificationInfo `json:"modificationInfo"`
	Access            []string         `json:"access,omitempty"`
	OriginAppID       string           `json:"originAppId,omitempty" yaml:"originAppId,omitempty"`
	OriginExtensionID string           `json:"originExtensionId,omitempty" yaml:"originExtensionId,omitempty"`
	Labels            []string         `json:"labels,omitempty" yaml:"labels,omitempty"`
	ShareInfo         *ShareInfo       `json:"shareInfo,omitempty" yaml:"shareInfo,omitempty"`
	UserContext       *UserContext     `json:"userContext,omitempty" yaml:"userContext,omitempty"`
}

DocumentMetadata represents detailed document metadata. Fields after Access are only populated when requested via DocumentFilters.AddFields.

func (*DocumentMetadata) UnmarshalJSON

func (m *DocumentMetadata) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaler for DocumentMetadata to handle version as string or int.

type EnvironmentShare

type EnvironmentShare struct {
	ID         string   `json:"id"`
	DocumentID string   `json:"documentId"`
	Access     []string `json:"access"`
	// ClaimCount > 0 means at least one user has claimed this share. A created-but-unclaimed
	// share exists on the server but doesn't flip the document's isPrivate flag.
	ClaimCount int `json:"claimCount"`
}

EnvironmentShare represents an environment-wide share for a document (a document shared with everyone in the environment, reflected as isPrivate=false on the document). The Document Service API returns `access` as a string array (e.g. ["read"] or ["read","write"]), not a single string. The create endpoint accepts either form and normalises server-side.

func (EnvironmentShare) ExactAccess

func (s EnvironmentShare) ExactAccess(level string) bool

ExactAccess reports whether the share grants exactly the given access level (no more, no less). Use this when deciding whether to replace a share: a "read-write" share is NOT an exact match for "read".

func (EnvironmentShare) HasAccess

func (s EnvironmentShare) HasAccess(level string) bool

HasAccess reports whether the share grants the given access level. Accepts "read" (present if "read" or "write" is in Access) or "read-write" (present if "write" is in Access).

type EnvironmentShareClaimResult

type EnvironmentShareClaimResult struct {
	DocumentID   string   `json:"documentId"`
	DocumentType string   `json:"documentType"`
	Access       []string `json:"access"`
}

EnvironmentShareClaimResult is what claiming an environment share returns: the document the share points to and the access the caller now holds on it.

type EnvironmentShareList

type EnvironmentShareList struct {
	Shares      []EnvironmentShare `json:"environment-shares"`
	TotalCount  int                `json:"totalCount"`
	NextPageKey string             `json:"nextPageKey,omitempty"`
}

EnvironmentShareList represents a list of environment shares. The API's JSON key is kebab-case: "environment-shares".

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles document resources (dashboards, notebooks, etc.)

func NewHandler

func NewHandler(c *httpclient.Client) *Handler

NewHandler creates a new document handler

func (*Handler) AddDirectShareRecipients

func (h *Handler) AddDirectShareRecipients(ctx context.Context, shareID string, recipients []SsoEntity) error

AddDirectShareRecipients adds recipients to a direct share

func (*Handler) AddDirectShareRecipientsWithOptions

func (h *Handler) AddDirectShareRecipientsWithOptions(ctx context.Context, shareID string, recipients []SsoEntity,
	opts AddDirectShareRecipientsOptions) error

AddDirectShareRecipientsWithOptions adds recipients to a direct share, honoring opts (for example, suppressing recipient notifications).

func (*Handler) ClaimEnvironmentShare

func (h *Handler) ClaimEnvironmentShare(ctx context.Context, shareID string) (*EnvironmentShareClaimResult, error)

ClaimEnvironmentShare claims an environment share, mirroring the browser's "Copy link to share" -> open flow. Claiming is how a recipient resolves a share link: GetEnvironmentShare only answers for the share's owner, so the claim response is the one place the recipient learns the document.

func (*Handler) Create

func (h *Handler) Create(ctx context.Context, req CreateRequest) (*Document, error)

Create creates a new document

func (*Handler) CreateDirectShare

func (h *Handler) CreateDirectShare(ctx context.Context, req CreateDirectShareRequest) (*DirectShare, error)

CreateDirectShare creates a direct share for a document

func (*Handler) CreateEnvironmentShare

func (h *Handler) CreateEnvironmentShare(ctx context.Context, req CreateEnvironmentShareRequest) (*EnvironmentShare, error)

CreateEnvironmentShare creates an environment-wide share for a document

func (*Handler) Delete

func (h *Handler) Delete(ctx context.Context, id string, version int) error

Delete deletes a document

func (*Handler) DeleteDirectShare

func (h *Handler) DeleteDirectShare(ctx context.Context, shareID string) error

DeleteDirectShare deletes a direct share

func (*Handler) DeleteEnvironmentShare

func (h *Handler) DeleteEnvironmentShare(ctx context.Context, shareID string) error

DeleteEnvironmentShare deletes an environment share

func (*Handler) DeleteSnapshot

func (h *Handler) DeleteSnapshot(ctx context.Context, documentID string, version int) error

DeleteSnapshot deletes a specific snapshot

func (*Handler) Get

func (h *Handler) Get(ctx context.Context, id string) (*Document, error)

Get retrieves a specific document by ID

func (*Handler) GetAtVersion

func (h *Handler) GetAtVersion(ctx context.Context, id string, version int) (*Document, error)

GetAtVersion retrieves a document's content at a specific snapshot version

func (*Handler) GetEnvironmentShare

func (h *Handler) GetEnvironmentShare(ctx context.Context, shareID string) (*EnvironmentShare, error)

GetEnvironmentShare retrieves an environment share by ID, resolving it to the document it points to. Environment share URLs (`.../document/v0/#share=<id>`) carry only the share ID, not the document ID, so this is how a share link gets resolved.

func (*Handler) GetMetadata

func (h *Handler) GetMetadata(ctx context.Context, id string) (*DocumentMetadata, error)

GetMetadata retrieves only the metadata for a document

func (*Handler) GetSnapshot

func (h *Handler) GetSnapshot(ctx context.Context, documentID string, version int) (*Snapshot, error)

GetSnapshot retrieves metadata for a specific snapshot

func (*Handler) List

func (h *Handler) List(ctx context.Context, filters DocumentFilters) (*DocumentList, error)

List retrieves documents matching the provided filters with automatic pagination

func (*Handler) ListDirectShares

func (h *Handler) ListDirectShares(ctx context.Context, documentID string) (*DirectShareList, error)

ListDirectShares lists direct shares for a document. Paginates automatically using the Document API style (page-size sent on every request).

func (*Handler) ListEnvironmentShares

func (h *Handler) ListEnvironmentShares(ctx context.Context, documentID string) (*EnvironmentShareList, error)

ListEnvironmentShares lists environment shares for a document (or all if documentID is empty). Paginates automatically using the Document API style (page-size sent on every request).

func (*Handler) ListSnapshots

func (h *Handler) ListSnapshots(ctx context.Context, documentID string) (*SnapshotList, error)

ListSnapshots retrieves all snapshots for a document

func (*Handler) RemoveDirectShareRecipients

func (h *Handler) RemoveDirectShareRecipients(ctx context.Context, shareID string, recipientIDs []string) error

RemoveDirectShareRecipients removes recipients from a direct share

func (*Handler) RestoreSnapshot

func (h *Handler) RestoreSnapshot(ctx context.Context, documentID string, version int) (*DocumentMetadata, error)

RestoreSnapshot restores a document to a specific snapshot version

func (*Handler) SetDocumentPublic

func (h *Handler) SetDocumentPublic(ctx context.Context, id string, version int) error

SetDocumentPublic flips a document's isPrivate flag to false, making it discoverable to everyone in the environment via the Notebooks/Dashboards app's listing. Requires the current document version for optimistic-locking. Uses the documents PATCH endpoint with a multipart form body (the same shape content updates use).

This is the half of the "Share with environment" UI action that the environment-share API does not cover: the env-share creates a claimable grant, but isPrivate=false is a separate owner-settable metadata flag.

func (*Handler) Update

func (h *Handler) Update(ctx context.Context, id string, version int, content []byte, contentType string) (*Document, error)

Update updates a document's content.

func (*Handler) UpdateDocument

func (h *Handler) UpdateDocument(ctx context.Context, id string, version int, req UpdateRequest) (*Document, error)

UpdateDocument performs a partial update of a document via the updateDocument endpoint. It is the general form behind Update / UpdateWithMetadata and is the only write path that can set labels (the create endpoint cannot).

func (*Handler) UpdateWithMetadata

func (h *Handler) UpdateWithMetadata(ctx context.Context, id string, version int, content []byte, contentType string, name string, description string) (*Document, error)

UpdateWithMetadata updates a document's content and optionally its metadata (name, description).

type ModificationInfo

type ModificationInfo struct {
	CreatedBy        string    `json:"createdBy"`
	CreatedTime      time.Time `json:"createdTime"`
	LastModifiedBy   string    `json:"lastModifiedBy"`
	LastModifiedTime time.Time `json:"lastModifiedTime"`
}

ModificationInfo contains creation and modification timestamps

type RestoreOptions

type RestoreOptions struct {
	Force   bool   // Restore even if name conflicts exist (not supported by API yet)
	NewName string // Restore with a new name (not supported by API yet)
}

RestoreOptions contains options for restoring a document

type ShareInfo

type ShareInfo struct {
	IsShared                bool `json:"isShared" yaml:"isShared"`
	IsSharedWithCurrentUser bool `json:"isSharedWithCurrentUser,omitempty" yaml:"isSharedWithCurrentUser,omitempty"`
}

ShareInfo describes share state for a document.

type Snapshot

type Snapshot struct {
	SnapshotVersion  int             `json:"snapshotVersion"`
	DocumentVersion  int             `json:"documentVersion"`
	Description      string          `json:"description,omitempty"`
	ModificationInfo SnapshotModInfo `json:"modificationInfo"`
	CreatedBy        string          `json:"-"`
	CreatedTime      time.Time       `json:"-"`
}

Snapshot represents a document snapshot (version)

func (*Snapshot) UnmarshalJSON

func (s *Snapshot) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaler for Snapshot to flatten modificationInfo and handle version fields as string or int.

type SnapshotList

type SnapshotList struct {
	Snapshots   []Snapshot `json:"snapshots"`
	TotalCount  int        `json:"totalCount"`
	NextPageKey string     `json:"nextPageKey,omitempty"`
}

SnapshotList represents a list of snapshots

type SnapshotModInfo

type SnapshotModInfo struct {
	CreatedBy   string    `json:"createdBy"`
	CreatedTime time.Time `json:"createdTime"`
}

SnapshotModInfo contains creation info for a snapshot

type SsoEntity

type SsoEntity struct {
	ID   string `json:"id"`
	Type string `json:"type"` // "user" or "group"
}

SsoEntity represents an SSO user or group

type TrashDocumentListEntry

type TrashDocumentListEntry struct {
	ID           string       `json:"id" yaml:"id"`
	Name         string       `json:"name" yaml:"name"`
	Type         string       `json:"type" yaml:"type"`
	DeletionInfo DeletionInfo `json:"deletionInfo" yaml:"deletionInfo"`
	// Computed fields for display
	DeletedBy string    `json:"-" yaml:"-"`
	DeletedAt time.Time `json:"-" yaml:"-"`
}

TrashDocumentListEntry represents a document in the trash list (from GET /trash/documents)

type TrashHandler

type TrashHandler struct {
	// contains filtered or unexported fields
}

TrashHandler handles trash operations for documents

func NewTrashHandler

func NewTrashHandler(c *httpclient.Client) *TrashHandler

NewTrashHandler creates a new trash handler

func (*TrashHandler) Delete

func (h *TrashHandler) Delete(ctx context.Context, id string) error

Delete permanently deletes a document from trash

func (*TrashHandler) Get

Get retrieves a specific trashed document by ID

func (*TrashHandler) List

List retrieves trashed documents matching the provided filters

func (*TrashHandler) Restore

func (h *TrashHandler) Restore(ctx context.Context, id string, opts RestoreOptions) error

Restore restores a document from trash

type TrashList

type TrashList struct {
	Documents   []TrashDocumentListEntry `json:"documents"`
	TotalCount  int                      `json:"totalCount"`
	NextPageKey string                   `json:"nextPageKey,omitempty"`
}

TrashList represents a list of trashed documents

type TrashListOptions

type TrashListOptions struct {
	Type          string    // Filter by type: "dashboard", "notebook"
	DeletedBy     string    // Filter by who deleted it
	DeletedAfter  time.Time // Show documents deleted after date
	DeletedBefore time.Time // Show documents deleted before date
	ChunkSize     int64     // Page size for pagination (0 = no chunking)
}

TrashListOptions contains filter options for listing trashed documents

type TrashedDocument

type TrashedDocument struct {
	ID               string           `json:"id" yaml:"id"`
	Name             string           `json:"name" yaml:"name"`
	Type             string           `json:"type" yaml:"type"`
	Version          int              `json:"version" yaml:"version"`
	Owner            string           `json:"owner" yaml:"owner"`
	DeletionInfo     DeletionInfo     `json:"deletionInfo" yaml:"deletionInfo"`
	ModificationInfo ModificationInfo `json:"modificationInfo,omitempty" yaml:"modificationInfo,omitempty"`
	// Computed fields for display
	DeletedBy string    `json:"-" yaml:"-"`
	DeletedAt time.Time `json:"-" yaml:"-"`
}

TrashedDocument represents a document in the trash (from GET /trash/documents/{id})

func (*TrashedDocument) UnmarshalJSON

func (t *TrashedDocument) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshaler for TrashedDocument to handle version as string or int.

type UpdateRequest

type UpdateRequest struct {
	Content     []byte   // Document content; omitted when empty (content unchanged)
	ContentType string   // Content-Type for Content; defaults to application/json
	Name        string   // New name; omitted when empty
	Description string   // New description; omitted when empty
	Labels      []string // Replacement label set; omitted when empty

	// CreateSnapshot asks the API to snapshot the document's current state
	// before applying this update, so the pre-update content stays retrievable
	// via ListSnapshots / RestoreSnapshot. Defaults to false: updates overwrite
	// without keeping history unless this is set.
	//
	// The API caps snapshot creation at 5 per document per 60 seconds and keeps
	// at most 50 snapshots per document (creating the 51st deletes the oldest).
	CreateSnapshot bool

	// SnapshotDescription labels the snapshot created by CreateSnapshot (max
	// 128 characters). Ignored when CreateSnapshot is false.
	SnapshotDescription string
}

UpdateRequest contains the (all optional) fields that can be changed on an existing document via updateDocument. Any zero-valued field is omitted from the request and the API leaves the corresponding attribute unchanged. A non-empty Labels slice replaces the document's entire label set; an empty or nil slice sends no labels, which the API also treats as "no change" (this endpoint offers no way to clear labels).

type UserContext

type UserContext struct {
	LastAccessedTime time.Time `json:"lastAccessedTime" yaml:"lastAccessedTime"`
}

UserContext describes per-user metadata for a document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL