0.6.15 • Published 23 days ago

@getflip/bridge v0.6.15

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
23 days ago

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");

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<{
  id: string;
  open: () => Promise<boolean>;
  close: () => Promise<boolean>;
  destroy: () => Promise<boolean>;
}>

Example

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

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

await dialog.open();

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<{
  id: string;
  open: () => Promise<boolean>;
  close: () => Promise<boolean>;
  destroy: () => 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",
});

await modal.open();

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",
});

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;
}

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.

0.6.14

24 days ago

0.6.13

25 days ago

0.6.15

23 days ago

0.6.10

1 month ago

0.6.12

30 days ago

0.6.11

1 month ago

0.6.9

1 month ago

0.6.8

1 month ago

0.6.7

2 months ago

0.6.6

2 months ago

0.6.5

2 months ago

0.6.4

2 months ago

0.6.3

2 months ago

0.6.2

2 months ago

0.6.1

2 months ago

0.6.0

2 months ago

0.5.72

2 months ago

0.5.71

2 months ago

0.5.70

2 months ago

0.5.69

2 months ago

0.5.67

2 months ago

0.5.68

2 months ago

0.5.65

3 months ago

0.5.66

3 months ago

0.5.63

3 months ago

0.5.64

3 months ago

0.5.61

3 months ago

0.5.62

3 months ago

0.5.60

3 months ago

0.5.11

6 months ago

0.5.18

6 months ago

0.5.19

6 months ago

0.5.16

6 months ago

0.5.17

6 months ago

0.5.14

6 months ago

0.5.15

6 months ago

0.5.12

6 months ago

0.5.13

6 months ago

0.5.54

3 months ago

0.5.55

3 months ago

0.5.52

3 months ago

0.5.53

3 months ago

0.5.50

4 months ago

0.5.51

4 months ago

0.5.58

3 months ago

0.5.59

3 months ago

0.5.56

3 months ago

0.5.57

3 months ago

0.5.43

4 months ago

0.5.44

4 months ago

0.5.41

4 months ago

0.5.42

4 months ago

0.5.40

4 months ago

0.5.49

4 months ago

0.5.47

4 months ago

0.5.48

4 months ago

0.5.45

4 months ago

0.5.46

4 months ago

0.5.32

4 months ago

0.5.33

4 months ago

0.5.30

4 months ago

0.5.31

4 months ago

0.5.38

4 months ago

0.5.39

4 months ago

0.5.36

4 months ago

0.5.37

4 months ago

0.5.34

4 months ago

0.5.35

4 months ago

0.5.21

5 months ago

0.5.22

5 months ago

0.5.20

6 months ago

0.5.29

5 months ago

0.5.27

5 months ago

0.5.28

5 months ago

0.5.25

5 months ago

0.5.26

5 months ago

0.5.23

5 months ago

0.5.24

5 months ago

0.5.10

6 months ago

0.5.8

6 months ago

0.5.9

6 months ago

0.5.6

6 months ago

0.5.7

6 months ago

0.5.5

6 months ago

0.5.4

6 months ago

0.5.3

6 months ago

0.5.2

6 months ago

0.5.0

7 months ago

0.5.1

7 months ago

0.4.98

7 months ago

0.4.99

7 months ago

0.4.97

7 months ago

0.4.95

7 months ago

0.4.96

7 months ago

0.4.94

7 months ago

0.4.93

7 months ago

0.4.87

7 months ago

0.4.89

7 months ago

0.4.91

7 months ago

0.4.92

7 months ago

0.4.90

7 months ago

0.4.86

7 months ago

0.4.84

7 months ago

0.4.85

7 months ago

0.4.82

7 months ago

0.4.83

7 months ago

0.4.81

8 months ago

0.4.80

8 months ago

0.4.79

8 months ago

0.4.77

8 months ago

0.4.78

8 months ago

0.4.76

8 months ago

0.4.75

8 months ago

0.4.73

8 months ago

0.4.74

8 months ago

0.4.72

8 months ago

0.4.71

8 months ago

0.4.70

8 months ago

0.4.68

8 months ago

0.4.69

8 months ago

0.4.64

8 months ago

0.4.65

8 months ago

0.4.63

8 months ago

0.4.66

8 months ago

0.4.67

8 months ago

0.4.62

8 months ago

0.4.61

8 months ago

0.4.60

8 months ago

0.4.54

8 months ago

0.4.59

8 months ago

0.4.57

8 months ago

