Skip to content

blocks-admin: batch /deco/invoke (and /live/invoke) ignores deco-runtime InvokePayload ({key, props, select}, aliases, saved blocks) #724

Open

Description

@aline-pereira

Summary

The batch endpoint (POST /deco/invoke, and /live/invoke via the alias from #645) only understands the framework's own shape { "<handler key>": props }. deco-runtime's contract (runtime/routes/batchInvoke.ts + utils/invoke.ts), which existing clients (mobile apps, partner integrations) were built against, is an InvokePayload:

  • a single call: { "key": "site/actions/foo.ts", "props": {…}, "select": ["a.b"] }
  • or aliases whose values are calls or nested aliases: { "alias": { "key": "…", "props": {…} } }
  • where key is a loader/action or a saved block name ("Global Config", "PLP Banners"), resolved with the saved props over the call's props, following block references.

Today dispatchInvoke treats each top-level key as a handler name, so both forms answer 200 with per-key errors:

POST /live/invoke {"key":"site/actions/apple-auth/exchange.ts","props":{…}}
→ 200 {"key":{"error":"Unknown handler: key…"},"props":{"error":"Unknown handler: props…"}}   (Fresh: the action's own 401)

POST /live/invoke {"globalConfig":{"key":"Global Config"}}
→ 200 {"globalConfig":{"error":"Unknown handler: globalConfig…"}}   (Fresh: the resolved block)

The framework's own useLoadMore (blocks/src/hooks/useLoadMore.ts) posts { key, props } to /deco/invoke, so it hits the same bug.

deco-runtime semantics worth matching

  • isInvokeFunc = has key; otherwise recurse into the object as aliases.
  • invoke resolver: registered handler → run; saved block → resolve({ ...props, ...savedProps, __resolveType }); unknown → { ...props, __resolveType: key }. A leading # in key is stripped. Function keys carry the extension (…/storeConfig.ts).
  • select: dot paths (pickPaths, mapped over arrays).
  • Result: a handler Response is returned as is (single call) / serializes to {} (inside a batch); undefined → 204; any throw fails the whole call with 500 and the error text as body.
  • CORS headers only for admin origins / localhost.

Proposal

Teach dispatchInvoke the InvokePayload shape (keeping the __resolveType batch for existing callers). Site-level workaround in deco-sites/oficina-tanstack: src/sdk/fresh-invoke.ts (QA-155 / QA-157).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions