class OpenUI::Rails::Actions::Dispatcher
The single authorization and execution path for every write-ish call, whether it originated from a component onAction or a browser toolProvider βQuery()`/`Mutation()`. It fails closed: with no authorizer configured, an action is denied.
Order of checks (all before any side effect):
1. resolve + validate the submission 2. action is registered (allowlist) 3. args match the schema 4. confirmation when the action is destructive 5. surface revision is current (stale protection) 6. authorizer allows it 7. idempotency claim (duplicates never execute twice)
Constants
- Result
-
Outcome returned after an action executes or replays.
Public Class Methods
# File lib/openui/rails/actions/dispatcher.rb, line 33 def self.from_configuration(configuration = OpenUI::Rails.configuration) new( registry: configuration.action_registry, idempotency_store: configuration.idempotency_store || Idempotency::MemoryStore.new, idempotency_ttl: configuration.idempotency_ttl, authorize_action: configuration.authorize_action, surface_resolver: configuration.surface_resolver, idempotency_scope: configuration.idempotency_scope ) end
Build a dispatcher from the process-wide configuration.
@param configuration [Configuration] @return [Dispatcher]
# File lib/openui/rails/actions/dispatcher.rb, line 59 def initialize(registry:, idempotency_store:, idempotency_ttl:, authorize_action: nil, surface_resolver: nil, idempotency_scope: nil) @registry = registry @idempotency_store = idempotency_store @idempotency_ttl = idempotency_ttl @authorize_action = authorize_action @surface_resolver = surface_resolver @idempotency_scope = idempotency_scope end
Build a dispatcher with explicit action and replay dependencies.
@param registry [Registry]
@param idempotency_store [#claim, #record]
@param idempotency_ttl [Numeric]
@param authorize_action [#call, nil]
@param surface_resolver [#call, nil]
@param idempotency_scope [#call, nil]
@return [Dispatcher]
Public Instance Methods
# File lib/openui/rails/actions/dispatcher.rb, line 86 def call(payload, actor: nil, surface: nil, tenant: nil, context: {}) started = Instrumentation.now outcome = "rejected" replayed = false code = nil submission = Submission.parse(payload) definition = @registry.fetch(submission.action) definition.schema.validate!(submission.args) check_confirmation!(definition, submission) surface ||= resolve_surface(submission.surface_id, actor, context) check_version!(submission, surface) invocation = Invocation.new( action: definition.name, args: submission.args, actor: actor, surface: surface, tenant: tenant, context: context, submission: submission ) authorize!(definition, invocation) replayed, stored, key, token = claim_idempotency(submission, invocation) if replayed outcome = "replayed" return result(submission, stored, replayed: true) end outcome = "failed" value = definition.handler.call(invocation) @idempotency_store.record(key, value, claim_token: token) outcome = "succeeded" result(submission, value, replayed: false) rescue StandardError => error code = Instrumentation.action_error_code(error) outcome = "failed" unless error.is_a?(Error) raise ensure Instrumentation.publish("action", started: started, outcome: outcome, code: code, replayed: replayed == true) end
@param payload [Hash, Submission]
@param actor [Object, nil] authenticated host actor
@param surface [Object, nil] already-resolved host surface
@param tenant [Object, nil] trusted host tenant identity
@param context [Hash] host-supplied request context
@return [Result]
Emits one content-free action.openui_rails outcome notification. Failed gates run before the handler. Handler and storage failures can occur after a business effect; hosts must reconcile that outcome.
@raise [OpenUI::Rails::Error] on a failed gate or domain operation