Module: Spree::AgentTools::DefaultCatalog

Defined in:
lib/spree/agent_tools/default_catalog.rb

Overview

The hand-written tools Spree ships: the generic reads and writes, reporting, imports, files and stock.

Back-office actions are not listed here. Every Admin API action is a tool built from its OpenAPI operation (OperationCatalog); an action that should not be one is marked in its rswag spec, with the reason.

Constant Summary collapse

TOOLS =

Read tools, and the writes that are not workflows.

%w[
  Spree::AgentTools::SearchResources
  Spree::AgentTools::GetResource
  Spree::AgentTools::DescribeResource
  Spree::AgentTools::CreateResource
  Spree::AgentTools::UpdateResource
  Spree::AgentTools::DeleteResource
  Spree::AgentTools::CurateProducts
  Spree::AgentTools::UploadFile
  Spree::AgentTools::CreateMedia
  Spree::AgentTools::CreateImport
  Spree::AgentTools::SetStock
  Spree::AgentTools::QueryReport
  Spree::AgentTools::DescribeReporting
  Spree::AgentTools::CreateExport
  Spree::AgentTools::GetImportStatus
  Spree::AgentTools::DescribeImportMapping
  Spree::AgentTools::ProposeImportMapping
].freeze
WORKFLOWS =
Deprecated.

The 6.0.0 workflow allowlist, kept only so a reference to it does not break through 6.0.x. Nothing reads it: Admin API operations are tools on their own. Removed in 6.3.

{
  # Catalog
  product_activate_workflow: 'write_products',
  product_draft_workflow: 'write_products',
  product_archive_workflow: 'write_products',
  # `note` and `auto` belong to the workflow, not to the endpoint: the
  # review action passes neither, so offering them would describe a
  # capability no caller has.
  product_approve_workflow: { permission: 'write_products', except: %i[note auto] },
  product_reject_workflow: 'write_products',
  variant_create_workflow: 'write_products',
  variant_update_workflow: 'write_products',
  catalog_activate_workflow: 'write_products',
  catalog_deactivate_workflow: 'write_products',
  price_list_activate_workflow: 'write_products',
  price_list_deactivate_workflow: 'write_products',

  # Orders. `restock_items` is hidden: it is deprecated and ignored, so
  # offering it would invite a model to set something that does nothing.
  # `validated` is for callers that already ran their own veto; offered
  # to a model it would be a way around orders.complete.validate.
  order_cancel_workflow: { permission: 'write_orders', except: %i[restock_items] },
  order_complete_workflow: { permission: 'write_orders', except: %i[validated] },

  # Fulfillment
  fulfillment_create_workflow: 'write_fulfillments',
  fulfillment_mark_delivered_workflow: 'write_fulfillments',
  delivery_update_tracking_workflow: 'write_orders',
  shipping_label_purchase_workflow: 'write_orders',
  shipping_label_refund_workflow: 'write_orders',

  # Money
  payment_capture_workflow: 'write_payments',
  payment_void_workflow: 'write_payments',
  refund_create_workflow: 'write_refunds',

  # Inventory
  stock_transfer_mark_ready_workflow: 'write_stock',
  stock_transfer_mark_in_transit_workflow: 'write_stock',
  stock_transfer_receive_workflow: 'write_stock',
  stock_transfer_cancel_workflow: 'write_stock',
  stock_transfer_mark_draft_workflow: 'write_stock',
  stock_transfer_close_workflow: 'write_stock',

  # Purchasing
  purchase_order_mark_ordered_workflow: 'write_purchasing',
  purchase_order_receive_workflow: 'write_purchasing',
  purchase_order_cancel_workflow: 'write_purchasing',
  purchase_order_mark_draft_workflow: 'write_purchasing',
  purchase_order_close_workflow: 'write_purchasing',

  # Marketplace
  seller_invite_workflow: 'write_sellers',
  seller_approve_workflow: 'write_sellers',
  seller_reject_workflow: 'write_sellers',
  seller_suspend_workflow: 'write_sellers',
  seller_reopen_onboarding_workflow: 'write_sellers',
  seller_requirement_submission_accept_workflow: 'write_sellers',
  seller_requirement_submission_reject_workflow: 'write_sellers',
  seller_requirement_submission_waive_workflow: 'write_sellers',

  # B2B
  tax_exemption_certificate_verify_workflow: 'write_customers'
}.freeze
EMAIL_TEMPLATE_EDITOR_REASON =
Deprecated.

