hsyuan-market-app-web-sdk
v1.0.4
Published
Reusable frontend integration layer for third-party app-market web applications.
Readme
market-app-web-sdk
@cregis/market-app-web-sdk is the reusable frontend integration layer for App Market third-party web applications.
It extracts the non-business browser-side logic that used to live inside the demo app, including:
- SSO bridge flow
- Local auth state storage
- Axios auth interception and re-auth trigger
- Route guard and visible-menu navigation
- App shell layout and menu refresh
- App-scoped permission helpers
Environment
- Node.js 18+
- npm 9+
- Vue 3 application
Install
Use a local file dependency during local development:
npm install @cregis/market-app-web-sdkOr declare it in package.json:
{
"dependencies": {
"@cregis/market-app-web-sdk": "1.0.0"
}
}Peer dependencies expected by the SDK:
vuevue-routeraxioselement-plus
Build
npm install
npm run buildCore Exports
Root exports:
createMarketAppHttpinstallMarketAppRouteGuarduseMarketAppPermissionuseMarketAppAnyPermissionuseMarketAppShelluseMarketAppSsoBridgeMarketAppShellMarketAppSsoBridge
Auth APIs:
bootstrapLogingetCurrentMenuAccessgetCurrentDataPermissiongetCurrentMenusgetPlatformUsersgetPlatformRoles
Minimal Integration
1. HTTP client
import { createMarketAppHttp } from '@cregis/market-app-web-sdk'
const http = createMarketAppHttp()The SDK reads VITE_MARKET_APP_SERVER_URL as the backend base URL.
2. Route guard
import { createRouter, createWebHistory } from 'vue-router'
import { installMarketAppRouteGuard } from '@cregis/market-app-web-sdk'
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', redirect: '/sso-bridge' },
{ path: '/sso-bridge', component: SsoBridge },
{ path: '/classes', component: ClassManager, meta: { menuAccess: ['class:query'] } },
],
})
installMarketAppRouteGuard(router)Business pages only declare the permission suffix such as class:query.
The SDK automatically resolves and matches the current appId: prefix.
3. SSO bridge page
<template>
<MarketAppSsoBridge
:bootstrap-login="bootstrapLogin"
:fetch-menu-access="getCurrentMenuAccess"
:fetch-data-permission="getCurrentDataPermission"
:fetch-menus="getCurrentMenus"
/>
</template>4. App shell
<template>
<MarketAppShell
app-title="Demo App"
:fetch-menu-access="getCurrentMenuAccess"
:fetch-menus="getCurrentMenus"
>
<router-view />
</MarketAppShell>
</template>5. Button permission
import { useMarketAppPermission } from '@cregis/market-app-web-sdk'
const canCreateClass = useMarketAppPermission('class:create')Runtime Contract
The SDK expects the backend to provide these endpoints:
POST /api/auth/bootstrapGET /api/auth/menu-accessGET /api/auth/data-permissionGET /api/auth/menusGET /api/auth/usersGET /api/auth/roles
The default auth flow is:
- Parent admin page loads the app iframe with
ticketandappCode - SSO bridge calls backend
/api/auth/bootstrap - Backend exchanges
ticketwith marketing and returns localdemoToken - SDK fetches menu access, data permission, and visible menus
- Route guard and shell render the visible pages
Re-Auth Behavior
When backend returns an auth-expired code, the SDK will:
- Clear local auth state
- Notify parent page by
postMessage - Ask the parent admin page to refresh
ticket - Redirect current iframe page to
/sso-bridge
Default message types:
APP_MARKET_REFRESH_TICKETAPP_MARKET_AUTH_STATE
Configuration
Default configuration is defined in src/config.ts:
demoServerUrlrefreshTicketMessageTypeauthStateMessageTypereAuthThrottleMs
Default backend URL:
VITE_MARKET_APP_SERVER_URL || http://192.168.2.231:8088For local development, set:
VITE_MARKET_APP_SERVER_URL=http://127.0.0.1:8088