Skip to content

shoplineapp/app-bridge-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

AppBridge

AppBridge lives in an iframe. It provides interface to trigger request to EC Admin(parent frame)

Configuration

import { AppBridge } from 'admin-app-extension';

const clientId = 'developer app client id';
const authUrl = 'https://developer.com/auth'
const appBridge = await AppBridge.init({clientId, authUrl});

API References


appBridge.onLanguageChanged(callback)

  • Triggered when admin language is changed
  • Returns an unsubscribe function
// to subscribe
const unsubscribe = appBridge.onLanguageChanged(function(language) {
  console.log(language)
});

// to unsubscribe
unsubscribe();

appBridge.getSessionToken()

  • returning a JWT token used to identify current logged in user
  • session token contains staff_id, merchant_id, client_id in token payload
const sessionToken = await appBridge.getSessionToken();

appBridge.redirect(url)

  • performing a parent frame redirect
appBridge.redirect('https://shoplineapp.com')

appBridge.redirectAdminPage(page)

  • performing a parent frame redirect to specific page

provided enums:

  • AppDetail: redirect to embedded app's app store page
appBridge.redirectAdminPage('AppDetail')

appBridge.goBack()

  • navigate to the last route. will not exit the admin app.
appBridge.goBack()

appBridge.oauth()

  • execute the oauth flow to obtain access token
appBridge.oauth()

appBridge.getLanguage()

  • get the current language setting from EC Admin
  const language = await appBridge.getLanguage()

appBridge.getCurrentUrl()

  • get the top frame url
  const parentUrl = await appBridge.getCurrentUrl()

appBridge.routeChange()

  • notify parent frame to update the top frame route
const path = '/page1';
const querystring = 'foo=bar&bar=foo';
appBridge.routeChange(path, querystring)

appBridge.intercom()

  • open intercom dialog in EC Admin
appBridge.intercom()

appBridge.changePageTitle()

  • change page title in EC Admin
appBridge.changePageTitle('Demo Page Title')

appBridge.interceptRouteChange(callback)

  • Intercept admin route change and trigger callback
  • Returns a function to stop interception
// to intercept
const stopInterception = appBridge.interceptRouteChange(function(fromUrl, toUrl) {
  console.log('From:', fromUrl);
  console.log('To:', toUrl);
});

// to stop interception
stopInterception();

appBridge.retryRouteChange()

  • Notify EC Admin to retry the latest intercepted route change
appBridge.retryRouteChange();

appBridge.getMerchantAuthorities()

  • Get merchant authorized state on app

Returns

  • authorized: boolean, indicates merchant currently authorized to the app or not
  • scopes: string array, indicates what scopes do merchant authorized to the app
  • versionType: enum string, indicates what version does merchant currently authorizing, types: TESTING LIVE
const authorityRes = await appBridge.getMerchantAuthorities();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors