Using the proxy execution context
You can inspect the execution result of each proxy in your Next.js middleware by passing a ProxiesContext map to defineProxy().exec(). Use the context to log proxy outcomes, debug middleware behaviour, or make downstream decisions based on proxy execution results.
The proxiesContext parameter is optional. Existing middleware implementations that do not pass a context map continue to work unchanged.
The proxy execution context is only available in Content SDK 2.2 or later.
Proxy execution context types
A new types.ts file defines the core data structures for the context feature:
|
Type |
Structure |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
A union type of |
Available result types per proxy
The following result types are available per proxy:
-
SuccessfulBotTrackingProxyExecution— includesbotDetected -
SuccessfulLocaleProxyExecution— includeslocaleandrewrote -
SuccessfulMultisiteProxyExecution— includessiteName,rewritePath,isSitecorePreview -
SuccessfulPersonalizeProxyExecution— includesidentifiedVariantIdsandrewritePath -
SuccessfulPreviewProxyExecution— includespageDataReceived -
SuccessfulRedirectsProxyExecution— includesrequestUrl,redirectUrl,redirectStatus,isExternal
All types are exported from @sitecore-content-sdk/nextjs.
Proxy implementation changes
Proxy implementations must now:
-
Expose a
name: stringproperty, which is used as the key in the context map. -
Accept an optional
proxiesContext?: ProxiesContextparameter in thehandle()method.
The defineProxy().exec() function forwards the context to each proxy in the execution chain.
After execution, each proxy writes its result into the shared ProxiesContext map using its name as the key. Successful executions use a proxy-specific success type. Failed executions use the shared FailedProxyExecution type.
To check execution results, use the generic isSuccessfulProxyExecution type guard to determine whether a proxy execution result is successful. If the result is successful, you can safely access proxy-specific fields. Otherwise, inspect the error field.
Using the proxy execution context
The following example shows how to pass a context map to the proxy chain, retrieve a proxy execution result using its name, safely narrow the result using a type guard, and handle both successful and failed executions.