0.6.15 • Published 2 months ago

@getflip/bridge v0.6.15

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
2 months 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

2 months ago

0.6.13

2 months ago

0.6.15

2 months ago

0.6.10

2 months ago

0.6.12

2 months ago

0.6.11

2 months ago

0.6.9

2 months ago

0.6.8

2 months ago

0.6.7

3 months ago

0.6.6

3 months ago

0.6.5

3 months ago

0.6.4

3 months ago

0.6.3

3 months ago

0.6.2

3 months ago

0.6.1

3 months ago

0.6.0

3 months ago

0.5.72

3 months ago

0.5.71

3 months ago

0.5.70

3 months ago

0.5.69

3 months ago

0.5.67

3 months ago

0.5.68

3 months ago

0.5.65

4 months ago

0.5.66

4 months ago

0.5.63

4 months ago

0.5.64

4 months ago

0.5.61

4 months ago

0.5.62

4 months ago

0.5.60

4 months ago

0.5.11

7 months ago

0.5.18

7 months ago

0.5.19

7 months ago

0.5.16

7 months ago

0.5.17

7 months ago

0.5.14

7 months ago

0.5.15

7 months ago

0.5.12

7 months ago

0.5.13

7 months ago

0.5.54

4 months ago

0.5.55

4 months ago

0.5.52

4 months ago

0.5.53

4 months ago

0.5.50

5 months ago

0.5.51

5 months ago

0.5.58

4 months ago

0.5.59

4 months ago

0.5.56

4 months ago

0.5.57

4 months ago

0.5.43

5 months ago

0.5.44

5 months ago

0.5.41

5 months ago

0.5.42

5 months ago

0.5.40

5 months ago

0.5.49

5 months ago

0.5.47

5 months ago

0.5.48

5 months ago

0.5.45

5 months ago

0.5.46

5 months ago

0.5.32

5 months ago

0.5.33

5 months ago

0.5.30

5 months ago

0.5.31

5 months ago

0.5.38

5 months ago

0.5.39

5 months ago

0.5.36

5 months ago

0.5.37

5 months ago

0.5.34

5 months ago

0.5.35

5 months ago

0.5.21

7 months ago

0.5.22

7 months ago

0.5.20

7 months ago

0.5.29

6 months ago

0.5.27

6 months ago

0.5.28

6 months ago

0.5.25

6 months ago

0.5.26

6 months ago

0.5.23

6 months ago

0.5.24

6 months ago

0.5.10

7 months ago

0.5.8

7 months ago

0.5.9

7 months ago

0.5.6

7 months ago

0.5.7

7 months ago

0.5.5

7 months ago

0.5.4

7 months ago

0.5.3

7 months ago

0.5.2

7 months ago

0.5.0

8 months ago

0.5.1

8 months ago

0.4.98

8 months ago

0.4.99

8 months ago

0.4.97

8 months ago

0.4.95

8 months ago

0.4.96

8 months ago

0.4.94

8 months ago

0.4.93

8 months ago

0.4.87

8 months ago

0.4.89

8 months ago

0.4.91

8 months ago

0.4.92

8 months ago

0.4.90

8 months ago

0.4.86

8 months ago

0.4.84

8 months ago

0.4.85

8 months ago

0.4.82

8 months ago

0.4.83

8 months ago

0.4.81

9 months ago

0.4.80

9 months ago

0.4.79

9 months ago

0.4.77

9 months ago

0.4.78

9 months ago

0.4.76

9 months ago

0.4.75

9 months ago

0.4.73

9 months ago

0.4.74

9 months ago

0.4.72

9 months ago

0.4.71

9 months ago

0.4.70

9 months ago

0.4.68

9 months ago

0.4.69

9 months ago

0.4.64

9 months ago

0.4.65

9 months ago

0.4.63

9 months ago

0.4.66

9 months ago

0.4.67

9 months ago

0.4.62

9 months ago

0.4.61

9 months ago

0.4.60

9 months ago

0.4.54

9 months ago

0.4.59

9 months ago

0.4.57

9 months ago

0.4.58

9 months ago

0.4.55

9 months ago

0.4.56

9 months ago

0.4.53

10 months ago

0.4.51

10 months ago

0.4.52

10 months ago

0.4.49

10 months ago

0.4.50

10 months ago

0.4.48

10 months ago

0.4.46

10 months ago

0.4.47

10 months ago

0.4.45

10 months ago

0.4.43

10 months ago

0.4.44

10 months ago

0.4.42

10 months ago

0.4.40

10 months ago

0.4.41

10 months ago

0.4.39

10 months ago

0.4.37

10 months ago

0.4.38

10 months ago

0.4.36

10 months ago

0.4.35

10 months ago

0.4.31

10 months ago

0.4.32

10 months ago

0.4.30

10 months ago

0.4.33

10 months ago

0.4.34

10 months ago

0.4.28

10 months ago

0.4.29

10 months ago

0.4.26

10 months ago

0.4.27

10 months ago

0.4.24

10 months ago

0.4.25

10 months ago

0.4.23

11 months ago

0.4.20

11 months ago

0.4.21

11 months ago

0.4.22

11 months ago

0.4.19

11 months ago

0.4.17

11 months ago

0.4.18

11 months ago

0.4.15

11 months ago

0.4.16

11 months ago

0.4.13

11 months ago

0.4.14

11 months ago

0.4.12

11 months ago

0.4.11

11 months ago

0.4.10

11 months ago

0.4.9

11 months ago

0.4.8

11 months ago

0.4.5

11 months ago

0.4.7

11 months ago

0.4.6

11 months ago

0.4.4

11 months ago

0.4.1

11 months ago

0.4.3

11 months ago

0.4.2

11 months ago

0.4.0

11 months ago

0.3.36

11 months ago

0.3.35

11 months ago

0.3.34

11 months ago

0.3.33

11 months ago

0.3.32

11 months ago

0.3.31

11 months ago

0.3.30

11 months ago

0.3.29

11 months ago

0.3.28

11 months ago

0.3.27

11 months ago

0.3.26

11 months ago

0.3.25

11 months ago

0.3.24

11 months ago

0.3.23

11 months ago

0.3.22

11 months ago

0.3.21

11 months ago

0.3.20

12 months ago

0.3.19

12 months ago

0.3.18

12 months ago

0.3.17

12 months ago

0.3.16

12 months ago

0.3.15

12 months ago

0.3.14

12 months ago

0.3.13

12 months ago

0.3.12

12 months ago

0.3.11

12 months ago

0.3.8

12 months ago

0.3.9

12 months ago

0.3.10

12 months ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year 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

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.4

1 year ago

0.3.3

1 year 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

2 years ago

0.2.120

2 years ago

0.2.119

2 years ago

0.2.118

2 years ago

0.2.117

2 years ago

0.2.116

2 years ago

0.2.115

2 years ago

0.2.114

2 years ago

0.2.113

2 years ago

0.2.112

2 years ago

0.2.111

2 years ago

0.2.110

2 years ago

0.2.109

2 years ago

0.2.108

2 years ago

0.2.107

2 years ago

0.2.106

2 years ago

0.2.105

2 years ago

0.2.104

2 years ago

0.2.103

2 years ago

0.2.102

2 years ago

0.2.101

2 years ago

0.2.100

2 years ago

0.2.99

2 years ago

0.2.98

2 years ago

0.2.96

2 years ago

0.2.95

2 years ago

0.2.94

2 years ago

0.2.93

2 years ago

0.2.92

2 years ago

0.2.91

2 years ago

0.2.90

2 years ago

0.2.97

2 years 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