New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@saleor/app-bridge

Package Overview
Dependencies
Maintainers
7
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saleor/app-bridge

Library for Dashboard <-> Saleor App communication

  • 0.1.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37
increased by54.17%
Maintainers
7
Weekly downloads
 
Created
Source

Saleor App Bridge

Installation

npm i @saleor/app-bridge

Usage

First initialize the package by running createApp():

import { createApp } from "@saleor/app-bridge";

const app = createApp();

Access app state:

const { token, domain, ready, id } = app.getState();

Events

Events are messages that originate in Saleor Dashboard.

Available methods

subscribe(eventType, callback) - can be used to listen to particular event type. It returns an unsubscribe function, which unregisters the callback.

Example:

const unsubscribe = app.subscribe("handshake", (payload) => {
  setToken(payload.token); // do something with event payload
  const { token } = app.getState(); // you can also get app's current state here
});

// unsubscribe when callback is no longer needed
unsubscribe();

unsubscribeAll(eventType?) - unregisters all callbacks of provided type. If no type was provided, it will remove all event callbacks.

Example:

app.unsubscribeAll("handshake"); // unsubscribe from all handshake events

app.unsubscribeAll(); // unsubscribe from all events

Available event types

Event typeDescription
handshakeFired when iFrame containing the App is initialized or new token is assigned
responseFired when Dashboard responds to an Action
redirectFired when Dashboard change a subpath within the app path
themeFired when Dashboard change the theme

Actions

Actions expose a high-level API to communicate with Saleor Dashboard. They're exported under an actions namespace.

Available methods

dispatch(action) - dispatches an Action. Returns a promise which resolves when action is successfully completed.

Example:

import { actions } from "@saleor/app-bridge";

const handleRedirect = async () => {
  await app.dispatch(actions.Redirect({ to: "/orders" }));
  console.log("Redirect complete!");
};

handleRedirect();

Available actions

ActionArgumentsDescription
Redirectto (string) - relative (inside Dashboard) or absolute URL path
newContext (boolean) - should open in a new browsing context

Keywords

FAQs

Package last updated on 03 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc