Repository navigation
feat(sdk/invoke): export default invoke singleton + add to barrel - #103
Merged
Merged
Conversation
`createAppInvoke()` was already in `src/sdk/invoke.ts` but only reachable
via the `@decocms/start/sdk/invoke` deep import — no default singleton,
no barrel export. Sites end up writing the same 3-line shim
(`export const invoke = createAppInvoke()`) in their own `~/runtime.ts`,
which is exactly the kind of duplicated boilerplate the migration plan
flags as movable into the framework.
This PR:
- Adds `export const invoke = createAppInvoke()` next to the factory.
Default basePath stays `/deco/invoke`. Sites that need a custom
basePath or typed handlers keep using `createAppInvoke<T>()` directly.
- Exposes `createAppInvoke`, `invoke`, and `NestedFromFlat` from the
`./sdk` barrel so they're discoverable via `@decocms/start/sdk` too,
matching the discoverability of `createInvokeProxy` / `batchInvoke`.
After release, sites with a `~/runtime.ts` shim can either:
1. Replace the file with `export { invoke } from "@decocms/start/sdk/invoke";`
2. Or just import `invoke` directly from the framework at call sites
and delete `~/runtime.ts` entirely.
bagaggio-tanstack will be the first consumer; casaevideo (the production
reference) is left untouched.
Tested: 9 unit tests covering nested key collection, .ts fallback,
"handler not found" failure, error body extraction, default empty body,
thenable trap, symbol guard, custom basePath, and the singleton's
binding to /deco/invoke. Full suite still 98/98.
Made-with: Cursor
|
🎉 This PR is included in version 2.4.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
vibe-dex
added a commit
that referenced
this pull request
May 1, 2026
…checklist (#109) Two stale areas in the deco-to-tanstack-migration skill, plus one brand-new reference distilling battle-tested cleanup patterns. ## Changes ### `templates/vite-config.md` — drop ~80 lines of stub duplication The old template inlined the entire `deco-server-only-stubs` plugin (react-dom/server, node:async_hooks, node:stream, node:stream/web, tanstack-head-scripts) — ~60 lines that exactly mirror what `@decocms/start/vite`'s `decoVitePlugin()` already does. The new template uses `decoVitePlugin()` and adds the production-grade boilerplate that real sites actually need (and that the old version omitted): VTEX dev proxy, CSP frame-ancestors header, build sourcemap, PLUGIN_WARNING filter, react-compiler config, `pure: ["console.log"]`, and the full `dedupe` list including `@decocms/start` + `@decocms/apps`. ### `references/vite-config/README.md` — fix "minimal" config that was broken The "post-migration minimal config" was missing `decoVitePlugin()` entirely. Without it, the client bundle crashes on transitively imported server modules. Added the plugin + the minimum dedupe list, and cross-referenced the full template. ### `references/post-migration-cleanup.md` — NEW Dedicated reference distilling the cleanup work that surfaces on every real migration: 1. Detect + delete unused `src/lib/*` shims (with a copy-paste detection script). Real-world data: baggagio-tanstack had 11 generated shims and 0 actual users; casaevideo had 11 generated and 1 used. 2. Drop the `site-manual-chunks` and `deco-stub-meta-gen` inline plugins that are now framework-provided in `@decocms/start >= 2.5.0`. 3. Drop the `runtime.ts` `invoke` shim — `@decocms/start/sdk` exports both `invoke` (singleton) and `createAppInvoke` (typed factory). 4. Drop site-local `withSiteGlobals` workaround — framework helper is now opt-in and tested. 5. Verify VTEX util imports point direct at `@decocms/apps/vtex/...`, not at dead `~/lib/vtex-*` shims (the migration script's stale `phase-cleanup.rewriteVtexUtilImports` was silently regressing them). 6. Search for orphan `TODO: move into framework` comments and either migrate, file an issue, or delete. Plus a verification checklist. ## Why now Validated in this session against three reference sites (casaevideo-storefront, baggagio-tanstack, casaevideo). Each cleanup step has a corresponding shipped or in-flight PR (#103/#106/#107/#108 on framework, #5/#6/#7 on baggagio-tanstack), so the checklist isn't speculative. ## Scope discipline This PR only edits skill content; no source/runtime changes. Both `.agents/skills/` and `.cursor/skills/` copies stay in sync. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes plan item 1.1 (framework side).
createAppInvoke()already existed insrc/sdk/invoke.tsbut was only reachable via deep import, with no default singleton. Every migrated site ends up writing the same 3-line shim — exactly the boilerplate the migration plan flags as movable.This PR:
export const invoke = createAppInvoke()next to the factory. Default basePath stays/deco/invoke. Custom basePath / typed handlers still usecreateAppInvoke<T>().createAppInvoke,invoke, andNestedFromFlatfrom the./sdkbarrel so they're discoverable via@decocms/start/sdk.Site impact (after release)
Before:
After:
bagaggio-tanstack will be the first consumer (2 call sites + 46 LOC delete). Casa&Video (the production reference) is left untouched.
Test plan
src/sdk/invoke.test.ts:vtex.actions.checkout.addItemsToCart→/deco/invoke/vtex/actions/checkout/addItemsToCart).tssuffix fallback when first key returns 404{}body when called with no propsthen/catch/finallytrap (avoid being treated as a thenable)Symbol.iteratoretc.)basePathinvokesingleton hits/deco/invokebiome checkcleancreateAppInvokewas already in the same file with this signatureNotes for reviewers
fetchonly fires on actual call. SSR-safe./deco/invokematches what every existing site uses; sites overriding the path were already callingcreateAppInvoke()themselves and aren't affected.NestedFromFlatbecause typed sites import it forcreateAppInvoke<Handlers>()calls.Made with Cursor