0.4.58

8 months ago

0.4.55

8 months ago

0.4.56

8 months ago

0.4.53

9 months ago

0.4.51

9 months ago

0.4.52

9 months ago

0.4.49

9 months ago

0.4.50

9 months ago

0.4.48

9 months ago

0.4.46

9 months ago

0.4.47

9 months ago

0.4.45

9 months ago

0.4.43

9 months ago

0.4.44

9 months ago

0.4.42

9 months ago

0.4.40

9 months ago

0.4.41

9 months ago

0.4.39

9 months ago

0.4.37

9 months ago

0.4.38

9 months ago

0.4.36

9 months ago

0.4.35

9 months ago

0.4.31

9 months ago

0.4.32

9 months ago

0.4.30

9 months ago

0.4.33

9 months ago

0.4.34

9 months ago

0.4.28

9 months ago

0.4.29

9 months ago

0.4.26

9 months ago

0.4.27

9 months ago

0.4.24

9 months ago

0.4.25

9 months ago

0.4.23

10 months ago

0.4.20

10 months ago

0.4.21

10 months ago

0.4.22

10 months ago

0.4.19

10 months ago

0.4.17

10 months ago

0.4.18

10 months ago

0.4.15

10 months ago

0.4.16

10 months ago

0.4.13

10 months ago

0.4.14

10 months ago

0.4.12

10 months ago

0.4.11

10 months ago

0.4.10

10 months ago

0.4.9

10 months ago

0.4.8

10 months ago

0.4.5

10 months ago

0.4.7

10 months ago

0.4.6

10 months ago

0.4.4

10 months ago

0.4.1

10 months ago

0.4.3

10 months ago

0.4.2

10 months ago

0.4.0

10 months ago

0.3.36

10 months ago

0.3.35

10 months ago

0.3.34

10 months ago

0.3.33

10 months ago

0.3.32

10 months ago

0.3.31

10 months ago

0.3.30

10 months ago

0.3.29

10 months ago

0.3.28

10 months ago

0.3.27

10 months ago

0.3.26

10 months ago

0.3.25

10 months ago

0.3.24

10 months ago

0.3.23

10 months ago

0.3.22

10 months ago

0.3.21

10 months ago

0.3.20

11 months ago

0.3.19

11 months ago

0.3.18

11 months ago

0.3.17

11 months ago

0.3.16

11 months ago

0.3.15

11 months ago

0.3.14

11 months ago

0.3.13

11 months ago

0.3.12

11 months ago

0.3.11

11 months ago

0.3.8

11 months ago

0.3.9

11 months ago

0.3.10

11 months ago

0.3.7

12 months ago

0.3.6

12 months ago

0.3.5

12 months ago

0.2.149

1 year ago

0.2.148

1 year ago

0.2.147

1 year ago

0.2.146

1 year ago

0.2.145

1 year ago

0.2.144

1 year ago

0.2.143

1 year ago

0.2.142

1 year ago

0.2.141

1 year ago

0.2.140

1 year ago

0.2.139

1 year ago

0.2.138

1 year ago

0.2.137

1 year ago

0.2.136

1 year ago

0.2.135

1 year ago

0.2.134

1 year ago

0.2.133

1 year ago

0.2.132

1 year ago

0.2.131

1 year ago

0.2.130

1 year ago

0.2.129

1 year ago

0.2.128

1 year ago

0.2.127

1 year ago

0.2.126

1 year ago

0.2.125

1 year ago

0.2.189

1 year ago

0.2.188

1 year ago

0.2.187

1 year ago

0.2.186

1 year ago

0.2.185

1 year ago

0.2.184

1 year ago

0.2.183

1 year ago

0.2.182

1 year ago

0.2.181

1 year ago

0.2.180

1 year ago

0.2.179

1 year ago

0.2.178

1 year ago

0.2.177

1 year ago

0.2.176

1 year ago

0.2.175

1 year ago

0.2.174

1 year ago

0.2.173

1 year ago

0.2.172

1 year ago

0.2.171

1 year ago

0.2.170

1 year ago

0.2.169

1 year ago

0.2.168

1 year ago

0.2.167

1 year ago

0.2.166

1 year ago

0.2.165

1 year ago

0.2.164

1 year ago

0.2.163

1 year ago

0.2.162

1 year ago

0.2.161

1 year ago

0.2.160

1 year ago

0.2.159

1 year ago

0.2.158

1 year ago

0.2.157

1 year ago

0.2.156

1 year ago

0.2.155

1 year ago

0.2.154

1 year ago

0.2.153

1 year ago

0.2.152

1 year ago

0.2.151

1 year ago

0.2.150

1 year ago

0.3.0

12 months ago

0.3.2

12 months ago

0.3.1

12 months ago

0.3.4

12 months ago

0.3.3

12 months ago

0.2.199

1 year ago

0.2.198

1 year ago

0.2.197

1 year ago

0.2.196

1 year ago

0.2.195

1 year ago

0.2.194

1 year ago

0.2.193

1 year ago

0.2.192

1 year ago

0.2.191

1 year ago

0.2.190

1 year ago

0.2.204

1 year ago

0.2.203

1 year ago

0.2.202

1 year ago

0.2.201

1 year ago

0.2.200

1 year ago

0.2.124

1 year ago

0.2.123

1 year ago

0.2.122

1 year ago

0.2.121

1 year ago

0.2.120

1 year ago

0.2.119

1 year ago

0.2.118

1 year ago

0.2.117

1 year ago

0.2.116

1 year ago

0.2.115

1 year ago

0.2.114

1 year ago

0.2.113

1 year ago

0.2.112

1 year ago

0.2.111

1 year ago

0.2.110

1 year ago

0.2.109

1 year ago

0.2.108

1 year ago

0.2.107

1 year ago

0.2.106

1 year ago

0.2.105

1 year ago

0.2.104

1 year ago

0.2.103

1 year ago

0.2.102

1 year ago

0.2.101

1 year ago

0.2.100

1 year ago

0.2.99

1 year ago

0.2.98

1 year ago

0.2.96

1 year ago

0.2.95

1 year ago

0.2.94

1 year ago

0.2.93

1 year ago

0.2.92

1 year ago

0.2.91

1 year ago

0.2.90

2 years ago

0.2.97

1 year ago

0.2.85

2 years ago

0.2.84

2 years ago

0.2.83

2 years ago

0.2.82

2 years ago

0.2.81

2 years ago

0.2.80

2 years ago

0.2.89

2 years ago

0.2.88

2 years ago

0.2.87

2 years ago

0.2.86

2 years ago

0.2.74

2 years ago

0.2.73

2 years ago

0.2.72

2 years ago

0.2.71

2 years ago

0.2.70

2 years ago

0.2.79

2 years ago

0.2.78

2 years ago

0.2.77

2 years ago

0.2.76

2 years ago

0.2.75

2 years ago

0.2.63

2 years ago

0.2.62

2 years ago

0.2.61

2 years ago

0.2.60

2 years ago

0.2.69

2 years ago

0.2.68

2 years ago

0.2.67

2 years ago

0.2.66

2 years ago

0.2.65

2 years ago

0.2.64

2 years ago

0.2.52

2 years ago

0.2.51

2 years ago

0.2.50

2 years ago

0.2.59

2 years ago

0.2.58

2 years ago

0.2.57

2 years ago

0.2.56

2 years ago

0.2.55

2 years ago

0.2.54

2 years ago

0.2.53

2 years ago

0.2.49

2 years ago

0.2.48

2 years ago

0.2.27

2 years ago

0.2.26

2 years ago

0.2.25

2 years ago

0.2.24

2 years ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.21

2 years ago

0.2.20

2 years ago

0.2.41

2 years ago

0.2.40

2 years ago

0.2.47

2 years ago

0.2.46

2 years ago

0.2.45

2 years ago

0.2.44

2 years ago

0.2.43

2 years ago

0.2.42

2 years ago

0.2.39

2 years ago

0.2.30

2 years ago

0.2.38

2 years ago

0.2.37

2 years ago

0.2.36

2 years ago

0.2.35

2 years ago

0.2.34

2 years ago

0.2.33

2 years ago

0.2.32

2 years ago

0.2.31

2 years ago

0.2.29

2 years ago

0.2.28

2 years ago

0.2.19

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.4

2 years ago

0.1.0

2 years ago

0.1.0-alpha.10

2 years ago

0.1.0-alpha.9

2 years ago

0.1.0-alpha.8

2 years ago

0.1.0-alpha.7

2 years ago

0.1.0-alpha.6

2 years ago

0.1.0-alpha.5

2 years ago

0.1.0-alpha.4

2 years ago

0.1.0-alpha.3

2 years ago

0.1.0-alpha.2

2 years ago

0.1.0-alpha.1

2 years ago