Vendure plugin (Admin CRUD + Storefront API) with an embedded Hyperse Dashboard UI for managing view widgets and their placements on Collection, Product, and the storefront Home page.
Features
- Define widget metadata
widgetGroupName to classify widgets
widgetViewType to choose how the storefront should render it
widgetDesc / widgetPreview for admin UX
- per-language
widgetViewConfig as a JSON object (stored as JSON)
- Manage placements
- Map a widget to an entity via
ViewWidgetEntity (Collection / Product / synthetic Home, plus custom entity types via strategies)
- Control priority via
displayOrder (higher value = higher priority)
- Admin GraphQL API for CRUD
- Create / update / delete widgets and placements
- Query widgets and placements with list options
- Discover supported placement entity types
- Admin query
viewWidgetSupportedEntityNames
- Storefront GraphQL API for rendering
viewWidgets(entities: ...) container query
- Returns widgets as strategy-defined
QueryViewWidget fields (e.g. collectionViewWidgets, productViewWidgets, homeViewWidgets)
- Returns
widgetViewConfig resolved as a JSON object
- Only resolves the
QueryViewWidget fields actually selected by the client (avoids unnecessary queries)
Requirements
- Node.js
>= 20
@vendure/core ^3.5.x (peer dependency via this package)
Installation
yarn add @hyperse-hub/hps-plugin-view-widget
Register the plugin in your Vendure config:
import { HpsPluginViewWidget } from '@hyperse-hub/hps-plugin-view-widget';
export const config = {
plugins: [
HpsPluginViewWidget.init(),
],
};
Admin UI (Hyperse Dashboard)
This package ships an admin UI extension page:
- Menu route:
/view-widget
- Permission:
Authenticated
- Tabs:
View Widgets: list/create/edit/delete ViewWidget
View Widget Entities: list/create/edit/delete ViewWidgetEntity (placements)
- Create inputs (channel-scoped):
channelId (admin channel; editable only in create mode)
languageCode
widgetGroupName (required)
widgetViewType (required)
widgetDesc (optional)
widgetPreview (optional)
widgetViewConfigJson (required; must be a JSON object)
- Edit mode:
channelId and languageCode are shown as read-only
- Create inputs:
channelId (admin channel; editable only in create mode)
viewWidgetId (select from existing widgets)
entityId (Collection/Product id, or synthetic keys like Home=home)
entityName (must be one of viewWidgetSupportedEntityNames)
displayOrder (integer, min: 0)
- Edit mode:
channelId is shown as read-only
GraphQL APIs
Admin API (CRUD + list)
The plugin extends Vendure's GraphQL schema with:
Notes
ViewWidgetEntity.entityId is a String (not ID) so placement keys like home are stored without Vendure ID encoding.
Queries
viewWidget(id: ID!): ViewWidget
viewWidgets(options: ViewWidgetListOptions): ViewWidgetList!
viewWidgetSupportedEntityNames: [String!]!
Mutations
createViewWidget(input: CreateViewWidgetInput!): ViewWidget!
updateViewWidget(input: UpdateViewWidgetInput!): ViewWidget!
deleteViewWidget(id: ID!): DeletionResponse!
createViewWidgetEntity(input: CreateViewWidgetEntityInput!): ViewWidgetEntity!
updateViewWidgetEntity(input: UpdateViewWidgetEntityInput!): ViewWidgetEntity!
deleteViewWidgetEntity(id: ID!): DeletionResponse!
Permissions follow Vendure core Catalog permissions:
- Read:
Permission.ReadCatalog
- Create:
Permission.CreateCatalog
- Update:
Permission.UpdateCatalog
- Delete:
Permission.DeleteCatalog
Shop API (storefront rendering)
Queries
viewWidgets(entities: [ViewWidgetEntityQueryInput!]!): QueryViewWidget!
ViewWidgetEntityQueryInput
entityName: String! (only registered strategies are allowed)
id?: String (not GraphQL ID — avoids Vendure decoding T_2 → internal 2, which would not match ViewWidgetEntity.entityId stored as the public id string)
slug?: String
QueryViewWidget exposes strategy-defined fields:
collectionViewWidgets: [ViewWidget!]!
productViewWidgets: [ViewWidget!]!
homeViewWidgets: [ViewWidget!]!
- plus any custom fields contributed by
entityQueryStrategies
QueryViewWidget.keys: [ViewWidgetEntityQueryKey!]! echoes the requested entity keys
Behavior:
- Returns widgets for the matching entity (active channel from
RequestContext)
- Ordering: sorted by
displayOrder descending (higher priority first)
widgetViewConfig is returned as a JSON object
- Prefer selecting only the
QueryViewWidget fields you need (the server may still evaluate other strategy fields as a fallback in some GraphQL execution setups)
Special placement: Home page (entityName: "Home")
The Home page is modeled as a synthetic placement target (not a Vendure entity):
- Admin placement (
ViewWidgetEntity):
entityName must be Home
entityId must be the fixed string home (this is the stable placement key)
- Shop query (
viewWidgets):
- Select
homeViewWidgets
- Pass
entities: [{ entityName: "Home", id: "home" }]
slug is ignored for Home
Example (shop) — Home page:
query HomeWidgets($entities: [ViewWidgetEntityQueryInput!]!) {
viewWidgets(entities: $entities) {
homeViewWidgets {
id
widgetGroupName
widgetViewType
widgetViewConfig
}
}
}
Variables:
{ "entities": [{ "entityName": "Home", "id": "home" }] }
Example (shop) — Collection page:
query CollectionWidgets($entities: [ViewWidgetEntityQueryInput!]!) {
viewWidgets(entities: $entities) {
keys {
entityName
id
slug
}
collectionViewWidgets {
id
widgetGroupName
widgetViewType
widgetViewConfig
}
}
}
Plugin options: bootstrap seeds
Use HpsPluginViewWidget.init(options) to seed default widgets and placements on server bootstrap (idempotent upsert / skip).
Options
defaultViewWidgets?: CreateViewWidgetInput[]
- Idempotent match per channel by
widgetGroupName + widgetViewType
- Each widget includes
translations[] with:
languageCode
widgetViewConfig (JSON object)
defaultViewWidgetEntities?: ViewWidgetEntitySeedInput[]
- Placement seeds referencing widgets from
defaultViewWidgets by index:
viewWidgetSeedIndex (0-based index into defaultViewWidgets)
- Each seed includes:
entityId
entityName (must be supported by strategies; default: Collection / Product / Home)
displayOrder
defaultSeedsChannelId?: ID
- When set, seeds run against this channel; otherwise the default channel is used.
entityQueryStrategies?: ViewWidgetEntityQueryStrategy[]
- Extends the Shop API
QueryViewWidget type with additional fields, and controls which entityName values are allowed.
- Default strategies for
Collection, Product, and Home are always included.
Seed example
import { LanguageCode } from '@vendure/core';
import { HpsPluginViewWidget } from '@hyperse-hub/hps-plugin-view-widget';
export const config = {
plugins: [
HpsPluginViewWidget.init({
defaultViewWidgets: [
{
widgetGroupName: 'CollectionTop',
widgetViewType: 'hero-banner',
widgetDesc: 'Example hero strip for category pages (dev)',
translations: [
{
languageCode: LanguageCode.en,
widgetViewConfig: {
variant: 'example',
slides: [{ title: 'Welcome', subtitle: 'Dev seed' }],
},
},
],
},
],
defaultViewWidgetEntities: [
{
displayOrder: 0,
entityId: '1',
entityName: 'Collection',
viewWidgetSeedIndex: 0,
},
],
}),
],
};
The Shop API viewWidgets() query returns a QueryViewWidget object whose fields are contributed by entityQueryStrategies.
Each strategy defines:
- a
queryFieldName (the QueryViewWidget field name, must be a valid GraphQL field name)
- an
entityName (stored in ViewWidgetEntity.entityName, also used to validate inputs/seeds)
- a
resolveEntityId() implementation (how id / slug resolves to a target entityId)
Example (add a blogPostViewWidgets field for entityName: "BlogPost"):
import type { ID, Injector, RequestContext } from '@vendure/core';
import { HpsPluginViewWidget } from '@hyperse-hub/hps-plugin-view-widget';
import type {
ViewWidgetEntityQueryArgs,
ViewWidgetEntityQueryStrategy,
} from '@hyperse-hub/hps-plugin-view-widget/dist/strategies/view-widget-entity-query.strategy.js';
class BlogPostViewWidgetsStrategy implements ViewWidgetEntityQueryStrategy {
readonly key = 'blogpost-view-widgets';
readonly queryFieldName = 'blogPostViewWidgets';
readonly entityName = 'BlogPost';
async init(_injector: Injector) {
}
async resolveEntityId(
_ctx: RequestContext,
args: ViewWidgetEntityQueryArgs
): Promise<ID | null> {
return (args.id ?? null) as any;
}
}
export const config = {
plugins: [
HpsPluginViewWidget.init({
entityQueryStrategies: [new BlogPostViewWidgetsStrategy()],
}),
],
};
Environment variables (UI / local dev)
Local dev uses an additional variable for the dev-server GraphQL mocking/bypass:
HPS_MOCK_BYPASS_VIEW_WIDGET_PLUGIN_API: bypass URL for this plugin in the dev server
Scripts
See this package's package.json:
yarn serve: run local dev server
yarn build: compile the package
yarn test: run unit/e2e tests
License
MIT — see LICENSE in the monorepo root.