@moudrey/fluxa-frames
v0.0.1
Published
Fluxa plugin for cross-frame transport.
Maintainers
Readme
Fluxa Frames Plugin
Plugin for Fluxa Core that adds cross-frame communication via postMessage.
Installation
npm install @moudrey/fluxa-frames @moudrey/fluxa-core
# or
pnpm add @moudrey/fluxa-frames @moudrey/fluxa-core
# or
yarn add @moudrey/fluxa-frames @moudrey/fluxa-coreUsage
import { Fluxa } from "@moudrey/fluxa-core";
import { framesPlugin } from "@moudrey/fluxa-frames";
type Events = {
"widget:ready": { id: string };
};
const bus = new Fluxa<Events>({
plugins: [
framesPlugin({
channel: "my-app",
allowedOrigins: ["https://example.com"],
targets: "parent",
direction: "both",
maxHops: 8,
targetOrigin: "https://example.com",
}),
],
});
bus.on("widget:ready", (payload) => {
console.log("Ready", payload.id);
});API
framesPlugin(options)options.channel?: string- channel identifier (defaultfluxa)options.allowedOrigins?: string[]- allowed origins for incoming messagesoptions.targets?: "parent" | "top" | "opener" | "children" | "all" | Window[]- where to post outbound messages (defaultparent)options.direction?: "in" | "out" | "both"- inbound/outbound toggle (defaultboth)options.filter?: (event, meta) => boolean- allowlist for inbound/outboundoptions.maxHops?: number- maxmeta.pathlength (default8)options.targetOrigin?: string | (target) => string-postMessagetargetOrigin (default*)options.serialize?: (envelope) => unknown- outbound serializeroptions.deserialize?: (data) => envelope | null- inbound parser
Architecture Notes
- The plugin is a fully separate feature and is only enabled via
pluginsinnew Fluxa(...). - If
allowedOriginsis not provided, messages from any origin are accepted. In production, always restrict this. - The transport uses
meta.pathto prevent loops;maxHopsprovides a hard stop.
Development
npm run build
npm run typecheck
npm run testLicense
MIT (c) Jan Moudry
