@getflip/bridge

中文文档
0.11.91发布于 2026/11/10SEE LICENSE IN LICENSE.mdTypeScriptESM + CJS构建来源已验证近 30 天下载 1万

Flip JavaScript Bridge for external integrations.

原始使用文档
文档目录21 节
  1. Installation
  2. Usage
  3. Methods
  4. Internationalization
  5. Navigation
  6. Theming
  7. Dialogs
  8. Modals
  9. Toasts
  10. Downloads
  11. Events
  12. NAVIGATION_END
  13. LANG_CHANGE
  14. PRIMARY_ACTION_CLICK
  15. SECONDARY_ACTION_CLICK
  16. THEME_CHANGE
  17. TITLE_CHANGE
  18. Error Handling
  19. FORBIDDEN_ORIGIN
  20. INVALID_REQUEST
  21. Development

Flip Bridge

The Flip Bridge handles communication between your embeddable apps and the Flip App or Flip Admin Console.

Contents

Installation

npm install --save @getflip/bridge
# or
yarn add @getflip/bridge

Usage

The library exposes a set of functions and listeners you can use to communicate with the Flip App and Flip Admin Console (host app for short).

Before using the provided functions, you have to call the initFlipBridge function to set up the Flip Bridge.

import { initFlipBridge } from "@getflip/bridge";

initFlipBridge({
  debug: true,
  hostAppOrigin: "http://localhost:4200", // has to be the origin of the targeted host app
});

Methods

Internationalization

getAvailableLangs

Get all available languages of the host app.

Returns Promise<string[]>

Example

import { getAvailableLangs } from "@getflip/bridge";

const availableLanguages = await getAvailableLangs(); // e.g. ['de', 'en', 'fr', …]

getLang

Get the current language of the host app.

Returns Promise<string>

Example

import { getLang } from "@getflip/bridge";

const currentLanguage = await getLang(); // e.g. 'en'

Navigation

navigate

Navigate to a specific route.

Param string

Returns Promise<boolean>

Example

import { navigate } from "@getflip/bridge";

await navigate("/my-app/settings");

close

Asks the host app to close the current integration (for example the same action as the host’s back or close control). Use this when you provide your own header and want a custom back or close button instead of relying on the host.

Returns Promise<boolean>

Example

import { close } from "@getflip/bridge";

await close();

Theming

getTheme

Get the current theme.

Returns

Promise<{
  activeTheme: "light" | "dark";
  preferredTheme: "light" | "dark" | undefined;
}>

Example

import { getTheme } from "@getflip/bridge";

const theme = await getTheme();

setTheme

Set the theme. Pass undefined to reset to the user's system theme.

Param "light" | "dark" | undefined

Returns Promise<"light" | "dark" | undefined>

Example

import { setTheme } from "@getflip/bridge";

const newTheme = await setTheme("dark");

Dialogs

createDialog

Creates a modal dialog rendered by the host app.

Param

{
  hideLabel?: boolean;
  id: string;
  intent?: 'primary' | 'critical';
  label: string;
  text: string;
  primaryAction?: {
    label: string;
  };
  secondaryAction?: {
    label: string;
  };
}

Returns

Promise<boolean>

Example

import { createDialog } from "@getflip/bridge";

const dialog = await createDialog({
  id: "my-dialog",
  label: "My Dialog",
  text: "Lorem ipsum",
  primaryAction: {
    label: "Close",
  },
});

openDialog

Opens a dialog.

Param

{
  id: string; // the dialog id
}

Returns Promise<boolean>

Example

import { createDialog, openDialog } from "@getflip/bridge";

await createDialog({
  id: "my-dialog",
  label: "My Dialog",
  text: "Lorem ipsum",
});

await openDialog({ id: "my-dialog" });

closeDialog

Closes a dialog.

Param

{
  id: string; // the dialog id
}

Returns Promise<boolean>

Example

import { closeDialog } from "@getflip/bridge";

await closeDialog({ id: "my-dialog" });

destroyDialog

Destroys a dialog, removing it from the DOM.

Param

{
  id: string; // the dialog id
}

Returns Promise<boolean>

Example

import { destroyDialog } from "@getflip/bridge";

await destroyDialog({ id: "my-dialog" });

Modals

createModal

Creates a modal rendered by the host app. The modal will show the passed URL as an iFrame.

Param

{
  id: string;
  label: string;
  primaryAction?: {
    label: string;
  };
  secondaryAction?: {
    label: string;
  };
  url: string;
}

Returns

Promise<boolean>

Example

import { createModal } from "@getflip/bridge";

const modal = await createModal({
  id: "my-moadl",
  label: "My Modal",
  primaryAction: {
    label: "Close",
  },
  url: "https://google.com",
});

openModal

Opens a modal.

Param

{
  id: string; // the modal id
}

Returns Promise<boolean>

Example

import { createModal, openModal } from "@getflip/bridge";

