@usemogul/connect-common
v0.4.0
Published
Shared schemas for the Mogul Connect embedded component: message types, event-name constants, and validators shared by the connect-js loader and the Mogul application.
Readme
@usemogul/connect-common
Shared schemas for the Mogul Connect embedded component. This is the single source of truth for
the postMessage contract between the Mogul application and the partner-side
loader (@usemogul/connect-js). Both sides depend on this package so the message
shapes can't drift.
Zero runtime dependencies. Ships ESM + CJS + TypeScript types.
Exports
FrameMessage/ParentMessage— the message unions (mogul:initcarries the sessiontokenand the partner's publicclientId)ConnectedIdentity— identity payload carried onmogul:successFRAME_EVENT/PARENT_EVENT— event-name constantsCONNECT_ERROR_CODE/ConnectErrorCode— themogul:errorcodes (token_error,invalid_target,client_mismatch,identity_unavailable,origin_not_allowed,verification_failed).mogul:error.codestays typed asstringon the wire, so handle unknown codes.parseFrameMessage(data)— for the loader: validates untrustedpostMessagedata into a knownFrameMessage, ornull.parseParentMessage(data)— for the frame: validates untrustedpostMessagedata into a knownParentMessage, ornull.
Both parsers rebuild the message from the checked fields, so unknown keys are dropped. Check the message origin before calling them.
import { parseFrameMessage, type ParentMessage } from '@usemogul/connect-common'Consumed by @usemogul/connect-js (bundled at build time) and by the Mogul application.
