import type { Brand, BrandDetails } from './brand'; import type { Entity, EntityDetails } from './entity'; import type { MerchantDetails } from './merchant'; import type { SegmentUser } from './user'; import type { ACCOUNT_SECTION } from './account'; export type AccountWidgetChangeEvent = { type: 'user:updated'; data: SegmentUser; } | { type: 'entity:updated'; data: Entity | EntityDetails; } | { type: 'brand:updated'; data: Brand | BrandDetails; } | { type: 'wallet:updated'; data: MerchantDetails['wallet']; }; /** Per-section widget config. `isAvailable`/`isEditable`/`isCreatable` are honored when set. */ export type AccountWidgetSectionPayload = { isAvailable?: boolean; isEditable?: boolean; isCreatable?: boolean; }; export type AccountWidgetSectionsPayload = { [ACCOUNT_SECTION.BRAND]?: AccountWidgetSectionPayload; [ACCOUNT_SECTION.ENTITY]?: AccountWidgetSectionPayload; [ACCOUNT_SECTION.USERS]?: AccountWidgetSectionPayload; [ACCOUNT_SECTION.USER_ROLES]?: AccountWidgetSectionPayload; [ACCOUNT_SECTION.APP_SETTINGS]?: Partial>; }; /** Pre-selected account records the widget operates on (the "validation fields"). */ export type AccountWidgetSelection = { segmentId?: string; boardId?: string; walletId?: string; bankAccountId?: string; entityId?: string; entityCountry?: string; brandId?: string; userId?: string; }; /** * Account Widget state/config owned by the Account App (`payload.accountWidget`). * Selections are seeded from the opener (internal app or external app) and live * under `selection`; `AccountWidgetPayload` carries no flat selection mirrors. */ export type AccountWidgetPayload = { initialSection?: ACCOUNT_SECTION; sections?: AccountWidgetSectionsPayload; /** Identifies the external application that opened the Account App for the widget. */ context?: AccountWidgetContext; selection: AccountWidgetSelection; }; /** How the Account App was reached. */ export type AccountWidgetSource = 'internal' | 'external'; /** * Contract the opening application passes when it opens the Account App for * the Account Widget. Carries the *external* application/service/window that * consumes the widget (e.g. the Business app) — not the Account app's own * codes. `windowId` lets the opener tell its own windows apart, since it can * have several open at once for the same app/service. Internal mode has no * opener, so the Account App backfills `appCode`/`serviceCode` and leaves * `windowId` empty. */ export type AccountWidgetContext = { windowId?: string; appCode?: string; serviceCode?: string; applicationId?: string; serviceId?: string; }; /** * Cross-MFE data sync parameters published by the Account App after a widget * mutation. Consumers (e.g. a board list in the opener application) use * `context`/`selections` to scope and match the record that changed. */ export type AccountWidgetDataChangedParams = { /** The external application/service the widget runs under. */ context: AccountWidgetContext; /** The selected account records the mutation applies to. */ selections: AccountWidgetSelection; /** The change events emitted by the widget (usually a single event). */ changes: AccountWidgetChangeEvent[]; };