await createModal({
  id: "my-modal",
  label: "My Modal",
  url: "https://google.com",
});

await openModal({ id: "my-modal" });

closeModal

Closes a modal.

Param

{
  id: string; // the modal id
}

Returns Promise<boolean>

Example

import { closeModal } from "@getflip/bridge";

await closeModal({ id: "my-modal" });

destroyModal

Destroys a modal, removing it from the DOM.

Param

{
  id: string; // the modal id
}

Returns Promise<boolean>

Example

import { destroyModal } from "@getflip/bridge";

await destroyModal({ id: "my-modal" });

Toasts

showToast

Shows a toast by the host app.

Param

{
  text: string;
  duration?: number;
  icon?: string;
  intent?: SwirlToastIntent;
}

Returns Promise<boolean>

Example

import { showToast } from "@getflip/bridge";

await showToast({
  text: "My toast",
  duration: 5000,
  icon: "icon",
  intent: "success",
});

Downloads

download

Downloads a file via the host app.

Param

{
  fileName: string; // filename
  fileType: string; // file type
  url?: string; // optional file URL
  dataUrl?: string; // optional base64 encoded file data
}

Returns Promise<boolean>

Example

import { download } from "@getflip/bridge";

await download({
  fileName: "my-file.txt",
  fileType: "text/plain",
  url: "https://example.com/my-file.txt",
});

Events

Use the subscribe functions to subscribe to events.

import { subscribe, BridgeEventType } from "@getflip/bridge";

const unsubscribe = await subscribe(BridgeEventType.THEME_CHANGE, (event) => {
  console.log(event.data);
});

// …

await unsubscribe();

NAVIGATION_END

Fires when the application successfully navigated to a different route.

Event

{
  data: {
    route: string; // e.g. '/notifications'
  }
  type: BridgeEventType.NAVIGATION_END;
}

LANG_CHANGE

Fires when the user selected language changes.

Event

{
  data: string; // e.g. 'en'
  type: BridgeEventType.LANG_CHANGE;
}

PRIMARY_ACTION_CLICK

Fires when the primary action button of a dialog or modal is clicked.

Event

{
  data: {
    parentId: string; // id of the action's dialog or modal
  }
  type: BridgeEventType.PRIMARY_ACTION_CLICK;
}

SECONDARY_ACTION_CLICK

Fires when the secondary action button of a dialog or modal is clicked.

Event

{
  data: {
    parentId: string; // id of the action's dialog or modal
  }
  type: BridgeEventType.SECONDARY_ACTION_CLICK;
}

THEME_CHANGE

Fires when the user theme changes.

Event

{
  data: {
    activeTheme: "light" | "dark";
    preferredTheme: "light" | "dark" | undefined;
  }
  type: BridgeEventType.THEME_CHANGE;
}

TITLE_CHANGE

Fires when the HTML title tag value of the app changes.

Event

{
  data: {
    title: string;
  }
  type: BridgeEventType.TITLE_CHANGE;
}

Error Handling

All provided functions return promises that throw an error if the execution failed. The errors have the following format.

{
  code: BridgeErrorCode; // e.g. 'FORBIDDEN_ORIGIN'
}

FORBIDDEN_ORIGIN

Thrown when the origin of the requesting app is not allowed by the host app. Please check if your app is correctly registered in the Flip Partner Dashboard and the hostAppOrigin option is set (see Usage).

INVALID_REQUEST

The host app identified the request as invalid. This typically occurs when the provided parameters are invalid.

Development

Start the compiler in watch mode for local development:

yarn dev

Production builds and releases are managed via our Github workflows. Make sure to create a Changeset using yarn changeset if you want to trigger a new release.

版本与发布记录

@getflip/bridge 共发布 949 个版本,首次发布于 2022/12/01;过去 12 个月发布了 275 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.11.91latest2026/11/105 天前
0.11.902026/11/0610 天前
0.11.892026/11/0510 天前
0.11.89-beta-20261105095642beta2026/11/0510 天前
0.11.882026/11/0412 天前
0.11.872026/10/2323 天前

其他发布通道:new-shell → 0.0.0-new-shell-20231130132058,beta → 0.11.89-beta-20261105095642。

关于 @getflip/bridge 的常见问题

@getflip/bridge 是什么?

Flip JavaScript Bridge for external integrations.

如何安装 @getflip/bridge?

在项目目录运行 npm install @getflip/bridge,或使用 pnpm add / yarn add / bun add。

@getflip/bridge 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@getflip/bridge 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@getflip/bridge 可以商用吗?

@getflip/bridge 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@getflip/bridge 的下载量有多少?

根据 npm 官方下载统计,@getflip/bridge 在 2026/10/17 – 2026/11/15 这 30 天内被下载 10,233 次,日均约 341 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@getflip/bridge 还在维护吗?

最新版本 0.11.91 发布于 2026/11/10(5 天前);至今共发布 949 个版本,其中过去 12 个月发布了 275 个;首次发布于 2022/12/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。