@fluid-app/portal-sdk/widgets/worker and declare every function the widget uses. The callable exports are under Variables in the Widget Worker SDK Reference.
Declare each function in uses
uses declaration.
Choose a capability family
The public worker facade provides functions for:- portal navigation, links, fullscreen, account, store, and profile state;
- content, catalog, media, metric, and calendar reads;
- content, playlist, share, and DAM mutations;
- member access, points, todos, account updates, and MySite data.
uses declaration. For example, see getPortalProfile and navigateTo.
Handle errors and partial data
PortalFunctionError for the supported error codes.
Give a widget its own backend
A widget has no server, database or secrets of its own. When it needs its own data model or API, put that in a server app, such as a Mist app, which comes with hosting and a Postgres database. The widget then reaches the server through a portal function that your portal implements. The worker can’t call the server directly. Even with network access, a widget’s requests tofluid.app addresses, including Mist app addresses, are blocked. So the call runs in the portal, which owns the handler.
1
Define the function
Define it once, in a module that both the widget and the portal import. Inputs and outputs must be JSON values.
2
Call it from the widget
Add the function to the widget’s
uses, then call it like any other portal function.3
Implement it in the portal
In the portal project’s
src/main.tsx, pass a handler for the function to createPortal. The handler calls your server.PortalFunctionError, so render a useful unavailable state.