/sitecore-marketplace:marketplace-sdk-clientfrom Sitecore Marketplace
Documents @sitecore-marketplace-sdk/client: ClientSDK.init, query/mutate/subscribe, extension points, custom-field values, errors, and test stubs for Marketplace apps communicating with the Cloud Portal.
Ships in Sitecore Marketplace. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill is a catalog, not a contract. It documents
ClientSDK.initoptions and thequery/mutate/subscribeverb shapes. It does not document the response envelope of any specific module (xmc.*,ai.*) — those are determined by the module's generated types innode_modules. Before writingclient.query(...), open the relevant*.d.tsand cite the path inline. Mock fixtures must match the declared types.
@sitecore-marketplace-sdk/client (required for all Marketplace apps)setup-scaffold skill) chose Scaffold 2 (Client-Side) or Scaffold 3 (Full-Stack)For XMC endpoints (xmc.* keys, GraphQL, content-transfer) see the marketplace-sdk-xmc skill.
For AI skills module see the marketplace-sdk-ai skill.
For app lifecycle, auth model, architectures (including experimental server-to-server mode) see the marketplace-sdk-lifecycle skill.
For local dev loop, iframe auth debugging see the marketplace-sdk-testing-debug skill.
| Package | Purpose |
|---|---|
@sitecore-marketplace-sdk/core | PostMessage bridge, handshake, event emitter (internal) |
@sitecore-marketplace-sdk/client | High-level query/mutate/subscribe API — this skill |
@sitecore-marketplace-sdk/xmc | XMC module — see the marketplace-sdk-xmc skill |
@sitecore-marketplace-sdk/ai | AI skills module — see the marketplace-sdk-ai skill |
The client package is what you import. The core package is an internal dependency. The xmc and ai modules plug into the client via the module system and extend its type maps.
Install (always latest): npm install @sitecore-marketplace-sdk/client@latest @sitecore-marketplace-sdk/xmc@latest @sitecore-marketplace-sdk/ai@latest — pick only the modules the app actually uses.
Scope of this file: client-side iframe integration (ClientSDK.init() + base query/mutate/subscribe). Module-specific keys live in their own files.
import { ClientSDK } from '@sitecore-marketplace-sdk/client';
import { XMC } from '@sitecore-marketplace-sdk/xmc';
import { AI } from '@sitecore-marketplace-sdk/ai';
const client = await ClientSDK.init({
target: window.parent, // REQUIRED — the host window (always window.parent in iframe)
modules: [XMC, AI], // Register zero or more modules
origin?: string, // Host origin — auto-detected if omitted
timeout?: number, // Handshake timeout in ms (default: 30000)
});
target: window.parent — Marketplace apps always run in an iframe. The target is the host window.ClientSDK.init() only once. Both patterns below enforce this: the Provider via useEffect + state, the singleton via a module-level promise.postMessage — it cannot run during SSR. Always guard with 'use client' and dynamic imports.client.destroy() — Call on unmount to clean up subscriptions and message listeners.The shadcn quickstart (the setup-marketplace-client-side skill) ships a React Context pattern in components/providers/marketplace.tsx — MarketplaceProvider wraps the app at app/layout.tsx, exposes client + applicationContext via context, renders children only after both resolve, and provides useMarketplaceClient() / useAppContext() hooks for consumers.
The full template (drop-in marketplace.tsx) lives at assets/marketplace-provider.tsx. Copy it verbatim if your scaffold doesn't already ship it; extend modules: [XMC] to [XMC, AI] when the app uses AI skills.
Use a module-level singleton promise when the SDK is consumed outside the React tree (library exports, utility modules, top-level scripts). Same init contract as the Provider, different consumption shape — getSDKClient() returns the resolved client and ensures ClientSDK.init() runs only once. The dynamic-imports inside the singleton avoid the SSR crash that bites if you statically import @sitecore-marketplace-sdk/client in a server component.
Drop-in template at assets/sdk-client-singleton.ts.
Do not mix both patterns in the same app — that creates two parallel init paths and risks duplicate handshakes. Pick one based on whether the SDK is consumed primarily inside or outside React.
For apps running outside the iframe (standalone, cron jobs, microservices, server routes that need XMC/AI without portal brokering), both the XMC and AI packages offer experimental direct clients (experimental_createXMCClient, experimental_createAIClient). These bypass the postMessage bridge and call XMC/AI APIs directly with an Auth0 access token you supply.
Experimental — subject to breaking changes. Only use when the iframe Client SDK path can't satisfy the requirement. For the architecture decision and Auth0 config, see the marketplace-sdk-lifecycle skill, § 4c + § 5. For the per-package API: the marketplace-sdk-xmc skill, § 2b, and the marketplace-sdk-ai skill, § 4.
The SDK exposes three verbs: query, mutate, subscribe. Each verb is fully typed via mapped types — the key string determines parameter and response types at compile time.
const result = await client.query(key, options?);
// result: { data, error, status, isLoading, isError, isSuccess, refetch, unsubscribe? }
.data for the payload.subscribe field in QueryMap).const response = await client.mutate(key, options?);
// response is the direct return value (typed per MutationMap)
marketplace-sdk-xmc or marketplace-sdk-ai skills) for its MutationMap.const unsubscribe = client.subscribe(eventKey, {
onData: (data) => { ... },
onError?: (error) => { ... },
});
// Call unsubscribe() to stop listening
unsubscribe function on cleanup.client.logout(): Promise<void>
client.openProfile(): Promise<void>
client.navigateToExternalUrl(url: string, newTab?: boolean): Promise<void>
client.emitRouteEvent(route: string): Promise<void>
client.getValue(): Promise<any>
client.setValue(value: string, canvasReload?: boolean): Promise<void>
client.closeApp(): Promise<void>
client.destroy(): void
getValue / setValue — the Custom Field read/write surfacegetValue / setValue are the primary read/write surface for the xmc:pages:customfield extension point (§ 7 → references/extension-points.md). There is no dedicated QueryMap / MutationMap key for custom-field values — these utility methods are the contract.
Runtime shape. At runtime the value is a string — typically JSON, but the SDK contract is "opaque string". setValue enforces this (value: string). getValue currently returns Promise<any> (upstream type sloppiness; in the meantime treat the return as Promise<string> in your own code).
async function readFieldValue(client: ClientSDK): Promise<unknown> {
const raw = await client.getValue();
if (typeof raw !== "string") return raw;
try {
return JSON.parse(raw);
} catch {
return raw; // plain string — field wasn't JSON-shaped
}
}
async function writeFieldValue(
client: ClientSDK,
value: unknown,
canvasReload = true,
): Promise<void> {
const payload = typeof value === "string" ? value : JSON.stringify(value);
await client.setValue(payload, canvasReload);
}
canvasReload parameter. Passing true tells Pages to re-render the canvas after the write — use this when the field change should be visible in the preview immediately (most common). Pass false for background writes where the canvas shouldn't flicker.
Do NOT propagate any out of your read wrapper — narrow it to string / unknown at the boundary. Downstream code that types its field shape should parse into a Zod / io-ts schema or a hand-rolled type guard, not a cast.
| Key | Params | Response | Subscribable |
|---|---|---|---|
'host.user' | void | UserInfo { id, name, email } — at runtime the full Auth0 claim set (see § 8h) | no |
'host.state' | void | HostState | yes |
'host.route' | void | string | no |
'application.context' | void | ApplicationContext | no |
'site.context' | void | SiteContext | no |
'pages.context' | void | PagesContext | yes |
For the full ApplicationContext and PagesContext interface shapes, plus the canonical sitecoreContextId extraction pattern (with the cast-vs-guard discussion and the requireContextId() typed helper), see references/base-maps.md.
| Key | Params | Response |
|---|---|---|
'pages.reloadCanvas' | void | void |
'pages.context' | { itemId?, language?, itemVersion? } | void |
Navigate to a page in Pages editor:
await client.mutate('pages.context', {
params: { itemId: 'GUID-HERE' },
});
The SDK exposes two different mechanisms for receiving live updates. They are not interchangeable — picking the wrong one is a typecheck error.
| Path | Trigger | Used for | Returns |
|---|---|---|---|
| A. Subscribe-via-query | client.query(K, { subscribe: true, onSuccess }) | QueryMap keys with subscribable: yes (e.g. pages.context, host.state) | QueryResult with optional unsubscribe |
| B. Subscribe-verb | client.subscribe(K, { onData, onError? }) | SubscribeMap keys — event-only firehoses (e.g. pages.content.fieldsUpdated) | () => void teardown |
How to pick: look up the key. QueryMap (§ 4) with subscribable: yes → path A. SubscribeMap events → path B. A key never lives in both maps; the wrong call won't typecheck.
For full mechanics — both code patterns, the SubscribeMap event table, the client-side filter trap on pages.content.fieldsUpdated, and the rationale for two paths — see references/subscriptions.md.
The per-extension-point table — which queries are available, iframe viewport constraints, what the host injects — is in references/extension-points.md. Open it when picking or wiring an extension point; getValue / setValue (§ 3) is the contract for xmc:pages:customfield.
as never or as anyThe SDK is fully typed. If TypeScript complains about a query key, the cause is one of:
modules: [XMC] or modules: [AI] missing from init)Fix: import the module, pass it to init, and use exact key strings. The TypeScript compiler will validate params and response types automatically.
Single vs double .data depends on the call family and on Mode A vs Mode B — the full matrix with worked examples is in references/response-unwrap-matrix.md. Never guess the depth; look it up.
SitecoreAI may set sandbox attributes on the iframe. Check application.context → permissions.iframe.sandbox to see what's allowed. If WebGL is blocked:
<canvas> element will render but getContext('webgl') or getContext('webgl2') returns nullThe SDK uses window.parent and postMessage — it cannot run server-side.
Rules:
'use client'next/dynamic with { ssr: false } for components that call the SDKAlways clean up subscriptions:
useEffect(() => {
const unsub = client.subscribe('pages.content.layoutUpdated', {
onData: (data) => { ... },
});
return () => unsub();
}, [client]);
Failing to clean up causes memory leaks and orphaned event listeners in the PostMessage bridge.
The error-code table (code → meaning → what to do) is in references/error-codes.md. Check it when a call rejects; the codes are stable across SDK versions.
Running over HTTP or with misconfigured session/transaction cookies makes iframe login fail with no clear error. See the marketplace-sdk-testing-debug skill, § 4 for the mandatory cookie block + symptom table, § 6 for the step-by-step debugging checklist. Do not reproduce the config here — it drifts.
tenantName is ABSENT on resourceAccess[] for a full-screen app — read the host.user claimApplicationResourceContext.tenantName is declared optional (core/dist/shared-types.d.ts:77), and
for an xmc:fullscreen app the host really leaves it out. Measured 2026-09-12 (a full-screen app on a live
org): resourceAccess[0] = { resourceId, tenantId, tenantDisplayName: "<org> / <environment>", context: { live, preview } } — no tenantName. Anything that needs the SitecoreAI tenant name — the
Page Builder deep link https://pages.sitecorecloud.io/editor?organization=&tenantName=&sc_site=&sc_itemid=&sc_lang=
above all — therefore read undefined and rendered a dead control, with every gate green.
The value IS on host.user. The SDK types the response as UserInfo { id, name, email }, but at
runtime it is the Auth0 claim set: https://auth.sitecorecloud.io/claims/tenant_name (also
…/tenant_id, …/org_id, …/org_name, …/roles, sc_org_region, sub, email). Resolve in order,
and keep the source:
const TENANT_NAME_CLAIM = "https://auth.sitecorecloud.io/claims/tenant_name";
const fromAccess = appCtx.resourceAccess?.find((r) => r.tenantName)?.tenantName;
const user = (await client.query("host.user")).data as Record<string, unknown>;
const tenantName = fromAccess ?? (user?.[TENANT_NAME_CLAIM] as string | undefined) ?? null;
Two consequences. (1) Do not build a half-address — a link with an empty tenantName opens Page
Builder on nothing, which reads as the app being broken; return null and say which part is missing.
(2) pages.context (the mutation) does not navigate from a full-screen app; the deep link in a
new tab is the working shape.
Unit-testing harness code that calls client.query / mutate / subscribe / destroy requires a stubbed ClientSDK. The SDK's call signatures are overloaded and generic, so naked vi.fn() will fail tsc --noEmit with TS2348: Value of type 'Mock<Procedure | Constructable>' is not callable. — always pass the call signature as a generic: vi.fn<ClientSDK['query']>().
For the full pattern — typed stubs per verb, default return values, call-shape assertions for query/mutate, and subscribe-lifecycle assertions — see references/vitest-stubs.md.
During architecture: When the architecture involves the Marketplace Client SDK, document the extension-point choice (§ 7 → references/extension-points.md) and whether modules (XMC, AI) are needed in the init. Record the handshake constraint (iframe-only) as an ADR if the app scope includes anything non-iframe.
During implementation planning: Specify (a) the singleton init pattern (§ 2), (b) which modules to register, (c) which extension points the app targets. All dev and validation runs against a registered test app in Cloud Portal — there is no mock-client path. For module-specific keys and params, defer to the marketplace-sdk-xmc or marketplace-sdk-ai skills.
During testing: Verify test scenarios for SDK error states (§ 8f: timeout, not connected, token error, handshake failed). Add a validation spike for iframe constraints if the app uses canvas/WebGL (§ 8c).
During implementation: Use the exact key strings documented here and in the module-specific files. Do not cast as never or as any — if TypeScript errors on a key, check that the right module is in modules: [...]. Unwrap results with .data. Always clean up subscriptions.
assets/marketplace-provider.tsx (opens in a new tab)assets/sdk-client-singleton.ts (opens in a new tab)references/base-maps.md (opens in a new tab)references/error-codes.md (opens in a new tab)references/extension-points.md (opens in a new tab)references/response-unwrap-matrix.md (opens in a new tab)references/subscriptions.md (opens in a new tab)references/vitest-stubs.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub chris1415/sitecore-skills-pocs --plugin sitecore-marketplace7 skills in this plugin
/marketplace-sdk-aiAPI reference for @sitecore-marketplace-sdk/ai: module vs experimental client, generateBrandReview, payload traps, file inputs. Load when a Marketplace app calls AI skills such as brand review or content compliance./marketplace-sdk-extension-routesPost-scaffold step for a Marketplace app: pick Cloud Portal extension points, generate a Next.js App Router route for each, and produce the App Studio values. Use right after scaffolding or when adding an extension point./marketplace-sdk-host-frame-testingVisual testing of a Marketplace app inside its real host (Cloud Portal, Pages, Dashboard): find the app iframe, clip it, compare against the design. Use for visual or regression tests; a standalone localhost render is not enough./marketplace-sdk-lifecycleLifecycle of a Sitecore Marketplace app: custom vs public, Cloud Portal registration, client-side vs full-stack vs server-to-server architecture, Auth0, hosting, Blok, submission. Load before any code when planning a Marketplace app./marketplace-sdk-testing-debugLocal dev loop for a Marketplace app: HTTPS with mkcert, test-app registration, Chrome Local Network Access, context ids, iframe sandbox limits, handshake and cookie debugging. Load during development and QA./marketplace-sdk-xmcAPI reference for @sitecore-marketplace-sdk/xmc: SitecoreAI endpoints (sites, pages, agent, authoring, preview, live, search), client modes, context id rules, response unwrapping. Load when a Marketplace app reads or writes SitecoreAI data.