The 6.0.0 exclusion list, kept like WORKFLOWS. Its reasons now travel as agent_tool false, reason: on the operation's rswag spec. Removed in 6.3.

The email template editor is a draft-and-publish surface: its steps move a draft through revisions against a live preview, and they mean nothing outside that screen. Publishing one sends real mail in the merchant's name, which is not a conversational action.

'A step of the dashboard\'s email template editor, which drafts and previews against a ' \
'live rendering. Publishing sends real mail in the merchant\'s name.'.freeze
GENERIC_WRITE_REASON =

Plain create, update and destroy reach these through the generic write tools, which dispatch to the controller — and the controller declares this very workflow, so both paths run the same code. Two tools for one job only cost a model a choice it has no basis to make.

'Ordinary CRUD: the generic create, update and destroy tools dispatch to the controller, ' \
'which declares this workflow, so exposing it again would be a second path to the same code.'
EXCLUDED_WORKFLOWS =
{
  product_create_workflow: GENERIC_WRITE_REASON,
  product_update_workflow: GENERIC_WRITE_REASON,
  product_destroy_workflow: GENERIC_WRITE_REASON,
  catalog_create_workflow: GENERIC_WRITE_REASON,
  catalog_update_workflow: GENERIC_WRITE_REASON,
  price_list_create_workflow: GENERIC_WRITE_REASON,
  price_list_update_workflow: GENERIC_WRITE_REASON,
  stock_transfer_create_workflow: GENERIC_WRITE_REASON,
  stock_transfer_update_workflow: GENERIC_WRITE_REASON,
  purchase_order_create_workflow: GENERIC_WRITE_REASON,
  purchase_order_update_workflow: GENERIC_WRITE_REASON,
  seller_create_workflow: GENERIC_WRITE_REASON,
  email_template_save_draft_workflow: EMAIL_TEMPLATE_EDITOR_REASON,
  email_template_publish_workflow: EMAIL_TEMPLATE_EDITOR_REASON,
  email_template_discard_draft_workflow: EMAIL_TEMPLATE_EDITOR_REASON,
  email_template_revert_workflow: EMAIL_TEMPLATE_EDITOR_REASON,
  email_template_restore_revision_workflow: EMAIL_TEMPLATE_EDITOR_REASON,
  customer_anonymize_workflow:
    'Irreversible erasure of a person\'s data under GDPR Art. 17. A deletion no one can undo ' \
    'is not something to offer a model behind one confirmation prompt.',
  invitation_accept_workflow:
    'Platform plumbing, not a merchant operation: it runs for the invited person from a ' \
    'tokenised link, and the controller skips the scope check entirely.',
  seller_payout_sweep_workflow:
    'Moves money to every eligible seller at once. A scheduled platform job, not a ' \
    'conversational action.',
  seller_payout_complete_workflow:
    'Settles a payout against the payment provider. Belongs to the payouts pipeline, which ' \
    'reconciles against provider state the agent cannot see.',
  stock_level_bulk_upsert_workflow:
    'Reached through its endpoint by set_stock, not run in process. The workflow takes ' \
    'ids it trusts; the endpoint resolves them against the store first, and that is the ' \
    'check an agent must not be able to skip.',
  import_start_mapping_workflow:
    'Reads the uploaded file and proposes its column mapping. Runs as part of creating ' \
    'an import rather than on its own — a mapping proposal against a file nobody has ' \
    'attached yet means nothing.',
  import_complete_mapping_workflow:
    'Step of the CSV import wizard; the mapping proposal that feeds it stays in the ' \
    'dashboard assistant, which has the model.',
  import_retry_failed_rows_workflow:
    'Step of the CSV import wizard, meaningful only against a run the agent did not start.'
}.freeze

Class Method Summary collapse

Class Method Details

.install(registry) ⇒ void

This method returns an undefined value.

Parameters:



167
168
169
# File 'lib/spree/agent_tools/default_catalog.rb', line 167

def install(registry)
  TOOLS.each { |tool| registry << tool }
end