Documentation
¶
Overview ¶
Package operations dispatches and executes definition-scoped operations for integrations
Index ¶
- Variables
- func CompleteRun(ctx context.Context, db *ent.Client, runID string, startedAt time.Time, ...) error
- func CreatePendingRun(ctx context.Context, db *ent.Client, installation *ent.Integration, ...) (*ent.IntegrationRun, error)
- func DependencyOrder(schemas []*entityops.Schema) []*entityops.Schema
- func ExportDocument[C DocClient](ctx context.Context, _ types.OperationRequest, svc C, cfg DocumentExport) (json.RawMessage, error)
- func LastSuccessfulRunAt(ctx context.Context, db *ent.Client, integrationID, operationName string) (*time.Time, error)
- func MarkRunRunning(ctx context.Context, db *ent.Client, runID string) error
- func NewChannelsListOperation[C any](list ListTeamsFunc[C], encodeErr error) types.OperationRef[ChannelsListOperation]
- func NewResourceSelectionOperation(store SelectionStore, limit int) types.OperationRef[ResourceSelection]
- func NewTestMessageOperation[C any, Config any, P messageConfig[Config]](...) types.OperationRef[TestMessageSendOperation]
- func NotifyDeleteOutcome(ctx context.Context, subject string, deleted map[string]int, deleteErr error) error
- func NotifyImportOutcome(ctx context.Context, subject string, result IngestResult, ingestErr error, ...) error
- func NotifyOutcome(ctx context.Context, objectType string, content entityops.NotificationContent) error
- func ReconcileUniqueKey(e ReconcileEnvelope) string
- func RetryRun(ctx context.Context, db *ent.Client, run *ent.IntegrationRun) (*ent.IntegrationRun, error)
- func RunSourceDelete(ctx context.Context, request types.OperationRequest, cfg DeleteSource) (json.RawMessage, error)
- func ValidateInput(ctx context.Context, req types.InstallationRequest, schema json.RawMessage, ...) error
- type Channel
- type ChannelsList
- type ChannelsListOperation
- type DeleteSource
- type DeleteSourceRecordsResult
- type DocClient
- type DocumentExport
- type Envelope
- type IngestContext
- type IngestOptions
- type IngestResult
- type ListTeamsFunc
- type MessageContent
- type MessageDelivery
- type MessageSendResult
- type ReconcileEnvelope
- type RecordFailure
- type ResourceSelection
- type RunResult
- type SelectionStore
- type Team
- type TestMessageSendOperation
- type UserInput
- type WebhookEnvelope
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGalaRequired indicates the gala dependency is missing ErrGalaRequired = errors.New("integrations/operations: gala required") // ErrDispatchInputInvalid indicates the queued operation request failed caller-input validation ErrDispatchInputInvalid = errors.New("integrations/operations: dispatch input invalid") // ErrInstallationIDRequired indicates the installation identifier is missing ErrInstallationIDRequired = errors.New("integrations/operations: installation id required") // ErrSelectionPersistFailed indicates a picker selection could not be stored on the installation ErrSelectionPersistFailed = errors.New("integrations/operations: selection persist failed") // ErrSelectionLimitExceeded indicates more resources were selected than the operation accepts ErrSelectionLimitExceeded = errors.New("integrations/operations: too many resources selected") // ErrRunIDRequired indicates the run identifier is missing ErrRunIDRequired = errors.New("integrations/operations: run id required") // ErrIngestDefinitionNotFound indicates the operation definition could not be resolved for ingest ErrIngestDefinitionNotFound = errors.New("integrations/operations: ingest definition not found") // ErrIngestSchemaNotFound indicates the generated ingest schema contract was not found ErrIngestSchemaNotFound = errors.New("integrations/operations: ingest schema not found") // ErrIngestSchemaNotDeclared indicates the payload schema was not declared in the operation's ingest contracts ErrIngestSchemaNotDeclared = errors.New("integrations/operations: ingest schema not declared in contracts") // ErrIngestMappingNotFound indicates the definition does not provide a mapping for the emitted payload variant ErrIngestMappingNotFound = errors.New("integrations/operations: ingest mapping not found") // ErrIngestFilterFailed indicates the CEL filter evaluation failed ErrIngestFilterFailed = errors.New("integrations/operations: ingest filter failed") // ErrIngestInstallationFilterConfigInvalid indicates the installation filter configuration could not be decoded ErrIngestInstallationFilterConfigInvalid = errors.New("integrations/operations: ingest installation filter config invalid") // ErrIngestTransformFailed indicates the CEL map evaluation failed ErrIngestTransformFailed = errors.New("integrations/operations: ingest transform failed") // ErrIngestMappedDocumentInvalid indicates the mapped payload did not satisfy the generated schema contract ErrIngestMappedDocumentInvalid = errors.New("integrations/operations: ingest mapped document invalid") // ErrIngestUpsertKeyMissing indicates the mapped payload omitted every generated upsert key ErrIngestUpsertKeyMissing = errors.New("integrations/operations: ingest upsert key missing") // ErrIngestUpsertConflict indicates the generated upsert keys matched more than one record ErrIngestUpsertConflict = errors.New("integrations/operations: ingest upsert conflict") // ErrIngestUnsupportedSchema indicates the runtime does not yet support the requested generated ingest schema ErrIngestUnsupportedSchema = errors.New("integrations/operations: ingest schema unsupported") // ErrSourceFilterRequired indicates a source delete was asked for without a definition and an instance or key ErrSourceFilterRequired = errors.New("integrations/operations: source delete requires a definition and an instance or key") // ErrSourceOperationContextRequired indicates a runtime source delete ran without its operation context ErrSourceOperationContextRequired = errors.New("integrations/operations: runtime source delete requires an operation context") // ErrSourceOwnerRequired indicates a source delete was dispatched without an organization to delete from ErrSourceOwnerRequired = errors.New("integrations/operations: source delete requires an organization") // ErrSourceKeepUnknown indicates a schema to keep is not part of the schemas being deleted ErrSourceKeepUnknown = errors.New("integrations/operations: kept schema is not in the delete order") // ErrSourceSchemaNotDeletable indicates a schema has no delete by source ErrSourceSchemaNotDeletable = errors.New("integrations/operations: schema cannot be deleted by source") // ErrSourceDeleteFailed indicates a schema's source rows could not be removed ErrSourceDeleteFailed = errors.New("integrations/operations: source delete failed") // ErrIngestSchemaNotSystemOwned indicates the schema carries no system_owned marker, so runtime ingest cannot persist it without an owner ErrIngestSchemaNotSystemOwned = errors.New("integrations/operations: ingest schema cannot be system owned") // ErrIngestPersistFailed indicates the mapped record could not be persisted ErrIngestPersistFailed = errors.New("integrations/operations: ingest persistence failed") // ErrIngestRecordExcluded indicates the record was skipped because an earlier run recorded it as failing ErrIngestRecordExcluded = errors.New("integrations/operations: ingest record excluded") // ErrIngestIntegrationUnresolved indicates the integration record could not be resolved for an ingest operation ErrIngestIntegrationUnresolved = errors.New("integrations/operations: ingest integration unresolved") // ErrIngestInstanceIDRequired indicates the installation carries no source instance id, which every ingested record needs for provenance ErrIngestInstanceIDRequired = errors.New("integrations/operations: ingest installation instance id required") // ErrIngestIntegrationRemoved indicates the integration installation was removed while ingest record jobs were still queued ErrIngestIntegrationRemoved = errors.New("integrations/operations: ingest integration removed") // ErrOperationDisabled indicates the operation is disabled for this installation and the reconcile cycle should stop ErrOperationDisabled = errors.New("integrations/operations: operation disabled") // ErrExportFailed indicates the Drive file export request failed ErrExportFailed = errors.New("integrations/operations: file export failed") // ErrResultEncode indicates an operation result could not be serialized ErrResultEncode = errors.New("integrations/operations: result encode failed") // ErrLinkFailed indicates a link operation failed ErrLinkFailed = errors.New("integrations/operations: link operation failed") // ErrVendorEntityTypeMissing indicates the organization has no vendor entity type ErrVendorEntityTypeMissing = errors.New("integrations/operations: vendor entity type missing") )
var DeleteSourceOp = types.OperationPayloadOf[DeleteSource](). HandlesRequest(RunSourceDelete). Policy(types.ExecutionPolicy{NoRetry: true}). CustomerSelectable(false). Internal(). Description("Remove the records one source key or instance wrote into the organization the operation is dispatched for")
DeleteSourceOp is the operation ref for removing the rows one source key or instance wrote, registered by any definition
var ReconcileTopic = gala.NamespacedTopicFor(gala.IntegrationReconcile, gala.WithUniqueKey(ReconcileUniqueKey))
ReconcileTopic is the durable reconcile topic: the name derives from the envelope type under the reconcile namespace, and every emission carries the loop uniqueness key
Functions ¶
func CompleteRun ¶
func CompleteRun(ctx context.Context, db *ent.Client, runID string, startedAt time.Time, result RunResult) error
CompleteRun writes the final run outcome
func CreatePendingRun ¶
func CreatePendingRun(ctx context.Context, db *ent.Client, installation *ent.Integration, operation types.OperationRegistration, runType enums.IntegrationRunType, config json.RawMessage) (*ent.IntegrationRun, error)
CreatePendingRun inserts one pending run record for a dispatched operation
func DependencyOrder ¶
DependencyOrder returns schemas with each after the schemas its foreign key edges point at
func ExportDocument ¶
func ExportDocument[C DocClient](ctx context.Context, _ types.OperationRequest, svc C, cfg DocumentExport) (json.RawMessage, error)
ExportDocument runs the document export against the typed client with the decoded export config
func LastSuccessfulRunAt ¶
func LastSuccessfulRunAt(ctx context.Context, db *ent.Client, integrationID, operationName string) (*time.Time, error)
LastSuccessfulRunAt returns the finish time of the most recent successful run for the given integration and operation, or nil if no successful run exists yet
func MarkRunRunning ¶
MarkRunRunning transitions one run to running
func NewChannelsListOperation ¶
func NewChannelsListOperation[C any](list ListTeamsFunc[C], encodeErr error) types.OperationRef[ChannelsListOperation]
NewChannelsListOperation builds the inline operation that lists message destinations through list
func NewResourceSelectionOperation ¶
func NewResourceSelectionOperation(store SelectionStore, limit int) types.OperationRef[ResourceSelection]
NewResourceSelectionOperation returns the inline operation ref that saves an installation's selected resources through store, accepting at most limit resources when limit is above zero
func NewTestMessageOperation ¶
func NewTestMessageOperation[C any, Config any, P messageConfig[Config]](send func(context.Context, types.OperationRequest, C, Config) (json.RawMessage, error)) types.OperationRef[TestMessageSendOperation]
NewTestMessageOperation builds the inline operation that posts a fixed test message to the picked channel through the integration's message send handler
func NotifyDeleteOutcome ¶
func NotifyDeleteOutcome(ctx context.Context, subject string, deleted map[string]int, deleteErr error) error
NotifyDeleteOutcome sends the organization notification summarizing a source delete subject names what was removed, deleted is the count per schema and deleteErr is the error that stopped it
func NotifyImportOutcome ¶
func NotifyImportOutcome(ctx context.Context, subject string, result IngestResult, ingestErr error, detail string) error
NotifyImportOutcome sends the organization notification summarizing an import subject names what was imported, and detail, such as how to retry, is appended to the body when set
func NotifyOutcome ¶
func NotifyOutcome(ctx context.Context, objectType string, content entityops.NotificationContent) error
NotifyOutcome sends the notification describing how a background operation finished to the caller's organization the title and body are sent as written, the type defaults to organization and the topic to import complete
func ReconcileUniqueKey ¶
func ReconcileUniqueKey(e ReconcileEnvelope) string
ReconcileUniqueKey derives the insert-time uniqueness key for one recurring loop, so any emitter of the topic collapses to at most one live loop per installation (or runtime definition) and operation
func RetryRun ¶
func RetryRun(ctx context.Context, db *ent.Client, run *ent.IntegrationRun) (*ent.IntegrationRun, error)
RetryRun inserts a fresh pending run for a re-executed attempt of the given run, carrying its operation, run type, and config, so every attempt writes records under its own run id
func RunSourceDelete ¶
func RunSourceDelete(ctx context.Context, request types.OperationRequest, cfg DeleteSource) (json.RawMessage, error)
RunSourceDelete removes the source's rows for the dispatching definition and notifies the organization, for any operation that resolves the source to delete itself
func ValidateInput ¶
func ValidateInput(ctx context.Context, req types.InstallationRequest, schema json.RawMessage, validate types.ValidateFunc, payload json.RawMessage, sentinel error) error
ValidateInput checks a payload against its schema and then its semantic validation, wrapping schema failures in sentinel
Types ¶
type Channel ¶
type Channel struct {
// ID is the channel identifier
ID string `json:"id"`
// DisplayName is the channel name
DisplayName string `json:"displayName"`
}
Channel is one channel within a team
type ChannelsList ¶
type ChannelsList struct {
// Teams are the teams with their channels
Teams []Team `json:"teams"`
}
ChannelsList lists the teams the connection can post to and the channels in each
type ChannelsListOperation ¶
type ChannelsListOperation struct{}
ChannelsListOperation holds per-invocation parameters for the channels list operation
type DeleteSource ¶
type DeleteSource struct {
// SourceKey is the source key runtime ingest wrote the rows under
SourceKey string `json:"sourceKey,omitempty" jsonschema:"title=Source Key,description=Source key the rows were written under"`
// InstanceID is the source instance an installation wrote the rows from
InstanceID string `json:"instanceId,omitempty" jsonschema:"title=Instance ID,description=Source instance the rows were written from"`
// Keep lists the schemas whose rows are kept
Keep []string `json:"keep,omitempty" jsonschema:"title=Keep,description=Schemas whose rows are kept"`
// Subject names what is removed in the outcome notification
Subject string `json:"subject,omitempty" jsonschema:"title=Subject,description=Names what is removed in the notification"`
}
DeleteSource selects the rows the dispatching definition wrote into the organization under one source key, from one source instance, or both
type DeleteSourceRecordsResult ¶
type DeleteSourceRecordsResult struct {
// Deleted is the number of rows removed per schema
Deleted map[string]int `json:"deleted"`
}
DeleteSourceRecordsResult reports the rows removed per schema
type DocClient ¶
type DocClient interface {
Export(ctx context.Context, cfg *DocumentExport) error
}
DocClient is the interface all document integrations must satisfy
type DocumentExport ¶
type DocumentExport struct {
// FileID is the external file identifier to export
FileID string `json:"fileId"`
// HTML is the exported document content as an embeddable iframe string (populated in the response)
HTML string `json:"html,omitempty"`
// PDF is the exported document content as raw PDF bytes (populated in the response)
PDF []byte `json:"pdf,omitempty"`
// MimeType is the content type of the downloaded file
MimeType string `json:"mimeType,omitempty"`
// Name is the file name without extension
Name string `json:"name,omitempty"`
}
DocumentExport holds the configuration and result for a integration document export
type Envelope ¶
type Envelope struct {
gala.OperationContext
// Config is the operation configuration payload
Config json.RawMessage `json:"config,omitempty"`
// ForceClientRebuild requests client cache bypass
ForceClientRebuild bool `json:"forceClientRebuild,omitempty"`
}
Envelope is the payload emitted to the operation topic
type IngestContext ¶
type IngestContext struct {
// Registry resolves the definition whose mappings the batch is ingested through
Registry types.DefinitionLookup
// DB is the ent client used for persistence
DB *ent.Client
// Runtime is the Gala instance used for async emit; nil on the synchronous persist path
Runtime *gala.Gala
// Integration is the integration record being ingested into, nil for runtime ingest
Integration *ent.Integration
// DefinitionID identifies the definition when ingesting on the runtime path, where no installation exists
DefinitionID string
}
IngestContext holds the stable per-integration dependencies shared across all ingest call paths
type IngestOptions ¶
type IngestOptions struct {
// RunID is a caller-supplied correlation identifier for the overall operation run
RunID string
// Webhook is the webhook name or identifier that triggered this ingest
Webhook string
// WebhookEvent is the event type reported by the webhook provider
WebhookEvent string
// DeliveryID is the provider-assigned delivery identifier; used for deduplication
DeliveryID string
// WorkflowMeta carries workflow instance context
WorkflowMeta *types.WorkflowMeta
}
IngestOptions carries the minimal ingest-time metadata needed by persistence
func IngestOptionsFromOperationContext ¶
func IngestOptionsFromOperationContext(oc gala.OperationContext) IngestOptions
IngestOptionsFromOperationContext derives ingest options from an integration operation context
type IngestResult ¶
type IngestResult struct {
Attempted int
// Persisted counts records this installation's definition created, changed, or left unchanged
Persisted int
// Filtered counts records excluded by configured filters
Filtered int
// Succeeded is the combined successful handling count
Succeeded int
// Changed counts records that created, modified, or durably queued rows, excluding unchanged rows
Changed int
// Skipped counts records left untouched by another definition or a newer run
Skipped int
// Failed counts records that could not be imported
Failed int
// Excluded counts records that failed again while tracked and were not requeued
Excluded int
// Removed counts rows marked removed by snapshot reconciliation
Removed int
// Failures lists each failed record with its cause
Failures []RecordFailure
}
IngestResult reports record-level work completed by a payload batch
func ProcessPayloadSets ¶
func ProcessPayloadSets(ctx context.Context, ic IngestContext, operationName string, contracts []types.IngestContract, policy types.ExecutionPolicy, payloadSets []types.IngestPayloadSet, options IngestOptions) (IngestResult, error)
ProcessPayloadSets persists one batch of mapped payload sets synchronously
func (IngestResult) FailureSummary ¶
func (r IngestResult) FailureSummary() string
FailureSummary renders a compact summary of the failed records, empty when none failed
func (*IngestResult) Merge ¶
func (r *IngestResult) Merge(other IngestResult)
Merge adds the counts and failures of other onto r
type ListTeamsFunc ¶
ListTeamsFunc lists the teams, or workspace, the connection can post to with the channels in each
type MessageContent ¶
type MessageContent struct {
// TemplateID references a notification template by database ID
TemplateID string `json:"templateId,omitempty" jsonschema:"title=Template ID"`
// TemplateKey references a notification template by key
TemplateKey string `json:"templateKey,omitempty" jsonschema:"title=Template Key"`
// TeamID is the workspace or team the channel belongs to, required by providers that scope channels to a team
TeamID string `json:"teamId,omitempty" jsonschema:"title=Team ID"`
// Channel is the channel identifier to post to
Channel string `json:"channel,omitempty" jsonschema:"title=Channel"`
// Text is the message content
Text string `json:"text,omitempty" jsonschema:"title=Message Text"`
// Subject is an optional message subject, ignored by providers without one
Subject string `json:"subject,omitempty" jsonschema:"title=Subject"`
}
MessageContent is the provider-neutral message every messaging integration's send operation accepts
func (MessageContent) ResolveTemplate ¶
func (m MessageContent) ResolveTemplate(ctx context.Context, req types.OperationRequest, cfg any) error
ResolveTemplate merges the referenced notification template's defaults into cfg, the operation config embedding this content
func (*MessageContent) SetMessageContent ¶
func (m *MessageContent) SetMessageContent(content MessageContent)
SetMessageContent replaces the content, letting shared operations fill any config that embeds it
type MessageDelivery ¶
type MessageDelivery struct {
// TeamID is the team the channel belongs to, empty for providers that do not scope channels to a team
TeamID string `json:"teamId,omitempty"`
// Channel is the channel the message was posted to
Channel string `json:"channel"`
// ID is the identifier of the posted message
ID string `json:"id"`
}
MessageDelivery captures one message delivery
type MessageSendResult ¶
type MessageSendResult struct {
// Channel is the first channel the message was posted to
Channel string `json:"channel,omitempty"`
// ID is the identifier of the first message posted
ID string `json:"id,omitempty"`
// Deliveries captures every channel delivery performed by the operation
Deliveries []MessageDelivery `json:"deliveries,omitempty"`
}
MessageSendResult is the result every messaging integration's send operation returns
func NewMessageSendResult ¶
func NewMessageSendResult(deliveries []MessageDelivery) MessageSendResult
NewMessageSendResult builds the send result from its deliveries, with the first delivery as the primary channel and message
type ReconcileEnvelope ¶
type ReconcileEnvelope struct {
gala.OperationContext
// Schedule is the adaptive scheduling state carried across cycles
Schedule gala.ScheduleState `json:"schedule"`
}
ReconcileEnvelope is the durable payload for one recurring operation cycle, either installation-bound (IntegrationID set) or runtime-bound (Runtime true); the type name is the durable topic identity and must not change
type RecordFailure ¶
type RecordFailure struct {
// Schema is the mapping schema name
Schema string
// Resource is the provider resource identifier
Resource string
// Message is the failure text carried in the serialized result
Message string
// Err is the underlying failure, available in process only
Err error `json:"-"`
}
RecordFailure identifies one mapped record that could not be imported
type ResourceSelection ¶
type ResourceSelection struct {
// Resources lists the selected provider resources, replacing any previous selection
Resources []types.SelectedResource `json:"resources" jsonschema:"required,title=Resources"`
}
ResourceSelection holds the provider resources a user selected for an installation
type RunResult ¶
type RunResult struct {
// Status is the terminal run status
Status enums.IntegrationRunStatus
// Summary is the optional summary text stored on the run
Summary string
// Error is the optional terminal error text stored on the run
Error string
// Metrics is the structured metrics payload stored on the run
Metrics map[string]any
}
RunResult captures the terminal state of one run
type SelectionStore ¶
type SelectionStore func(ctx context.Context, request types.OperationRequest, resources []types.SelectedResource) error
SelectionStore saves the resources a user selected onto the installation field the definition reads them from
type Team ¶
type Team struct {
// ID is the team identifier
ID string `json:"id"`
// DisplayName is the team name
DisplayName string `json:"displayName"`
// Channels are the channels in the team
Channels []Channel `json:"channels"`
}
Team is one team or workspace
type TestMessageSendOperation ¶
type TestMessageSendOperation struct {
// TeamID is the workspace or team the channel belongs to
TeamID string `json:"teamId,omitempty" jsonschema:"title=Team ID"`
// ChannelID is the target channel identifier
ChannelID string `json:"channelId" jsonschema:"required,title=Channel ID"`
}
TestMessageSendOperation holds the target the console's shared messaging picker sends for a test message
type UserInput ¶
type UserInput struct {
// Primary marks this installation as the authoritative source for live document exports
Primary bool `json:"primary,omitempty" jsonschema:"title=Primary"`
}
UserInput holds installation-specific configuration collected from the user
type WebhookEnvelope ¶
type WebhookEnvelope struct {
gala.OperationContext
// Payload is the raw webhook request body
Payload json.RawMessage `json:"payload"`
// Headers contains the inbound HTTP request headers
Headers map[string]string `json:"headers,omitempty"`
}
WebhookEnvelope is the durable payload emitted for one inbound integration webhook event